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 Project: google-java-format   Author: google   File: RemoveUnusedImports.java    License: 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 Project: lua-for-android   Author: qtiuto   File: DocCommentParser.java    License: 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 Project: hottub   Author: dsrg-uoft   File: DocCommentParser.java    License: 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 #4
Source Project: TencentKona-8   Author: Tencent   File: DocCommentParser.java    License: 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 #5
Source Project: TencentKona-8   Author: Tencent   File: DocCommentParser.java    License: 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 Project: TencentKona-8   Author: Tencent   File: DocCommentParser.java    License: 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 #7
Source Project: hottub   Author: dsrg-uoft   File: DocCommentParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void addPendingText(ListBuffer<DCTree> list, int textEnd) {
    if (textStart != -1) {
        if (textStart <= textEnd) {
            list.add(m.at(textStart).Text(newString(textStart, textEnd + 1)));
        }
        textStart = -1;
    }
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: DocCommentParser.java    License: 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 #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DocCommentParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void addPendingText(ListBuffer<DCTree> list, int textEnd) {
    if (textStart != -1) {
        if (textStart <= textEnd) {
            list.add(m.at(textStart).newTextTree(newString(textStart, textEnd + 1)));
        }
        textStart = -1;
    }
}
 
Example #10
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: 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 #11
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #12
Source Project: openjdk-8-source   Author: keerath   File: DocCommentParser.java    License: 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 #13
Source Project: TencentKona-8   Author: Tencent   File: DocCommentTester.java    License: 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 #14
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Void visitValue(ValueTree node, Void p) {
    print("{");
    printTagName(node);
    if (node.getReference() != null) {
        print(" ");
        print((DCTree)node.getReference());
    }
    print("}");
    return null;
}
 
Example #15
Source Project: jdk8u60   Author: chenghanpeng   File: DocCommentParser.java    License: 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 #16
Source Project: openjdk-8-source   Author: keerath   File: DocCommentParser.java    License: 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 #17
Source Project: hottub   Author: dsrg-uoft   File: DocCommentParser.java    License: 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 #18
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: 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 #19
Source Project: jdk8u60   Author: chenghanpeng   File: DocCommentParser.java    License: 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 #20
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #21
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: 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 #22
Source Project: openjdk-8   Author: bpupadhyaya   File: DocCommentParser.java    License: 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 #23
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: 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 #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #26
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #27
Source Project: netbeans   Author: apache   File: VeryPretty.java    License: 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 #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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 #29
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DocCommentTester.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocCommentParser.java    License: 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);
    }
}