|
Lines 27-32
Link Here
|
| 27 |
import org.eclipse.jdt.core.ICompilationUnit; |
27 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 28 |
import org.eclipse.jdt.core.dom.AST; |
28 |
import org.eclipse.jdt.core.dom.AST; |
| 29 |
import org.eclipse.jdt.core.dom.ASTNode; |
29 |
import org.eclipse.jdt.core.dom.ASTNode; |
|
|
30 |
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; |
| 30 |
import org.eclipse.jdt.core.dom.Assignment; |
31 |
import org.eclipse.jdt.core.dom.Assignment; |
| 31 |
import org.eclipse.jdt.core.dom.Block; |
32 |
import org.eclipse.jdt.core.dom.Block; |
| 32 |
import org.eclipse.jdt.core.dom.BooleanLiteral; |
33 |
import org.eclipse.jdt.core.dom.BooleanLiteral; |
|
Lines 55-62
Link Here
|
| 55 |
import org.eclipse.jdt.core.dom.PrefixExpression; |
56 |
import org.eclipse.jdt.core.dom.PrefixExpression; |
| 56 |
import org.eclipse.jdt.core.dom.PrimitiveType; |
57 |
import org.eclipse.jdt.core.dom.PrimitiveType; |
| 57 |
import org.eclipse.jdt.core.dom.QualifiedName; |
58 |
import org.eclipse.jdt.core.dom.QualifiedName; |
|
|
59 |
import org.eclipse.jdt.core.dom.QualifiedType; |
| 58 |
import org.eclipse.jdt.core.dom.ReturnStatement; |
60 |
import org.eclipse.jdt.core.dom.ReturnStatement; |
| 59 |
import org.eclipse.jdt.core.dom.SimpleName; |
61 |
import org.eclipse.jdt.core.dom.SimpleName; |
|
|
62 |
import org.eclipse.jdt.core.dom.SimpleType; |
| 60 |
import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
63 |
import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
| 61 |
import org.eclipse.jdt.core.dom.Statement; |
64 |
import org.eclipse.jdt.core.dom.Statement; |
| 62 |
import org.eclipse.jdt.core.dom.StringLiteral; |
65 |
import org.eclipse.jdt.core.dom.StringLiteral; |
|
Lines 123-129
Link Here
|
| 123 |
|| getReplaceIfElseWithConditionalProposals(context, coveringNode, null) || getReplaceConditionalWithIfElseProposals(context, coveringNode, null) |
126 |
|| getReplaceIfElseWithConditionalProposals(context, coveringNode, null) || getReplaceConditionalWithIfElseProposals(context, coveringNode, null) |
| 124 |
|| getInverseLocalVariableProposals(context, coveringNode, null) || getPushNegationDownProposals(context, coveringNode, null) |
127 |
|| getInverseLocalVariableProposals(context, coveringNode, null) || getPushNegationDownProposals(context, coveringNode, null) |
| 125 |
|| getPullNegationUpProposals(context, coveredNodes, null) || getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null) |
128 |
|| getPullNegationUpProposals(context, coveredNodes, null) || getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null) |
| 126 |
|| getConvertSwitchToIfProposals(context, coveringNode, null) || GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null); |
129 |
|| getConvertSwitchToIfProposals(context, coveringNode, null) || GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null) |
|
|
130 |
|| getQualifyTypenameProposals(context, coveringNode, null); |
| 127 |
} |
131 |
} |
| 128 |
return false; |
132 |
return false; |
| 129 |
} |
133 |
} |
|
Lines 161-166
Link Here
|
| 161 |
getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections); |
165 |
getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections); |
| 162 |
getConvertSwitchToIfProposals(context, coveringNode, resultingCollections); |
166 |
getConvertSwitchToIfProposals(context, coveringNode, resultingCollections); |
| 163 |
GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections); |
167 |
GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections); |
|
|
168 |
getQualifyTypenameProposals(context, coveringNode, resultingCollections); |
| 164 |
} |
169 |
} |
| 165 |
|
170 |
|
| 166 |
return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); |
171 |
return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); |
|
Lines 785-790
Link Here
|
| 785 |
return parenthesizedExpression; |
790 |
return parenthesizedExpression; |
| 786 |
} |
791 |
} |
| 787 |
|
792 |
|
|
|
793 |
private static boolean getQualifyTypenameProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { |
| 794 |
if (!(node instanceof SimpleName)) |
| 795 |
return false; |
| 796 |
SimpleName simpleName = (SimpleName) node; |
| 797 |
ASTNode parent= simpleName.getParent(); |
| 798 |
// part of a qualified name |
| 799 |
if (parent instanceof Name) |
| 800 |
return false; |
| 801 |
// part of a qualified type |
| 802 |
if (parent instanceof SimpleType |
| 803 |
&& ((SimpleType)parent).getParent() instanceof QualifiedType |
| 804 |
&& ((QualifiedType)((SimpleType)parent).getParent()).getName() == parent |
| 805 |
|| parent instanceof QualifiedType |
| 806 |
&& ((QualifiedType)parent).getName() == simpleName) |
| 807 |
return false; |
| 808 |
if (parent instanceof AbstractTypeDeclaration |
| 809 |
&& ((AbstractTypeDeclaration)parent).getName() == simpleName) |
| 810 |
return false; |
| 811 |
IBinding binding= simpleName.resolveBinding(); |
| 812 |
if (!(binding instanceof ITypeBinding)) |
| 813 |
return false; |
| 814 |
ITypeBinding typeBinding= (ITypeBinding) binding; |
| 815 |
if (typeBinding.isArray()) |
| 816 |
typeBinding= typeBinding.getElementType(); |
| 817 |
if (typeBinding == null) |
| 818 |
return false; |
| 819 |
// no local type !!! |
| 820 |
if (typeBinding.isPrimitive() || typeBinding.isNullType() |
| 821 |
|| typeBinding.isAnonymous() || typeBinding.isLocal()) |
| 822 |
return false; |
| 823 |
if (typeBinding.isGenericType() || typeBinding.isTypeVariable()) |
| 824 |
return false; |
| 825 |
// we only want to add "left" information |
| 826 |
String pkg= typeBinding.getPackage().getName(); |
| 827 |
if (pkg.length() == 0) |
| 828 |
return false; |
| 829 |
if (resultingCollections == null) { |
| 830 |
return true; |
| 831 |
} |
| 832 |
StringBuffer buf = new StringBuffer(); |
| 833 |
if (typeBinding.getDeclaringClass() != null) |
| 834 |
buf.append(typeBinding.getDeclaringClass().getQualifiedName()); |
| 835 |
else |
| 836 |
buf.append(pkg); |
| 837 |
buf.append('.'); |
| 838 |
if (typeBinding.isParameterizedType()) |
| 839 |
buf.append(typeBinding.getErasure().getName()); |
| 840 |
else |
| 841 |
buf.append(typeBinding.getName()); |
| 842 |
String qn= buf.toString(); |
| 843 |
AST ast = simpleName.getAST(); |
| 844 |
ASTRewrite rewrite= ASTRewrite.create(ast); |
| 845 |
ASTNode newQName= rewrite.createStringPlaceholder(qn, ASTNode.QUALIFIED_NAME); |
| 846 |
rewrite.replace(simpleName, newQName, null); |
| 847 |
// add correction proposal |
| 848 |
String label= CorrectionMessages.AdvancedQuickAssistProcessor_qualifyTypename_description; |
| 849 |
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); |
| 850 |
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); |
| 851 |
resultingCollections.add(proposal); |
| 852 |
return true; |
| 853 |
} |
| 854 |
|
| 788 |
private static boolean getSplitAndConditionProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { |
855 |
private static boolean getSplitAndConditionProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { |
| 789 |
Operator andOperator= InfixExpression.Operator.CONDITIONAL_AND; |
856 |
Operator andOperator= InfixExpression.Operator.CONDITIONAL_AND; |
| 790 |
// check that user invokes quick assist on infix expression |
857 |
// check that user invokes quick assist on infix expression |