use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class AFReducingVisitor method visitDeclared_Declared.
// From the JLS Spec:
// If F has the form G<..., Yk-1,U, Yk+1, ...>, where U involves Tj
@Override
public Void visitDeclared_Declared(AnnotatedDeclaredType subtype, AnnotatedDeclaredType supertype, Set<AFConstraint> constraints) {
if (subtype.isUnderlyingTypeRaw() || supertype.isUnderlyingTypeRaw()) {
// inference will be aborted, but type-checking will continue.
throw new BugInCF("Can't infer type arguments when raw types are involved.");
}
if (!TypesUtils.isErasedSubtype(subtype.getUnderlyingType(), supertype.getUnderlyingType(), typeFactory.getChecker().getTypeUtils())) {
return null;
}
AnnotatedDeclaredType subAsSuper = AnnotatedTypes.castedAsSuper(typeFactory, subtype, supertype);
final List<AnnotatedTypeMirror> subTypeArgs = subAsSuper.getTypeArguments();
final List<AnnotatedTypeMirror> superTypeArgs = supertype.getTypeArguments();
for (int i = 0; i < subTypeArgs.size(); i++) {
final AnnotatedTypeMirror subTypeArg = subTypeArgs.get(i);
final AnnotatedTypeMirror superTypeArg = superTypeArgs.get(i);
// Since we always have both bounds in the checker framework we always compare both
if (superTypeArg.getKind() == TypeKind.WILDCARD) {
final AnnotatedWildcardType superWc = (AnnotatedWildcardType) superTypeArg;
if (subTypeArg.getKind() == TypeKind.WILDCARD) {
final AnnotatedWildcardType subWc = (AnnotatedWildcardType) subTypeArg;
TypeArgInferenceUtil.checkForUninferredTypes(subWc);
addConstraint(subWc.getExtendsBound(), superWc.getExtendsBound(), constraints);
addInverseConstraint(superWc.getSuperBound(), subWc.getSuperBound(), constraints);
} else {
addConstraint(subTypeArg, superWc.getExtendsBound(), constraints);
addInverseConstraint(superWc.getSuperBound(), subTypeArg, constraints);
}
} else {
// if F has the form G<..., Yk-1, U, Yk+1, ...>, where U is a type expression that involves
// Tj
addEqualityConstraint(subTypeArg, superTypeArg, constraints);
}
}
return null;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class MustCallInferenceLogic method getNormalSuccessors.
/**
* Returns the non-exceptional successors of the current block.
*
* @param cur the current block
* @return the successors of this current block
*/
private List<Block> getNormalSuccessors(Block cur) {
List<Block> successorBlock = new ArrayList<>();
if (cur.getType() == Block.BlockType.CONDITIONAL_BLOCK) {
ConditionalBlock ccur = (ConditionalBlock) cur;
successorBlock.add(ccur.getThenSuccessor());
successorBlock.add(ccur.getElseSuccessor());
} else {
if (!(cur instanceof SingleSuccessorBlock)) {
throw new BugInCF("BlockImpl is neither a conditional block nor a SingleSuccessorBlock");
}
Block b = ((SingleSuccessorBlock) cur).getSuccessor();
if (b != null) {
successorBlock.add(b);
}
}
return successorBlock;
}
use of org.checkerframework.javacutil.BugInCF 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) {
throw new BugInCF("Couldn't load " + checkerClassName + " class.");
}
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class AnnotatedTypes method findEffectiveLowerBoundAnnotations.
/**
* This method returns the effective annotation on the lower bound of a type, or on the type
* itself if the type has no lower bound (it is not a type variable, wildcard, or intersection).
*
* @return the set of effective annotation mirrors in all hierarchies
*/
public static Set<AnnotationMirror> findEffectiveLowerBoundAnnotations(final QualifierHierarchy qualifierHierarchy, final AnnotatedTypeMirror toSearch) {
AnnotatedTypeMirror source = toSearch;
TypeKind kind = source.getKind();
while (kind == TypeKind.TYPEVAR || kind == TypeKind.WILDCARD || kind == TypeKind.INTERSECTION) {
switch(source.getKind()) {
case TYPEVAR:
source = ((AnnotatedTypeVariable) source).getLowerBound();
break;
case WILDCARD:
source = ((AnnotatedWildcardType) source).getSuperBound();
break;
case INTERSECTION:
// if there are multiple conflicting annotations, choose the lowest
final Set<AnnotationMirror> glb = glbOfBounds((AnnotatedIntersectionType) source, qualifierHierarchy);
return glb;
default:
throw new BugInCF("Unexpected AnnotatedTypeMirror with no primary annotation;" + " toSearch=" + toSearch + " source=" + source);
}
kind = source.getKind();
}
return source.getAnnotations();
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class AnnotatedTypes method glbSubtype.
/**
* Returns the annotated greatest lower bound of {@code subtype} and {@code supertype}, where the
* underlying Java types are in a subtyping relationship.
*
* <p>This handles cases 1, 2, and 3 mentioned in the Javadoc of {@link
* #annotatedGLB(AnnotatedTypeFactory, AnnotatedTypeMirror, AnnotatedTypeMirror)}.
*
* @param qualifierHierarchy QualifierHierarchy
* @param subtype annotated type whose underlying type is a subtype of {@code supertype}
* @param supertype annotated type whose underlying type is a supertype of {@code subtype}
* @return the annotated greatest lower bound of {@code subtype} and {@code supertype}
*/
private static AnnotatedTypeMirror glbSubtype(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror subtype, AnnotatedTypeMirror supertype) {
AnnotatedTypeMirror glb = subtype.deepCopy();
glb.clearPrimaryAnnotations();
for (AnnotationMirror top : qualifierHierarchy.getTopAnnotations()) {
AnnotationMirror subAnno = subtype.getAnnotationInHierarchy(top);
AnnotationMirror superAnno = supertype.getAnnotationInHierarchy(top);
if (subAnno != null && superAnno != null) {
glb.addAnnotation(qualifierHierarchy.greatestLowerBound(subAnno, superAnno));
} else if (subAnno == null && superAnno == null) {
if (subtype.getKind() != TypeKind.TYPEVAR || supertype.getKind() != TypeKind.TYPEVAR) {
throw new BugInCF("Missing primary annotations: subtype: %s, supertype: %s", subtype, supertype);
}
} else if (subAnno == null) {
if (subtype.getKind() != TypeKind.TYPEVAR) {
throw new BugInCF("Missing primary annotations: subtype: %s", subtype);
}
Set<AnnotationMirror> lb = findEffectiveLowerBoundAnnotations(qualifierHierarchy, subtype);
AnnotationMirror lbAnno = qualifierHierarchy.findAnnotationInHierarchy(lb, top);
if (lbAnno != null && !qualifierHierarchy.isSubtype(lbAnno, superAnno)) {
// The superAnno is lower than the lower bound annotation, so add it.
glb.addAnnotation(superAnno);
}
// else don't add any annotation.
} else {
throw new BugInCF("GLB: subtype: %s, supertype: %s", subtype, supertype);
}
}
return glb;
}
Aggregations