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 7404 Details for
Bug 37643
[quick assist] convert == to equals() and vice versa
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
fix
37643.txt (text/plain), 6.62 KB, created by
Sebastian Davids
on 2004-01-12 04:57:36 EST
(
hide
)
Description:
fix
Filename:
MIME Type:
Creator:
Sebastian Davids
Created:
2004-01-12 04:57:36 EST
Size:
6.62 KB
patch
obsolete
>Index: CorrectionMessages.properties >=================================================================== >retrieving revision 1.103 >diff -u -r1.103 CorrectionMessages.properties >--- CorrectionMessages.properties 8 Jan 2004 17:37:43 -0000 1.103 >+++ CorrectionMessages.properties 12 Jan 2004 09:49:19 -0000 >@@ -188,6 +188,9 @@ > > QuickAssistProcessor.invertequals.description=Invert equals > >+QuickAssistProcessor.replaceequalswithsame.description=Change equals to == >+QuickAssistProcessor.replacesamewithequals.description=Change == to equals >+ > LinkedNamesAssistProposal.proposalinfo=Link all references for a local rename (does not change references in other files) > LinkedNamesAssistProposal.description=Local Rename > >Index: QuickAssistProcessor.java >=================================================================== >retrieving revision 1.38 >diff -u -r1.38 QuickAssistProcessor.java >--- QuickAssistProcessor.java 9 Jan 2004 14:21:36 -0000 1.38 >+++ QuickAssistProcessor.java 12 Jan 2004 09:49:20 -0000 >@@ -7,7 +7,8 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Sebastian Davids <sdavids@gmx.de> - Bug 37432 getInvertEqualsProposal >+ * Sebastian Davids <sdavids@gmx.de> - Bug 37432 getInvertEqualsProposal, >+ * bug 37643 getChangeEqualsToSame, getChangeSameToEquals > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -58,7 +59,9 @@ > || getAddElseProposals(context, coveringNode, null) > || getSplitVariableProposals(context, coveringNode, null) > || getAddBlockProposals(context, coveringNode, null) >- || getInvertEqualsProposal(context, coveringNode, null); >+ || getInvertEqualsProposal(context, coveringNode, null) >+ || getChangeEqualsToSameProposal(context, coveringNode, null) >+ || getChangeSameToEqualsProposal(context, coveringNode, null); > } > return false; > } >@@ -85,6 +88,8 @@ > getAddElseProposals(context, coveringNode, resultingCollections); > getAddBlockProposals(context, coveringNode, resultingCollections); > getInvertEqualsProposal(context, coveringNode, resultingCollections); >+ getChangeEqualsToSameProposal(context, coveringNode, resultingCollections); >+ getChangeSameToEqualsProposal(context, coveringNode, resultingCollections); > } > return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); > } >@@ -756,4 +761,84 @@ > resultingCollections.add(proposal); > return true; > } >+ >+ private boolean getChangeEqualsToSameProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) throws CoreException { >+ ASTNode parent= node.getParent(); >+ if (!(parent instanceof MethodInvocation)) { >+ return false; >+ } >+ MethodInvocation method= (MethodInvocation) parent; >+ if (!"equals".equals(method.getName().getIdentifier())) { //$NON-NLS-1$ >+ return false; >+ } >+ List arguments= method.arguments(); >+ if (arguments.size() != 1) { //overloaded equals w/ more than 1 arg >+ return false; >+ } >+ Expression right= (Expression) arguments.get(0); >+ ITypeBinding binding = right.resolveTypeBinding(); >+ if (!(binding.isClass() || binding.isInterface() || binding.isNullType())) { //overloaded equals w/ non-class/interface arg >+ return false; >+ } >+ Expression left= method.getExpression(); >+ if (!(right instanceof NullLiteral)) { >+ System.out.println(binding.getQualifiedName()+":"+left.resolveTypeBinding().getQualifiedName()); >+ if (!binding.getQualifiedName().equals(left.resolveTypeBinding().getQualifiedName())) { >+ return false; >+ } >+ } >+ >+ ASTRewrite rewrite= new ASTRewrite(method.getParent()); >+ AST ast= rewrite.getAST(); >+ InfixExpression replacement= ast.newInfixExpression(); >+ replacement.setLeftOperand((left == null) ? ast.newThisExpression() : (Expression) rewrite.createCopy(left)); >+ replacement.setRightOperand((Expression) rewrite.createCopy(right)); >+ replacement.setOperator(InfixExpression.Operator.EQUALS); >+ rewrite.markAsReplaced(method, replacement); >+ >+ String label= CorrectionMessages.getString("QuickAssistProcessor.replaceequalswithsame.description"); //$NON-NLS-1$ >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ >+ LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); >+ proposal.ensureNoModifications(); >+ resultingCollections.add(proposal); >+ return true; >+ } >+ >+ private boolean getChangeSameToEqualsProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) throws CoreException { >+ if (!(node instanceof InfixExpression)) { >+ return false; >+ } >+ InfixExpression same= (InfixExpression) node; >+ if (!same.getOperator().equals(InfixExpression.Operator.EQUALS)) { >+ return false; >+ } >+ Expression right= same.getRightOperand(); >+ ITypeBinding binding = right.resolveTypeBinding(); >+ if (!(binding.isClass() || binding.isInterface() || binding.isNullType())) { >+ return false; >+ } >+ Expression left= same.getLeftOperand(); >+ if (left instanceof NullLiteral) { >+ return false; >+ } >+ >+ ASTRewrite rewrite= new ASTRewrite(same.getParent()); >+ AST ast= rewrite.getAST(); >+ MethodInvocation replacement= ast.newMethodInvocation(); >+ if (!(left instanceof ThisExpression)) { >+ replacement.setExpression((Expression) rewrite.createCopy(left)); >+ } >+ replacement.arguments().add(rewrite.createCopy(right)); >+ replacement.setName(ast.newSimpleName("equals"));//$NON-NLS-1$ >+ rewrite.markAsReplaced(same, replacement); >+ >+ String label= CorrectionMessages.getString("QuickAssistProcessor.replacesamewithequals.description"); //$NON-NLS-1$ >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ >+ LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); >+ proposal.ensureNoModifications(); >+ resultingCollections.add(proposal); >+ return true; >+ } > }
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 37643
:
7404
|
7405
|
7406