Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 33 additions & 41 deletions src/refval/RefValAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RefValAnnotatedTypeFactory extends BaseAnnotatedTypeFactory {
* For each Java type is present in the target program, typeNamesMap maps
* String of the type to the TypeMirror.
*/
private final Map<String, TypeMirror> typeNamesMap = new HashMap<String, TypeMirror>();
private final Map<String, TypeMirror> typeNamesMap = new HashMap<>();

public RefValAnnotatedTypeFactory(BaseTypeChecker checker) {
super(checker);
Expand Down Expand Up @@ -124,18 +124,18 @@ public RefValQualifierHierarchy(MultiGraphFactory f, AnnotationMirror bottom) {
*/
private boolean isSubtypeWithRoots(AnnotationMirror rhs, AnnotationMirror lhs) {

Set<String> rTypeNamesSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> rTypeNamesSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNames(rhs)));
Set<String> lTypeNamesSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> lTypeNamesSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNames(lhs)));
Set<String> rRootsSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> rRootsSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNameRoots(rhs)));
Set<String> lRootsSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> lRootsSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNameRoots(lhs)));
Set<String> combinedTypeNames = new HashSet<String>();
Set<String> combinedTypeNames = new HashSet<>();
combinedTypeNames.addAll(rTypeNamesSet);
combinedTypeNames.addAll(lTypeNamesSet);
Set<String> combinedRoots = new HashSet<String>();
Set<String> combinedRoots = new HashSet<>();
combinedRoots.addAll(rRootsSet);
combinedRoots.addAll(lRootsSet);

Expand All @@ -144,11 +144,7 @@ private boolean isSubtypeWithRoots(AnnotationMirror rhs, AnnotationMirror lhs) {
AnnotationMirror refinedCombinedAnno = refineRefVal(combinedAnno);
AnnotationMirror refinedLhs = refineRefVal(lhs);

if (AnnotationUtils.areSame(refinedCombinedAnno, refinedLhs)) {
return true;
} else {
return false;
}
return AnnotationUtils.areSame(refinedCombinedAnno, refinedLhs);
}

/**
Expand All @@ -162,15 +158,11 @@ private boolean isSubtypeWithRoots(AnnotationMirror rhs, AnnotationMirror lhs) {
* @return true is rhs is subtype of lhs, otherwise return false.
*/
private boolean isSubtypeWithoutRoots(AnnotationMirror rhs, AnnotationMirror lhs) {
Set<String> rTypeNamesSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> rTypeNamesSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNames(rhs)));
Set<String> lTypeNamesSet = new HashSet<String>(Arrays.asList(RefValUtils
Set<String> lTypeNamesSet = new HashSet<>(Arrays.asList(RefValUtils
.getTypeNames(lhs)));
if (lTypeNamesSet.containsAll(rTypeNamesSet)) {
return true;
} else {
return false;
}
return lTypeNamesSet.containsAll(rTypeNamesSet);
}

@Override
Expand All @@ -180,7 +172,8 @@ public boolean isSubtype(AnnotationMirror rhs, AnnotationMirror lhs) {
return isSubtypeWithRoots(rhs, lhs);
// return isSubtypeWithoutRoots(rhs, lhs);
} else {
// if (rhs != null && lhs != null)
// Remove typeNames and typeNameRoots from @RefVal
// to make it in the subtype hierarchy
if (AnnotationUtils.areSameByName(rhs, REFVAL)) {
rhs = REFVAL;
} else if (AnnotationUtils.areSameByName(lhs, REFVAL)) {
Expand Down Expand Up @@ -219,9 +212,8 @@ public Void visitNewClass(NewClassTree node, AnnotatedTypeMirror type) {
@Override
public Void visitLiteral(LiteralTree node, AnnotatedTypeMirror type) {
if (!node.getKind().equals(Kind.NULL_LITERAL)) {
AnnotatedTypeMirror annoType = type;
AnnotationMirror refValType = RefValUtils.generateRefValAnnoFromLiteral(annoType,
processingEnv);
AnnotationMirror refValType = RefValUtils.generateRefValAnnoFromLiteral(type,
processingEnv);
type.replaceAnnotation(refValType);
}
return super.visitLiteral(node, type);
Expand Down Expand Up @@ -253,33 +245,33 @@ public Void visitMethodInvocation(MethodInvocationTree node, AnnotatedTypeMirror
*/
public AnnotationMirror refineRefVal(AnnotationMirror type) {
String[] typeNameRoots = RefValUtils.getTypeNameRoots(type);
Set<String> refinedRoots = new HashSet<String>();
Set<String> refinedRoots = new HashSet<>();

if (typeNameRoots.length == 0) {

} else if (typeNameRoots.length == 1) {
refinedRoots.add(typeNameRoots[0]);
} else {
List<String> rootsList = new ArrayList<String>(Arrays.asList(typeNameRoots));
while (rootsList.size() != 0) {
TypeMirror decType = getTypeMirror(rootsList.get(0));
if (!isComparable(decType, rootsList)) {
refinedRoots.add(rootsList.get(0));
rootsList.remove(0);
if (typeNameRoots.length != 0) {
if (typeNameRoots.length == 1) {
refinedRoots.add(typeNameRoots[0]);
} else {
List<String> rootsList = new ArrayList<>(Arrays.asList(typeNameRoots));
while (rootsList.size() != 0) {
TypeMirror decType = getTypeMirror(rootsList.get(0));
if (!isComparable(decType, rootsList)) {
refinedRoots.add(rootsList.get(0));
rootsList.remove(0);
}
}
}
}

String[] typeNames = RefValUtils.getTypeNames(type);
Arrays.sort(typeNames);
Set<String> refinedTypeNames = new HashSet<String>();
Set<String> refinedTypeNames = new HashSet<>();

if (refinedRoots.size() == 0) {
refinedTypeNames = new HashSet<String>(Arrays.asList(typeNames));
refinedTypeNames = new HashSet<>(Arrays.asList(typeNames));
return RefValUtils.createRefValAnnotation(refinedTypeNames, processingEnv);
} else {
for (String typeName : typeNames) {
if (typeName == "") {
if (typeName.equals("")) {
continue;
}
TypeMirror decType = getTypeMirror(typeName);
Expand Down Expand Up @@ -312,7 +304,7 @@ private void replaceArrayComponentATM(AnnotatedArrayType arrayAtm) {

private boolean isComparable(TypeMirror decType, List<String> rootsList) {
for (int i = 1; i < rootsList.size(); i++) {
if (rootsList.get(i) == "") {
if (rootsList.get(i).equals("")) {
continue;
}
TypeMirror comparedDecType = getTypeMirror(rootsList.get(i));
Expand All @@ -330,7 +322,7 @@ private boolean isComparable(TypeMirror decType, List<String> rootsList) {

private boolean shouldPresent(TypeMirror decType, Set<String> refinedRoots) {
for (String refinedRoot : refinedRoots) {
if (refinedRoot == "") {
if (refinedRoot.equals("")) {
continue;
}
TypeMirror comparedDecType = getTypeMirror(refinedRoot);
Expand All @@ -344,7 +336,7 @@ private boolean shouldPresent(TypeMirror decType, Set<String> refinedRoots) {
}

private TypeMirror getTypeMirror(String typeName) {
if (this.typeNamesMap.keySet().contains(typeName)) {
if (this.typeNamesMap.containsKey(typeName)) {
return this.typeNamesMap.get(typeName);
} else {
return elements.getTypeElement(convertToReferenceType(typeName)).asType();
Expand Down
24 changes: 2 additions & 22 deletions src/refval/RefValChecker.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package refval;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.util.Elements;

import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory;
import org.checkerframework.javacutil.AnnotationBuilder;

import checkers.inference.BaseInferrableChecker;
import checkers.inference.InferenceChecker;
import checkers.inference.InferrableChecker;
import checkers.inference.SlotManager;
import checkers.inference.model.ConstraintManager;
import refval.qual.RefVal;
import refval.qual.UnknownRefVal;

/**
* Checker for RefVal type system.
Expand All @@ -21,19 +15,6 @@
*
*/
public class RefValChecker extends BaseInferrableChecker {
public AnnotationMirror REFVAL, UNKNOWNREFVAL;

@Override
public void initChecker() {
super.initChecker();
setAnnotations();
}

protected void setAnnotations() {
final Elements elements = processingEnv.getElementUtils();
REFVAL = AnnotationBuilder.fromClass(elements, RefVal.class);
UNKNOWNREFVAL = AnnotationBuilder.fromClass(elements, UnknownRefVal.class);
}

@Override
public RefValVisitor createVisitor(InferenceChecker ichecker, BaseAnnotatedTypeFactory factory,
Expand All @@ -50,9 +31,8 @@ public RefValAnnotatedTypeFactory createRealTypeFactory() {
public RefValInferenceAnnotatedTypeFactory createInferenceATF(InferenceChecker inferenceChecker,
InferrableChecker realChecker, BaseAnnotatedTypeFactory realTypeFactory,
SlotManager slotManager, ConstraintManager constraintManager) {
RefValInferenceAnnotatedTypeFactory refValInferenceTypeFactory = new RefValInferenceAnnotatedTypeFactory(
return new RefValInferenceAnnotatedTypeFactory(
inferenceChecker, realChecker.withCombineConstraints(), realTypeFactory, realChecker,
slotManager, constraintManager);
return refValInferenceTypeFactory;
}
}
}
8 changes: 4 additions & 4 deletions src/refval/RefValInferenceAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public AnnotatedDeclaredType getBoxedType(AnnotatedPrimitiveType type) {
AnnotationMirror am = RefValUtils.createRefValAnnotation(typeElt.asType().toString(),
this.processingEnv);
AnnotatedDeclaredType dt = fromElement(typeElt);
ConstantSlot cs = InferenceMain.getInstance().getSlotManager().createConstantSlot(am);
dt.addAnnotation(InferenceMain.getInstance().getSlotManager().getAnnotation(cs));
ConstantSlot cs = slotManager.createConstantSlot(am);
dt.addAnnotation(slotManager.getAnnotation(cs));
dt.addAnnotation(cs.getValue());
return dt;
}
Expand All @@ -66,8 +66,8 @@ public AnnotatedPrimitiveType getUnboxedType(AnnotatedDeclaredType type)
this.processingEnv);
AnnotatedPrimitiveType pt = (AnnotatedPrimitiveType) AnnotatedTypeMirror.createType(
primitiveType, this, false);
ConstantSlot cs = InferenceMain.getInstance().getSlotManager().createConstantSlot(am);
pt.addAnnotation(InferenceMain.getInstance().getSlotManager().getAnnotation(cs));
ConstantSlot cs = slotManager.createConstantSlot(am);
pt.addAnnotation(slotManager.getAnnotation(cs));
pt.addAnnotation(cs.getValue());
return pt;
}
Expand Down
5 changes: 2 additions & 3 deletions src/refval/RefValInferenceTreeAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public Void visitMethodInvocation(MethodInvocationTree methodInvocationTree,

private void replaceATM(AnnotatedTypeMirror atm, AnnotationMirror refValAM) {
final ConstantSlot cs = slotManager.createConstantSlot(refValAM);
slotManager.createConstantSlot(refValAM);
AnnotationBuilder ab = new AnnotationBuilder(realTypeFactory.getProcessingEnv(), VarAnnot.class);
ab.setValue("value", cs.getId());
AnnotationMirror varAnno = ab.build();
Expand All @@ -137,7 +136,7 @@ private void replaceATM(AnnotatedTypeMirror atm, AnnotationMirror refValAM) {
/**
* Add the bytecode default RefVal annotation for component type of the given {@link AnnotatedArrayType}.
*
*<p> For multi-dimensional array, this method will recursively add bytecode default RefVal annotation to array's component type.
* <p> For multi-dimensional array, this method will recursively add bytecode default RefVal annotation to array's component type.
*
* @param arrayAtm the given {@link AnnotatedArrayType}, whose component type will be added the bytecode default.
*/
Expand All @@ -148,7 +147,7 @@ private void replaceArrayComponentATM(AnnotatedArrayType arrayAtm) {
replaceATM(componentAtm, componentAnno);

if (componentAtm.getKind() == TypeKind.ARRAY) {
//if component is also an array type, then recursively annotate its component also.
// if component is also an array type, then recursively annotate its component also.
replaceArrayComponentATM((AnnotatedArrayType) componentAtm);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/refval/solvers/classic/RefValSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public InferenceResult solve(Map<String, String> configuration,
List<RefValTypeSolution> solutions = new ArrayList<>();
try {
if (refValSolvers.size() > 0) {
solutions = solveInparallel(refValSolvers);
solutions = solveInParallel(refValSolvers);
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Expand All @@ -80,7 +80,7 @@ public InferenceResult solve(Map<String, String> configuration,
return getMergedResultFromSolutions(processingEnvironment, solutions);
}

private List<RefValTypeSolution> solveInparallel(List<RefValTypeSolver> refValSolvers)
private List<RefValTypeSolution> solveInParallel(List<RefValTypeSolver> refValSolvers)
throws InterruptedException, ExecutionException {
ExecutorService service = Executors.newFixedThreadPool(refValSolvers.size());

Expand Down
Loading