com.sun.tools.javac.tree.DCTree Java Examples

The following examples show how to use com.sun.tools.javac.tree.DCTree. 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: RemoveUnusedImports.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitReference(ReferenceTree referenceTree, Void unused) {
  DCReference reference = (DCReference) referenceTree;
  long basePos =
      reference.getSourcePosition((DCTree.DCDocComment) getCurrentPath().getDocComment());
  // the position of trees inside the reference node aren't stored, but the qualifier's
  // start position is the beginning of the reference node
  if (reference.qualifierExpression != null) {
    new ReferenceScanner(basePos).scan(reference.qualifierExpression, null);
  }
  // Record uses inside method parameters. The javadoc tool doesn't use these, but
  // IntelliJ does.
  if (reference.paramTypes != null) {
    for (JCTree param : reference.paramTypes) {
      // TODO(cushon): get start positions for the parameters
      new ReferenceScanner(-1).scan(param, null);
    }
  }
  return null;
}
 
Example #2
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public DCDocComment parse() {
    String c = comment.getText();
    buf = new char[c.length() + 1];
    c.getChars(0, c.length(), buf, 0);
    buf[buf.length - 1] = EOI;
    buflen = buf.length - 1;
    bp = -1;
    nextChar();

    List<DCTree> body = blockContent();
    List<DCTree> tags = blockTags();
    int pos = !body.isEmpty()
            ? body.head.pos
            : !tags.isEmpty() ? tags.head.pos : Position.NOPOS;

    DCDocComment dc = m.at(pos).newDocCommentTree(comment, body, tags);
    return dc;
}
 
Example #3
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitLink(LinkTree node, Void p) {
    print("{");
    printTagName(node);
    print(" ");
    doAccept((DCTree)node.getReference());
    if (!node.getLabel().isEmpty()) {
        print(" ");
        for (DocTree docTree : node.getLabel()) {
            doAccept((DCTree)docTree);
        }
    }
    print("}");
    return null;
}
 
Example #4
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitAuthor(AuthorTree node, Void p) {
    printTagName(node);
    print(" ");
    for (DocTree docTree : node.getName()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
Example #5
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void inlineTag(ListBuffer<DCTree> list) {
    newline = false;
    nextChar();
    if (ch == '@') {
        addPendingText(list, bp - 2);
        list.add(inlineTag());
        textStart = bp;
        lastNonWhite = -1;
    } else {
        if (textStart == -1)
            textStart = bp - 1;
        lastNonWhite = bp;
    }
}
 
Example #6
Source File: DocCommentParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a single block tag, including its content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected DCTree blockTag() {
    int p = bp;
    try {
        nextChar();
        if (isIdentifierStart(ch)) {
            Name name = readTagName();
            TagParser tp = tagParsers.get(name);
            if (tp == null) {
                List<DCTree> content = blockContent();
                return m.at(p).UnknownBlockTag(name, content);
            } else {
                switch (tp.getKind()) {
                    case BLOCK:
                        return tp.parse(p);
                    case INLINE:
                        return erroneous("dc.bad.inline.tag", p);
                }
            }
        }
        blockContent();

        return erroneous("dc.no.tag.name", p);
    } catch (ParseException e) {
        blockContent();
        return erroneous(e.getMessage(), p);
    }
}
 
Example #7
Source File: DocCommentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a single inline tag, including its content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 * Malformed tags may be returned as {@link Erroneous}.
 */
protected DCTree inlineTag() {
    int p = bp - 1;
    try {
        nextChar();
        if (isIdentifierStart(ch)) {
            Name name = readTagName();
            skipWhitespace();

            TagParser tp = tagParsers.get(name);
            if (tp == null) {
                DCTree text = inlineText();
                if (text != null) {
                    nextChar();
                    return m.at(p).UnknownInlineTag(name, List.of(text)).setEndPos(bp);
                }
            } else if (tp.getKind() == TagParser.Kind.INLINE) {
                DCEndPosTree<?> tree = (DCEndPosTree<?>) tp.parse(p);
                if (tree != null) {
                    return tree.setEndPos(bp);
                }
            } else {
                inlineText(); // skip content
                nextChar();
            }
        }
        return erroneous("dc.no.tag.name", p);
    } catch (ParseException e) {
        return erroneous(e.getMessage(), p);
    }
}
 
Example #8
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isSentenceBreak(DCTree t) {
    switch (t.getKind()) {
        case START_ELEMENT:
            return isSentenceBreak(((DCStartElement) t).getName());

        case END_ELEMENT:
            return isSentenceBreak(((DCEndElement) t).getName());
    }
    return false;
}
 
Example #9
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitAttribute(AttributeTree node, Void p) {
    print(node.getName());
    String quote;
    switch (node.getValueKind()) {
        case EMPTY:
            return null;
        case UNQUOTED:
            quote = "";
            break;
        case SINGLE:
            quote = "'";
            break;
        case DOUBLE:
            quote = "\"";
            break;
        default:
            throw new AssertionError();
    }
    print("=");
    print(quote);
    for (DocTree docTree : node.getValue()) {
        doAccept((DCTree)docTree);
    }
    print(quote);
    return null;
}
 
Example #10
Source File: DocCommentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

        case '{':
            inlineTag(list);
            break;

        default:
            nextChar();
    }
}
 
Example #11
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

        case '{':
            inlineTag(list);
            break;

        default:
            nextChar();
    }
}
 
Example #12
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

        case '{':
            inlineTag(list);
            break;

        default:
            nextChar();
    }
}
 
Example #13
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void printPrecedingComments(JCTree tree, boolean printWhitespace) {
    if (!precedingCommentsHandled.add(tree)) {
        return;
    }
    CommentSet commentSet = commentHandler.getComments(tree);
    java.util.List<Comment> pc = commentSet.getComments(CommentSet.RelativePosition.PRECEDING);
    DocCommentTree doc = tree2Doc.get(tree);
    if (!pc.isEmpty()) {
        Comment javadoc = null;
        for (Comment comment : pc) {
            if(comment.style() == Style.JAVADOC) {
                javadoc = comment;
            }
        }
        for (Comment c : pc) {
            if(doc != null && c == javadoc) {
                print((DCTree)doc);
                doc = null;
            } else {
                printComment(c, true, printWhitespace);
            }
        }
    }
    if(doc!=null) {
        print((DCTree)doc);
    }
}
 
Example #14
Source File: DocCommentParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a series of block tags, including their content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected List<DCTree> blockTags() {
    ListBuffer<DCTree> tags = new ListBuffer<DCTree>();
    while (ch == '@')
        tags.add(blockTag());
    return tags.toList();
}
 
Example #15
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitHidden(HiddenTree node, Void p) {
    printTagName(node);
    if (!node.getBody().isEmpty()) {
        print(" ");
        for (DocTree docTree : node.getBody()) {
            doAccept((DCTree)docTree);
        }
    }
    return null;
}
 
Example #16
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void inlineTag(ListBuffer<DCTree> list) {
    newline = false;
    nextChar();
    if (ch == '@') {
        addPendingText(list, bp - 2);
        list.add(inlineTag());
        textStart = bp;
        lastNonWhite = -1;
    } else {
        if (textStart == -1)
            textStart = bp - 1;
        lastNonWhite = bp;
    }
}
 
Example #17
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Read a series of block tags, including their content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected List<DCTree> blockTags() {
    ListBuffer<DCTree> tags = new ListBuffer<>();
    while (ch == '@')
        tags.add(blockTag());
    return tags.toList();
}
 
Example #18
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitIndex(IndexTree node, Void p) {
    print("{");
    printTagName(node);
    print(" ");
    doAccept((DCTree)node.getSearchTerm());
    if (!node.getDescription().isEmpty()) {
        print(" ");
        for (DocTree docTree : node.getDescription()) {
            doAccept((DCTree)docTree);
        }
    }
    print("}");
    return null;
}
 
Example #19
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a single block tag, including its content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected DCTree blockTag() {
    int p = bp;
    try {
        nextChar();
        if (isIdentifierStart(ch)) {
            Name name = readTagName();
            TagParser tp = tagParsers.get(name);
            if (tp == null) {
                List<DCTree> content = blockContent();
                return m.at(p).UnknownBlockTag(name, content);
            } else {
                switch (tp.getKind()) {
                    case BLOCK:
                        return tp.parse(p);
                    case INLINE:
                        return erroneous("dc.bad.inline.tag", p);
                }
            }
        }
        blockContent();

        return erroneous("dc.no.tag.name", p);
    } catch (ParseException e) {
        blockContent();
        return erroneous(e.getMessage(), p);
    }
}
 
Example #20
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a series of block tags, including their content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected List<DCTree> blockTags() {
    ListBuffer<DCTree> tags = new ListBuffer<DCTree>();
    while (ch == '@')
        tags.add(blockTag());
    return tags.toList();
}
 
Example #21
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a single block tag, including its content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected DCTree blockTag() {
    int p = bp;
    try {
        nextChar();
        if (isIdentifierStart(ch)) {
            Name name = readTagName();
            TagParser tp = tagParsers.get(name);
            if (tp == null) {
                List<DCTree> content = blockContent();
                return m.at(p).UnknownBlockTag(name, content);
            } else {
                switch (tp.getKind()) {
                    case BLOCK:
                        return tp.parse(p);
                    case INLINE:
                        return erroneous("dc.bad.inline.tag", p);
                }
            }
        }
        blockContent();

        return erroneous("dc.no.tag.name", p);
    } catch (ParseException e) {
        blockContent();
        return erroneous(e.getMessage(), p);
    }
}
 
Example #22
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void inlineTag(ListBuffer<DCTree> list) {
    newline = false;
    nextChar();
    if (ch == '@') {
        addPendingText(list, bp - 2);
        list.add(inlineTag());
        textStart = bp;
        lastNonWhite = -1;
    } else {
        if (textStart == -1)
            textStart = bp - 1;
        lastNonWhite = bp;
    }
}
 
Example #23
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
    print("@");
    print(node.getTagName());
    print(" ");
    for (DocTree docTree : node.getContent()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
Example #24
Source File: DocCommentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an HTML entity.
 * {@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; }
 */
protected DCTree entity() {
    int p = bp;
    nextChar();
    Name name = null;
    boolean checkSemi = false;
    if (ch == '#') {
        int namep = bp;
        nextChar();
        if (isDecimalDigit(ch)) {
            nextChar();
            while (isDecimalDigit(ch))
                nextChar();
            name = names.fromChars(buf, namep, bp - namep);
        } else if (ch == 'x' || ch == 'X') {
            nextChar();
            if (isHexDigit(ch)) {
                nextChar();
                while (isHexDigit(ch))
                    nextChar();
                name = names.fromChars(buf, namep, bp - namep);
            }
        }
    } else if (isIdentifierStart(ch)) {
        name = readIdentifier();
    }

    if (name == null)
        return erroneous("dc.bad.entity", p);
    else {
        if (ch != ';')
            return erroneous("dc.missing.semicolon", p);
        nextChar();
        return m.at(p).Entity(name);
    }
}
 
Example #25
Source File: DocCommentTester.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
void check(TreePath path, Name name) throws Exception {
    JavaFileObject fo = path.getCompilationUnit().getSourceFile();
    final CharSequence cs = fo.getCharContent(true);

    final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
    DCTree t = (DCTree) trees.getDocCommentTree(path);

    DocTreeScanner scanner = new DocTreeScanner<Void,Void>() {
        @Override
        public Void scan(DocTree node, Void ignore) {
            if (node != null) {
                try {
                    String expect = getExpectText(node);
                    long pos = ((DCTree) node).getSourcePosition(dc);
                    String found = getFoundText(cs, (int) pos, expect.length());
                    if (!found.equals(expect)) {
                        System.err.println("expect: " + expect);
                        System.err.println("found:  " + found);
                        error("mismatch");
                    }

                } catch (StringIndexOutOfBoundsException e) {
                    error(node.getClass() + ": " + e.toString());
                        e.printStackTrace();
                }
            }
            return super.scan(node, ignore);
        }
    };

    scanner.scan(t, null);
}
 
Example #26
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read an HTML entity.
 * {@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; }
 */
protected DCTree entity() {
    int p = bp;
    nextChar();
    Name name = null;
    boolean checkSemi = false;
    if (ch == '#') {
        int namep = bp;
        nextChar();
        if (isDecimalDigit(ch)) {
            nextChar();
            while (isDecimalDigit(ch))
                nextChar();
            name = names.fromChars(buf, namep, bp - namep);
        } else if (ch == 'x' || ch == 'X') {
            nextChar();
            if (isHexDigit(ch)) {
                nextChar();
                while (isHexDigit(ch))
                    nextChar();
                name = names.fromChars(buf, namep, bp - namep);
            }
        }
    } else if (isIdentifierStart(ch)) {
        name = readIdentifier();
    }

    if (name == null)
        return erroneous("dc.bad.entity", p);
    else {
        if (ch != ';')
            return erroneous("dc.missing.semicolon", p);
        nextChar();
        return m.at(p).Entity(name);
    }
}
 
Example #27
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

        case '{':
            inlineTag(list);
            break;

        default:
            nextChar();
    }
}
 
Example #28
Source File: DocCommentParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void entity(ListBuffer<DCTree> list) {
    newline = false;
    addPendingText(list, bp - 1);
    list.add(entity());
    if (textStart == -1) {
        textStart = bp;
        lastNonWhite = -1;
    }
}
 
Example #29
Source File: DocCommentTester.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
void check(TreePath path, Name name) throws Exception {
    JavaFileObject fo = path.getCompilationUnit().getSourceFile();
    final CharSequence cs = fo.getCharContent(true);

    final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path);
    DCTree t = (DCTree) trees.getDocCommentTree(path);

    DocTreeScanner scanner = new DocTreeScanner<Void,Void>() {
        @Override
        public Void scan(DocTree node, Void ignore) {
            if (node != null) {
                try {
                    String expect = getExpectText(node);
                    long pos = ((DCTree) node).getSourcePosition(dc);
                    String found = getFoundText(cs, (int) pos, expect.length());
                    if (!found.equals(expect)) {
                        System.err.println("expect: " + expect);
                        System.err.println("found:  " + found);
                        error("mismatch");
                    }

                } catch (StringIndexOutOfBoundsException e) {
                    error(node.getClass() + ": " + e.toString());
                        e.printStackTrace();
                }
            }
            return super.scan(node, ignore);
        }
    };

    scanner.scan(t, null);
}
 
Example #30
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read a single block tag, including its content.
 * Standard tags parse their content appropriately.
 * Non-standard tags are represented by {@link UnknownBlockTag}.
 */
protected DCTree blockTag() {
    int p = bp;
    try {
        nextChar();
        if (isIdentifierStart(ch)) {
            Name name = readTagName();
            TagParser tp = tagParsers.get(name);
            if (tp == null) {
                List<DCTree> content = blockContent();
                return m.at(p).newUnknownBlockTagTree(name, content);
            } else {
                switch (tp.getKind()) {
                    case BLOCK:
                        return tp.parse(p);
                    case INLINE:
                        return erroneous("dc.bad.inline.tag", p);
                }
            }
        }
        blockContent();

        return erroneous("dc.no.tag.name", p);
    } catch (ParseException e) {
        blockContent();
        return erroneous(e.getMessage(), p);
    }
}