本文整理汇总了Java中org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal类的典型用法代码示例。如果您正苦于以下问题:Java ASTRewriteCorrectionProposal类的具体用法?Java ASTRewriteCorrectionProposal怎么用?Java ASTRewriteCorrectionProposal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ASTRewriteCorrectionProposal类属于org.eclipse.jdt.ui.text.java.correction包,在下文中一共展示了ASTRewriteCorrectionProposal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRedundantSuperInterfaceProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void addRedundantSuperInterfaceProposal(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof Name)) {
return;
}
ASTNode node = ASTNodes.getNormalizedNode(selectedNode);
ASTRewrite rewrite = ASTRewrite.create(node.getAST());
rewrite.remove(node, null);
String label = CorrectionMessages.LocalCorrectionsSubProcessor_remove_redundant_superinterface;
Image image =
JavaPluginImages.get(
JavaPluginImages
.IMG_TOOL_DELETE); // JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
rewrite,
IProposalRelevance.REMOVE_REDUNDANT_SUPER_INTERFACE,
image);
proposals.add(proposal);
}
示例2: createNoSideEffectProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
private static ASTRewriteCorrectionProposal createNoSideEffectProposal(
IInvocationContext context,
SimpleName nodeToQualify,
IVariableBinding fieldBinding,
String label,
int relevance) {
AST ast = nodeToQualify.getAST();
Expression qualifier;
if (Modifier.isStatic(fieldBinding.getModifiers())) {
ITypeBinding declaringClass = fieldBinding.getDeclaringClass();
qualifier = ast.newSimpleName(declaringClass.getTypeDeclaration().getName());
} else {
qualifier = ast.newThisExpression();
}
ASTRewrite rewrite = ASTRewrite.create(ast);
FieldAccess access = ast.newFieldAccess();
access.setName((SimpleName) rewrite.createCopyTarget(nodeToQualify));
access.setExpression(qualifier);
rewrite.replace(nodeToQualify, access, null);
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
return new ASTRewriteCorrectionProposal(
label, context.getCompilationUnit(), rewrite, relevance, image);
}
示例3: createMissingDefaultProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
private static void createMissingDefaultProposal(
IInvocationContext context,
SwitchStatement switchStatement,
Image image,
Collection<ICommandAccess> proposals) {
AST ast = switchStatement.getAST();
ASTRewrite astRewrite = ASTRewrite.create(ast);
ListRewrite listRewrite =
astRewrite.getListRewrite(switchStatement, SwitchStatement.STATEMENTS_PROPERTY);
SwitchCase newSwitchCase = ast.newSwitchCase();
newSwitchCase.setExpression(null);
listRewrite.insertLast(newSwitchCase, null);
listRewrite.insertLast(ast.newBreakStatement(), null);
String label = CorrectionMessages.LocalCorrectionsSubProcessor_add_default_case_description;
proposals.add(
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
astRewrite,
IProposalRelevance.ADD_MISSING_DEFAULT_CASE,
image));
}
示例4: createCastProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static ASTRewriteCorrectionProposal createCastProposal(
IInvocationContext context,
ITypeBinding castTypeBinding,
Expression nodeToCast,
int relevance) {
ICompilationUnit cu = context.getCompilationUnit();
String label;
String castType =
BindingLabelProvider.getBindingLabel(castTypeBinding, JavaElementLabels.ALL_DEFAULT);
if (nodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) {
label =
Messages.format(
CorrectionMessages.TypeMismatchSubProcessor_changecast_description, castType);
} else {
label =
Messages.format(
CorrectionMessages.TypeMismatchSubProcessor_addcast_description, castType);
}
return new CastCorrectionProposal(label, cu, nodeToCast, castTypeBinding, relevance);
}
示例5: removeOverrideAnnotationProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void removeOverrideAnnotationProposal(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof MethodDeclaration)) {
return;
}
MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
Annotation annot = findAnnotation("java.lang.Override", methodDecl.modifiers()); // $NON-NLS-1$
if (annot != null) {
ASTRewrite rewrite = ASTRewrite.create(annot.getAST());
rewrite.remove(annot, null);
String label = CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
proposals.add(proposal);
QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
}
}
示例6: removeMismatchedArguments
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void removeMismatchedArguments(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveredNode(context.getASTRoot());
if (!(selectedNode instanceof SimpleName)) {
return;
}
ASTNode normalizedNode = ASTNodes.getNormalizedNode(selectedNode);
if (normalizedNode instanceof ParameterizedType) {
ASTRewrite rewrite = ASTRewrite.create(normalizedNode.getAST());
ParameterizedType pt = (ParameterizedType) normalizedNode;
ASTNode mt = rewrite.createMoveTarget(pt.getType());
rewrite.replace(pt, mt, null);
String label = CorrectionMessages.TypeArgumentMismatchSubProcessor_removeTypeArguments;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label, cu, rewrite, IProposalRelevance.REMOVE_TYPE_ARGUMENTS, image);
proposals.add(proposal);
}
}
示例7: addMethodWithConstrNameProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void addMethodWithConstrNameProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof MethodDeclaration) {
MethodDeclaration declaration = (MethodDeclaration) selectedNode;
ASTRewrite rewrite = ASTRewrite.create(declaration.getAST());
rewrite.set(declaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.TRUE, null);
String label = CorrectionMessages.ReturnTypeSubProcessor_constrnamemethod_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label, cu, rewrite, IProposalRelevance.CHANGE_TO_CONSTRUCTOR, image);
proposals.add(proposal);
}
}
示例8: createTypeRefChangeFullProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
static CUCorrectionProposal createTypeRefChangeFullProposal(
ICompilationUnit cu, ITypeBinding binding, ASTNode node, int relevance) {
ASTRewrite rewrite = ASTRewrite.create(node.getAST());
String label =
Messages.format(
CorrectionMessages.UnresolvedElementsSubProcessor_change_full_type_description,
BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_DEFAULT));
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(label, cu, rewrite, relevance, image);
ImportRewrite imports = proposal.createImportRewrite((CompilationUnit) node.getRoot());
Type type = imports.addImport(binding, node.getAST());
rewrite.replace(node, type, null);
return proposal;
}
示例9: getRemoveJavadocTagProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void getRemoveJavadocTagProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
while (node != null && !(node instanceof TagElement)) {
node = node.getParent();
}
if (node == null) {
return;
}
ASTRewrite rewrite = ASTRewrite.create(node.getAST());
rewrite.remove(node, null);
String label = CorrectionMessages.JavadocTagsSubProcessor_removetag_description;
Image image =
JavaPluginImages.get(
JavaPluginImages
.IMG_TOOL_DELETE); // JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
proposals.add(
new ASTRewriteCorrectionProposal(
label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG, image));
}
示例10: addRedundantSuperInterfaceProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void addRedundantSuperInterfaceProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof Name)) {
return;
}
ASTNode node= ASTNodes.getNormalizedNode(selectedNode);
ASTRewrite rewrite= ASTRewrite.create(node.getAST());
rewrite.remove(node, null);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_remove_redundant_superinterface;
Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_REDUNDANT_SUPER_INTERFACE, image);
proposals.add(proposal);
}
示例11: createNoSideEffectProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
private static ASTRewriteCorrectionProposal createNoSideEffectProposal(IInvocationContext context, SimpleName nodeToQualify, IVariableBinding fieldBinding, String label, int relevance) {
AST ast= nodeToQualify.getAST();
Expression qualifier;
if (Modifier.isStatic(fieldBinding.getModifiers())) {
ITypeBinding declaringClass= fieldBinding.getDeclaringClass();
qualifier= ast.newSimpleName(declaringClass.getTypeDeclaration().getName());
} else {
qualifier= ast.newThisExpression();
}
ASTRewrite rewrite= ASTRewrite.create(ast);
FieldAccess access= ast.newFieldAccess();
access.setName((SimpleName) rewrite.createCopyTarget(nodeToQualify));
access.setExpression(qualifier);
rewrite.replace(nodeToQualify, access, null);
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
return new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, relevance, image);
}
示例12: addCasesOmittedProposals
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) {
AST ast= selectedNode.getAST();
SwitchStatement parent= (SwitchStatement) selectedNode.getParent();
for (Statement statement : (List<Statement>) parent.statements()) {
if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) {
// insert //$CASES-OMITTED$:
ASTRewrite rewrite= ASTRewrite.create(ast);
rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
ASTNode casesOmittedComment= rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
listRewrite.insertBefore(casesOmittedComment, statement, null);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED, image);
proposals.add(proposal);
break;
}
}
}
}
示例13: removeOverrideAnnotationProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu= context.getCompilationUnit();
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof MethodDeclaration)) {
return;
}
MethodDeclaration methodDecl= (MethodDeclaration) selectedNode;
Annotation annot= findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$
if (annot != null) {
ASTRewrite rewrite= ASTRewrite.create(annot.getAST());
rewrite.remove(annot, null);
String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image);
proposals.add(proposal);
QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ModifierCorrectionSubProcessor.java
示例14: addGetterProposal
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
/**
* Proposes a getter for this field.
*
* @param context the proposal parameter
* @param relevance relevance of this proposal
* @return the proposal if available or null
*/
private static ChangeCorrectionProposal addGetterProposal(ProposalParameter context, int relevance) {
IMethodBinding method= findGetter(context);
if (method != null) {
Expression mi= createMethodInvocation(context, method, null);
context.astRewrite.replace(context.accessNode, mi, null);
String label= Messages.format(CorrectionMessages.GetterSetterCorrectionSubProcessor_replacewithgetter_description, BasicElementLabels.getJavaCodeString(ASTNodes.asString(context.accessNode)));
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.compilationUnit, context.astRewrite, relevance, image);
return proposal;
} else {
IJavaElement element= context.variableBinding.getJavaElement();
if (element instanceof IField) {
IField field= (IField) element;
try {
if (RefactoringAvailabilityTester.isSelfEncapsulateAvailable(field))
return new SelfEncapsulateFieldProposal(relevance, field);
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
}
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:GetterSetterCorrectionSubProcessor.java
示例15: removeMismatchedArguments
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal; //导入依赖的package包/类
public static void removeMismatchedArguments(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals){
ICompilationUnit cu= context.getCompilationUnit();
ASTNode selectedNode= problem.getCoveredNode(context.getASTRoot());
if (!(selectedNode instanceof SimpleName)) {
return;
}
ASTNode normalizedNode=ASTNodes.getNormalizedNode(selectedNode);
if (normalizedNode instanceof ParameterizedType) {
ASTRewrite rewrite = ASTRewrite.create(normalizedNode.getAST());
ParameterizedType pt = (ParameterizedType) normalizedNode;
ASTNode mt = rewrite.createMoveTarget(pt.getType());
rewrite.replace(pt, mt, null);
String label= CorrectionMessages.TypeArgumentMismatchSubProcessor_removeTypeArguments;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_TYPE_ARGUMENTS, image);
proposals.add(proposal);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:TypeArgumentMismatchSubProcessor.java