Bug 425410: [1.8][quick assist] Conversion from anonymous class having
generic method to lambda expression
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
index de67ce7..4520a6b 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -465,6 +465,33 @@
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
+ public void testConvertToLambda13() throws Exception {
+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("interface J {\n");
+ buf.append(" <M> J run(M x);\n");
+ buf.append("}\n");
+ buf.append("\n");
+ buf.append("class Test {\n");
+ buf.append(" J j = new J() {\n");
+ buf.append(" @Override\n");
+ buf.append(" public <M> J run(M x) {\n");
+ buf.append(" return null;\n");
+ buf.append(" }\n");
+ buf.append(" }; \n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null);
+
+ int offset= buf.toString().indexOf("J()"); // generic lambda not allowed
+ AssistContext context= getCorrectionContext(cu, offset, 0);
+ assertNoErrors(context);
+ List proposals= collectAssists(context, false);
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+ assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression);
+ }
+
public void testConvertToAnonymousClassCreation1() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
index 2412b9f..af23ec4 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -402,9 +402,18 @@
BodyDeclaration bodyDeclaration= bodyDeclarations.get(0);
if (!(bodyDeclaration instanceof MethodDeclaration))
return false;
-
+
+ MethodDeclaration methodDecl= (MethodDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding= methodDecl.resolveBinding();
+
+ if (methodBinding == null)
+ return false;
+ // generic lambda expressions are not allowed
+ if (methodBinding.isGenericMethod())
+ return false;
+
// lambda cannot refer to 'this'/'super' literals
- if (SuperThisReferenceFinder.hasReference((MethodDeclaration) bodyDeclaration))
+ if (SuperThisReferenceFinder.hasReference(methodDecl))
return false;
if (!isInTargetTypeContext(node))