Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2014-02-03 16:59:46 +0000
committerssankaran2014-02-03 16:59:46 +0000
commitb399cc14c85cc6279d3fbdd38ff116c9655dc352 (patch)
treebf965b7c27fc5951669bee290f4f06aa938dd22d
parent9ecc2f6122d7f7a662b22f71e69ff3081609219c (diff)
downloadeclipse.jdt.core-b399cc14c85cc6279d3fbdd38ff116c9655dc352.tar.gz
eclipse.jdt.core-b399cc14c85cc6279d3fbdd38ff116c9655dc352.tar.xz
eclipse.jdt.core-b399cc14c85cc6279d3fbdd38ff116c9655dc352.zip
Fixed Bug 425743 - [1.8][api] CompilationUnit#findDeclaringNode(IBinding
binding) returns null for type inferred lambda parameter
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java25
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java1
2 files changed, 26 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 81132c2a52..d6f1f4d8f3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -3997,4 +3997,29 @@ public class ASTConverter18Test extends ConverterTestSetup {
VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
checkSourceRange(variableDeclaration, "int x", contents);
}
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=425743, [1.8][api] CompilationUnit#findDeclaringNode(IBinding binding) returns null for type inferred lambda parameter
+ */
+ public void testBug425743() throws JavaModelException {
+ String contents =
+ "public class X{\n" +
+ " FI fi = (x2) -> x2;\n" +
+ "}\n" +
+ "interface FI {\n" +
+ " int foo(int n);\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(contents, this.workingCopy, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0);
+ FieldDeclaration fi = ((TypeDeclaration) node).getFields()[0];
+ VariableDeclarationFragment vdf = (VariableDeclarationFragment) fi.fragments().get(0);
+ LambdaExpression lambda = (LambdaExpression) vdf.getInitializer();
+ VariableDeclaration param = (VariableDeclaration) lambda.parameters().get(0);
+ IBinding binding = param.getName().resolveBinding();
+ ASTNode astNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull(astNode);
+ assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, astNode.getNodeType());
+ }
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index f1692e6af6..888e5fd4e3 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -2230,6 +2230,7 @@ class ASTConverter {
if (this.resolveBindings) {
recordNodes(simpleName, argument);
recordNodes(variableDeclarationFragment, argument);
+ variableDeclarationFragment.resolveBinding();
}
variableDeclarationFragment.setName(simpleName);
variableDeclarationFragment.setSourceRange(start, end - start + 1);

Back to the top