diff options
author | ssankaran | 2014-03-12 07:25:38 +0000 |
---|---|---|
committer | ssankaran | 2014-03-12 07:25:38 +0000 |
commit | 4ef16554233e88a1cac441a4decc46191fae29b1 (patch) | |
tree | f294249d67fb90b652b72f4933e172baa8be334a | |
parent | 2323f3f57de6c106bba7d022fda77960201afa72 (diff) | |
download | eclipse.jdt.core-4ef16554233e88a1cac441a4decc46191fae29b1.tar.gz eclipse.jdt.core-4ef16554233e88a1cac441a4decc46191fae29b1.tar.xz eclipse.jdt.core-4ef16554233e88a1cac441a4decc46191fae29b1.zip |
Fixed Bug 430141 - [1.8][hierarchy] Incorrect hierarchy with lambda
elements missing
3 files changed, 71 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java index 496245b2a4..184142fd11 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElement8Tests.java @@ -434,4 +434,68 @@ public class JavaElement8Tests extends AbstractJavaModelTests { } } } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=430141, [1.8][hierarchy] Incorrect hierarchy with lambda elements missing + public void test430141() throws Exception { + try { + IJavaProject project = createJavaProject("Bug430141", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); + project.open(null); + String fileContent = + "interface I {\n" + + " void doit();\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " J j = () -> { System.out.println(\"Lambda\"); };\n" + + " j.doit();\n" + + " }\n" + + "}\n"; + createFile( "/Bug430141/src/X.java", fileContent); + IType type = getCompilationUnit("/Bug430141/src/X.java").getType("I"); + ITypeHierarchy h = type.newTypeHierarchy(null); + assertHierarchyEquals( + "Focus: I [in X.java [in <default> [in src [in Bug430141]]]]\n" + + "Super types:\n" + + "Sub types:\n" + + " J [in X.java [in <default> [in src [in Bug430141]]]]\n" + + " Lambda(J) [in main(String[]) [in X [in X.java [in <default> [in src [in Bug430141]]]]]]\n", + h); + } + finally { + deleteProject("Bug430141"); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=430141, [1.8][hierarchy] Incorrect hierarchy with lambda elements missing + public void test430141a() throws Exception { + try { + IJavaProject project = createJavaProject("Bug430141", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8"); + project.open(null); + String fileContent = + "interface I {\n" + + " void doit();\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " J j = () -> { System.out.println(\"Lambda\"); };\n" + + " j.doit();\n" + + " }\n" + + "}\n"; + createFile( "/Bug430141/src/X.java", fileContent); + IType type = getCompilationUnit("/Bug430141/src/X.java").getType("J"); + ITypeHierarchy h = type.newTypeHierarchy(null); + assertHierarchyEquals( + "Focus: J [in X.java [in <default> [in src [in Bug430141]]]]\n" + + "Super types:\n" + + " I [in X.java [in <default> [in src [in Bug430141]]]]\n" + + "Sub types:\n" + + " Lambda(J) [in main(String[]) [in X [in X.java [in <default> [in src [in Bug430141]]]]]]\n", + h); + } + finally { + deleteProject("Bug430141"); + } + } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LambdaExpression.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LambdaExpression.java index 89d83661bc..5b2d98d9e1 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LambdaExpression.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LambdaExpression.java @@ -40,11 +40,11 @@ public class LambdaExpression extends SourceType { // Construction from AST node public LambdaExpression(JavaElement parent, org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression) { - super(parent, new String("Lambda(") + new String(lambdaExpression.descriptor.declaringClass.sourceName()) + ')'); //$NON-NLS-1$ + super(parent, new String("Lambda(") + new String(lambdaExpression.resolvedType.sourceName()) + ')'); //$NON-NLS-1$ this.sourceStart = lambdaExpression.sourceStart; this.sourceEnd = lambdaExpression.sourceEnd; this.arrowPosition = lambdaExpression.arrowPosition; - this.interphase = new String(CharOperation.replaceOnCopy(lambdaExpression.descriptor.declaringClass.genericTypeSignature(), '/', '.')); + this.interphase = new String(CharOperation.replaceOnCopy(lambdaExpression.resolvedType.genericTypeSignature(), '/', '.')); this.elementInfo = makeTypeElementInfo(this, this.interphase, this.sourceStart, this.sourceEnd, this.arrowPosition); this.lambdaMethod = LambdaMethod.make(this, lambdaExpression); this.elementInfo.children = new IJavaElement[] { this.lambdaMethod }; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java index 5034b19332..3563d735f4 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java @@ -180,15 +180,15 @@ public class SourceIndexer extends AbstractIndexer implements ITypeRequestor, Su private void reduceParseTree(CompilationUnitDeclaration unit) { // remove statements from methods that have no functional interface types. TypeDeclaration[] types = unit.types; - for (int i = 0, l = types.length; i < l; i++) + for (int i = 0, l = types == null ? 0 : types.length; i < l; i++) purgeMethodStatements(types[i]); } private void purgeMethodStatements(TypeDeclaration type) { AbstractMethodDeclaration[] methods = type.methods; - for (int j = 0, length = methods.length; j < length; j++) { + for (int j = 0, length = methods == null ? 0 : methods.length; j < length; j++) { AbstractMethodDeclaration method = methods[j]; - if ((method.bits & ASTNode.HasFunctionalInterfaceTypes) == 0) { + if (method != null && (method.bits & ASTNode.HasFunctionalInterfaceTypes) == 0) { method.statements = null; method.javadoc = null; } @@ -208,7 +208,7 @@ public class SourceIndexer extends AbstractIndexer implements ITypeRequestor, Su if (expression instanceof LambdaExpression) { LambdaExpression lambdaExpression = (LambdaExpression) expression; if (lambdaExpression.binding != null && lambdaExpression.binding.isValidBinding()) { - final char[] superinterface = lambdaExpression.descriptor.declaringClass.sourceName(); + final char[] superinterface = lambdaExpression.resolvedType.sourceName(); if (DEBUG) { System.out.println('\t' + new String(superinterface) + '.' + new String(lambdaExpression.descriptor.selector) + "-> {}"); //$NON-NLS-1$ @@ -234,7 +234,7 @@ public class SourceIndexer extends AbstractIndexer implements ITypeRequestor, Su MethodBinding binding = referenceExpression.getMethodBinding(); if (binding != null && binding.isValidBinding()) { if (DEBUG) { - System.out.println('\t' + new String(referenceExpression.descriptor.declaringClass.sourceName()) + "::" //$NON-NLS-1$ + System.out.println('\t' + new String(referenceExpression.resolvedType.sourceName()) + "::" //$NON-NLS-1$ + new String(referenceExpression.descriptor.selector) + " == " + new String(binding.declaringClass.sourceName()) + '.' + //$NON-NLS-1$ new String(binding.selector)); } |