com.sun.tools.javac.parser.Tokens.Comment Java Examples

The following examples show how to use com.sun.tools.javac.parser.Tokens.Comment. 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: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;

    Locale locale = (fac.locale == null) ? Locale.getDefault() : fac.locale;

    Options options = fac.options;
    boolean useBreakIterator = options.isSet("breakIterator");
    if (useBreakIterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage()))
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);

    initTagParsers();
}
 
Example #2
Source File: DocCommentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;

    Locale locale = (fac.locale == null) ? Locale.getDefault() : fac.locale;

    Options options = fac.options;
    boolean useBreakIterator = options.isSet("breakIterator");
    if (useBreakIterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage()))
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);

    initTagParsers();
}
 
Example #3
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;

    Locale locale = (fac.locale == null) ? Locale.getDefault() : fac.locale;

    Options options = fac.options;
    boolean useBreakIterator = options.isSet("breakIterator");
    if (useBreakIterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage()))
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);

    initTagParsers();
}
 
Example #4
Source File: DocCommentParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;

    Locale locale = (fac.locale == null) ? Locale.getDefault() : fac.locale;

    Options options = fac.options;
    boolean useBreakIterator = options.isSet("breakIterator");
    if (useBreakIterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage()))
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);

    initTagParsers();
}
 
Example #5
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static Comment createJavadocComment(final String text, final JavacNode field) {
	return new Comment() {
		@Override public String getText() {
			return text;
		}
		
		@Override public int getSourcePos(int index) {
			return -1;
		}
		
		@Override public CommentStyle getStyle() {
			return CommentStyle.JAVADOC;
		}
		
		@Override public boolean isDeprecated() {
			return text.contains("@deprecated") && field.getKind() == Kind.FIELD && isFieldDeprecated(field);
		}
	};
}
 
Example #6
Source File: Documentifier.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void documentifyBase(JCClassDecl base, boolean isTopLevel, boolean isFxStyle) {
    // add doc comment to class itself
    Comment comm = comment(docGen.getBaseComment(base, isTopLevel));
    curDocComments.putComment(base, comm);

    // add doc comments to members
    for (JCTree member : base.getMembers()) {
        switch (member.getTag()) {
            case VARDEF:
                documentifyField(base, (JCVariableDecl)member, isFxStyle);
                break;
            case METHODDEF:
                documentifyMethod(base, (JCMethodDecl)member, isFxStyle);
                break;
            case CLASSDEF:
                documentifyBase((JCClassDecl)member, false, isFxStyle);
                break;
        }
    }
}
 
Example #7
Source File: DocCommentParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;

    Locale locale = (fac.locale == null) ? Locale.getDefault() : fac.locale;

    Options options = fac.options;
    boolean useBreakIterator = options.isSet("breakIterator");
    if (useBreakIterator || !locale.getLanguage().equals(Locale.ENGLISH.getLanguage()))
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);

    initTagParsers();
}
 
Example #8
Source File: DocCommentIntegrator.java    From EasyMPermission with MIT License 6 votes vote down vote up
static void attach(final JCTree node, String docCommentContent, Object map_) {
	final String docCommentContent_ = docCommentContent;
	((DocCommentTable) map_).putComment(node, new Comment() {
		@Override public String getText() {
			return docCommentContent_;
		}
		
		@Override public int getSourcePos(int index) {
			return -1;
		}
		
		@Override public CommentStyle getStyle() {
			return CommentStyle.JAVADOC;
		}
		
		@Override public boolean isDeprecated() {
			return JavacHandlerUtil.nodeHasDeprecatedFlag(node);
		}
	});
}
 
Example #9
Source File: DocTreeMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
    ListBuffer<DCTree> lb = new ListBuffer<>();
    lb.addAll(cast(fullBody));
    List<DCTree> fBody = lb.toList();

    // A dummy comment to keep the diagnostics logic happy.
    Comment c = new Comment() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public int getSourcePos(int index) {
            return Position.NOPOS;
        }

        @Override
        public CommentStyle getStyle() {
            return CommentStyle.JAVADOC;
        }

        @Override
        public boolean isDeprecated() {
            return false;
        }
    };
    Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
    DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags));
    return tree;
}
 
Example #10
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode, Object dc) {
	DocCommentTable dct = (DocCommentTable) dc;
	Comment javadoc = dct.getComment(from.get());
	
	if (javadoc != null) {
		String[] filtered = copyMode.split(javadoc.getText());
		if (copyMode == CopyJavadoc.SETTER && shouldReturnThis(from)) {
			filtered[0] = addReturnsThisIfNeeded(filtered[0]);
		}
		dct.putComment(to, createJavadocComment(filtered[0], from));
		dct.putComment(from.get(), createJavadocComment(filtered[1], from));
	}
}
 
Example #11
Source File: CommentCollectingTokenizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override
protected Comment processComment(int pos, int endPos, CommentStyle style) {
	int prevEndPos = Math.max(prevEndPosition, endComment);
	endComment = endPos;
	String content = new String(reader.getRawCharacters(pos, endPos));
	StartConnection start = determineStartConnection(prevEndPos, pos);
	EndConnection end = determineEndConnection(endPos); 

	CommentInfo comment = new CommentInfo(prevEndPos, pos, endPos, content, start, end);
	comments.append(comment);

	return super.processComment(pos, endPos, style);
}
 
Example #12
Source File: DCTree.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public DCDocComment(Comment comment,
        List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
    this.comment = comment;
    this.firstSentence = firstSentence;
    this.body = body;
    this.tags = tags;
}
 
Example #13
Source File: NBParserFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List<JCTypeParameter> typarams, boolean isInterface, boolean isVoid, Comment dc) {
    if (cancelService != null) {
        cancelService.abortIfCanceled();
    }
    return super.methodDeclaratorRest(pos, mods, type, name, typarams, isInterface, isVoid, dc);
}
 
Example #14
Source File: NBParserFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) {
    if (cancelService != null) {
        cancelService.abortIfCanceled();
    }
    return super.enumDeclaration(mods, dc);
}
 
Example #15
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;
    initTagParsers();
}
 
Example #16
Source File: DCTree.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public DCDocComment(Comment comment,
        List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
    this.comment = comment;
    this.firstSentence = firstSentence;
    this.body = body;
    this.tags = tags;
}
 
Example #17
Source File: DCTree.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public DCDocComment(Comment comment,
        List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
    this.comment = comment;
    this.firstSentence = firstSentence;
    this.body = body;
    this.tags = tags;
}
 
Example #18
Source File: DocTreeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
    ListBuffer<DCTree> lb = new ListBuffer<>();
    lb.addAll(cast(fullBody));
    List<DCTree> fBody = lb.toList();

    // A dummy comment to keep the diagnostics logic happy.
    Comment c = new Comment() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public int getSourcePos(int index) {
            return Position.NOPOS;
        }

        @Override
        public CommentStyle getStyle() {
            return CommentStyle.JAVADOC;
        }

        @Override
        public boolean isDeprecated() {
            return false;
        }
    };
    Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
    DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags));
    return tree;
}
 
Example #19
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
    this.fac = fac;
    this.diagSource = diagSource;
    this.comment = comment;
    names = fac.names;
    m = fac.docTreeMaker;
    initTagParsers();
}
 
Example #20
Source File: DCTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public DCDocComment(Comment comment,
        List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
    this.comment = comment;
    this.firstSentence = firstSentence;
    this.body = body;
    this.tags = tags;
}
 
Example #21
Source File: Documentifier.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void documentifyField(JCClassDecl base, JCVariableDecl field, boolean isFxStyle) {
    Kind baseKind = base.getKind();
    Set<Modifier> fieldMods = field.getModifiers().getFlags();
    String doc = (baseKind == Kind.ENUM
                  && fieldMods.contains(Modifier.PUBLIC)
                  && fieldMods.contains(Modifier.STATIC)
                  && fieldMods.contains(Modifier.FINAL)) ?
                 docGen.getConstComment() :
                 docGen.getFieldComment(base, field, isFxStyle);
    Comment comm = comment(doc);
    curDocComments.putComment(field, comm);
}
 
Example #22
Source File: DCTree.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public DCDocComment(Comment comment,
        List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) {
    this.comment = comment;
    this.firstSentence = firstSentence;
    this.body = body;
    this.tags = tags;
}
 
Example #23
Source File: NBParserFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) {
    if (cancelService != null) {
        cancelService.abortIfCanceled();
    }
    return super.interfaceDeclaration(mods, dc);
}
 
Example #24
Source File: LazyDocCommentTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
Entry(Comment c) {
    comment = c;
}
 
Example #25
Source File: LazyDocCommentTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Comment getComment(JCTree tree) {
    Entry e = table.get(tree);
    return (e == null) ? null : e.comment;
}
 
Example #26
Source File: LazyDocCommentTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public String getCommentText(JCTree tree) {
    Comment c = getComment(tree);
    return (c == null) ? null : c.getText();
}
 
Example #27
Source File: JavacTrees.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DocCommentTree getDocCommentTree(FileObject fileObject) {
    JavaFileObject jfo = asJavaFileObject(fileObject);
    DiagnosticSource diagSource = new DiagnosticSource(jfo, log);

    final Comment comment = new Comment() {
        int offset = 0;
        @Override
        public String getText() {
            try {
                CharSequence rawDoc = fileObject.getCharContent(true);
                Pattern bodyPat =
                        Pattern.compile("(?is).*?<body\\b[^>]*>(.*)</body\\b.*");
                Matcher m = bodyPat.matcher(rawDoc);
                if (m.matches()) {
                    offset = m.end(1);
                    return m.group(1);
                } else {
                    // Assume doclint will do the right thing.
                    return "";
                }
            } catch (IOException ignore) {
                // do nothing
            }
            return "";
        }

        @Override
        public int getSourcePos(int index) {
            return offset + index;
        }

        @Override
        public CommentStyle getStyle() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isDeprecated() {
            throw new UnsupportedOperationException();
        }
    };

    return new DocCommentParser(parser, diagSource, comment).parse();
}
 
Example #28
Source File: JavadocTokenizer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Comment processComment(int pos, int endPos, CommentStyle style) {
    char[] buf = reader.getRawCharacters(pos, endPos);
    return new JavadocComment(new DocReader(fac, buf, buf.length, pos), style);
}
 
Example #29
Source File: LazyDocCommentTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void putComment(JCTree tree, Comment c) {
    table.put(tree, new Entry(c));
}
 
Example #30
Source File: LazyDocCommentTable.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Comment getComment(JCTree tree) {
    Entry e = table.get(tree);
    return (e == null) ? null : e.comment;
}