Skip to content

Commit

Permalink
Bug 424223: [1.8][quick assist][clean up] convert anonymous to lambda…
Browse files Browse the repository at this point in the history
… results in code with conflicting variable names

Comment 14: lambdas nested inside other expressions
  • Loading branch information
mkeller committed Apr 30, 2014
1 parent 8ad64db commit f91da12
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,64 @@ public void testConvertToLambda17() throws Exception {
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}

public void testConvertToLambda18() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
buf.append("interface FIOther {\n");
buf.append(" void run(int x);\n");
buf.append("}\n");
buf.append("\n");
buf.append("public class TestOther {\n");
buf.append(" void init() {\n");
buf.append(" String x;\n");
buf.append(" m(x1 -> {\n");
buf.append(" FIOther fi = new FIOther() {\n");
buf.append(" @Override\n");
buf.append(" public void run(int x1) { \n");
buf.append(" return;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" });\n");
buf.append(" }\n");
buf.append("\n");
buf.append(" void m(FIOther fi) {\n");
buf.append(" };\n");
buf.append("}\n");
ICompilationUnit cu= pack1.createCompilationUnit("TestOther.java", buf.toString(), false, null);

int offset= buf.toString().indexOf("FIOther()");
AssistContext context= getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals= collectAssists(context, false);

assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);

buf= new StringBuffer();
buf.append("package test1;\n");
buf.append("interface FIOther {\n");
buf.append(" void run(int x);\n");
buf.append("}\n");
buf.append("\n");
buf.append("public class TestOther {\n");
buf.append(" void init() {\n");
buf.append(" String x;\n");
buf.append(" m(x1 -> {\n");
buf.append(" FIOther fi = x11 -> { \n");
buf.append(" return;\n");
buf.append(" };\n");
buf.append(" });\n");
buf.append(" }\n");
buf.append("\n");
buf.append(" void m(FIOther fi) {\n");
buf.append(" };\n");
buf.append("}\n");
String expected1= buf.toString();

assertExpectedExistInProposals(proposals, new String[] { expected1 });
}

public void testConvertToLambdaAmbiguousOverridden() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.Initializer;
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.Modifier;
Expand Down Expand Up @@ -702,7 +701,7 @@ public boolean visit(FieldDeclaration node) {
}

@Override
public boolean visit(LambdaExpression node) {
public boolean visit(Expression node) {
return !fBreak && isInside(node);
}

Expand Down

0 comments on commit f91da12

Please sign in to comment.