### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui.tests diff --git ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java index 0aad318..b497c8b 100644 --- ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java +++ ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java @@ -74,6 +74,7 @@ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); } + @Override protected void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath()); } @@ -930,6 +931,424 @@ assertExpectedExistInProposals(proposals, new String[] { expected1 }); } + // Bug 421479 + public void testConvertToLambda19() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func2 {\n"); + buf.append(" enum En {\n"); + buf.append(" A, B;\n"); + buf.append(" enum COLOR {\n"); + buf.append(" D, E\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" void foo();\n"); + buf.append("\n"); + buf.append(" String NAME = \"\";\n"); + buf.append("\n"); + buf.append(" static String staticName() {\n"); + buf.append(" return NAME;\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test2 {\n"); + buf.append(" void bar() {\n"); + buf.append(" Func2 f = new Func2() {\n"); + buf.append(" @Override\n"); + buf.append(" public void foo() {\n"); + buf.append(" System.out.println(NAME);\n"); + buf.append(" System.out.println(Func2.NAME);\n"); + buf.append(" System.out.println(En.A);\n"); + buf.append(" System.out.println(Func2.En.A);\n"); + buf.append(" System.out.println(En.COLOR.D);\n"); + buf.append(" System.out.println(Func2.En.COLOR.D);\n"); + buf.append(" System.out.println(Test2.this);\n"); + buf.append(" bar();\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); + + int offset= buf.toString().indexOf("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + buf= new StringBuffer(); + buf.append("package test1;\n\n"); + buf.append("import test1.Func2.En;\n\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func2 {\n"); + buf.append(" enum En {\n"); + buf.append(" A, B;\n"); + buf.append(" enum COLOR {\n"); + buf.append(" D, E\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" void foo();\n"); + buf.append("\n"); + buf.append(" String NAME = \"\";\n"); + buf.append("\n"); + buf.append(" static String staticName() {\n"); + buf.append(" return NAME;\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test2 {\n"); + buf.append(" void bar() {\n"); + buf.append(" Func2 f = () -> {\n"); + buf.append(" System.out.println(Func2.NAME);\n"); + buf.append(" System.out.println(Func2.NAME);\n"); + buf.append(" System.out.println(Func2.En.A);\n"); + buf.append(" System.out.println(Func2.En.A);\n"); + buf.append(" System.out.println(En.COLOR.D);\n"); + buf.append(" System.out.println(Func2.En.COLOR.D);\n"); + buf.append(" System.out.println(Test2.this);\n"); + buf.append(" bar();\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + // Bug 421479 + public void testConvertToLambda20() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("interface Func {\n"); + buf.append(" void go();\n"); + buf.append(" String NAME = Func.class.getName();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("public class Test {\n"); + buf.append(" void foo() {\n"); + buf.append(" Func f= new Func() {\n"); + buf.append(" @Override\n"); + buf.append(" public void go() {\n"); + buf.append(" System.out.println(NAME);\n"); + buf.append(" }\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("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("interface Func {\n"); + buf.append(" void go();\n"); + buf.append(" String NAME = Func.class.getName();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("public class Test {\n"); + buf.append(" void foo() {\n"); + buf.append(" Func f= () -> System.out.println(Func.NAME);\n"); + buf.append(" }\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + // Bug 421479 + public void testConvertToLambda21() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import test1.Func2.En.COLOR;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func2 {\n"); + buf.append(" enum En {\n"); + buf.append(" A, B;\n"); + buf.append(" enum COLOR {\n"); + buf.append(" D, E\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" void foo();\n"); + buf.append("\n"); + buf.append(" String NAME = \"\";\n"); + buf.append("\n"); + buf.append(" static String staticName() {\n"); + buf.append(" return NAME;\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test2 {\n"); + buf.append(" void bar() {\n"); + buf.append(" Func2 f = new Func2() {\n"); + buf.append(" @Override\n"); + buf.append(" public void foo() {\n"); + buf.append(" System.out.println(COLOR.D);\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); + + int offset= buf.toString().indexOf("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import test1.Func2.En.COLOR;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func2 {\n"); + buf.append(" enum En {\n"); + buf.append(" A, B;\n"); + buf.append(" enum COLOR {\n"); + buf.append(" D, E\n"); + buf.append(" }\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" void foo();\n"); + buf.append("\n"); + buf.append(" String NAME = \"\";\n"); + buf.append("\n"); + buf.append(" static String staticName() {\n"); + buf.append(" return NAME;\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test2 {\n"); + buf.append(" void bar() {\n"); + buf.append(" Func2 f = () -> System.out.println(COLOR.D);\n"); + buf.append(" }\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + // Bug 421479 + public void testConvertToLambda22() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func {\n"); + buf.append(" class C {\n"); + buf.append(" static class CIn { static int i= 0; } \n"); + buf.append(" static String NAME = \"\";\n"); + buf.append(" }\n"); + buf.append(" void foo();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test {\n"); + buf.append(" static class C {\n"); + buf.append(" static class CIn { static int i= 1; } \n"); + buf.append(" static String NAME = \"\";\n"); + buf.append(" }\n"); + buf.append(" void bar() {\n"); + buf.append(" Func f = new Func() {\n"); + buf.append(" @Override\n"); + buf.append(" public void foo() {\n"); + buf.append(" System.out.println(C.CIn.i);\n"); + buf.append(" System.out.println(C.NAME);\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); + + int offset= buf.toString().indexOf("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func {\n"); + buf.append(" class C {\n"); + buf.append(" static class CIn { static int i= 0; } \n"); + buf.append(" static String NAME = \"\";\n"); + buf.append(" }\n"); + buf.append(" void foo();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test {\n"); + buf.append(" static class C {\n"); + buf.append(" static class CIn { static int i= 1; } \n"); + buf.append(" static String NAME = \"\";\n"); + buf.append(" }\n"); + buf.append(" void bar() {\n"); + buf.append(" Func f = () -> {\n"); + buf.append(" System.out.println(test1.Func.C.CIn.i);\n"); + buf.append(" System.out.println(Func.C.NAME);\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + // Bug 421479 + public void testConvertToLambda23() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func {\n"); + buf.append(" class C {\n"); + buf.append(" static class CIn { static int i= 0; } \n"); + buf.append(" }\n"); + buf.append(" void foo();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test extends TT {\n"); + buf.append(" static class C {\n"); + buf.append(" static class CIn { static int i= 1; } \n"); + buf.append(" }\n"); + buf.append(" void bar() {\n"); + buf.append(" test1.Func f = new test1.Func() {\n"); + buf.append(" @Override\n"); + buf.append(" public void foo() {\n"); + buf.append(" System.out.println(C.CIn.i); // [1]\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class TT {\n"); + buf.append(" class Func {\n"); + buf.append(" }\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("Func.java", buf.toString(), false, null); + + int offset= buf.toString().indexOf("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func {\n"); + buf.append(" class C {\n"); + buf.append(" static class CIn { static int i= 0; } \n"); + buf.append(" }\n"); + buf.append(" void foo();\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test extends TT {\n"); + buf.append(" static class C {\n"); + buf.append(" static class CIn { static int i= 1; } \n"); + buf.append(" }\n"); + buf.append(" void bar() {\n"); + buf.append(" test1.Func f = () -> System.out.println(test1.Func.C.CIn.i);\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class TT {\n"); + buf.append(" class Func {\n"); + buf.append(" }\n"); + buf.append("}\n"); + String expected1= buf.toString(); + + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + // Bug 421479 + public void testConvertToLambda24() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("@FunctionalInterface\n"); + buf.append("interface Func2 {\n"); + buf.append(" enum En {\n"); + buf.append(" A, B\n"); + buf.append(" }\n"); + buf.append("\n"); + buf.append(" void foo();\n"); + buf.append("\n"); + buf.append(" String NAME = \"\";\n"); + buf.append("\n"); + buf.append(" static String staticName() {\n"); + buf.append(" return NAME;\n"); + buf.append(" }\n"); + buf.append("}\n"); + buf.append("\n"); + buf.append("class Test2 {\n"); + buf.append(" void bar() {\n"); + buf.append(" Func2 f = new Func2() {\n"); + buf.append(" @Override\n"); + buf.append(" public void foo() {\n"); + buf.append(" foo();\n"); + buf.append(" }\n"); + buf.append(" };\n"); + buf.append(" }\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("Func2.java", buf.toString(), false, null); + + int offset= buf.toString().indexOf("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 0); + } + + // Bug 421479 + public void testConvertToLambda25() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.function.Consumer;\n"); + buf.append("\n"); + buf.append("public class Test {\n"); + buf.append(" static void run(Consumer consumer) {\n"); + buf.append(" System.out.println(\"consumer\");\n"); + buf.append(" }\n"); + buf.append(" static {\n"); + buf.append(" run(new Consumer() {\n"); + buf.append(" @Override\n"); + buf.append(" public void accept(Integer integer) {\n"); + buf.append(" System.out.println(andThen(null));\n"); + buf.append(" }\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("public void"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 0); + } + public void testConvertToLambdaAmbiguousOverridden() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); #P org.eclipse.jdt.ui diff --git core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java index dec2ec4..6afc8d9 100644 --- core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java +++ core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java @@ -21,6 +21,9 @@ import org.eclipse.text.edits.TextEditGroup; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IImportDeclaration; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; @@ -36,11 +39,15 @@ import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.LambdaExpression; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Statement; import org.eclipse.jdt.core.dom.SuperFieldAccess; @@ -71,6 +78,62 @@ import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; public class LambdaExpressionsFix extends CompilationUnitRewriteOperationsFix { + + private static final class InterfaceAccessQualifier extends HierarchicalASTVisitor { + + List nameNodes; + + private ITypeBinding typeBinding; + + public InterfaceAccessQualifier(ITypeBinding typeBinding) { + this.typeBinding= typeBinding; + nameNodes= new ArrayList(); + } + + @Override + public boolean visit(SimpleName node) { + IBinding resolveBinding= node.resolveBinding(); + ITypeBinding declaringClass= null; + if (resolveBinding instanceof IVariableBinding) { + declaringClass= ((IVariableBinding) resolveBinding).getDeclaringClass(); + } else if (resolveBinding instanceof ITypeBinding) { + declaringClass= ((ITypeBinding) resolveBinding).getDeclaringClass(); + } + if (declaringClass != null && Bindings.equals(typeBinding, declaringClass)) { + nameNodes.add(node); + } + return true; + } + + @Override + public boolean visit(QualifiedName node) { + Name qualifier= node.getQualifier(); + ITypeBinding qualifierTypeBinding= qualifier.resolveTypeBinding(); + // Ignore if already qualified with the functional interface + if (Bindings.equals(typeBinding, qualifierTypeBinding)) { + return false; + } + qualifierTypeBinding= ASTNodes.getLeftMostSimpleName(qualifier).resolveTypeBinding(); + if (qualifierTypeBinding == null || Bindings.equals(typeBinding, qualifierTypeBinding)) { + return false; + } + IBinding resolveBinding= node.resolveBinding(); + ITypeBinding declaringClass= null; + if (resolveBinding instanceof IVariableBinding) { + declaringClass= ((IVariableBinding) resolveBinding).getDeclaringClass(); + } else if (resolveBinding instanceof ITypeBinding) { + declaringClass= ((ITypeBinding) resolveBinding).getDeclaringClass(); + } + while (declaringClass != null) { + if (Bindings.equals(typeBinding, declaringClass)) { + nameNodes.add(qualifier); + return false; + } + declaringClass= declaringClass.getDeclaringClass(); + } + return false; + } + } private static final class FunctionalAnonymousClassesFinder extends ASTVisitor { @@ -176,8 +239,9 @@ @Override public boolean visit(MethodInvocation node) { IMethodBinding binding= node.resolveMethodBinding(); - if (binding != null && !JdtFlags.isStatic(binding) && node.getExpression() == null - && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, false)) + if (binding != null + && ((!JdtFlags.isStatic(binding) && node.getExpression() == null && Bindings.isSuperType(binding.getDeclaringClass(), fFunctionalInterface, true)) + || (Bindings.equals(binding, fMethodDeclaration.resolveBinding())))) throw new AbortSearchException(); return true; } @@ -250,9 +314,10 @@ } } } - //TODO: Bug 421479: [1.8][clean up][quick assist] convert anonymous to lambda must consider lost scope of interface -// lambdaBody.accept(new InterfaceAccessQualifier(rewrite, classInstanceCreation.getType().resolveBinding())); //TODO: maybe need a separate ASTRewrite and string placeholder - + ITypeBinding typeBinding= classInstanceCreation.getType().resolveBinding(); + InterfaceAccessQualifier visitor= new InterfaceAccessQualifier(typeBinding); + lambdaBody.accept(visitor); + qualifyNameNodes(cuRewrite, classInstanceCreation, visitor.nameNodes, group); lambdaExpression.setBody(rewrite.createCopyTarget(lambdaBody)); Expression replacement= lambdaExpression; if (ASTNodes.isTargetAmbiguous(classInstanceCreation, lambdaParameters.isEmpty())) { @@ -260,7 +325,7 @@ cast.setExpression(lambdaExpression); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite); - Type castType= importRewrite.addImport(classInstanceCreation.getType().resolveBinding(), ast, importRewriteContext); + Type castType= importRewrite.addImport(typeBinding, ast, importRewriteContext); cast.setType(castType); importRemover.registerAddedImports(castType); replacement= cast; @@ -270,6 +335,56 @@ importRemover.registerRemovedNode(classInstanceCreation); importRemover.registerRetainedNode(lambdaBody); } + } + + private void qualifyNameNodes(CompilationUnitRewrite cuRewrite, ClassInstanceCreation classInstanceCreation, List nameNodes, TextEditGroup group) { + AST ast= cuRewrite.getAST(); + IImportDeclaration[] availableImports= null; + ICompilationUnit cu= cuRewrite.getCu(); + try { + availableImports= cu.getImports(); + } catch (JavaModelException e) { + // ignore + } + ITypeBinding typeBinding= classInstanceCreation.getType().resolveBinding(); + for (Name name : nameNodes) { + Type addImport= null; + if (name instanceof QualifiedName) { + ITypeBinding resolveTypeBinding= ASTNodes.getLeftMostSimpleName(name).resolveTypeBinding(); + if (resolveTypeBinding != null) { + ImportRewrite importRewrite= cuRewrite.getImportRewrite(); + ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite); + addImport= importRewrite.addImport(resolveTypeBinding, ast, importRewriteContext); + if (addImport instanceof SimpleType) { + Name qualifiedName= ((SimpleType) addImport).getName(); + if (qualifiedName instanceof QualifiedName) { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + rewrite.set(name, QualifiedName.QUALIFIER_PROPERTY, qualifiedName, group); + } else { + ImportRemover importRemover= cuRewrite.getImportRemover(); + importRemover.registerAddedImports(addImport); + } + } + } + } else if (name instanceof SimpleName) { + ITypeBinding resolvedTypeBinding= name.resolveTypeBinding(); + if (!isTypeImported(availableImports, resolvedTypeBinding.getQualifiedName())) { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + String qualifier= typeBinding.getErasure().getName(); + SimpleName simpleName= ast.newSimpleName(((SimpleName) name).getIdentifier()); + rewrite.set(name, SimpleName.IDENTIFIER_PROPERTY, ast.newQualifiedName(ast.newName(qualifier), simpleName).getFullyQualifiedName(), group); + } + } + } + } + + private boolean isTypeImported(IImportDeclaration[] availableImports, String qualifiedName) { + for (IImportDeclaration iImportDeclaration : availableImports) { + if (qualifiedName.equals(iImportDeclaration.getElementName())) { + return true; + } + } + return false; } private HashSet makeNamesUnique(HashSet excludedNames, MethodDeclaration methodDeclaration, ASTRewrite rewrite, TextEditGroup group) { @@ -547,7 +662,7 @@ return methodBinding.getReturnType().getFunctionalInterfaceMethod() != null; } - //TODO: should also check whether variable is of a functional type + //TODO: should also check whether variable is of a functional type return locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY || locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY || locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY