View | Details | Raw Unified | Return to bug 425412 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java (+50 lines)
Lines 675-680 Link Here
675
		assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression);
675
		assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression);
676
	}
676
	}
677
677
678
	public void testConvertToLambda14() throws Exception {
679
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
680
		StringBuffer buf= new StringBuffer();
681
		buf.append("package test1;\n");
682
		buf.append("import java.util.List;\n");
683
		buf.append("\n");
684
		buf.append("interface I<T> {\n");
685
		buf.append("    void goo(List<T> i);\n");
686
		buf.append("}\n");
687
		buf.append("\n");
688
		buf.append("public class X {\n");
689
		buf.append("    public static void main(String[] args) {\n");
690
		buf.append("        I i = new I<String>() {\n");
691
		buf.append("            @Override\n");
692
		buf.append("            public void goo(List<String> ls) {\n");
693
		buf.append("                String s = ls.get(0);\n");
694
		buf.append("            }\n");
695
		buf.append("        };\n");
696
		buf.append("    }\n");
697
		buf.append("}\n");
698
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
699
700
		int offset= buf.toString().indexOf("I<String>()");
701
		AssistContext context= getCorrectionContext(cu, offset, 0);
702
		assertNoErrors(context);
703
		List proposals= collectAssists(context, false);
704
705
		assertNumberOfProposals(proposals, 2);
706
		assertCorrectLabels(proposals);
707
708
		buf= new StringBuffer();
709
		buf.append("package test1;\n");
710
		buf.append("import java.util.List;\n");
711
		buf.append("\n");
712
		buf.append("interface I<T> {\n");
713
		buf.append("    void goo(List<T> i);\n");
714
		buf.append("}\n");
715
		buf.append("\n");
716
		buf.append("public class X {\n");
717
		buf.append("    public static void main(String[] args) {\n");
718
		buf.append("        I i = (I<String>) ls -> {\n");
719
		buf.append("            String s = ls.get(0);\n");
720
		buf.append("        };\n");
721
		buf.append("    }\n");
722
		buf.append("}\n");
723
		String expected1= buf.toString();
724
725
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
726
	}
727
678
	public void testConvertToAnonymousClassCreation1() throws Exception {
728
	public void testConvertToAnonymousClassCreation1() throws Exception {
679
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
729
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
680
		StringBuffer buf= new StringBuffer();
730
		StringBuffer buf= new StringBuffer();
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 554-559 Link Here
554
	public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) {
554
	public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) {
555
		ITypeBinding initializerType= initializer.resolveTypeBinding();
555
		ITypeBinding initializerType= initializer.resolveTypeBinding();
556
		ITypeBinding referenceType= reference.resolveTypeBinding();
556
		ITypeBinding referenceType= reference.resolveTypeBinding();
557
		if (reference instanceof ClassInstanceCreation) {
558
			referenceType= ((ClassInstanceCreation) reference).getType().resolveBinding();
559
		}
557
		if (initializerType == null || referenceType == null)
560
		if (initializerType == null || referenceType == null)
558
			return null;
561
			return null;
559
		
562
		
(-)a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFix.java (-2 / +3 lines)
Lines 246-257 Link Here
246
				
246
				
247
				lambdaExpression.setBody(rewrite.createCopyTarget(lambdaBody));
247
				lambdaExpression.setBody(rewrite.createCopyTarget(lambdaBody));
248
				Expression replacement= lambdaExpression;
248
				Expression replacement= lambdaExpression;
249
				if (ASTNodes.isTargetAmbiguous(classInstanceCreation)) {
249
				ITypeBinding cicTypeBinding= classInstanceCreation.getType().resolveBinding();
250
				if (ASTNodes.isTargetAmbiguous(classInstanceCreation) || cicTypeBinding != ASTNodes.getTargetType(classInstanceCreation)) {
250
					CastExpression cast= ast.newCastExpression();
251
					CastExpression cast= ast.newCastExpression();
251
					cast.setExpression(lambdaExpression);
252
					cast.setExpression(lambdaExpression);
252
					ImportRewrite importRewrite= cuRewrite.getImportRewrite();
253
					ImportRewrite importRewrite= cuRewrite.getImportRewrite();
253
					ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite);
254
					ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite);
254
					cast.setType(importRewrite.addImport(classInstanceCreation.getType().resolveBinding(), ast, importRewriteContext));
255
					cast.setType(importRewrite.addImport(cicTypeBinding, ast, importRewriteContext));
255
					replacement= cast;
256
					replacement= cast;
256
				}
257
				}
257
				rewrite.replace(classInstanceCreation, replacement, group);
258
				rewrite.replace(classInstanceCreation, replacement, group);

Return to bug 425412