|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2003 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2004 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 Common Public License v1.0 |
4 |
* are made available under the terms of the Common Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Sebastian Davids <sdavids@gmx.de> - Bug 37432 getInvertEqualsProposal |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.ui.text.correction; |
12 |
package org.eclipse.jdt.internal.ui.text.correction; |
| 12 |
|
13 |
|
|
Lines 56-62
Link Here
|
| 56 |
|| getAddFinallyProposals(context, coveringNode, null) |
57 |
|| getAddFinallyProposals(context, coveringNode, null) |
| 57 |
|| getAddElseProposals(context, coveringNode, null) |
58 |
|| getAddElseProposals(context, coveringNode, null) |
| 58 |
|| getSplitVariableProposals(context, coveringNode, null) |
59 |
|| getSplitVariableProposals(context, coveringNode, null) |
| 59 |
|| getAddBlockProposals(context, coveringNode, null); |
60 |
|| getAddBlockProposals(context, coveringNode, null) |
|
|
61 |
|| getInvertEqualsProposal(context, coveringNode, null); |
| 60 |
} |
62 |
} |
| 61 |
return false; |
63 |
return false; |
| 62 |
} |
64 |
} |
|
Lines 82-87
Link Here
|
| 82 |
getAddFinallyProposals(context, coveringNode, resultingCollections); |
84 |
getAddFinallyProposals(context, coveringNode, resultingCollections); |
| 83 |
getAddElseProposals(context, coveringNode, resultingCollections); |
85 |
getAddElseProposals(context, coveringNode, resultingCollections); |
| 84 |
getAddBlockProposals(context, coveringNode, resultingCollections); |
86 |
getAddBlockProposals(context, coveringNode, resultingCollections); |
|
|
87 |
getInvertEqualsProposal(context, coveringNode, resultingCollections); |
| 85 |
} |
88 |
} |
| 86 |
return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); |
89 |
return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); |
| 87 |
} |
90 |
} |
|
Lines 690-695
Link Here
|
| 690 |
return true; |
693 |
return true; |
| 691 |
} |
694 |
} |
| 692 |
|
695 |
|
| 693 |
|
696 |
private boolean getInvertEqualsProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) throws CoreException { |
| 694 |
|
697 |
ASTNode parent= node.getParent(); |
|
|
698 |
if (!(parent instanceof MethodInvocation)) { |
| 699 |
return false; |
| 700 |
} |
| 701 |
MethodInvocation method= (MethodInvocation) parent; |
| 702 |
if (!"equals".equals(method.getName().getIdentifier())) { //$NON-NLS-1$ |
| 703 |
return false; |
| 704 |
} |
| 705 |
Expression left= method.getExpression(); //always non-null |
| 706 |
List arguments= method.arguments(); |
| 707 |
if (arguments.size() != 1) { //overloaded equals w/ more than 1 arg |
| 708 |
return false; |
| 709 |
} |
| 710 |
Expression right= (Expression) arguments.get(0); |
| 711 |
ITypeBinding binding = right.resolveTypeBinding(); |
| 712 |
if (!(binding.isClass() || binding.isInterface())) { //overloaded equals w/ non-class/interface arg |
| 713 |
return false; |
| 714 |
} |
| 715 |
|
| 716 |
ASTRewrite rewrite= new ASTRewrite(method); |
| 717 |
|
| 718 |
if (left instanceof ParenthesizedExpression) { |
| 719 |
Expression ex = ((ParenthesizedExpression) left).getExpression(); |
| 720 |
rewrite.markAsReplaced(right, rewrite.createCopy(ex)); |
| 721 |
} else { |
| 722 |
rewrite.markAsReplaced(right, left); |
| 723 |
} |
| 724 |
if ((right instanceof CastExpression) |
| 725 |
|| (right instanceof Assignment) |
| 726 |
|| (right instanceof ConditionalExpression) |
| 727 |
|| (right instanceof InfixExpression)) { |
| 728 |
ParenthesizedExpression paren = method.getAST().newParenthesizedExpression(); |
| 729 |
paren.setExpression((Expression) rewrite.createCopy(right)); |
| 730 |
rewrite.markAsReplaced(left, paren); |
| 731 |
} else { |
| 732 |
rewrite.markAsReplaced(left, right); |
| 733 |
} |
| 734 |
|
| 735 |
String label= CorrectionMessages.getString("QuickAssistProcessor.invertequals.description"); //$NON-NLS-1$ |
| 736 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); |
| 737 |
|
| 738 |
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); |
| 739 |
proposal.ensureNoModifications(); |
| 740 |
resultingCollections.add(proposal); |
| 741 |
return true; |
| 742 |
} |
| 695 |
} |
743 |
} |