use of org.checkerframework.javacutil.UserError in project checker-framework by typetools.
the class SourceChecker method useConservativeDefault.
/**
* Should conservative defaults be used for the kind of unchecked code indicated by the parameter?
*
* @param kindOfCode source or bytecode
* @return whether conservative defaults should be used
*/
public boolean useConservativeDefault(String kindOfCode) {
final boolean useUncheckedDefaultsForSource = false;
final boolean useUncheckedDefaultsForByteCode = false;
String option = this.getOption("useConservativeDefaultsForUncheckedCode");
// Temporary, for backward compatibility.
if (option == null) {
this.getOption("useDefaultsForUncheckedCode");
}
String[] args = option != null ? option.split(",") : new String[0];
for (String arg : args) {
boolean value = arg.indexOf("-") != 0;
arg = value ? arg : arg.substring(1);
if (arg.equals(kindOfCode)) {
return value;
}
}
if (kindOfCode.equals("source")) {
return useUncheckedDefaultsForSource;
} else if (kindOfCode.equals("bytecode")) {
return useUncheckedDefaultsForByteCode;
} else {
throw new UserError("SourceChecker: unexpected argument to useConservativeDefault: " + kindOfCode);
}
}
use of org.checkerframework.javacutil.UserError in project checker-framework by typetools.
the class DOTCFGVisualizer method shutdown.
/**
* Write a file {@code methods.txt} that contains a mapping from source code location to generated
* dot file.
*/
@Override
public void shutdown() {
try {
// Open for append, in case of multiple sub-checkers.
FileWriter fstream = new FileWriter(outDir + "/methods.txt", true);
BufferedWriter out = new BufferedWriter(fstream);
for (Map.Entry<String, String> kv : generated.entrySet()) {
out.write(kv.getKey());
out.append("\t");
out.write(kv.getValue());
out.append(lineSeparator);
}
out.close();
} catch (IOException e) {
throw new UserError("Error creating methods.txt file in: " + outDir + "; ensure the path is valid", e);
}
}
use of org.checkerframework.javacutil.UserError in project checker-framework by typetools.
the class FormatterVisitor method forwardsArguments.
/**
* Returns true if {@code invocationTree}'s arguments are {@code enclosingMethod}'s formal
* parameters. In other words, {@code invocationTree} forwards {@code enclosingMethod}'s
* arguments.
*
* <p>Only arguments from the first String formal parameter onward count. Returns false if there
* is no String formal parameter.
*
* @param invocationTree an invocation of a method
* @param enclosingMethod the method that contains the call
* @return true if {@code invocationTree} is a call to a method that forwards its containing
* method's arguments
*/
private boolean forwardsArguments(MethodInvocationTree invocationTree, @Nullable MethodTree enclosingMethod) {
if (enclosingMethod == null) {
return false;
}
ExecutableElement enclosingMethodElement = TreeUtils.elementFromDeclaration(enclosingMethod);
int paramIndex = formatStringIndex(enclosingMethodElement);
if (paramIndex == -1) {
return false;
}
ExecutableElement calledMethodElement = TreeUtils.elementFromUse(invocationTree);
int callIndex = formatStringIndex(calledMethodElement);
if (callIndex == -1) {
throw new UserError("Method " + calledMethodElement + " is annotated @FormatMethod but has no String formal parameter");
}
List<? extends ExpressionTree> args = invocationTree.getArguments();
List<? extends VariableTree> params = enclosingMethod.getParameters();
if (params.size() - paramIndex != args.size() - callIndex) {
return false;
}
while (paramIndex < params.size()) {
ExpressionTree argTree = args.get(callIndex);
if (argTree.getKind() != Tree.Kind.IDENTIFIER) {
return false;
}
VariableTree param = params.get(paramIndex);
if (param.getName() != ((IdentifierTree) argTree).getName()) {
return false;
}
paramIndex++;
callIndex++;
}
return true;
}
use of org.checkerframework.javacutil.UserError in project checker-framework by typetools.
the class CalledMethodsAnnotatedTypeFactory method enableFrameworks.
/**
* Enables support for the default builder-generation frameworks, except those listed in the
* disabled builder frameworks parsed from the -AdisableBuilderFrameworkSupport option's
* arguments. Throws a UserError if the user included an unsupported framework in the list of
* frameworks to be disabled.
*
* @param disabledFrameworks the disabled builder frameworks
*/
private void enableFrameworks(String[] disabledFrameworks) {
boolean enableAutoValueSupport = true;
boolean enableLombokSupport = true;
for (String framework : disabledFrameworks) {
switch(framework) {
case "autovalue":
enableAutoValueSupport = false;
break;
case "lombok":
enableLombokSupport = false;
break;
default:
throw new UserError("Unsupported builder framework in -AdisableBuilderFrameworkSupports: " + framework);
}
}
if (enableAutoValueSupport) {
builderFrameworkSupports.add(new AutoValueSupport(this));
}
if (enableLombokSupport) {
builderFrameworkSupports.add(new LombokSupport(this));
}
}
use of org.checkerframework.javacutil.UserError in project checker-framework by typetools.
the class SourceChecker method init.
@Override
public final synchronized void init(ProcessingEnvironment env) {
ProcessingEnvironment unwrappedEnv = unwrapProcessingEnvironment(env);
super.init(unwrappedEnv);
// The processingEnvironment field will be set by the superclass's init method.
// This is used to trigger AggregateChecker's setProcessingEnvironment.
setProcessingEnvironment(unwrappedEnv);
// Keep in sync with check in checker-framework/build.gradle and text in installation
// section of manual.
int jreVersion = SystemUtil.getJreVersion();
if (jreVersion != 8 && jreVersion != 11 && jreVersion != 17) {
message((hasOption("permitUnsupportedJdkVersion") ? Kind.NOTE : Kind.WARNING), "Use JDK 8, 11, or 17 to run the Checker Framework. You are using version %d.", jreVersion);
}
if (!hasOption("warnUnneededSuppressionsExceptions")) {
warnUnneededSuppressionsExceptions = null;
} else {
String warnUnneededSuppressionsExceptionsString = getOption("warnUnneededSuppressionsExceptions");
if (warnUnneededSuppressionsExceptionsString == null) {
throw new UserError("Must supply an argument to -AwarnUnneededSuppressionsExceptions");
}
try {
warnUnneededSuppressionsExceptions = Pattern.compile(warnUnneededSuppressionsExceptionsString);
} catch (PatternSyntaxException e) {
throw new UserError("Argument to -AwarnUnneededSuppressionsExceptions is not a regular expression: " + e.getMessage());
}
}
if (hasOption("printGitProperties")) {
printGitProperties();
}
}
Aggregations