use of org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal in project che by eclipse.
the class JavadocTagsSubProcessor method getMissingJavadocTagProposals.
public static void getMissingJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
node = ASTNodes.getNormalizedNode(node);
BodyDeclaration bodyDeclaration = ASTResolving.findParentBodyDeclaration(node);
if (bodyDeclaration == null) {
return;
}
Javadoc javadoc = bodyDeclaration.getJavadoc();
if (javadoc == null) {
return;
}
String label;
StructuralPropertyDescriptor location = node.getLocationInParent();
if (location == SingleVariableDeclaration.NAME_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
if (node.getParent().getLocationInParent() != MethodDeclaration.PARAMETERS_PROPERTY) {
// paranoia checks
return;
}
} else if (location == TypeParameter.NAME_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
StructuralPropertyDescriptor parentLocation = node.getParent().getLocationInParent();
if (parentLocation != MethodDeclaration.TYPE_PARAMETERS_PROPERTY && parentLocation != TypeDeclaration.TYPE_PARAMETERS_PROPERTY) {
// paranoia checks
return;
}
} else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_returntag_description;
} else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_throwstag_description;
} else {
return;
}
ASTRewriteCorrectionProposal proposal = new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDeclaration, node, IProposalRelevance.ADD_MISSING_TAG);
proposals.add(proposal);
String label2 = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description;
ASTRewriteCorrectionProposal addAllMissing = new AddAllMissingJavadocTagsProposal(label2, context.getCompilationUnit(), bodyDeclaration, IProposalRelevance.ADD_ALL_MISSING_TAGS);
proposals.add(addAllMissing);
}
use of org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal in project che by eclipse.
the class JavadocTagsSubProcessor method getInvalidQualificationProposals.
public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (!(node instanceof Name)) {
return;
}
Name name = (Name) node;
IBinding binding = name.resolveBinding();
if (!(binding instanceof ITypeBinding)) {
return;
}
ITypeBinding typeBinding = (ITypeBinding) binding;
AST ast = node.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null);
String label = CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME, image);
proposals.add(proposal);
}
use of org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal in project che by eclipse.
the class JavadocTagsSubProcessor method getRemoveJavadocTagProposals.
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;
//JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
Image image = JavaPluginImages.get(JavaPluginImages.IMG_TOOL_DELETE);
proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG, image));
}
use of org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal in project che by eclipse.
the class JavadocTagsSubProcessor method getUnusedAndUndocumentedParameterOrExceptionProposals.
public static void getUnusedAndUndocumentedParameterOrExceptionProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
IJavaProject project = cu.getJavaProject();
if (!JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true))) {
return;
}
int problemId = problem.getProblemId();
boolean isUnusedTypeParam = problemId == IProblem.UnusedTypeParameter;
boolean isUnusedParam = problemId == IProblem.ArgumentIsNeverUsed || isUnusedTypeParam;
String key = isUnusedParam ? JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE : JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE;
if (!JavaCore.ENABLED.equals(project.getOption(key, true))) {
return;
}
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
BodyDeclaration bodyDecl = ASTResolving.findParentBodyDeclaration(node);
if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) {
return;
}
String label;
if (isUnusedTypeParam) {
label = CorrectionMessages.JavadocTagsSubProcessor_document_type_parameter_description;
} else if (isUnusedParam) {
label = CorrectionMessages.JavadocTagsSubProcessor_document_parameter_description;
} else {
node = ASTNodes.getNormalizedNode(node);
label = CorrectionMessages.JavadocTagsSubProcessor_document_exception_description;
}
ASTRewriteCorrectionProposal proposal = new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDecl, node, IProposalRelevance.DOCUMENT_UNUSED_ITEM);
proposals.add(proposal);
}
use of org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal in project che by eclipse.
the class LocalCorrectionsSubProcessor method addUnnecessaryInstanceofProposal.
public static void addUnnecessaryInstanceofProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
ASTNode curr = selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr = ((ParenthesizedExpression) curr).getExpression();
}
if (curr instanceof InstanceofExpression) {
AST ast = curr.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
InstanceofExpression inst = (InstanceofExpression) curr;
InfixExpression expression = ast.newInfixExpression();
expression.setLeftOperand((Expression) rewrite.createCopyTarget(inst.getLeftOperand()));
expression.setOperator(InfixExpression.Operator.NOT_EQUALS);
expression.setRightOperand(ast.newNullLiteral());
rewrite.replace(inst, expression, null);
String label = CorrectionMessages.LocalCorrectionsSubProcessor_unnecessaryinstanceof_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.UNNECESSARY_INSTANCEOF, image);
proposals.add(proposal);
}
}
Aggregations