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 238951 Details for
Bug 425412
[1.8][quick assist] Conversion from anonymous class to lambda loses parameterized type details
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix + Test
Fixed-bug-425412-1.8-quick-assist-Conversion-to-lambda-parameterized-cast.patch (text/plain), 5.21 KB, created by
Noopur Gupta
on 2014-01-14 03:28:58 EST
(
hide
)
Description:
Fix + Test
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2014-01-14 03:28:58 EST
Size:
5.21 KB
patch
obsolete
>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 2586f60..21e260d 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 >@@ -675,6 +675,56 @@ > assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression); > } > >+ public void testConvertToLambda14() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import java.util.List;\n"); >+ buf.append("\n"); >+ buf.append("interface I<T> {\n"); >+ buf.append(" void goo(List<T> i);\n"); >+ buf.append("}\n"); >+ buf.append("\n"); >+ buf.append("public class X {\n"); >+ buf.append(" public static void main(String[] args) {\n"); >+ buf.append(" I i = new I<String>() {\n"); >+ buf.append(" @Override\n"); >+ buf.append(" public void goo(List<String> ls) {\n"); >+ buf.append(" String s = ls.get(0);\n"); >+ buf.append(" }\n"); >+ buf.append(" };\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("I<String>()"); >+ 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("import java.util.List;\n"); >+ buf.append("\n"); >+ buf.append("interface I<T> {\n"); >+ buf.append(" void goo(List<T> i);\n"); >+ buf.append("}\n"); >+ buf.append("\n"); >+ buf.append("public class X {\n"); >+ buf.append(" public static void main(String[] args) {\n"); >+ buf.append(" I i = (I<String>) ls -> {\n"); >+ buf.append(" String s = ls.get(0);\n"); >+ buf.append(" };\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ > 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/dom/ASTNodes.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java >index 5144411..41e0828 100644 >--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java >+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2013 IBM Corporation and others. >+ * Copyright (c) 2000, 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 >@@ -554,6 +554,9 @@ > public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) { > ITypeBinding initializerType= initializer.resolveTypeBinding(); > ITypeBinding referenceType= reference.resolveTypeBinding(); >+ if (reference instanceof ClassInstanceCreation) { >+ referenceType= ((ClassInstanceCreation) reference).getType().resolveBinding(); >+ } > if (initializerType == null || referenceType == null) > return null; > >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 cdabfb1..d6ccf20 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 >@@ -246,12 +246,13 @@ > > lambdaExpression.setBody(rewrite.createCopyTarget(lambdaBody)); > Expression replacement= lambdaExpression; >- if (ASTNodes.isTargetAmbiguous(classInstanceCreation)) { >+ ITypeBinding cicTypeBinding= classInstanceCreation.getType().resolveBinding(); >+ if (ASTNodes.isTargetAmbiguous(classInstanceCreation) || cicTypeBinding != ASTNodes.getTargetType(classInstanceCreation)) { > CastExpression cast= ast.newCastExpression(); > cast.setExpression(lambdaExpression); > ImportRewrite importRewrite= cuRewrite.getImportRewrite(); > ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(classInstanceCreation, importRewrite); >- cast.setType(importRewrite.addImport(classInstanceCreation.getType().resolveBinding(), ast, importRewriteContext)); >+ cast.setType(importRewrite.addImport(cicTypeBinding, ast, importRewriteContext)); > replacement= cast; > } > rewrite.replace(classInstanceCreation, replacement, group);
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 425412
:
238951
|
242431