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 143705 Details for
Bug 285573
[quick fix] Wrong quickfix proposal for operations involving double and Integer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix
285573_patch.txt (text/plain), 18.49 KB, created by
Markus Keller
on 2009-08-06 15:02:09 EDT
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
Markus Keller
Created:
2009-08-06 15:02:09 EDT
Size:
18.49 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties,v >retrieving revision 1.259 >diff -u -r1.259 CorrectionMessages.properties >--- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 26 May 2009 13:37:18 -0000 1.259 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 6 Aug 2009 19:04:31 -0000 >@@ -117,7 +117,6 @@ > LocalCorrectionsSubProcessor_setparenteses_instanceof_description=Put 'instanceof' in parentheses > LocalCorrectionsSubProcessor_qualify_left_hand_side_description=Qualify left hand side > LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}'' >-TypeMismatchSubProcessor_0=boolean > TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}'' > TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}'' > TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}'' >@@ -127,7 +126,7 @@ > TypeArgumentMismatchSubProcessor_removeTypeArguments=Remove type arguments > TypeMismatchSubProcessor_addexceptions_description=Add exceptions to ''{0}.{1}(..)'' > TypeMismatchSubProcessor_incompatible_for_each_type_description=Change type of ''{0}'' to ''{1}'' >-TypeMismatchSubProcessor_insertnullcheck_description=Insert null check >+TypeMismatchSubProcessor_insertnullcheck_description=Insert '!= null' check > > RemoveDeclarationCorrectionProposal_removeunusedfield_description=Remove declaration of ''{0}'' and assignments without possible side effects > RemoveDeclarationCorrectionProposal_removeunusedmethod_description=Remove method ''{0}'' >Index: ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java,v >retrieving revision 1.198 >diff -u -r1.198 UnresolvedElementsSubProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java 20 Mar 2009 08:50:10 -0000 1.198 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java 6 Aug 2009 19:04:31 -0000 >@@ -1289,16 +1289,27 @@ > } > if (castType != null) { > ITypeBinding binding= nodeToCast.resolveTypeBinding(); >- if (binding == null || binding.isCastCompatible(castType)) { >- ASTRewriteCorrectionProposal proposal= TypeMismatchSubProcessor.createCastProposal(context, castType, nodeToCast, 6); >- String castTypeName= BindingLabelProvider.getBindingLabel(castType, JavaElementLabels.ALL_DEFAULT); >+ ITypeBinding castFixType= null; >+ if (binding == null || castType.isCastCompatible(binding)) { >+ castFixType= castType; >+ } else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) { >+ ITypeBinding boxUnboxedTypeBinding= TypeMismatchSubProcessor.boxUnboxPrimitives(castType, binding, nodeToCast.getAST()); >+ if (boxUnboxedTypeBinding != castType && boxUnboxedTypeBinding.isCastCompatible(binding)) { >+ castFixType= boxUnboxedTypeBinding; >+ } >+ } >+ if (castFixType != null) { >+ ASTRewriteCorrectionProposal proposal= TypeMismatchSubProcessor.createCastProposal(context, castFixType, nodeToCast, 6); >+ String castTypeName= BindingLabelProvider.getBindingLabel(castFixType, JavaElementLabels.ALL_DEFAULT); > String[] arg= new String[] { getArgumentName(arguments, idx), castTypeName}; > proposal.setDisplayName(Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addargumentcast_description, arg)); > proposals.add(proposal); > } >+ > TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, nodeToCast, castType, false, 5, proposals); > } > } >+ > if (nDiffs == 2) { // try to swap > int idx1= indexOfDiff[0]; > int idx2= indexOfDiff[1]; >Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java,v >retrieving revision 1.83 >diff -u -r1.83 CorrectionMessages.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 26 May 2009 13:37:18 -0000 1.83 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 6 Aug 2009 19:04:31 -0000 >@@ -108,7 +108,6 @@ > public static String LocalCorrectionsSubProcessor_setparenteses_instanceof_description; > public static String LocalCorrectionsSubProcessor_InferGenericTypeArguments; > public static String LocalCorrectionsSubProcessor_InferGenericTypeArguments_description; >- public static String TypeMismatchSubProcessor_0; > public static String TypeMismatchSubProcessor_addcast_description; > public static String TypeMismatchSubProcessor_changecast_description; > public static String TypeMismatchSubProcessor_changereturntype_description; >Index: ui/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchSubProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchSubProcessor.java,v >retrieving revision 1.47 >diff -u -r1.47 TypeMismatchSubProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchSubProcessor.java 6 Aug 2009 16:02:18 -0000 1.47 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchSubProcessor.java 6 Aug 2009 19:04:31 -0000 >@@ -47,6 +47,7 @@ > > import org.eclipse.jdt.internal.corext.dom.ASTNodes; > import org.eclipse.jdt.internal.corext.dom.Bindings; >+import org.eclipse.jdt.internal.corext.util.JavaModelUtil; > import org.eclipse.jdt.internal.corext.util.Messages; > > import org.eclipse.jdt.ui.JavaElementLabels; >@@ -125,15 +126,23 @@ > return; > } > >+ ITypeBinding currBinding= nodeToCast.resolveTypeBinding(); >+ > if (!(nodeToCast instanceof ArrayInitializer)) { >- ITypeBinding binding= nodeToCast.resolveTypeBinding(); >- if (binding == null || binding.isCastCompatible(castTypeBinding) || nodeToCast instanceof CastExpression) { >- proposals.add(createCastProposal(context, castTypeBinding, nodeToCast, 7)); >+ ITypeBinding castFixType= null; >+ if (currBinding == null || castTypeBinding.isCastCompatible(currBinding) || nodeToCast instanceof CastExpression) { >+ castFixType= castTypeBinding; >+ } else if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) { >+ ITypeBinding boxUnboxedTypeBinding= boxUnboxPrimitives(castTypeBinding, currBinding, ast); >+ if (boxUnboxedTypeBinding != castTypeBinding && boxUnboxedTypeBinding.isCastCompatible(currBinding)) { >+ castFixType= boxUnboxedTypeBinding; >+ } >+ } >+ if (castFixType != null) { >+ proposals.add(createCastProposal(context, castFixType, nodeToCast, 7)); > } > } > >- ITypeBinding currBinding= nodeToCast.resolveTypeBinding(); >- > boolean nullOrVoid= currBinding == null || "void".equals(currBinding.getName()); //$NON-NLS-1$ > > // change method return statement to actual type >@@ -185,7 +194,7 @@ > > addChangeSenderTypeProposals(context, nodeToCast, castTypeBinding, false, 5, proposals); > >- if (castTypeBinding == ast.resolveWellKnownType(CorrectionMessages.TypeMismatchSubProcessor_0) && currBinding != null && !currBinding.isPrimitive() && !Bindings.isVoidType(currBinding)) { >+ if (castTypeBinding == ast.resolveWellKnownType("boolean") && currBinding != null && !currBinding.isPrimitive() && !Bindings.isVoidType(currBinding)) { //$NON-NLS-1$ > String label= CorrectionMessages.TypeMismatchSubProcessor_insertnullcheck_description; > Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); > ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); >@@ -201,6 +210,22 @@ > > } > >+ public static ITypeBinding boxUnboxPrimitives(ITypeBinding castType, ITypeBinding toCast, AST ast) { >+ /* >+ * e.g: >+ * void m(toCast var) { >+ * castType i= var; >+ * } >+ */ >+ if (castType.isPrimitive() && !toCast.isPrimitive()) { >+ return Bindings.getBoxedTypeBinding(castType, ast); >+ } else if (!castType.isPrimitive() && toCast.isPrimitive()) { >+ return Bindings.getUnboxedTypeBinding(castType, ast); >+ } else { >+ return castType; >+ } >+ } >+ > public static void addChangeSenderTypeProposals(IInvocationContext context, Expression nodeToCast, ITypeBinding castTypeBinding, boolean isAssignedNode, int relevance, Collection proposals) throws JavaModelException { > IBinding callerBinding= Bindings.resolveExpressionBinding(nodeToCast, false); > >@@ -264,9 +289,7 @@ > ICompilationUnit cu= context.getCompilationUnit(); > > String label; >- ITypeBinding toCastBinding= nodeToCast.resolveTypeBinding(); >- ITypeBinding resultingTypeBinding= CastCorrectionProposal.getBoxedTypeBindingIfNeeded(castTypeBinding, toCastBinding, nodeToCast.getAST()); >- String castType= BindingLabelProvider.getBindingLabel(resultingTypeBinding, JavaElementLabels.ALL_DEFAULT); >+ String castType= BindingLabelProvider.getBindingLabel(castTypeBinding, JavaElementLabels.ALL_DEFAULT); > if (nodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) { > label= Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changecast_description, castType); > } else { >Index: core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java,v >retrieving revision 1.136 >diff -u -r1.136 Bindings.java >--- core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java 14 Nov 2008 13:01:57 -0000 1.136 >+++ core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java 6 Aug 2009 19:04:31 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 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 >@@ -1288,6 +1288,55 @@ > } > > /** >+ * Returns the unboxed type binding according to JLS3 5.1.7, or the original binding if >+ * the given type is not a boxed type. >+ * >+ * @param type a type binding >+ * @param ast an AST to resolve the unboxed type >+ * @return the unboxed type, or the original type if no unboxed type found >+ */ >+ public static ITypeBinding getUnboxedTypeBinding(ITypeBinding type, AST ast) { >+ if (!type.isClass()) >+ return type; >+ String unboxedTypeName= getUnboxedTypeName(type.getQualifiedName()); >+ if (unboxedTypeName == null) >+ return type; >+ ITypeBinding unboxed= ast.resolveWellKnownType(unboxedTypeName); >+ if (unboxed == null) >+ return type; >+ return unboxed; >+ } >+ >+ private static String getUnboxedTypeName(String boxedName) { >+ if ("java.lang.Long".equals(boxedName)) //$NON-NLS-1$ >+ return "long"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Integer".equals(boxedName)) //$NON-NLS-1$ >+ return "int"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Short".equals(boxedName)) //$NON-NLS-1$ >+ return "short"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Character".equals(boxedName)) //$NON-NLS-1$ >+ return "char"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Byte".equals(boxedName)) //$NON-NLS-1$ >+ return "byte"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Boolean".equals(boxedName)) //$NON-NLS-1$ >+ return "boolean"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Float".equals(boxedName)) //$NON-NLS-1$ >+ return "float"; //$NON-NLS-1$ >+ >+ else if ("java.lang.Double".equals(boxedName)) //$NON-NLS-1$ >+ return "double"; //$NON-NLS-1$ >+ >+ else >+ return null; >+ } >+ >+ /** > * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression > * (e.g. nested in parentheses, cast, ...). > * >Index: ui/org/eclipse/jdt/internal/ui/text/correction/proposals/CastCorrectionProposal.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/CastCorrectionProposal.java,v >retrieving revision 1.4 >diff -u -r1.4 CastCorrectionProposal.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/proposals/CastCorrectionProposal.java 6 Aug 2009 16:10:54 -0000 1.4 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/proposals/CastCorrectionProposal.java 6 Aug 2009 19:04:31 -0000 >@@ -32,7 +32,6 @@ > import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; > > import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; >-import org.eclipse.jdt.internal.corext.dom.Bindings; > > import org.eclipse.jdt.internal.ui.JavaPluginImages; > import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; >@@ -44,6 +43,15 @@ > private final Expression fNodeToCast; > private final ITypeBinding fCastType; > >+ /** >+ * Creates a cast correction proposal. >+ * >+ * @param label the display name of the proposal >+ * @param targetCU the compilation unit that is modified >+ * @param nodeToCast the node to cast >+ * @param castType the type to cast to, may be <code>null</code> >+ * @param relevance the relevance of this proposal >+ */ > public CastCorrectionProposal(String label, ICompilationUnit targetCU, Expression nodeToCast, ITypeBinding castType, int relevance) { > super(label, targetCU, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST)); > fNodeToCast= nodeToCast; >@@ -51,24 +59,13 @@ > setCommandId(ADD_CAST_ID); > } > >- public static ITypeBinding getBoxedTypeBindingIfNeeded(ITypeBinding castType, ITypeBinding toCast, AST ast) { >- // e.g: m(toCast var) { castType i= var; } >- if (castType.isPrimitive() && !toCast.isPrimitive()) { >- ITypeBinding boxedTypeBinding= Bindings.getBoxedTypeBinding(castType, ast); >- return boxedTypeBinding; >- } else { >- return castType; >- } >- } >- > private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) { > AST ast= rewrite.getAST(); > > ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite); > >- ITypeBinding nodeToCastBinding= fNodeToCast.resolveTypeBinding(); > if (fCastType != null) { >- return importRewrite.addImport(getBoxedTypeBindingIfNeeded(fCastType, nodeToCastBinding, ast), ast,context); >+ return importRewrite.addImport(fCastType, ast,context); > } > > ASTNode node= fNodeToCast; >@@ -87,7 +84,7 @@ > IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node); > ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext); > if (bindings.length > 0) { >- ITypeBinding first= getCastFavorite(bindings, nodeToCastBinding); >+ ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding()); > > Type newTypeNode= importRewrite.addImport(first, ast, context); > addLinkedPosition(rewrite.track(newTypeNode), true, "casttype"); //$NON-NLS-1$ >#P org.eclipse.jdt.ui.tests >Index: ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java,v >retrieving revision 1.71 >diff -u -r1.71 UnresolvedMethodsQuickFixTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java 20 Feb 2009 15:17:52 -0000 1.71 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java 6 Aug 2009 19:04:36 -0000 >@@ -1802,6 +1802,67 @@ > assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 }); > } > >+ public void testParameterMismatchCastBoxing() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer i) {\n"); >+ buf.append(" foo(1.0);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu1); >+ ArrayList proposals= collectCorrections(cu1, astRoot); >+ assertNumberOfProposals(proposals, 3); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); >+ String preview1= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer i) {\n"); >+ buf.append(" foo((int) 1.0);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ proposal= (CUCorrectionProposal) proposals.get(1); >+ String preview2= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer i) {\n"); >+ buf.append(" foo(1.0);\n"); >+ buf.append(" }\n"); >+ buf.append("\n"); >+ buf.append(" private void foo(double d) {\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected2= buf.toString(); >+ >+ proposal= (CUCorrectionProposal) proposals.get(2); >+ String preview3= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(double d) {\n"); >+ buf.append(" foo(1.0);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected3= buf.toString(); >+ >+ >+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 }); >+ } >+ > public void testParameterMismatchChangeVarType() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer();
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 285573
: 143705