Java源码示例:com.sun.tools.javac.tree.DCTree

示例1
@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;
}
 
示例2
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;
}
 
示例3
/**
 * 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);
    }
}
 
示例4
/**
 * 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);
    }
}
 
示例5
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;
    }
}
 
示例6
/**
 * 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);
    }
}
 
示例7
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;
    }
}
 
示例8
protected void entity(ListBuffer<DCTree> list) {
    newline = false;
    addPendingText(list, bp - 1);
    list.add(entity());
    if (textStart == -1) {
        textStart = bp;
        lastNonWhite = -1;
    }
}
 
示例9
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;
    }
}
 
示例10
@Override
public Void visitAuthor(AuthorTree node, Void p) {
    printTagName(node);
    print(" ");
    for (DocTree docTree : node.getName()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
示例11
/**
 * 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);
    }
}
 
示例12
/**
 * 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);
    }
}
 
示例13
@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);
}
 
示例14
@Override
public Void visitValue(ValueTree node, Void p) {
    print("{");
    printTagName(node);
    if (node.getReference() != null) {
        print(" ");
        print((DCTree)node.getReference());
    }
    print("}");
    return null;
}
 
示例15
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;
    }
}
 
示例16
/**
 * 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);
    }
}
 
示例17
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;
}
 
示例18
@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;
}
 
示例19
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

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

        default:
            nextChar();
    }
}
 
示例20
protected void attrValueChar(ListBuffer<DCTree> list) {
    switch (ch) {
        case '&':
            entity(list);
            break;

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

        default:
            nextChar();
    }
}
 
示例21
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);
    }
}
 
示例22
/**
 * 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();
}
 
示例23
@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;
}
 
示例24
/**
 * 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();
}
 
示例25
/**
 * 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);
    }
}
 
示例26
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;
    }
}
 
示例27
@Override
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
    print("@");
    print(node.getTagName());
    print(" ");
    for (DocTree docTree : node.getContent()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
示例28
/**
 * 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);
    }
}
 
示例29
@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);
}
 
示例30
/**
 * 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);
    }
}