Java Code Examples for javax.tools.Diagnostic#Kind

The following examples show how to use javax.tools.Diagnostic#Kind . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TurbineDiagnostic.java    From turbine with Apache License 2.0 6 votes vote down vote up
private static TurbineDiagnostic create(
    Diagnostic.Kind severity,
    ErrorKind kind,
    ImmutableList<Object> args,
    SourceFile source,
    int position) {
  switch (kind) {
    case SYMBOL_NOT_FOUND:
      {
        checkArgument(
            args.size() == 1 && getOnlyElement(args) instanceof ClassSymbol,
            "diagnostic (%s) has invalid argument %s",
            kind,
            args);
        break;
      }
    default: // fall out
  }
  return new TurbineDiagnostic(severity, kind, args, source, position);
}
 
Example 2
Source File: JsonModel.java    From manifold with Apache License 2.0 6 votes vote down vote up
void report( DiagnosticListener<JavaFileObject> errorHandler )
{
  if( errorHandler == null )
  {
    return;
  }

  List<IIssue> issues = getIssues();
  if( issues.isEmpty() )
  {
    return;
  }

  JavaFileObject file = new SourceJavaFileObject( getFile().toURI() );
  for( IIssue issue : issues )
  {
    Diagnostic.Kind kind = issue.getKind() == IIssue.Kind.Error ? Diagnostic.Kind.ERROR : Diagnostic.Kind.WARNING;
    errorHandler.report( new JavacDiagnostic( file, kind, issue.getStartOffset(), issue.getLine(), issue.getColumn(), issue.getMessage() ) );
  }
}
 
Example 3
Source File: BindingGraphValidator.java    From dagger2-sample with Apache License 2.0 6 votes vote down vote up
BindingGraphValidator(
    Types types,
    InjectBindingRegistry injectBindingRegistry,
    ValidationType scopeCycleValidationType,
    Diagnostic.Kind nullableValidationType,
    ProvisionBindingFormatter provisionBindingFormatter,
    ProductionBindingFormatter productionBindingFormatter,
    MethodSignatureFormatter methodSignatureFormatter,
    DependencyRequestFormatter dependencyRequestFormatter,
    KeyFormatter keyFormatter) {
  this.types = types;
  this.injectBindingRegistry = injectBindingRegistry;
  this.scopeCycleValidationType = scopeCycleValidationType;
  this.nullableValidationType = nullableValidationType;
  this.provisionBindingFormatter = provisionBindingFormatter;
  this.productionBindingFormatter = productionBindingFormatter;
  this.methodSignatureFormatter = methodSignatureFormatter;
  this.dependencyRequestFormatter = dependencyRequestFormatter;
  this.keyFormatter = keyFormatter;
}
 
Example 4
Source File: Messages.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void record(Messages.Group g, Diagnostic.Kind dkind, String code) {
    if (codeCounts == null) {
        return;
    }
    groupCounts[g.ordinal()]++;
    dkindCounts[dkind.ordinal()]++;
    if (code == null) {
        code = NO_CODE;
    }
    Integer i = codeCounts.get(code);
    codeCounts.put(code, (i == null) ? 1 : i + 1);
}
 
Example 5
Source File: Messages.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void record(Messages.Group g, Diagnostic.Kind dkind, String code) {
    if (codeCounts == null) {
        return;
    }
    groupCounts[g.ordinal()]++;
    dkindCounts[dkind.ordinal()]++;
    if (code == null) {
        code = NO_CODE;
    }
    Integer i = codeCounts.get(code);
    codeCounts.put(code, (i == null) ? 1 : i + 1);
}
 
Example 6
Source File: ErrorTranslationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String getKind(Diagnostic.Kind kind) {
    switch (kind) {
        case WARNING:
            return "|  Warning:";
        case ERROR:
            return "|  Error:";
        default:
            throw new AssertionError("Unsupported kind: " + kind);
    }
}
 
Example 7
Source File: JCDiagnostic.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Diagnostic.Kind getKind() {
    switch (type) {
    case NOTE:
        return Diagnostic.Kind.NOTE;
    case WARNING:
        return flags.contains(DiagnosticFlag.MANDATORY)
                ? Diagnostic.Kind.MANDATORY_WARNING
                : Diagnostic.Kind.WARNING;
    case ERROR:
        return Diagnostic.Kind.ERROR;
    default:
        return Diagnostic.Kind.OTHER;
    }
}
 
Example 8
Source File: Messages.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void report(Group group, Diagnostic.Kind dkind, Tree tree, String code, Object... args) {
    if (options.isEnabled(group, env.currAccess)) {
        String msg = localize(code, args);
        env.trees.printMessage(dkind, msg, tree, env.currPath.getCompilationUnit());

        stats.record(group, dkind, code);
    }
}
 
Example 9
Source File: DocLintTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
Message(Diagnostic.Kind kind, String text) {
    this.kind = kind;
    this.text = text;
}
 
Example 10
Source File: AnnotatedMixinElementHandler.java    From Mixin with MIT License 4 votes vote down vote up
public final void printMessage(IMessagerSuppressible messager, Diagnostic.Kind kind, CharSequence msg, SuppressedBy suppressedBy) {
    messager.printMessage(kind, msg, this.element, this.annotation.asMirror(), suppressedBy);
}
 
Example 11
Source File: Messages.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void report(Diagnostic.Kind k, DocTreePath p, String msg) {
    initReporter();
    reporter.print(k, p, msg);
}
 
Example 12
Source File: JavacMessager.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void printMessage(Diagnostic.Kind kind, CharSequence msg) {
    printMessage(kind, msg, null, null, null);
}
 
Example 13
Source File: Warn5.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void check(Result<?> res) {

        EnumSet<WarningKind> foundWarnings = EnumSet.noneOf(WarningKind.class);
        for (Diagnostic.Kind kind : new Kind[] { Kind.ERROR, Kind.MANDATORY_WARNING, Kind.WARNING}) {
            for (Diagnostic<? extends JavaFileObject> diag : res.diagnosticsForKind(kind)) {
                for (WarningKind wk : WarningKind.values()) {
                    if (wk.code.equals(diag.getCode())) {
                        foundWarnings.add(wk);
                    }
                }
            }
        }

        EnumSet<WarningKind> expectedWarnings =
                EnumSet.noneOf(WarningKind.class);

        if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
                trustMe == TrustMe.TRUST &&
                suppressLevel != SuppressLevel.VARARGS &&
                xlint != XlintOption.NONE &&
                sig.isVarargs &&
                !sig.isReifiableArg &&
                body.hasAliasing &&
                (methKind == MethodKind.CONSTRUCTOR ||
                (methKind == MethodKind.METHOD &&
                 modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
                 (modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0)))) {
            expectedWarnings.add(WarningKind.UNSAFE_BODY);
        }

        if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
                trustMe == TrustMe.DONT_TRUST &&
                sig.isVarargs &&
                !sig.isReifiableArg &&
                xlint == XlintOption.ALL) {
            expectedWarnings.add(WarningKind.UNSAFE_DECL);
        }

        if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
                trustMe == TrustMe.TRUST &&
                (!sig.isVarargs ||
                 ((modKind == ModifierKind.NONE ||
                 modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) < 0 ) &&
                 methKind == MethodKind.METHOD))) {
            expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
        }

        if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
                trustMe == TrustMe.TRUST &&
                xlint != XlintOption.NONE &&
                suppressLevel != SuppressLevel.VARARGS &&
                (modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
                 (modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0) ||
                 methKind == MethodKind.CONSTRUCTOR) &&
                sig.isVarargs &&
                sig.isReifiableArg) {
            expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS);
        }

        if (!expectedWarnings.containsAll(foundWarnings) ||
                !foundWarnings.containsAll(expectedWarnings)) {
            fail("invalid diagnostics for source:\n" +
                    res.compilationInfo() +
                    "\nOptions: " + xlint.getXlintOption() +
                    "\nSource Level: " + sourceLevel +
                    "\nExpected warnings: " + expectedWarnings +
                    "\nFound warnings: " + foundWarnings);
        }
    }
 
Example 14
Source File: CompletionFilter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void printMessage(Diagnostic.Kind kind, CharSequence cs, DocTree dt, DocCommentTree dct, CompilationUnitTree cut) {
    delegate.printMessage(kind, cs, dt, dct, cut);
}
 
Example 15
Source File: JavacMessager.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void printMessage(Diagnostic.Kind kind, CharSequence msg,
                  Element e) {
    printMessage(kind, msg, e, null, null);
}
 
Example 16
Source File: Message.java    From Mixin with MIT License 4 votes vote down vote up
/**
 * Get the message kind
 */
public Diagnostic.Kind getKind() {
    return this.kind;
}
 
Example 17
Source File: Messager.java    From preferencebinder with Apache License 2.0 2 votes vote down vote up
/**
 * Prints a message of the specified kind at the location of the
 * annotation mirror of the annotated element.
 *
 * @param kind the kind of message
 * @param msg  the message, or an empty string if none
 * @param e    the annotated element
 * @param a    the annotation to use as a position hint
 */
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a);
 
Example 18
Source File: Messager.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Prints a message of the specified kind at the location of the
 * element.
 *
 * @param kind the kind of message
 * @param msg  the message, or an empty string if none
 * @param e    the element to use as a position hint
 */
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e);
 
Example 19
Source File: Trees.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Prints a message of the specified kind at the location of the
 * tree within the provided compilation unit
 *
 * @param kind the kind of message
 * @param msg  the message, or an empty string if none
 * @param t    the tree to use as a position hint
 * @param root the compilation unit that contains tree
 */
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
        com.sun.source.tree.Tree t,
        com.sun.source.tree.CompilationUnitTree root);
 
Example 20
Source File: Messager.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Prints a message of the specified kind at the location of the
 * annotation mirror of the annotated element.
 *
 * @param kind the kind of message
 * @param msg  the message, or an empty string if none
 * @param e    the annotated element
 * @param a    the annotation to use as a position hint
 */
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a);