use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class AnnotationFileElementTypes method parseJdkJarEntry.
/**
* Parses the stub file in the given jar entry.
*
* @param jarEntryName name of the jar entry to parse
*/
private void parseJdkJarEntry(String jarEntryName) {
JarURLConnection connection = getJarURLConnectionToJdk();
parsing = true;
try (JarFile jarFile = connection.getJarFile()) {
InputStream jdkStub;
try {
jdkStub = jarFile.getInputStream(jarFile.getJarEntry(jarEntryName));
} catch (IOException e) {
throw new BugInCF("cannot open the jdk stub file " + jarEntryName, e);
}
AnnotationFileParser.parseJdkFileAsStub(jarEntryName, jdkStub, factory, factory.getProcessingEnv(), annotationFileAnnos);
} catch (IOException e) {
throw new BugInCF("cannot open the Jar file " + connection.getEntryName(), e);
} catch (BugInCF e) {
throw new BugInCF("Exception while parsing " + jarEntryName + ": " + e.getMessage(), e);
} finally {
parsing = false;
}
}
use of org.checkerframework.javacutil.BugInCF 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 org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class SourceChecker method getProperties.
// /////////////////////////////////////////////////////////////////////////
// / Miscellaneous
// /
/**
* A helper function to parse a Properties file.
*
* @param cls the class whose location is the base of the file path
* @param filePath the name/path of the file to be read
* @param permitNonExisting if true, return an empty Properties if the file does not exist or
* cannot be parsed; if false, issue an error
* @return the properties
*/
protected Properties getProperties(Class<?> cls, String filePath, boolean permitNonExisting) {
Properties prop = new Properties();
try {
InputStream base = cls.getResourceAsStream(filePath);
if (base == null) {
// The property file was not found.
if (permitNonExisting) {
return prop;
} else {
throw new BugInCF("Couldn't locate properties file " + filePath);
}
}
prop.load(base);
} catch (IOException e) {
throw new BugInCF("Couldn't parse properties file: " + filePath, e);
}
return prop;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class SourceChecker method shouldSkipUses.
// /////////////////////////////////////////////////////////////////////////
// / Skipping uses and defs
// /
/**
* Tests whether the class owner of the passed element is an unannotated class and matches the
* pattern specified in the {@code checker.skipUses} property.
*
* @param element an element
* @return true iff the enclosing class of element should be skipped
*/
public final boolean shouldSkipUses(Element element) {
if (element == null) {
return false;
}
TypeElement typeElement = ElementUtils.enclosingTypeElement(element);
if (typeElement == null) {
throw new BugInCF("enclosingTypeElement(%s [%s]) => null%n", element, element.getClass());
}
// TypeElement.toString(): @FullyQualifiedName
@SuppressWarnings("signature:assignment") @FullyQualifiedName String name = typeElement.toString();
return shouldSkipUses(name);
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class SourceChecker method getCheckerVersion.
/**
* Returns the version of the Checker Framework.
*
* @return the Checker Framework version
*/
private String getCheckerVersion() {
Properties gitProperties = getProperties(getClass(), "/git.properties", false);
String version = gitProperties.getProperty("git.build.version");
if (version != null) {
return version;
}
throw new BugInCF("Could not find the version in git.properties");
}
Aggregations