本文整理汇总了Java中com.google.javascript.jscomp.parsing.parser.trees.Comment类的典型用法代码示例。如果您正苦于以下问题:Java Comment类的具体用法?Java Comment怎么用?Java Comment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Comment类属于com.google.javascript.jscomp.parsing.parser.trees包,在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseInlineTypeDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
/**
* Parses inline type info.
*/
private JSDocInfo parseInlineTypeDoc(Comment node) {
String comment = node.value;
int lineno = lineno(node.location.start);
int charno = charno(node.location.start);
// The JsDocInfoParser expects the comment without the initial '/**'.
int numOpeningChars = 3;
JsDocInfoParser parser =
new JsDocInfoParser(
new JsDocTokenStream(comment.substring(numOpeningChars),
lineno,
charno + numOpeningChars),
comment,
node.location.start.offset,
templateNode,
config,
errorReporter);
return parser.parseInlineTypeDoc();
}
示例2: skipMultiLineComment
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private void skipMultiLineComment() {
int startOffset = index;
nextChar(); // '/'
nextChar(); // '*'
while (!isAtEnd() && (peekChar() != '*' || peekChar(1) != '/')) {
nextChar();
}
if (!isAtEnd()) {
nextChar();
nextChar();
Comment.Type type = (index - startOffset > 4
&& this.source.contents.charAt(startOffset + 2) == '*')
? Comment.Type.JSDOC
: Comment.Type.BLOCK;
SourceRange range = getLineNumberTable().getSourceRange(
startOffset, index);
String value = this.source.contents.substring(
startOffset, index);
recordComment(type, range, value);
} else {
reportError("unterminated comment");
}
}
示例3: getJsDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private Comment getJsDoc(SourceRange location) {
Comment closestPreviousComment = null;
while (currentComment != null &&
currentComment.location.end.offset <= location.start.offset) {
if (currentComment.type == Comment.Type.JSDOC) {
closestPreviousComment = currentComment;
}
if (this.nextCommentIter.hasNext()) {
currentComment = this.nextCommentIter.next();
} else {
currentComment = null;
}
}
return closestPreviousComment;
}
示例4: createJsDocInfoParser
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
/**
* Creates a JsDocInfoParser and parses the JsDoc string.
*
* Used both for handling individual JSDoc comments and for handling
* file-level JSDoc comments (@fileoverview and @license).
*
* @param node The JsDoc Comment node to parse.
* @return A JsDocInfoParser. Will contain either fileoverview JsDoc, or
* normal JsDoc, or no JsDoc (if the method parses to the wrong level).
*/
private JsDocInfoParser createJsDocInfoParser(Comment node) {
String comment = node.value;
int lineno = lineno(node.location.start);
int charno = charno(node.location.start);
int position = node.location.start.offset;
// The JsDocInfoParser expects the comment without the initial '/**'.
int numOpeningChars = 3;
JsDocInfoParser jsdocParser =
new JsDocInfoParser(
new JsDocTokenStream(comment.substring(numOpeningChars),
lineno,
charno + numOpeningChars),
comment,
position,
null,
sourceFile,
config,
errorReporter);
jsdocParser.setFileLevelJsDocBuilder(fileLevelJsDocBuilder);
jsdocParser.setFileOverviewJSDocInfo(fileOverviewInfo);
jsdocParser.parse();
return jsdocParser;
}
示例5: parseInlineTypeDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
/**
* Parses inline type info.
*/
private JSDocInfo parseInlineTypeDoc(Comment node) {
String comment = node.value;
int lineno = lineno(node.location.start);
int charno = charno(node.location.start);
// The JsDocInfoParser expects the comment without the initial '/**'.
int numOpeningChars = 3;
JsDocInfoParser parser =
new JsDocInfoParser(
new JsDocTokenStream(comment.substring(numOpeningChars),
lineno,
charno + numOpeningChars),
comment,
node.location.start.offset,
null,
sourceFile,
config,
errorReporter);
return parser.parseInlineTypeDoc();
}
示例6: process
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
for (Node script : root.children()) {
if (script.isScript()) {
// Note: this doesn't actually copy the list since the underlying list is already an
// immutable list.
ImmutableList<Comment> comments =
ImmutableList.copyOf(compiler.getComments(script.getSourceFileName()));
NodeTraversal.traverseEs6(compiler, script, new LinkCommentsForOneFile(comments));
}
}
}
示例7: addComments
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
@Override
void addComments(String filename, List<Comment> comments) {
if (!getOptions().preservesDetailedSourceInfo()) {
throw new UnsupportedOperationException(
"addComments may only be called in IDE mode.");
}
commentsPerFile.put(filename, comments);
}
示例8: getComments
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
@Override
public List<Comment> getComments(String filename) {
if (!getOptions().preservesDetailedSourceInfo()) {
throw new UnsupportedOperationException(
"getComments may only be called in IDE mode.");
}
return commentsPerFile.get(filename);
}
示例9: parse
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
/** Internal implementation to produce the {@link FileInfo} object. */
private static FileInfo parse(String code, String filename, @Nullable Reporter reporter) {
ErrorReporter errorReporter = new DelegatingReporter(reporter);
Compiler compiler = new Compiler();
compiler.init(
ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), new CompilerOptions());
Config config =
ParserRunner.createConfig(
// TODO(sdh): ES8 STRICT, with a non-strict fallback - then give warnings.
Config.LanguageMode.ECMASCRIPT8,
Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE,
Config.RunMode.KEEP_GOING,
/* extraAnnotationNames */ ImmutableSet.<String>of(),
/* parseInlineSourceMaps */ true,
Config.StrictMode.SLOPPY);
SourceFile source = SourceFile.fromCode(filename, code);
FileInfo info = new FileInfo(errorReporter);
ParserRunner.ParseResult parsed = ParserRunner.parse(source, code, config, errorReporter);
parsed.ast.setInputId(new InputId(filename));
String version = parsed.features.version();
if (!version.equals("es3")) {
info.loadFlags.add(JsArray.of("lang", version));
}
for (Comment comment : parsed.comments) {
if (comment.type == Comment.Type.JSDOC) {
parseComment(comment, info);
}
}
NodeTraversal.traverseEs6(compiler, parsed.ast, new Traverser(info));
return info;
}
示例10: IRFactory
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private IRFactory(String sourceString,
StaticSourceFile sourceFile,
Config config,
ErrorReporter errorReporter,
ImmutableList<Comment> comments) {
this.sourceString = sourceString;
this.nextCommentIter = comments.iterator();
this.currentComment = skipNonJsDoc(nextCommentIter);
this.newlines = new ArrayList<>();
this.sourceFile = sourceFile;
// The template node properties are applied to all nodes in this transform.
this.templateNode = createTemplateNode();
this.fileLevelJsDocBuilder =
new JSDocInfoBuilder(config.jsDocParsingMode().shouldParseDescriptions());
// Pre-generate all the newlines in the file.
for (int charNo = 0; true; charNo++) {
charNo = sourceString.indexOf('\n', charNo);
if (charNo == -1) {
break;
}
newlines.add(charNo);
}
// Sometimes this will be null in tests.
this.sourceName = sourceFile == null ? null : sourceFile.getName();
this.config = config;
this.errorReporter = errorReporter;
this.transformDispatcher = new TransformDispatcher();
if (config.strictMode().isStrict()) {
reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS;
} else if (config.languageMode() == LanguageMode.ECMASCRIPT3) {
reservedKeywords = null; // use TokenStream.isKeyword instead
} else {
reservedKeywords = ES5_RESERVED_KEYWORDS;
}
}
示例11: skipNonJsDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private static Comment skipNonJsDoc(UnmodifiableIterator<Comment> comments) {
while (comments.hasNext()) {
Comment comment = comments.next();
if (comment.type == Comment.Type.JSDOC) {
return comment;
}
}
return null;
}
示例12: transformTree
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
public static IRFactory transformTree(ProgramTree tree,
StaticSourceFile sourceFile,
String sourceString,
Config config,
ErrorReporter errorReporter) {
IRFactory irFactory = new IRFactory(sourceString, sourceFile,
config, errorReporter, tree.sourceComments);
// don't call transform as we don't want standard jsdoc handling.
Node n = irFactory.transformDispatcher.process(tree);
irFactory.setSourceInfo(n, tree);
if (tree.sourceComments != null) {
for (Comment comment : tree.sourceComments) {
if ((comment.type == Comment.Type.JSDOC || comment.type == Comment.Type.IMPORTANT)
&& !irFactory.parsedComments.contains(comment)) {
irFactory.handlePossibleFileOverviewJsDoc(comment);
} else if (comment.type == Comment.Type.BLOCK) {
irFactory.handleBlockComment(comment);
}
}
}
irFactory.setFileOverviewJsDoc(n);
irFactory.validateAll(n);
irFactory.resultNode = n;
return irFactory;
}
示例13: handleBlockComment
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
/**
* Check to see if the given block comment looks like it should be JSDoc.
*/
private void handleBlockComment(Comment comment) {
if (COMMENT_PATTERN.matcher(comment.value).find()) {
errorReporter.warning(
SUSPICIOUS_COMMENT_WARNING,
sourceName,
lineno(comment.location.start),
charno(comment.location.start));
}
}
示例14: getJsDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private Comment getJsDoc(SourceRange location) {
Comment closestPreviousComment = null;
while (hasPendingCommentBefore(location)) {
closestPreviousComment = currentComment;
currentComment = skipNonJsDoc(nextCommentIter);
}
return closestPreviousComment;
}
示例15: handleJsDoc
import com.google.javascript.jscomp.parsing.parser.trees.Comment; //导入依赖的package包/类
private JSDocInfo handleJsDoc(Comment comment) {
if (comment != null) {
JsDocInfoParser jsDocParser = createJsDocInfoParser(comment);
parsedComments.add(comment);
if (!handlePossibleFileOverviewJsDoc(jsDocParser)) {
return recordJsDoc(comment.location,
jsDocParser.retrieveAndResetParsedJSDocInfo());
}
}
return null;
}