Skip to content

Commit 61f6bae

Browse files
fix the binding related setting issue for jdt ast parser (microsoft#46)
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent 4852313 commit 61f6bae

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
121121
}
122122
String source = readFile(filePath, cs);
123123
parser.setSource(source.toCharArray());
124+
/**
125+
* See the java doc for { @link ASTParser#setResolveBindings(boolean) }.
126+
* Binding information is obtained from the Java model. This means that the compilation unit must be located relative to the Java model.
127+
* This happens automatically when the source code comes from either setSource(ICompilationUnit) or setSource(IClassFile).
128+
* When source is supplied by setSource(char[]), the location must be established explicitly
129+
* by setting an environment using setProject(IJavaProject) or setEnvironment(String [], String [], String [], boolean)
130+
* and a unit name setUnitName(String).
131+
*/
132+
parser.setEnvironment(new String[0], new String[0], null, true);
133+
parser.setUnitName(Paths.get(filePath).getFileName().toString());
134+
/**
135+
* See the java doc for { @link ASTParser#setSource(char[]) },
136+
* the user need specify the compiler options explicitly.
137+
*/
138+
Map<String, String> options = JavaCore.getOptions();
139+
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
140+
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
141+
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
142+
parser.setCompilerOptions(options);
124143
astUnit = (CompilationUnit) parser.createAST(null);
125144
} else {
126145
// For non-file uri (e.g. jdt://contents/rt.jar/java.io/PrintStream.class),

0 commit comments

Comments
 (0)