use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.
the class JavadocTagsSubProcessor method getRemoveJavadocTagProposals.
public static void getRemoveJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> 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;
proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG));
}
use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.
the class JavadocTagsSubProcessor method findParamTag.
public static TagElement findParamTag(Javadoc javadoc, String arg) {
List<TagElement> tags = javadoc.tags();
int nTags = tags.size();
for (int i = 0; i < nTags; i++) {
TagElement curr = tags.get(i);
String currName = curr.getTagName();
if (TagElement.TAG_PARAM.equals(currName)) {
String argument = getArgument(curr);
if (arg.equals(argument)) {
return curr;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.
the class JavadocTagsSubProcessor method insertTag.
public static void insertTag(ListRewrite rewriter, TagElement newElement, Set<String> sameKindLeadingNames, TextEditGroup groupDescription) {
List<? extends ASTNode> tags = rewriter.getRewrittenList();
String insertedTagName = newElement.getTagName();
ASTNode after = null;
int tagRanking = getTagRanking(insertedTagName);
for (int i = tags.size() - 1; i >= 0; i--) {
TagElement curr = (TagElement) tags.get(i);
String tagName = curr.getTagName();
if (tagName == null || tagRanking > getTagRanking(tagName)) {
after = curr;
break;
}
if (sameKindLeadingNames != null && isSameTag(insertedTagName, tagName)) {
String arg = getArgument(curr);
if (arg != null && sameKindLeadingNames.contains(arg)) {
after = curr;
break;
}
}
}
if (after != null) {
rewriter.insertAfter(newElement, after, groupDescription);
} else {
rewriter.insertFirst(newElement, groupDescription);
}
}
use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.
the class JavadocTagsSubProcessor method findTag.
public static TagElement findTag(Javadoc javadoc, String name, String arg) {
List<TagElement> tags = javadoc.tags();
int nTags = tags.size();
for (int i = 0; i < nTags; i++) {
TagElement curr = tags.get(i);
if (name.equals(curr.getTagName())) {
if (arg != null) {
String argument = getArgument(curr);
if (arg.equals(argument)) {
return curr;
}
} else {
return curr;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.
the class ReturnTypeSubProcessor method addMissingReturnStatementProposals.
public static void addMissingReturnStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
ReturnStatement existingStatement = (selectedNode instanceof ReturnStatement) ? (ReturnStatement) selectedNode : null;
// Lambda Expression can be in a MethodDeclaration or a Field Declaration
if (selectedNode instanceof LambdaExpression) {
MissingReturnTypeInLambdaCorrectionProposal proposal = new MissingReturnTypeInLambdaCorrectionProposal(cu, (LambdaExpression) selectedNode, existingStatement, IProposalRelevance.MISSING_RETURN_TYPE);
proposals.add(proposal);
} else {
BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(selectedNode);
if (decl instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) decl;
Block block = methodDecl.getBody();
if (block == null) {
return;
}
proposals.add(new MissingReturnTypeCorrectionProposal(cu, methodDecl, existingStatement, IProposalRelevance.MISSING_RETURN_TYPE));
Type returnType = methodDecl.getReturnType2();
if (returnType != null && !"void".equals(ASTNodes.asString(returnType))) {
// $NON-NLS-1$
AST ast = methodDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
rewrite.replace(returnType, ast.newPrimitiveType(PrimitiveType.VOID), null);
Javadoc javadoc = methodDecl.getJavadoc();
if (javadoc != null) {
TagElement tagElement = JavadocTagsSubProcessor.findTag(javadoc, TagElement.TAG_RETURN, null);
if (tagElement != null) {
rewrite.remove(tagElement, null);
}
}
String label = CorrectionMessages.ReturnTypeSubProcessor_changetovoid_description;
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.CHANGE_RETURN_TYPE_TO_VOID);
proposals.add(proposal);
}
}
}
}
Aggregations