use of com.sun.tools.javac.util.Log in project checker-framework by typetools.
the class SourceChecker method typeProcess.
/**
* Type-check the code using this checker's visitor.
*
* @see Processor#process(Set, RoundEnvironment)
*/
@Override
public void typeProcess(TypeElement e, TreePath p) {
if (javacErrored) {
reportJavacError(p);
return;
}
// Cannot use BugInCF here because it is outside of the try/catch for BugInCF.
if (e == null) {
messager.printMessage(Kind.ERROR, "Refusing to process empty TypeElement");
return;
}
if (p == null) {
messager.printMessage(Kind.ERROR, "Refusing to process empty TreePath in TypeElement: " + e);
return;
}
if (!warnedAboutGarbageCollection) {
String gcUsageMessage = SystemPlume.gcUsageMessage(.25, 60);
if (gcUsageMessage != null) {
messager.printMessage(Kind.WARNING, gcUsageMessage);
warnedAboutGarbageCollection = true;
}
}
Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
Source source = Source.instance(context);
// Also the enum constant Source.JDK1_8 was renamed at some point...
if (!warnedAboutSourceLevel && source.compareTo(Source.lookup("8")) < 0) {
messager.printMessage(Kind.WARNING, "-source " + source.name + " does not support type annotations");
warnedAboutSourceLevel = true;
}
Log log = Log.instance(context);
if (log.nerrors > this.errsOnLastExit) {
this.errsOnLastExit = log.nerrors;
javacErrored = true;
reportJavacError(p);
return;
}
if (visitor == null) {
// there. Don't also cause a NPE here.
return;
}
if (p.getCompilationUnit() != currentRoot) {
setRoot(p.getCompilationUnit());
if (hasOption("filenames")) {
// TODO: Have a command-line option to turn the timestamps on/off too, because
// they are nondeterministic across runs.
// Add timestamp to indicate how long operations are taking.
// Duplicate messages are suppressed, so this might not appear in front of every "
// is type-checking " message (when a file takes less than a second to type-check).
message(Kind.NOTE, Instant.now().toString());
message(Kind.NOTE, "%s is type-checking %s", (Object) this.getClass().getSimpleName(), currentRoot.getSourceFile().getName());
}
}
// Visit the attributed tree.
try {
visitor.visit(p);
warnUnneededSuppressions();
} catch (UserError ce) {
logUserError(ce);
} catch (TypeSystemError ce) {
logTypeSystemError(ce);
} catch (BugInCF ce) {
logBugInCF(ce);
} catch (Throwable t) {
logBugInCF(wrapThrowableAsBugInCF("SourceChecker.typeProcess", t, p));
} finally {
// Also add possibly deferred diagnostics, which will get published back in
// AbstractTypeProcessor.
this.errsOnLastExit = log.nerrors;
}
}
use of com.sun.tools.javac.util.Log in project checker-framework by typetools.
the class BaseTypeChecker method typeProcess.
// AbstractTypeProcessor delegation
@Override
public void typeProcess(TypeElement element, TreePath tree) {
if (!getSubcheckers().isEmpty()) {
// TODO: I expected this to only be necessary if (parentChecker == null).
// However, the NestedAggregateChecker fails otherwise.
messageStore.clear();
}
// Errors (or other messages) issued via
// SourceChecker#message(Diagnostic.Kind, Object, String, Object...)
// are stored in messageStore until all checkers have processed this compilation unit.
// All other messages are printed immediately. This includes errors issued because the
// checker threw an exception.
// In order to run the next checker on this compilation unit even if the previous issued errors,
// the next checker's errsOnLastExit needs to include all errors issued by previous checkers.
Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
Log log = Log.instance(context);
int nerrorsOfAllPreviousCheckers = this.errsOnLastExit;
for (BaseTypeChecker subchecker : getSubcheckers()) {
subchecker.errsOnLastExit = nerrorsOfAllPreviousCheckers;
subchecker.messageStore = messageStore;
int errorsBeforeTypeChecking = log.nerrors;
subchecker.typeProcess(element, tree);
int errorsAfterTypeChecking = log.nerrors;
nerrorsOfAllPreviousCheckers += errorsAfterTypeChecking - errorsBeforeTypeChecking;
}
this.errsOnLastExit = nerrorsOfAllPreviousCheckers;
super.typeProcess(element, tree);
if (!getSubcheckers().isEmpty()) {
printStoredMessages(tree.getCompilationUnit());
// Update errsOnLastExit to reflect the errors issued.
this.errsOnLastExit = log.nerrors;
}
}
use of com.sun.tools.javac.util.Log in project checker-framework by typetools.
the class Resolver method findPackage.
/**
* Finds the package with name {@code name}.
*
* @param name the name of the package
* @param path the tree path to the local scope
* @return the {@code PackageSymbol} for the package if it is found, {@code null} otherwise
*/
@Nullable
public PackageSymbol findPackage(String name, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res = wrapInvocationOnResolveInstance(FIND_IDENT, env, names.fromString(name), Kinds.KindSelector.PCK);
// a.b.c.MyClass.myStaticField. "exists()" must be called on it to ensure that it exists.
if (res.getKind() == ElementKind.PACKAGE) {
PackageSymbol ps = (PackageSymbol) res;
return ps.exists() ? ps : null;
} else {
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}
use of com.sun.tools.javac.util.Log in project checker-framework by typetools.
the class CFGProcessor method typeProcessingOver.
@Override
public void typeProcessingOver() {
if (rootTree == null) {
result = new CFGProcessResult("Root tree is null.");
} else if (classTree == null) {
result = new CFGProcessResult("Method tree is null.");
} else if (methodTree == null) {
result = new CFGProcessResult("Class tree is null.");
} else {
Log log = getCompilerLog();
if (log.nerrors > 0) {
result = new CFGProcessResult("Compilation issued an error.");
} else {
ControlFlowGraph cfg = CFGBuilder.build(rootTree, methodTree, classTree, processingEnv);
result = new CFGProcessResult(cfg);
}
}
super.typeProcessingOver();
}
use of com.sun.tools.javac.util.Log in project checker-framework by typetools.
the class Resolver method findLocalVariableOrParameter.
/**
* Finds the local variable (including formal parameters) with name {@code name} in the given
* scope.
*
* @param name the name of the local variable
* @param path the tree path to the local scope
* @return the element for the local variable, {@code null} otherwise
*/
@Nullable
public VariableElement findLocalVariableOrParameter(String name, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res = wrapInvocationOnResolveInstance(FIND_VAR, env, names.fromString(name));
if (res.getKind() == ElementKind.LOCAL_VARIABLE || res.getKind() == ElementKind.PARAMETER) {
return (VariableElement) res;
} else {
// The Element might be FIELD or a SymbolNotFoundError.
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}
Aggregations