当前位置: 首页>>代码示例>>Java>>正文


Java DiagnosticSource类代码示例

本文整理汇总了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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DocCommentParser.java

示例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));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:19,代码来源:Lints.java

示例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();
}
 
开发者ID:google,项目名称:error-prone,代码行数:19,代码来源:ErrorProneError.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:DocCommentParser.java

示例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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Analyzer.java

示例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());
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:11,代码来源:JDK8Shim.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:TreeFactory.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:DCTree.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:DocTreeMaker.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:DCTree.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:DocTreeMaker.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:JavacTrees.java


注:本文中的com.sun.tools.javac.util.DiagnosticSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。