1 11 12 package org.eclipse.jdt.internal.corext.refactoring.util; 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.text.edits.TextEditGroup; 19 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.dom.AST; 22 import org.eclipse.jdt.core.dom.Javadoc; 23 import org.eclipse.jdt.core.dom.MethodDeclaration; 24 import org.eclipse.jdt.core.dom.SimpleName; 25 import org.eclipse.jdt.core.dom.SingleVariableDeclaration; 26 import org.eclipse.jdt.core.dom.TagElement; 27 import org.eclipse.jdt.core.dom.TextElement; 28 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; 29 import org.eclipse.jdt.core.dom.rewrite.ListRewrite; 30 31 import org.eclipse.jdt.internal.ui.text.correction.JavadocTagsSubProcessor; 32 33 import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; 34 35 36 public class JavadocUtil { 37 38 private JavadocUtil() { 39 } 41 42 public static TagElement createParamTag(String parameterName, AST ast, IJavaProject javaProject) { 44 TagElement paramNode= ast.newTagElement(); 45 paramNode.setTagName(TagElement.TAG_PARAM); 46 47 SimpleName simpleName= ast.newSimpleName(parameterName); 48 paramNode.fragments().add(simpleName); 49 50 TextElement textElement= ast.newTextElement(); 51 String text= StubUtility.getTodoTaskTag(javaProject); 52 if (text != null) 53 textElement.setText(text); paramNode.fragments().add(textElement); 55 56 return paramNode; 57 } 58 59 64 public static boolean shouldAddParamJavadoc(MethodDeclaration methodDeclaration) { 65 Javadoc javadoc= methodDeclaration.getJavadoc(); 66 if (javadoc == null) 67 return false; 68 if (methodDeclaration.parameters().size() == 0) 69 return true; 70 List tags= javadoc.tags(); 71 for (Iterator iter= tags.iterator(); iter.hasNext();) { 72 TagElement element= (TagElement) iter.next(); 73 if (TagElement.TAG_PARAM.equals(element.getTagName())) 74 return true; 75 } 76 return false; 77 } 78 79 80 88 public static void addParamJavadoc(String parameterName, MethodDeclaration methodDeclaration, 89 ASTRewrite astRewrite, IJavaProject javaProject, TextEditGroup groupDescription) { 90 if (! shouldAddParamJavadoc(methodDeclaration)) 91 return; 92 93 ListRewrite tagsRewrite= astRewrite.getListRewrite(methodDeclaration.getJavadoc(), Javadoc.TAGS_PROPERTY); 94 HashSet leadingNames= new HashSet (); 95 for (Iterator iter= methodDeclaration.parameters().iterator(); iter.hasNext();) { 96 SingleVariableDeclaration curr= (SingleVariableDeclaration) iter.next(); 97 leadingNames.add(curr.getName().getIdentifier()); 98 } 99 TagElement parameterTag= createParamTag(parameterName, astRewrite.getAST(), javaProject); 100 JavadocTagsSubProcessor.insertTag(tagsRewrite, parameterTag, leadingNames, groupDescription); 101 } 102 103 } 104 | Popular Tags |