com.sun.source.doctree.ParamTree Java Examples

The following examples show how to use com.sun.source.doctree.ParamTree. 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 Project: netbeans   Author: apache   File: VeryPretty.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Void visitParam(ParamTree node, Void p) {
    printTagName(node);
    needSpace();
    if(node.isTypeParameter()) {
       print('<');
    }
    doAccept((DCTree)node.getName());
    if(node.isTypeParameter()) {
       print('>');
    }
    if(!node.getDescription().isEmpty()) {
        needSpace();
    }
    for (DocTree docTree : node.getDescription()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
Example #2
Source Project: netbeans   Author: apache   File: JavadocImports.java    License: Apache License 2.0 6 votes vote down vote up
private static Element paramElementFor(Element methodOrClass, ParamTree ptag) {
    ElementKind kind = methodOrClass.getKind();
    List<? extends Element> params = Collections.emptyList();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        ExecutableElement ee = (ExecutableElement) methodOrClass;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        TypeElement te = (TypeElement) methodOrClass;
        params = te.getTypeParameters();
    }

    for (Element param : params) {
        if (param.getSimpleName().contentEquals(ptag.getName().getName())) {
            return param;
        }
    }
    return null;
}
 
Example #3
Source Project: netbeans   Author: apache   File: Analyzer.java    License: Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({"# {0} - @param name", "UNKNOWN_TYPEPARAM_DESC=Unknown @param: {0}",
                    "# {0} - @param name", "DUPLICATE_PARAM_DESC=Duplicate @param name: {0}"})
private void checkParamDeclared(ParamTree tree, List<? extends Element> list,
        DocTreePathHandle dtph, int start, int end, List<ErrorDescription> errors) {
    Name name = tree.getName().getName();
    boolean found = false;
    for (Element e: list) {
        if(ctx.isCanceled()) { return; }
        if (name.equals(e.getSimpleName())) {
            if(!foundParams.add(e)) {
                errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_PARAM_DESC(name), new RemoveTagFix(dtph, "@param").toEditorFix())); // NOI18N
            }
            found = true;
        }
    }
    if (!found) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, UNKNOWN_TYPEPARAM_DESC(name), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
    }
}
 
Example #4
Source Project: spring-auto-restdocs   Author: ScaCap   File: MethodDocumentation.java    License: Apache License 2.0 6 votes vote down vote up
public static MethodDocumentation fromMethodDoc(DocletEnvironment docEnv,
        Element methodElement) {
    MethodDocumentation md = new MethodDocumentation();
    md.comment = cleanupDocComment(docEnv.getElementUtils().getDocComment(methodElement));

    Optional.ofNullable(docEnv.getDocTrees().getDocCommentTree(methodElement))
            .ifPresent(docCommentTree -> docCommentTree.getBlockTags().forEach(tag -> {
                if (tag.getKind().equals(DocTree.Kind.PARAM)) {
                    ParamTree paramTag = (ParamTree) tag;
                    md.parameters.put(paramTag.getName().toString(),
                            unescapeJava(paramTag.getDescription().toString()));
                } else if (tag instanceof BlockTagTree) {
                    md.tags.put(
                            cleanupTagName(((BlockTagTree) tag).getTagName()),
                            unescapeJava(cleanupTagValue(tag.toString())));
                }
            }));

    return md;
}
 
Example #5
Source Project: TencentKona-8   Author: Tencent   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #8
Source Project: netbeans   Author: apache   File: ImmutableDocTreeTranslator.java    License: Apache License 2.0 5 votes vote down vote up
protected final ParamTree rewriteChildren(ParamTree tree) {
    ParamTree value = tree;
    IdentifierTree name = (IdentifierTree) translate(tree.getName());
    List<? extends DocTree> description = translateDoc(tree.getDescription());
    if (name != tree.getName() || description != tree.getDescription()) {
        value = make.Param(tree.isTypeParameter(), name, description);
    }
    return value;
}
 
Example #9
Source Project: netbeans   Author: apache   File: JavadocCompletionQuery.java    License: Apache License 2.0 5 votes vote down vote up
private boolean containsParam(List<? extends DocTree> blockTags, String name) {
    for (DocTree blockTag : blockTags) {
        if(blockTag.getKind() == Kind.PARAM) {
            ParamTree param = (ParamTree) blockTag;
            if(name.contentEquals(param.getName().getName())) {
                return true;
            }
        }
    }
    return false;
}
 
Example #10
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #11
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        boolean unique = foundParams.add(paramElement);

        if (!unique) {
            env.messages.warning(REFERENCE, tree, "dc.exists.param", nameTree);
        }
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #12
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CommentHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public String getParameterName(DocTree dtree) {
    if (dtree.getKind() == PARAM) {
        return ((ParamTree) dtree).getName().toString();
    } else {
        return null;
    }
}
 
Example #13
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CommentHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public IdentifierTree getName(DocTree dtree) {
    switch (dtree.getKind()) {
        case PARAM:
            return ((ParamTree)dtree).getName();
        case SERIAL_FIELD:
            return ((SerialFieldTree)dtree).getName();
        default:
            return null;
        }
}
 
Example #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Utils.java    License: GNU General Public License v2.0 5 votes vote down vote up
private  List<? extends DocTree> getParamTrees(Element element, boolean isTypeParameters) {
    List<DocTree> out = new ArrayList<>();
    for (DocTree dt : getBlockTags(element, PARAM)) {
        ParamTree pt = (ParamTree) dt;
        if (pt.isTypeParameter() == isTypeParameters) {
            out.add(dt);
        }
    }
    return out;
}
 
Example #15
Source Project: hottub   Author: dsrg-uoft   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #16
Source Project: openjdk-8-source   Author: keerath   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #17
Source Project: openjdk-8   Author: bpupadhyaya   File: Checker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public Void visitParam(ParamTree tree, Void ignore) {
    boolean typaram = tree.isTypeParameter();
    IdentifierTree nameTree = tree.getName();
    Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null;

    if (paramElement == null) {
        switch (env.currElement.getKind()) {
            case CLASS: case INTERFACE: {
                if (!typaram) {
                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                    break;
                }
            }
            case METHOD: case CONSTRUCTOR: {
                env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found");
                break;
            }

            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
    } else {
        foundParams.add(paramElement);
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #18
Source Project: j2objc   Author: google   File: JavadocConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitParam(ParamTree node, TagElement tag) {
  IdentifierTree identifier = node.getName();
  if (identifier == null || node.isTypeParameter()) {
    return null;
  }
  List<? extends VariableElement> params = element instanceof ExecutableElement
      ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
      tag.setTagKind(TagElement.TagKind.PARAM);
  String name = identifier.toString();
  VariableElement param = null;
  for (VariableElement p : params) {
    if (name.equals(p.getSimpleName().toString())) {
      param = p;
      break;
    }
  }
  // param will be null if the @param tag refers to a nonexistent parameter.
  TreeNode nameNode = param != null ? new SimpleName(param) : new SimpleName(name);
  setPos(identifier, nameNode);
  tag.addFragment(nameNode);
  scan(node.getDescription(), tag);
  int lastEnd = nameNode.getStartPosition();
  for (TreeNode fragment : tag.getFragments()) {
    // Fix up positions to match JDT's.
    // TODO(tball): remove and fix JavadocGenerator after javac switch.
    if (fragment.getKind() == TreeNode.Kind.TEXT_ELEMENT) {
      TextElement text = (TextElement) fragment;
      text.setText(" " + text.getText());
      text.setSourceRange(text.getStartPosition(), text.getLength() + 1);
    }
    int thisEnd = lastEnd + fragment.getLength();
    setPos(fragment, lastEnd, thisEnd);
    lastEnd = thisEnd;
  }
  setPos(tag, pos(node), endPos(node));
  tag.setLineNumber(nameNode.getLineNumber());
  return null;
}
 
Example #19
Source Project: cxf   Author: apache   File: DumpJavaDoc.java    License: Apache License 2.0 5 votes vote down vote up
private int getParamIndex(final ExecutableElement method, final ParamTree paramTree) {
    final List<? extends VariableElement> parameters = method.getParameters();
    
    for (int i = 0; i < parameters.size(); ++i) {
        if (paramTree.getName().getName().contentEquals(parameters.get(i).getSimpleName())) {
            return i;
        }
    } 
    
    return -1;
}
 
Example #20
Source Project: netbeans   Author: apache   File: ImmutableDocTreeTranslator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitParam(ParamTree tree, Object p) {
    return rewriteChildren(tree);
}
 
Example #21
Source Project: netbeans   Author: apache   File: TreeFactory.java    License: Apache License 2.0 4 votes vote down vote up
public ParamTree Param(boolean isTypeParameter, com.sun.source.doctree.IdentifierTree name, List<? extends DocTree> description) {
    return docMake.at(NOPOS).newParamTree(isTypeParameter, name, description);
}
 
Example #22
Source Project: netbeans   Author: apache   File: DoctreeTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testAddDocComment() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile,
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "\n" +
        "    private void test() {\n" +
        "    }\n" +
        "}\n");
    String golden =
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "\n" +
        "    /**\n" +
        "     * Test method\n" +
        "     * @param test\n" +
        "     */\n" +
        "    private void test() {\n" +
        "    }\n" +
        "}\n";

    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {
        @Override
        public void run(final WorkingCopy wc) throws IOException {
            wc.toPhase(JavaSource.Phase.RESOLVED);
            final TreeMaker make = wc.getTreeMaker();
            new ErrorAwareTreePathScanner<Void, Void>() {
                @Override
                public Void visitMethod(final MethodTree mt, Void p) {
                    ParamTree param = make.Param(false, make.DocIdentifier("test"), new LinkedList<DocTree>());
                    DocCommentTree newDoc = make.DocComment(
                            Collections.singletonList(make.Text("Test method")),
                            Collections.EMPTY_LIST,
                            Collections.singletonList(param));
                    wc.rewrite(mt, null, newDoc);
                    return super.visitMethod(mt, p);
                }
            }.scan(wc.getCompilationUnit(), null);
        }
    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    //System.err.println(res);
    assertEquals(golden, res);
}
 
Example #23
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @since 1.47
 */
@Override
public DocTree visitParam(ParamTree node, Element p) {
    return docScanner.visitParam(node, p, null);
}
 
Example #24
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitParam(ParamTree node, Element p) {
    return instance.visitParam(node, p);
}
 
Example #25
Source Project: netbeans   Author: apache   File: RefactoringVisitor.java    License: Apache License 2.0 4 votes vote down vote up
public DocTree visitParam(ParamTree node, Element p, Void ignore) {
    return super.visitParam(node, p);
}
 
Example #26
Source Project: netbeans   Author: apache   File: ChangeParamsTransformer.java    License: Apache License 2.0 4 votes vote down vote up
public static int compareTag(DocTree t, DocTree t1) {
    if(t.getKind() == t1.getKind()) {
        if(t.getKind() == DocTree.Kind.PARAM) {
            ParamTree p = (ParamTree) t;
            ParamTree p1 = (ParamTree) t1;
            if(p.isTypeParameter() && !p1.isTypeParameter()) {
                return HIGHER;
            } else if(!p.isTypeParameter() && p1.isTypeParameter()) {
                return LOWER;
            }
        }
        return EQUAL;
    }
    switch(t.getKind()) {
        case AUTHOR:
            return HIGHER;
        case VERSION:
            if(t1.getKind() == DocTree.Kind.AUTHOR) {
                return LOWER;
            }
            return HIGHER;
        case PARAM:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION) {
                return LOWER;
            }
            return HIGHER;
        case RETURN:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM) {
                return LOWER;
            }
            return HIGHER;
        case EXCEPTION:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN) {
                return LOWER;
            }
            return HIGHER;
        case THROWS:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION) {
                return LOWER;
            }
            return HIGHER;
        case SEE:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS) {
                return LOWER;
            }
            return HIGHER;
        case SINCE:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS
                    || t1.getKind() == DocTree.Kind.SEE) {
                return LOWER;
            }
            return HIGHER;
        case SERIAL:
        case SERIAL_DATA:
        case SERIAL_FIELD:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS
                    || t1.getKind() == DocTree.Kind.SEE
                    || t1.getKind() == DocTree.Kind.SINCE) {
                return LOWER;
            }
            return HIGHER;
        case DEPRECATED:
            if(t1.getKind() == DocTree.Kind.UNKNOWN_BLOCK_TAG) {
                return HIGHER;
            }
            return LOWER;
        case UNKNOWN_BLOCK_TAG:
            return LOWER;
    }
    return LOWER;
}
 
Example #27
Source Project: netbeans   Author: apache   File: AddTagFix.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(DocTree t, DocTree t1) {
    if(t.getKind() == t1.getKind()) {
        if(t.getKind() == DocTree.Kind.PARAM) {
            ParamTree p = (ParamTree) t;
            ParamTree p1 = (ParamTree) t1;
            if(p.isTypeParameter() && !p1.isTypeParameter()) {
                return HIGHER;
            } else if(!p.isTypeParameter() && p1.isTypeParameter()) {
                return LOWER;
            }
        }
        return EQUAL;
    }
    switch(t.getKind()) {
        case AUTHOR:
            return HIGHER;
        case VERSION:
            if(t1.getKind() == DocTree.Kind.AUTHOR) {
                return LOWER;
            }
            return HIGHER;
        case PARAM:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION) {
                return LOWER;
            }
            return HIGHER;
        case RETURN:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM) {
                return LOWER;
            }
            return HIGHER;
        case EXCEPTION:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN) {
                return LOWER;
            }
            return HIGHER;
        case THROWS:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION) {
                return LOWER;
            }
            return HIGHER;
        case SEE:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS) {
                return LOWER;
            }
            return HIGHER;
        case SINCE:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS
                    || t1.getKind() == DocTree.Kind.SEE) {
                return LOWER;
            }
            return HIGHER;
        case SERIAL:
        case SERIAL_DATA:
        case SERIAL_FIELD:
            if(t1.getKind() == DocTree.Kind.AUTHOR
                    || t1.getKind() == DocTree.Kind.VERSION
                    || t1.getKind() == DocTree.Kind.PARAM
                    || t1.getKind() == DocTree.Kind.RETURN
                    || t1.getKind() == DocTree.Kind.EXCEPTION
                    || t1.getKind() == DocTree.Kind.THROWS
                    || t1.getKind() == DocTree.Kind.SEE
                    || t1.getKind() == DocTree.Kind.SINCE) {
                return LOWER;
            }
            return HIGHER;
        case DEPRECATED:
            if(t1.getKind() == DocTree.Kind.UNKNOWN_BLOCK_TAG) {
                return HIGHER;
            }
            return LOWER;
        case UNKNOWN_BLOCK_TAG:
            return LOWER;
    }
    return LOWER;
}
 
Example #28
Source Project: netbeans   Author: apache   File: Analyzer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    @NbBundle.Messages({"# {0} - tag name", "# {1} - element type", "INVALID_TAG_DESC={0} tag cannot be used on {1}."})
    public Void visitParam(ParamTree tree, List<ErrorDescription> errors) {
        boolean oldInheritDoc = foundInheritDoc;
        DocTreePath currentDocPath = getCurrentPath();
        DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
        if(dtph == null) {
            return null;
        }
        DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
        int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
        int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
        if(ctx.isCanceled()) { return null; }
        boolean typaram = tree.isTypeParameter();
        switch (currentElement.getKind()) {
            case METHOD:
            case CONSTRUCTOR: {
                ExecutableElement ee = (ExecutableElement) currentElement;
                checkParamDeclared(tree, typaram ? ee.getTypeParameters() : ee.getParameters(), dtph, start, end, errors);
                break;
            }
            case CLASS:
            case INTERFACE: {
                TypeElement te = (TypeElement) currentElement;
                if (typaram) {
                    checkParamDeclared(tree, te.getTypeParameters(), dtph, start, end, errors);
                } else {
                    errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, INVALID_TAG_DESC("@param", currentElement.getKind()), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
//                    env.messages.error(REFERENCE, tree, "dc.invalid.param");
                }
                break;
            }
            default:
                errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, INVALID_TAG_DESC("@param", currentElement.getKind()), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
//                env.messages.error(REFERENCE, tree, "dc.invalid.param");
                break;
        }
        warnIfEmpty(tree, tree.getDescription());
        super.visitParam(tree, errors);
        foundInheritDoc = oldInheritDoc;
        return null;
    }
 
Example #29
Source Project: netbeans   Author: apache   File: Analyzer.java    License: Apache License 2.0 4 votes vote down vote up
private void findInheritedParams(ExecutableElement method, TypeElement typeElement, Set<String> inheritedParams, Set<String> inheritedTypeParams, Set<String> inheritedThrows) {
    if(typeElement == null) return;

    List<TypeMirror> superTypes = new ArrayList<>();

    superTypes.add(typeElement.getSuperclass());
    superTypes.addAll(typeElement.getInterfaces());

    for (TypeMirror typeMirror : superTypes) {
        for (Element el : javac.getElementUtilities().getMembers(typeMirror, (e, type) -> e.getKind() == ElementKind.METHOD)) {
            if(ctx.isCanceled()) { return; }
            if(javac.getElements().overrides(method, (ExecutableElement) el, typeElement)) {
                ElementHandle<ExecutableElement> overriddenMethod = ElementHandle.create((ExecutableElement) el);
                FileObject source = SourceUtils.getFile(overriddenMethod, ctx.getInfo().getClasspathInfo());
                if (source == null) {
                    continue;
                }
                try {
                    JavaSource.forFileObject(source).runUserActionTask(cc -> {
                        cc.toPhase(Phase.ELEMENTS_RESOLVED);
                        if (ctx.isCanceled()) {
                            return ; //cancel
                        }
                        ExecutableElement m = overriddenMethod.resolve(cc);
                        TreePath tp = m != null ? cc.getTrees().getPath(m) : null;
                        if (tp == null) {
                            return ; //TODO: log???
                        }
                        DocCommentTree methodDoc = cc.getDocTrees().getDocCommentTree(tp);
                        if(methodDoc != null) {
                            for (DocTree tag : methodDoc.getBlockTags()) {
                                switch (tag.getKind()) {
                                    case PARAM:
                                        String name = ((ParamTree) tag).getName().getName().toString();
                                        if (((ParamTree) tag).isTypeParameter()) {
                                            inheritedTypeParams.add(name);
                                        } else {
                                            inheritedParams.add(name);
                                        }
                                        break;
                                    case THROWS:
                                        Element thrownType = cc.getDocTrees().getElement(new DocTreePath(new DocTreePath(new DocTreePath(tp, methodDoc), tag), ((ThrowsTree) tag).getExceptionName()));
                                        if (thrownType != null && thrownType.getKind().isClass()) {
                                            inheritedThrows.add(((TypeElement) thrownType).getQualifiedName().toString());
                                        }
                                        break;
                                    case RETURN:
                                        returnTypeFound |= true;
                                }
                            }
                        }
                    }, true);
                } catch (IOException ex) {
                    LOG.log(Level.FINE, null, ex);
                }
            }
        }
    }
}
 
Example #30
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JavadocFormatter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Object visitParam(ParamTree node, Object p) {
    return formatDef(node.getName().getName(), node.getDescription());
}