Java Code Examples for com.sun.source.doctree.ParamTree#isTypeParameter()

The following examples show how to use com.sun.source.doctree.ParamTree#isTypeParameter() . 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: VeryPretty.java    From netbeans with 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 File: JavadocImports.java    From netbeans with 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 File: Checker.java    From TencentKona-8 with 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 4
Source File: Checker.java    From jdk8u60 with 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 5
Source File: Checker.java    From openjdk-jdk8u with 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 File: Checker.java    From openjdk-jdk8u-backup with 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 File: Checker.java    From openjdk-jdk9 with 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 8
Source File: Utils.java    From openjdk-jdk9 with 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 9
Source File: Checker.java    From hottub with 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 10
Source File: Checker.java    From openjdk-8-source with 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 File: Checker.java    From openjdk-8 with 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 12
Source File: JavadocConverter.java    From j2objc with 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 13
Source File: ChangeParamsTransformer.java    From netbeans with 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 14
Source File: AddTagFix.java    From netbeans with 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 15
Source File: Analyzer.java    From netbeans with 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;
    }