Java Code Examples for org.eclipse.jdt.core.dom.TagElement#setTagName()
The following examples show how to use
org.eclipse.jdt.core.dom.TagElement#setTagName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodLimitQuickfix.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { @SuppressWarnings("unchecked") public boolean visit(MethodDeclaration node) { Javadoc doc = node.getJavadoc(); if (doc == null) { doc = node.getAST().newJavadoc(); node.setJavadoc(doc); } TagElement newTag = node.getAST().newTagElement(); newTag.setTagName("TODO Added by MethodLimit Sample quickfix"); doc.tags().add(0, newTag); return true; } }; }
Example 2
Source File: DelegateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private TagElement getDelegateJavadocTag(BodyDeclaration declaration) throws JavaModelException { Assert.isNotNull(declaration); String msg= RefactoringCoreMessages.DelegateCreator_use_member_instead; int firstParam= msg.indexOf("{0}"); //$NON-NLS-1$ Assert.isTrue(firstParam != -1); List<ASTNode> fragments= new ArrayList<>(); TextElement text= getAst().newTextElement(); text.setText(msg.substring(0, firstParam).trim()); fragments.add(text); fragments.add(createJavadocMemberReferenceTag(declaration, getAst())); text= getAst().newTextElement(); text.setText(msg.substring(firstParam + 3).trim()); fragments.add(text); final TagElement tag= getAst().newTagElement(); tag.setTagName(TagElement.TAG_DEPRECATED); tag.fragments().addAll(fragments); return tag; }
Example 3
Source File: JavadocTagsSubProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) { AST ast= typeDecl.getAST(); Javadoc javadoc= typeDecl.getJavadoc(); ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); List<TypeParameter> typeParams= typeDecl.typeParameters(); for (int i= typeParams.size() - 1; i >= 0; i--) { TypeParameter decl= typeParams.get(i); String name= '<' + decl.getName().getIdentifier() + '>'; if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) { TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_PARAM); TextElement text= ast.newTextElement(); text.setText(name); newTag.fragments().add(text); insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); //$NON-NLS-1$ insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl)); } } }
Example 4
Source File: DelegateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private TagElement getDelegateJavadocTag(BodyDeclaration declaration) throws JavaModelException { Assert.isNotNull(declaration); String msg= RefactoringCoreMessages.DelegateCreator_use_member_instead; int firstParam= msg.indexOf("{0}"); //$NON-NLS-1$ Assert.isTrue(firstParam != -1); List<ASTNode> fragments= new ArrayList<ASTNode>(); TextElement text= getAst().newTextElement(); text.setText(msg.substring(0, firstParam).trim()); fragments.add(text); fragments.add(createJavadocMemberReferenceTag(declaration, getAst())); text= getAst().newTextElement(); text.setText(msg.substring(firstParam + 3).trim()); fragments.add(text); final TagElement tag= getAst().newTagElement(); tag.setTagName(TagElement.TAG_DEPRECATED); tag.fragments().addAll(fragments); return tag; }
Example 5
Source File: JavadocTagsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) { AST ast= typeDecl.getAST(); Javadoc javadoc= typeDecl.getJavadoc(); ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); List<TypeParameter> typeParams= typeDecl.typeParameters(); for (int i= typeParams.size() - 1; i >= 0; i--) { TypeParameter decl= typeParams.get(i); String name= '<' + decl.getName().getIdentifier() + '>'; if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) { TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_PARAM); TextElement text= ast.newTextElement(); text.setText(name); newTag.fragments().add(text); insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); //$NON-NLS-1$ insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl)); } } }
Example 6
Source File: DelegateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private TagElement createJavadocMemberReferenceTag(BodyDeclaration declaration, final AST ast) throws JavaModelException { Assert.isNotNull(ast); Assert.isNotNull(declaration); ASTNode javadocReference= createDocReference(declaration); final TagElement element= ast.newTagElement(); element.setTagName(TagElement.TAG_LINK); element.fragments().add(javadocReference); return element; }
Example 7
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private TagElement createReturnTag() { TagElement returnNode= getASTRewrite().getAST().newTagElement(); returnNode.setTagName(TagElement.TAG_RETURN); TextElement textElement= getASTRewrite().getAST().newTextElement(); String text= StubUtility.getTodoTaskTag(fCuRewrite.getCu().getJavaProject()); if (text != null) textElement.setText(text); //TODO: use template with {@todo} ... returnNode.fragments().add(textElement); return returnNode; }
Example 8
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private TagElement createExceptionTag(String simpleName) { TagElement excptNode= getASTRewrite().getAST().newTagElement(); excptNode.setTagName(TagElement.TAG_THROWS); SimpleName nameNode= getASTRewrite().getAST().newSimpleName(simpleName); excptNode.fragments().add(nameNode); TextElement textElement= getASTRewrite().getAST().newTextElement(); String text= StubUtility.getTodoTaskTag(fCuRewrite.getCu().getJavaProject()); if (text != null) textElement.setText(text); //TODO: use template with {@todo} ... excptNode.fragments().add(textElement); return excptNode; }
Example 9
Source File: DelegateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private TagElement createJavadocMemberReferenceTag(BodyDeclaration declaration, final AST ast) throws JavaModelException { Assert.isNotNull(ast); Assert.isNotNull(declaration); ASTNode javadocReference= createDocReference(declaration); final TagElement element= ast.newTagElement(); element.setTagName(TagElement.TAG_LINK); element.fragments().add(javadocReference); return element; }
Example 10
Source File: JavadocUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static TagElement createParamTag(String parameterName, AST ast, IJavaProject javaProject) { TagElement paramNode= ast.newTagElement(); paramNode.setTagName(TagElement.TAG_PARAM); SimpleName simpleName= ast.newSimpleName(parameterName); paramNode.fragments().add(simpleName); TextElement textElement= ast.newTextElement(); String text= StubUtility.getTodoTaskTag(javaProject); if (text != null) textElement.setText(text); //TODO: use template with {@todo} ... paramNode.fragments().add(textElement); return paramNode; }
Example 11
Source File: ModifierCorrectionSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject()); MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; AST ast= methodDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); if (is50OrHigher) { Annotation annot= ast.newMarkerAnnotation(); annot.setTypeName(ast.newName("Deprecated")); //$NON-NLS-1$ rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null); } Javadoc javadoc= methodDecl.getJavadoc(); if (javadoc != null || !is50OrHigher) { if (!is50OrHigher) { javadoc= ast.newJavadoc(); rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null); } TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_DEPRECATED); JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null); } String label= CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image); proposals.add(proposal); }
Example 12
Source File: ReturnTypeSubProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) { ICompilationUnit cu= context.getCompilationUnit(); CompilationUnit astRoot= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(astRoot); if (selectedNode == null) { return; } BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl; ReturnStatementCollector eval= new ReturnStatementCollector(); decl.accept(eval); AST ast= astRoot.getAST(); ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST()); typeBinding= Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$ } if (typeBinding.isWildcardType()) { typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast); } ASTRewrite rewrite= ASTRewrite.create(ast); String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProviderCore.getBindingLabel(typeBinding, BindingLabelProviderCore.DEFAULT_TEXTFLAGS)); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, CodeActionKind.QuickFix, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE); ImportRewrite imports= proposal.createImportRewrite(astRoot); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); Type type= imports.addImport(typeBinding, ast, importRewriteContext, TypeLocation.RETURN_TYPE); rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null); rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null); Javadoc javadoc= methodDeclaration.getJavadoc(); if (javadoc != null && typeBinding != null) { TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_RETURN); TextElement commentStart= ast.newTextElement(); newTag.fragments().add(commentStart); JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null); proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$ } String key= "return_type"; //$NON-NLS-1$ proposal.addLinkedPosition(rewrite.track(type), true, key); if (typeBinding != null) { ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding); for (int i= 0; i < bindings.length; i++) { proposal.addLinkedPositionProposal(key, bindings[i]); } } proposals.add(proposal); // change to constructor ASTNode parentType= ASTResolving.findParentType(decl); if (parentType instanceof AbstractTypeDeclaration) { boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface(); if (!isInterface) { String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier(); ASTNode nameNode= methodDeclaration.getName(); label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName)); proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR)); } } } }
Example 13
Source File: NewVariableCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private ASTRewrite doAddParam(CompilationUnit cu) { AST ast= cu.getAST(); SimpleName node= fOriginalNode; BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(node); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl; ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewrite imports= createImportRewrite((CompilationUnit) decl.getRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); SingleVariableDeclaration newDecl= ast.newSingleVariableDeclaration(); newDecl.setType(evaluateVariableType(ast, imports, importRewriteContext, methodDeclaration.resolveBinding(), TypeLocation.PARAMETER)); newDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(decl, MethodDeclaration.PARAMETERS_PROPERTY); listRewriter.insertLast(newDecl, null); // add javadoc tag Javadoc javadoc= methodDeclaration.getJavadoc(); if (javadoc != null) { HashSet<String> leadingNames= new HashSet<>(); for (Iterator<SingleVariableDeclaration> iter= methodDeclaration.parameters().iterator(); iter.hasNext();) { SingleVariableDeclaration curr= iter.next(); leadingNames.add(curr.getName().getIdentifier()); } SimpleName newTagRef= ast.newSimpleName(node.getIdentifier()); TagElement newTagElement= ast.newTagElement(); newTagElement.setTagName(TagElement.TAG_PARAM); newTagElement.fragments().add(newTagRef); TextElement commentStart= ast.newTextElement(); newTagElement.fragments().add(commentStart); ListRewrite tagsRewriter= rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); JavadocTagsSubProcessor.insertTag(tagsRewriter, newTagElement, leadingNames); } return rewrite; } return null; }
Example 14
Source File: ReturnTypeSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ICompilationUnit cu= context.getCompilationUnit(); CompilationUnit astRoot= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(astRoot); if (selectedNode == null) { return; } BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl; ReturnStatementCollector eval= new ReturnStatementCollector(); decl.accept(eval); AST ast= astRoot.getAST(); ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST()); typeBinding= Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$ } if (typeBinding.isWildcardType()) { typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast); } ASTRewrite rewrite= ASTRewrite.create(ast); String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProvider.getBindingLabel(typeBinding, BindingLabelProvider.DEFAULT_TEXTFLAGS)); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE, image); ImportRewrite imports= proposal.createImportRewrite(astRoot); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); Type type= imports.addImport(typeBinding, ast, importRewriteContext); rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null); rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null); Javadoc javadoc= methodDeclaration.getJavadoc(); if (javadoc != null && typeBinding != null) { TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_RETURN); TextElement commentStart= ast.newTextElement(); newTag.fragments().add(commentStart); JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null); proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$ } String key= "return_type"; //$NON-NLS-1$ proposal.addLinkedPosition(rewrite.track(type), true, key); if (typeBinding != null) { ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding); for (int i= 0; i < bindings.length; i++) { proposal.addLinkedPositionProposal(key, bindings[i]); } } proposals.add(proposal); // change to constructor ASTNode parentType= ASTResolving.findParentType(decl); if (parentType instanceof AbstractTypeDeclaration) { boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface(); if (!isInterface) { String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier(); ASTNode nameNode= methodDeclaration.getName(); label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName)); proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR)); } } } }
Example 15
Source File: NewVariableCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private ASTRewrite doAddParam(CompilationUnit cu) { AST ast= cu.getAST(); SimpleName node= fOriginalNode; BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(node); if (decl instanceof MethodDeclaration) { MethodDeclaration methodDeclaration= (MethodDeclaration) decl; ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewrite imports= createImportRewrite((CompilationUnit) decl.getRoot()); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports); SingleVariableDeclaration newDecl= ast.newSingleVariableDeclaration(); newDecl.setType(evaluateVariableType(ast, imports, importRewriteContext, methodDeclaration.resolveBinding())); newDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(decl, MethodDeclaration.PARAMETERS_PROPERTY); listRewriter.insertLast(newDecl, null); addLinkedPosition(rewrite.track(node), true, KEY_NAME); // add javadoc tag Javadoc javadoc= methodDeclaration.getJavadoc(); if (javadoc != null) { HashSet<String> leadingNames= new HashSet<String>(); for (Iterator<SingleVariableDeclaration> iter= methodDeclaration.parameters().iterator(); iter.hasNext();) { SingleVariableDeclaration curr= iter.next(); leadingNames.add(curr.getName().getIdentifier()); } SimpleName newTagRef= ast.newSimpleName(node.getIdentifier()); TagElement newTagElement= ast.newTagElement(); newTagElement.setTagName(TagElement.TAG_PARAM); newTagElement.fragments().add(newTagRef); TextElement commentStart= ast.newTextElement(); newTagElement.fragments().add(commentStart); addLinkedPosition(rewrite.track(newTagRef), false, KEY_NAME); addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$ ListRewrite tagsRewriter= rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); JavadocTagsSubProcessor.insertTag(tagsRewriter, newTagElement, leadingNames); } addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE); addLinkedPosition(rewrite.track(newDecl.getName()), false, KEY_NAME); return rewrite; } return null; }