Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 236088 Details for
Bug 417017
[1.8] Incorrect parameters in resolved method binding for LambdaExpression
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Alternate patch
lambdapa.patch (text/plain), 15.44 KB, created by
Srikanth Sankaran
on 2013-10-04 01:40:10 EDT
(
hide
)
Description:
Alternate patch
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2013-10-04 01:40:10 EDT
Size:
15.44 KB
patch
obsolete
>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 8078766..a8ec10c 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 >@@ -2645,6 +2645,200 @@ > typeBinding = type.resolveBinding(); > assertFalse("A Functional interface", typeBinding.isFunctionalInterface()); > } >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017a() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", >+ true/* resolve */); >+ String contents = "package test417017;" >+ + "interface I {\n" >+ + " int foo(int x);\n" >+ + "}\n" >+ + "public class X {\n" >+ + " void fun(int a) {\n" >+ +" I i1 = x1-> x1;\n" >+ +" I i2 = xxx-> {\n" >+ +" i1.foo(a);\n" >+ +" return xxx;\n" >+ +" };\n" >+ +" }\n" >+ +"}\n"; >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); >+ TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; >+ VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(1)).fragments().get(0); >+ LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); >+ List parameters = lambda.parameters(); >+ assertTrue("Incorrect Number of parameters", parameters.size() == 1); >+ ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "int", parameterTypes[0].toString()); >+ } >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017b() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", >+ true/* resolve */); >+ String contents = "package test417017;" + >+ "interface I1 {\n" + >+ " int foo(int a);\n" + >+ "}\n" + >+ "\n" + >+ "interface I2 {\n" + >+ " public default int foo() {\n" + >+ " I1 i1 = (a) -> {\n" + >+ " return a;\n" + >+ " };\n" + >+ " //return 0;\n" + // Error on purpose >+ " }\n" + >+ "}\n" ; >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy, false); >+ TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; >+ VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0)).fragments().get(0); >+ LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); >+ List parameters = lambda.parameters(); >+ assertTrue("Incorrect Number of parameters", parameters.size() == 1); >+ ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "int", parameterTypes[0].toString()); >+ } >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017c() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", >+ true/* resolve */); >+ String contents = "package test417017;" + >+ "interface I1 {\n" + >+ " int foo(int a);\n" + >+ "}\n" + >+ "\n" + >+ "interface I2 {\n" + >+ " public default int foo() {\n" + >+ " I1 i1 = (float a) -> {\n" + >+ " return a;\n" + >+ " };\n" + >+ " //return 0;\n" + // Error on purpose >+ " }\n" + >+ "}\n" ; >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy, false); >+ TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; >+ VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0)).fragments().get(0); >+ LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); >+ List parameters = lambda.parameters(); >+ assertTrue("Incorrect Number of parameters", parameters.size() == 1); >+ ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "float", parameterTypes[0].toString()); >+ } >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017d() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", >+ true/* resolve */); >+ String contents = "package test399794;" + >+ "interface I {\n" + >+ " void foo(X x);\n" + >+ "}\n" + >+ "public class X {\n" + >+ " void foo(X x) {\n" + >+ " }\n" + >+ " I i = this::foo;\n" + >+ "}\n"; >+ >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ FieldDeclaration field = typeDeclaration.getFields()[0]; >+ >+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); >+ Expression expression = fragment.getInitializer(); >+ ExpressionMethodReference methodReference = (ExpressionMethodReference) expression; >+ IMethodBinding methodBinding = methodReference.resolveMethodBinding(); >+ assertNotNull(methodBinding); >+ ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "X", parameterTypes[0].getName()); >+ } >+ >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017e() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", >+ true/* resolve */); >+ String contents = "package test399794;" + >+ "interface I {\n" + >+ " int [] foo(int x);\n" + >+ "}\n" + >+ "public class X {\n" + >+ " I i = int []::new;\n" + >+ "}\n"; >+ >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ FieldDeclaration field = typeDeclaration.getFields()[0]; >+ >+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); >+ Expression expression = fragment.getInitializer(); >+ CreationReference creationReference = (CreationReference) expression; >+ IMethodBinding methodBinding = creationReference.resolveMethodBinding(); >+ assertNotNull(methodBinding); >+ assertEquals("Wrong name", "lambda$0", methodBinding.getName()); >+ ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "int", parameterTypes[0].getName()); >+ } >+ >+ /** >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 >+ * >+ * @throws JavaModelException >+ */ >+ public void test417017f() throws JavaModelException { >+ this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", >+ true/* resolve */); >+ String contents = "package test399794;" + >+ "interface I {\n" + >+ " void foo(X x);\n" + >+ "}\n" + >+ "public class X {\n" + >+ " private void foo(X x) {\n" + >+ " }\n" + >+ " class Y {\n" + >+ " I i = X.this::foo;\n" + >+ " }\n" + >+ "}\n"; >+ >+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); >+ TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); >+ typeDeclaration = typeDeclaration.getTypes()[0]; >+ FieldDeclaration field = typeDeclaration.getFields()[0]; >+ >+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); >+ Expression expression = fragment.getInitializer(); >+ ExpressionMethodReference reference = (ExpressionMethodReference) expression; >+ IMethodBinding methodBinding = reference.resolveMethodBinding(); >+ assertNotNull(methodBinding); >+ assertEquals("Wrong name", "foo", methodBinding.getName()); >+ ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); >+ assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); >+ assertEquals("Incorrect parameter type", "X", parameterTypes[0].getName()); >+ } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=413942 > // also refer https://bugs.eclipse.org/bugs/show_bug.cgi?id=413569 > public void testBug413942() throws JavaModelException { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java >index 4e64752..b2e589d 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java >@@ -38,7 +38,8 @@ > > TypeBinding expectedType; > public MethodBinding descriptor; >- public MethodBinding binding; >+ public MethodBinding binding; // Code generation binding. May include synthetics. See getMethodBinding() >+ protected MethodBinding actualMethodBinding; // void of synthetics. > boolean ignoreFurtherInvestigation; > protected ExpressionContext expressionContext = VANILLA_CONTEXT; > protected SimpleLookupTable resultExpressions; >@@ -51,7 +52,10 @@ > public FunctionalExpression(CompilationResult compilationResult) { > this.compilationResult = compilationResult; > } >- >+ // Return the actual (non-code generation) method binding that is void of synthetics. >+ public MethodBinding getMethodBinding() { >+ return null; >+ } > public void setExpectedType(TypeBinding expectedType) { > this.expectedType = this.ellipsisArgument ? ((ArrayBinding) expectedType).elementsType() : expectedType; > } >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java >index fcbd1d0..ffe9add 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java >@@ -49,6 +49,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.Scope; > import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding; >+import org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.TagBits; > import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; >@@ -783,6 +784,17 @@ > return this.outerLocalVariables[i]; > return null; > } >+ >+ // Return the actual method binding devoid of synthetics. >+ public MethodBinding getMethodBinding() { >+ if (this.actualMethodBinding == null) { >+ this.actualMethodBinding = new MethodBinding(this.binding.modifiers, this.binding.selector, this.binding.returnType, >+ this.binding instanceof SyntheticMethodBinding ? this.descriptor.parameters : this.binding.parameters, // retain any faults in parameter list. >+ this.binding.thrownExceptions, this.binding.declaringClass); >+ this.actualMethodBinding.tagBits = this.binding.tagBits; >+ } >+ return this.actualMethodBinding; >+ } > } > class IncongruentLambdaException extends RuntimeException { > private static final long serialVersionUID = 4145723509219836114L; >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java >index 6dc9e6b..b80d1b8 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java >@@ -81,6 +81,7 @@ > } > > public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { >+ this.actualMethodBinding = this.binding; // grab before synthetics come into play. > SourceTypeBinding sourceType = currentScope.enclosingSourceType(); > if (this.receiverType.isArrayType()) { > if (isConstructorReference()) { >@@ -637,4 +638,10 @@ > tSam = t.getSingleAbstractMethod(this.enclosingScope); > return resultExpression.tIsMoreSpecific(tSam.returnType, sSam.returnType); > } >+ >+ public org.eclipse.jdt.internal.compiler.lookup.MethodBinding getMethodBinding() { >+ if (this.actualMethodBinding == null) // array new/clone, no real binding. >+ this.actualMethodBinding = this.binding; >+ return this.actualMethodBinding; >+ } > } >diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java >index e1e37e8..062758c 100644 >--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java >+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java >@@ -883,7 +883,7 @@ > Object oldNode = this.newAstToOldAst.get(lambda); > if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.LambdaExpression) { > org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression = (org.eclipse.jdt.internal.compiler.ast.LambdaExpression) oldNode; >- IMethodBinding methodBinding = getMethodBinding(lambdaExpression.binding); >+ IMethodBinding methodBinding = getMethodBinding(lambdaExpression.getMethodBinding()); > if (methodBinding == null) { > return null; > } >@@ -934,7 +934,7 @@ > Object oldNode = this.newAstToOldAst.get(methodReference); > if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { > org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) oldNode; >- IMethodBinding methodBinding = getMethodBinding(referenceExpression.binding); >+ IMethodBinding methodBinding = getMethodBinding(referenceExpression.getMethodBinding()); > if (methodBinding == null) { > return null; > } >@@ -1166,7 +1166,7 @@ > return method.getReturnType(); > } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { > org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node; >- IMethodBinding method = getMethodBinding(referenceExpression.binding); >+ IMethodBinding method = getMethodBinding(referenceExpression.getMethodBinding()); > if (method == null) return null; > return method.getReturnType(); > } >@@ -1431,7 +1431,7 @@ > return getMethodBinding(memberValuePair.binding); > } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { > org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node; >- return getMethodBinding(referenceExpression.binding); >+ return getMethodBinding(referenceExpression.getMethodBinding()); > } > return null; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 417017
:
235490
|
235788
|
236060
|
236064
| 236088