use of org.checkerframework.framework.source.SourceChecker in project checker-framework by typetools.
the class FactoryTestChecker method initChecker.
@Override
public void initChecker() {
super.initChecker();
// Find factory constructor
String checkerClassName = getOption("checker");
try {
if (checkerClassName != null) {
Class<?> checkerClass = Class.forName(checkerClassName);
Constructor<?> constructor = checkerClass.getConstructor();
Object o = constructor.newInstance();
if (o instanceof SourceChecker) {
checker = (SourceChecker) o;
}
}
} catch (Exception e) {
errorAbort("Couldn't load " + checkerClassName + " class.");
}
}
use of org.checkerframework.framework.source.SourceChecker in project checker-framework by typetools.
the class DependentTypesHelper method reportErrors.
protected void reportErrors(Tree errorTree, List<DependentTypesError> errors) {
if (errors.isEmpty()) {
return;
}
SourceChecker checker = factory.getContext().getChecker();
String error = PluginUtil.join("\n", errors);
checker.report(Result.failure("expression.unparsable.type.invalid", error), errorTree);
}
use of org.checkerframework.framework.source.SourceChecker in project checker-framework by typetools.
the class DefaultTypeArgumentInference method inferTypeArgs.
@Override
public Map<TypeVariable, AnnotatedTypeMirror> inferTypeArgs(AnnotatedTypeFactory typeFactory, ExpressionTree expressionTree, ExecutableElement methodElem, AnnotatedExecutableType methodType) {
final List<AnnotatedTypeMirror> argTypes = TypeArgInferenceUtil.getArgumentTypes(expressionTree, typeFactory);
final TreePath pathToExpression = typeFactory.getPath(expressionTree);
assert pathToExpression != null;
final AnnotatedTypeMirror assignedTo = TypeArgInferenceUtil.assignedTo(typeFactory, pathToExpression);
SourceChecker checker = typeFactory.getContext().getChecker();
if (showInferenceSteps) {
checker.message(Kind.NOTE, "DTAI: expression: %s\n argTypes: %s\n assignedTo: %s\n", expressionTree.toString().replace("\n", " "), argTypes, assignedTo);
}
final Set<TypeVariable> targets = TypeArgInferenceUtil.methodTypeToTargets(methodType);
if (assignedTo == null && TreeUtils.getAssignmentContext(pathToExpression) != null) {
// If the type of the assignment context isn't found, but the expression is assigned,
// then don't attempt to infere type arguments, because the Java type inferred will be
// incorrect. The assignment type is null when it includes uninferred type arguments.
// For example:
// <T> T outMethod()
// <U> void inMethod(U u);
// inMethod(outMethod())
// would require solving the constraints for both type argument inferences
// simultaneously
Map<TypeVariable, AnnotatedTypeMirror> inferredArgs = new LinkedHashMap<>();
handleUninferredTypeVariables(typeFactory, methodType, targets, inferredArgs);
return inferredArgs;
}
Map<TypeVariable, AnnotatedTypeMirror> inferredArgs;
try {
inferredArgs = infer(typeFactory, argTypes, assignedTo, methodElem, methodType, targets, true);
if (showInferenceSteps) {
checker.message(Kind.NOTE, " after infer: %s\n", inferredArgs);
}
handleNullTypeArguments(typeFactory, methodElem, methodType, argTypes, assignedTo, targets, inferredArgs);
if (showInferenceSteps) {
checker.message(Kind.NOTE, " after handleNull: %s\n", inferredArgs);
}
} catch (Exception ex) {
// Catch any errors thrown by inference.
inferredArgs = new LinkedHashMap<>();
if (showInferenceSteps) {
checker.message(Kind.NOTE, " exception: %s\n", ex.getLocalizedMessage());
}
}
handleUninferredTypeVariables(typeFactory, methodType, targets, inferredArgs);
if (showInferenceSteps) {
checker.message(Kind.NOTE, " results: %s\n", inferredArgs);
}
return inferredArgs;
}
use of org.checkerframework.framework.source.SourceChecker in project checker-framework by typetools.
the class SignaturePrinter method init.
// /////// Initialization /////////////
private void init(ProcessingEnvironment env, String checkerName) {
if (checkerName != null) {
try {
Class<?> checkerClass = Class.forName(checkerName);
Constructor<?> cons = checkerClass.getConstructor();
checker = (SourceChecker) cons.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
checker = new SourceChecker() {
@Override
protected SourceVisitor<?, ?> createSourceVisitor() {
return null;
}
@Override
public AnnotationProvider getAnnotationProvider() {
throw new UnsupportedOperationException("getAnnotationProvider is not implemented for this class.");
}
};
}
checker.init(env);
}
use of org.checkerframework.framework.source.SourceChecker in project checker-framework by typetools.
the class DependentTypesHelper method checkAnnotation.
/**
* Checks every Java expression element of the annotation to see if the expression is an error
* string as specified by DependentTypesError#isExpressionError. If any expression is an error,
* then an error is reported at {@code errorTree}.
*
* @param annotation annotation to check
* @param errorTree location at which to issue errors
*/
public void checkAnnotation(AnnotationMirror annotation, Tree errorTree) {
List<DependentTypesError> errors = checkForError(annotation);
if (errors.isEmpty()) {
return;
}
SourceChecker checker = factory.getContext().getChecker();
String error = PluginUtil.join("\n", errors);
checker.report(Result.failure("flowexpr.parse.error", error), errorTree);
}
Aggregations