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


Java Diagnostic.getSource方法代码示例

本文整理汇总了Java中javax.tools.Diagnostic.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java Diagnostic.getSource方法的具体用法?Java Diagnostic.getSource怎么用?Java Diagnostic.getSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.Diagnostic的用法示例。


在下文中一共展示了Diagnostic.getSource方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSrcSpan

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static Spannable createSrcSpan(Resources resources, @NonNull Diagnostic diagnostic) {
    if (diagnostic.getSource() == null) {
        return new SpannableString("Unknown");
    }
    if (!(diagnostic.getSource() instanceof JavaFileObject)) {
        return new SpannableString(diagnostic.getSource().toString());
    }
    try {
        JavaFileObject source = (JavaFileObject) diagnostic.getSource();
        File file = new File(source.getName());
        String name = file.getName();
        String line = diagnostic.getLineNumber() + ":" + diagnostic.getColumnNumber();
        SpannableString span = new SpannableString(name + ":" + line);
        span.setSpan(new ForegroundColorSpan(resources.getColor(R.color.dark_color_diagnostic_file)),
                0, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span;
    } catch (Exception e) {

    }
    return new SpannableString(diagnostic.getSource().toString());
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:SpanUtil.java

示例2: click

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void click(Diagnostic diagnostic) {
    Log.d(TAG, "click() called with: diagnostic = [" + diagnostic + "]");
    mMainActivity.closeDrawer(GravityCompat.START);

    Object source = diagnostic.getSource();
    if (source instanceof JavaFileObject && diagnostic.getKind() == Diagnostic.Kind.ERROR) {
        String path = ((JavaFileObject) source).getName();
        int i = mPagePresenter.gotoPage(path);
        if (i == -1) {
            mPagePresenter.addPage(path, true);
        }
        EditPageContract.SourceView editor = mPagePresenter.getCurrentPage();
        if (editor == null) {
            Log.d(TAG, "click: editor null");
            return;
        }
        int startPosition = (int) diagnostic.getStartPosition();
        int endPosition = (int) diagnostic.getEndPosition();
        editor.highlightError(startPosition, endPosition);
        editor.setCursorPosition(endPosition);
    } else {
        // TODO: 19/07/2017 implement other
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:DiagnosticPresenter.java

示例3: report

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void report(Diagnostic<? extends JavaFileObject> message) {
    if (partialReparseErrors != null) {
        if (this.jfo != null && this.jfo == message.getSource()) {
            partialReparseErrors.add(message);
            if (message.getKind() == Kind.ERROR) {
                partialReparseRealErrors = true;
            }
        }
    } else {
        Diagnostics errors = getErrors(message.getSource());
        errors.add((int) message.getPosition(), message);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CompilationInfoImpl.java

示例4: isCurrTreeItem

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private static TreeItem<Path> isCurrTreeItem(Diagnostic diagnostic) {
    JavaFileObject javaFileObject = (JavaFileObject) diagnostic.getSource();
    Optional<TreeItem<Path>> item = treeItems.parallelStream()
            .filter(c -> javaFileObject.getName().equals(c.getValue().toString()))
            .findFirst();

    if (item.isPresent()) {
        TreeItem<Path> treeItem = item.get();
        treeItems.remove(treeItem);
        return treeItem;
    }

    return null;
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:15,代码来源:HighlightCell.java

示例5: getSourceContent

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private CharSequence getSourceContent(Diagnostic diagnostic) {
  CharSequence sourceContent = null;
  Object source = diagnostic.getSource();
  if (source != null) {
    JavaSourceFileObject sourceFile = JavaSourceFileObject.class.cast(source);
    sourceContent = sourceFile.getCharContent(true);
  }
  return sourceContent;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:10,代码来源:JavaSourceCompiler.java

示例6: diag

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public Diag diag(Diagnostic<? extends JavaFileObject> d) {
    SourceMemoryJavaFileObject smjfo = (SourceMemoryJavaFileObject) d.getSource();
    if (smjfo == null) {
        // Handle failure that doesn't preserve mapping
        return new StringSourceHandler().diag(d);
    }
    OuterWrap w = (OuterWrap) smjfo.getOrigin();
    return w.wrapDiag(d);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TaskFactory.java

示例7: main

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (compiler == null) {
        throw new RuntimeException("can't get javax.tools.JavaCompiler!");
    }
    DiagnosticCollector<JavaFileObject> diagColl =
        new DiagnosticCollector<JavaFileObject>();
    try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
        List<String> options = new ArrayList<String>();
        options.add("-processor");
        options.add("MyProcessor");
        options.add("-proc:only");
        List<File> files = new ArrayList<File>();
        files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
        final CompilationTask task = compiler.getTask(null, fm, diagColl,
            options, null, fm.getJavaFileObjectsFromFiles(files));
        task.call();
        int diagCount = 0;
        for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
            if (diag.getKind() != Diagnostic.Kind.WARNING) {
                throw new AssertionError("Only warnings expected");
            }
            System.out.println(diag);
            if (diag.getPosition() == Diagnostic.NOPOS) {
                throw new AssertionError("No position info in message");
            }
            if (diag.getSource() == null) {
                throw new AssertionError("No source info in message");
            }
            diagCount++;
        }
        if (diagCount != 2) {
            throw new AssertionError("unexpected number of warnings: " +
                diagCount + ", expected: 2");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:T6458823.java

示例8: brokenPlatform

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static void brokenPlatform(
        @NonNull final Context ctx,
        @NonNull final Iterable<? extends CompileTuple> files,
        @NullAllowed final Diagnostic<JavaFileObject> diagnostic) {
    if (diagnostic == null) {
        return;
    }
    final Diagnostic<JavaFileObject> error = new Diagnostic<JavaFileObject>() {

        @Override
        public Kind getKind() {
            return Kind.ERROR;
        }

        @Override
        public JavaFileObject getSource() {
            return diagnostic.getSource();
        }

        @Override
        public long getPosition() {
            return diagnostic.getPosition();
        }

        @Override
        public long getStartPosition() {
            return diagnostic.getStartPosition();
        }

        @Override
        public long getEndPosition() {
            return diagnostic.getEndPosition();
        }

        @Override
        public long getLineNumber() {
            return diagnostic.getLineNumber();
        }

        @Override
        public long getColumnNumber() {
            return diagnostic.getColumnNumber();
        }

        @Override
        public String getCode() {
            return diagnostic.getCode();
        }

        @Override
        public String getMessage(Locale locale) {
            return diagnostic.getMessage(locale);
        }
    };
    for (CompileTuple file : files) {
        if (!file.virtual) {
            ErrorsCache.setErrors(
                ctx.getRootURI(),
                file.indexable,
                Collections.<Diagnostic<JavaFileObject>>singleton(error),
                ERROR_CONVERTOR);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:65,代码来源:JavaCustomIndexer.java


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