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


Java Diagnostic.getMessage方法代码示例

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


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

示例1: javap

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private String javap(List<String> args, List<String> classes) {
    DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavaFileManager fm = JavapFileManager.create(dc, pw);
    JavapTask t = new JavapTask(pw, fm, dc, args, classes);
    if (t.run() != 0)
        throw new Error("javap failed unexpectedly");

    List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
    for (Diagnostic<? extends JavaFileObject> d: diags) {
        if (d.getKind() == Diagnostic.Kind.ERROR)
            throw new Error(d.getMessage(Locale.ENGLISH));
    }
    return sw.toString();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:T7190862.java

示例2: createMessage

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public String createMessage(CompilationInfo info, Diagnostic d, int offset, TreePath treePath, ErrorRule.Data data) {
    String msg = d.getMessage(null);
    Matcher m = LOCATION_LINE.matcher(msg);
    if (!m.find()) {
        return null;
    }
    String location = m.group(1);
    int idx = location.indexOf("$JShell$"); // NOI18N
    if (idx == -1) {
        idx = location.indexOf("$JSHELL$"); // NOI18N
        if (idx == -1) {
            return null;
        }
    }
    String[] components = location.substring(idx).split("\\."); // NOI18N
    String last = components[components.length - 1];
    if (last.startsWith("$JShell$") || last.startsWith("$JSHELL$")) { // NOI18N
        // leave out the location at all
        return msg.substring(0, m.start(0));
    } else {
        return msg.substring(0, m.start(0)) + Bundle.Format_Location(last) + 
                msg.substring(m.end(0));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:LocationSuppressRule.java

示例3: assertErrorsOnLines

import javax.tools.Diagnostic; //导入方法依赖的package包/类
/**
 * Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
 * on the given lines of the given file. If there should be multiple errors on a line, the line
 * number must appear multiple times. There may not be any errors in any other file.
 */
public void assertErrorsOnLines(String file,
    List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
  ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
  for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
    String message = diagnostic.getMessage(Locale.US);

    // The source may be null, e.g. for diagnostics about command-line flags
    assertNotNull(message, diagnostic.getSource());
    String sourceName = diagnostic.getSource().getName();

    assertEquals(
        "unexpected error in source file " + sourceName + ": " + message,
        file, sourceName);

    actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());

    // any errors from the compiler that are not related to this checker should fail
    assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
  }

  assertEquals(
      ImmutableMultiset.copyOf(Longs.asList(lines)),
      ImmutableMultiset.copyOf(actualErrors.get(file)));
}
 
开发者ID:google,项目名称:guava-beta-checker,代码行数:30,代码来源:TestCompiler.java

示例4: run

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private void run() {
    File classToCheck = new File(System.getProperty("test.classes"),
        getClass().getSimpleName() + ".class");

    DiagnosticCollector<JavaFileObject> dc =
            new DiagnosticCollector<JavaFileObject>();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavaFileManager fm = JavapFileManager.create(dc, pw);
    JavapTask t = new JavapTask(pw, fm, dc, null,
            Arrays.asList(classToCheck.getPath()));
    if (t.run() != 0)
        throw new Error("javap failed unexpectedly");

    List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
    for (Diagnostic<? extends JavaFileObject> d: diags) {
        if (d.getKind() == Diagnostic.Kind.ERROR)
            throw new AssertionError(d.getMessage(Locale.ENGLISH));
    }
    String lineSep = System.getProperty("line.separator");
    String out = sw.toString().replace(lineSep, "\n");
    if (!out.equals(expOutput)) {
        throw new AssertionError("The output is not equal to the one expected");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:JavapTaskCtorFailWithNPE.java

示例5: hasMessage

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static Matcher<Diagnostic<? extends JavaFileObject>> hasMessage( Matcher<String> messageMatcher ) {
  return new FeatureMatcher<Diagnostic<? extends JavaFileObject>, String>(messageMatcher, "message", "message") {
    @Override
    protected String featureValueOf(Diagnostic<? extends JavaFileObject> actual) {
      return actual.getMessage(Locale.ENGLISH);
    }
  };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:CompilerWarningIT.java

示例6: assertError

import javax.tools.Diagnostic; //导入方法依赖的package包/类
void assertError(String expMsg) {
    StringBuilder sb = new StringBuilder();
    sb.append("Can't find ").append(expMsg).append(" among:");
    for (Diagnostic<? extends JavaFileObject> e : errors) {
        String msg = e.getMessage(Locale.US);
        if (msg.contains(expMsg)) {
            return;
        }
        sb.append("\n");
        sb.append(msg);
    }
    fail(sb.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:Compile.java

示例7: failIfHTMLPageDoesNotExist

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Test public void failIfHTMLPageDoesNotExist() throws Exception {
    String html = "<html><body>"
            + "</body></html>";
    String code = "package x.y.z;\n"
            + "import org.netbeans.api.htmlui.OpenHTMLRegistration;\n"
            + "import org.openide.awt.ActionID;\n"
            + "class X {\n"
            + "  @ActionID(category=\"test\", id=\"test.id.at.x\")\n"
            + "  @OpenHTMLRegistration(url=\"does-not-exist.html\", displayName=\"X\")\n"
            + "  public static void someMethod() {\n"
            + "  }\n"
            + "}\n";

    Compile c = Compile.create("different.html", html, code);
    assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
    boolean ok = false;
    StringBuilder msgs = new StringBuilder();
    for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
        String msg = e.getMessage(Locale.ENGLISH);
        if (msg.contains("Cannot find resource")) {
            ok = true;
        }
        msgs.append("\n").append(msg);
    }
    if (!ok) {
        fail("Should contain warning about Cannot find resource:" + msgs);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:HTMLViewProcessorTest.java

示例8: methodIsNotStatic

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Test public void methodIsNotStatic() throws Exception {
    String html = "<html><body>"
            + "</body></html>";
    String code = "package x.y.z;\n"
            + "import org.netbeans.api.htmlui.OpenHTMLRegistration;\n"
            + "import org.openide.awt.ActionID;\n"
            + "public final class X {\n"
            + "  @ActionID(category=\"test\", id=\"test.id.at.x\")\n"
            + "  @OpenHTMLRegistration(url=\"page.html\", displayName=\"X\")\n"
            + "  public void someMethod() {\n"
            + "  }\n"
            + "}\n";

    Compile c = Compile.create("page.html", html, code);
    assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
    boolean ok = false;
    StringBuilder msgs = new StringBuilder();
    for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
        String msg = e.getMessage(Locale.ENGLISH);
        if (msg.contains("needs to be static")) {
            ok = true;
        }
        msgs.append("\n").append(msg);
    }
    if (!ok) {
        fail("Should contain warning about static:" + msgs);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:HTMLViewProcessorTest.java

示例9: methodNeedsToBeInPublicClass

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Test public void methodNeedsToBeInPublicClass() throws Exception {
    String html = "<html><body>"
            + "</body></html>";
    String code = "package x.y.z;\n"
            + "import org.netbeans.api.htmlui.OpenHTMLRegistration;\n"
            + "import org.openide.awt.ActionID;\n"
            + "final class X {\n"
            + "  @ActionID(category=\"test\", id=\"test.id.at.x\")\n"
            + "  @OpenHTMLRegistration(url=\"page.html\", displayName=\"X\")\n"
            + "  public static void someMethod() {\n"
            + "  }\n"
            + "}\n";

    Compile c = Compile.create("page.html", html, code);
    assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
    boolean ok = false;
    StringBuilder msgs = new StringBuilder();
    for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
        String msg = e.getMessage(Locale.ENGLISH);
        if (msg.contains("needs to be public")) {
            ok = true;
        }
        msgs.append("\n").append(msg);
    }
    if (!ok) {
        fail("Should contain warning about public:" + msgs);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:HTMLViewProcessorTest.java

示例10: methodWithNoParamsIsOK

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Test public void methodWithNoParamsIsOK() throws Exception {
    String html = "<html><body>"
            + "</body></html>";
    String code = "package x.y.z;\n"
            + "import org.netbeans.api.htmlui.OpenHTMLRegistration;\n"
            + "import org.openide.awt.ActionID;\n"
            + "public class X {\n"
            + "  @ActionID(category=\"test\", id=\"test.id.at.x\")\n"
            + "  @OpenHTMLRegistration(url=\"page.html\", displayName=\"X\")\n"
            + "  public static void someMethod(int x) {\n"
            + "  }\n"
            + "}\n";

    Compile c = Compile.create("page.html", html, code);
    assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
    boolean ok = false;
    StringBuilder msgs = new StringBuilder();
    for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
        String msg = e.getMessage(Locale.ENGLISH);
        if (msg.contains("no arguments")) {
            ok = true;
        }
        msgs.append("\n").append(msg);
    }
    if (!ok) {
        fail("Should contain warning about arguments:" + msgs);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:HTMLViewProcessorTest.java

示例11: ErrorNode

import javax.tools.Diagnostic; //导入方法依赖的package包/类
/** Creates a new instance of ErrorNode */
public ErrorNode(CompilationInfo info, Diagnostic diag) {
    super(Children.LEAF); //always leaf
    this.info = info;
    this.diag = diag;
    String ss = diag.getMessage(Locale.ENGLISH);
    setDisplayName(diag.getCode() + " " + diag.getKind() + ": " + ss); //NOI18N
    setIconBaseWithExtension("org/netbeans/modules/java/debug/resources/element.png"); //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ErrorNode.java

示例12: getInvalidModifier

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private String getInvalidModifier(CompilationInfo compilationInfo, TreePath treePath, Set<String> codes) {
    long start = compilationInfo.getTrees().getSourcePositions().getStartPosition(compilationInfo.getCompilationUnit(), treePath.getLeaf());
    Diagnostic diagnostic = getDiagnostic(compilationInfo, start, codes);
    if (null==diagnostic){
        return null;
    }
    //parse the error message
    //HACK: hope this will be stable in the long term
    String message = diagnostic.getMessage(Locale.ENGLISH);
    Matcher matcher = Pattern.compile(ERROR_PATTERN).matcher(message);
    if (!matcher.find()) {
        return null;
    }
    return matcher.group(1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:RemoveInvalidModifier.java

示例13: ensureCompilable

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private void ensureCompilable(FileObject file) throws IOException, AssertionError, IllegalArgumentException {
    CompilationInfo info = parse(file);

    assertNotNull(info);

    for (Diagnostic d : info.getDiagnostics()) {
        if (d.getKind() == Diagnostic.Kind.ERROR)
            throw new AssertionError(d.getLineNumber() + ":" + d.getColumnNumber() + " " + d.getMessage(null));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:HintTest.java

示例14: showDiagnostics

import javax.tools.Diagnostic; //导入方法依赖的package包/类
private void showDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
	String message;
	for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
		if (StringUtils.equals(diagnostic.getKind().name(), Diagnostic.Kind.ERROR.name())) {
			message = diagnostic.getMessage(null);
			new CustomMessageBox(SWT.ERROR, message, Messages.INVALID_EXPRESSION_TITLE).open();
		} else {
			new CustomMessageBox(SWT.ICON_INFORMATION, Messages.VALID_EXPRESSION_TITLE, Messages.VALID_EXPRESSION_TITLE).open();
		}
		break;
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:13,代码来源:ValidateExpressionToolButton.java

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