本文整理汇总了Java中com.sun.tools.javac.util.DiagnosticSource类的典型用法代码示例。如果您正苦于以下问题:Java DiagnosticSource类的具体用法?Java DiagnosticSource怎么用?Java DiagnosticSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiagnosticSource类属于com.sun.tools.javac.util包,在下文中一共展示了DiagnosticSource类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DocCommentParser
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
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();
}
示例2: position
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
private static Range position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
error = ((ClientCodeWrapper.DiagnosticSourceUnwrapper) error).d;
JCDiagnostic diagnostic = (JCDiagnostic) error;
DiagnosticSource source = diagnostic.getDiagnosticSource();
long start = error.getStartPosition(), end = error.getEndPosition();
if (end == start) end = start + 1;
return new Range(
new Position(
source.getLineNumber((int) start) - 1,
source.getColumnNumber((int) start, true) - 1),
new Position(
source.getLineNumber((int) end) - 1,
source.getColumnNumber((int) end, true) - 1));
}
示例3: formatMessage
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
private static String formatMessage(
String checkName, JavaFileObject file, DiagnosticPosition pos, Throwable cause) {
DiagnosticSource source = new DiagnosticSource(file, /*log=*/ null);
int column = source.getColumnNumber(pos.getStartPosition(), /*expandTabs=*/ true);
int line = source.getLineNumber(pos.getStartPosition());
String snippet = source.getLine(pos.getStartPosition());
StringBuilder sb = new StringBuilder();
sb.append(
String.format(
"\n%s:%d: %s: An exception was thrown by Error Prone: %s\n",
source.getFile().getName(), line, checkName, cause.getMessage()));
sb.append(snippet).append('\n');
if (column > 0) {
sb.append(Strings.repeat(" ", column - 1));
}
sb.append("^\n");
return sb.toString();
}
示例4: DocCommentParser
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment) {
this.fac = fac;
this.diagSource = diagSource;
this.comment = comment;
names = fac.names;
m = fac.docTreeMaker;
initTagParsers();
}
示例5: doAnalysis
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
void doAnalysis(AnalysisContext context) {
DiagnosticSource prevSource = log.currentSource();
LocalCacheContext localCacheContext = argumentAttr.withLocalCacheContext();
try {
log.useSource(context.env.toplevel.getSourceFile());
JCStatement treeToAnalyze = (JCStatement)context.tree;
if (context.env.info.scope.owner.kind == Kind.TYP) {
//add a block to hoist potential dangling variable declarations
treeToAnalyze = make.Block(Flags.SYNTHETIC, List.of((JCStatement)context.tree));
}
TreeMapper treeMapper = new TreeMapper(context);
//TODO: to further refine the analysis, try all rewriting combinations
deferredAttr.attribSpeculative(treeToAnalyze, context.env, attr.statInfo, treeMapper,
t -> new AnalyzeDeferredDiagHandler(context), argumentAttr.withLocalCacheContext());
context.treeMap.entrySet().forEach(e -> {
context.treesToAnalyzer.get(e.getKey())
.process(e.getKey(), e.getValue(), context.errors.nonEmpty());
});
} catch (Throwable ex) {
Assert.error("Analyzer error when processing: " + context.tree);
} finally {
log.useSource(prevSource.getFile());
localCacheContext.leave();
}
}
示例6: resetEndPosMap
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
@Override
public void resetEndPosMap(JavaCompiler compiler, JavaFileObject sourceFile) {
try {
DiagnosticSource diagnosticSource = (DiagnosticSource)
ABSTRACT_LOG__GET_SOURCE.invoke(compiler.log, sourceFile);
DIAGNOSTIC_SOURCE__END_POS_TABLE.set(diagnosticSource, null);
} catch (Exception e) {
throw new LinkageError(e.getMessage());
}
}
示例7: Erroneous
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
public com.sun.source.doctree.ErroneousTree Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) {
String msg = "Erroneous tree implemented: "
+ text
+ " " + code;
throw new AssertionError(msg);
}
示例8: DCErroneous
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
DCErroneous(String body, JCDiagnostic.Factory diags, DiagnosticSource diagSource, String code, Object... args) {
this.body = body;
this.diag = diags.error(diagSource, this, code, args);
}
示例9: Erroneous
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) {
DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
tree.pos = pos;
return tree;
}
示例10: DCErroneous
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
DCErroneous(String body, JCDiagnostic.Factory diags, DiagnosticSource diagSource, String code, Object... args) {
this.body = body;
this.diag = diags.error(null, diagSource, this, code, args);
}
示例11: newErroneousTree
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
public DCErroneous newErroneousTree(String text, DiagnosticSource diagSource, String code, Object... args) {
DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args);
tree.pos = pos;
return tree;
}
示例12: getDocCommentTree
import com.sun.tools.javac.util.DiagnosticSource; //导入依赖的package包/类
@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();
}