Skip to content

Commit ae16f7c

Browse files
Check the class name of ASTNode to see if it's unnamed class (#544)
1 parent 1a06b1f commit ae16f7c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
import java.nio.file.Files;
2121
import java.nio.file.Paths;
2222
import java.util.ArrayList;
23+
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.HashMap;
26+
import java.util.HashSet;
2527
import java.util.List;
2628
import java.util.Map;
2729
import java.util.Objects;
30+
import java.util.Set;
2831
import java.util.jar.Attributes;
2932
import java.util.jar.Manifest;
3033
import java.util.logging.Level;
@@ -57,7 +60,6 @@
5760
import org.eclipse.jdt.core.dom.IMethodBinding;
5861
import org.eclipse.jdt.core.dom.ITypeBinding;
5962
import org.eclipse.jdt.core.dom.LambdaExpression;
60-
import org.eclipse.jdt.core.dom.UnnamedClass;
6163
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
6264
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
6365
import org.eclipse.jdt.launching.IVMInstall;
@@ -87,6 +89,9 @@ public class JdtSourceLookUpProvider implements ISourceLookUpProvider {
8789
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
8890
private static final String JDT_SCHEME = "jdt";
8991
private static final String PATH_SEPARATOR = "/";
92+
private static final Set<String> IMPLICITLY_DECLARED_CLASSES = new HashSet<>(
93+
Arrays.asList("org.eclipse.jdt.core.dom.UnnamedClass",
94+
"org.eclipse.jdt.core.dom.ImplicitTypeDeclaration"));
9095
private ISourceContainer[] sourceContainers = null;
9196

9297
private HashMap<String, Object> options = new HashMap<String, Object>();
@@ -176,7 +181,10 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB
176181
if (astUnit != null) {
177182
List<?> types = astUnit.types();
178183
String unnamedClass = null;
179-
if (types.size() == 1 && types.get(0) instanceof UnnamedClass) {
184+
// See https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2220
185+
// Given that the JDT plans to rename UnamedClass to ImplicitTypeDeclaration, we will check
186+
// the class name of the ASTNode to prevent the potential breaking in the future.
187+
if (types.size() == 1 && IMPLICITLY_DECLARED_CLASSES.contains(types.get(0).getClass().getName())) {
180188
unnamedClass = inferPrimaryTypeName(sourceUri, astUnit);
181189
}
182190
Map<Integer, BreakpointLocation[]> resolvedLocations = new HashMap<>();

0 commit comments

Comments
 (0)