Skip to content

Commit 7fed2e0

Browse files
AndrewShfbaoruiz
andcommitted
addDeepPreference to cfi
Co-authored-by: Baorui Zhou <[email protected]>
1 parent 1771984 commit 7fed2e0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/checkers/inference/InferenceVisitor.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.Annotation;
2323
import java.util.Arrays;
2424
import java.util.HashSet;
25+
import java.util.LinkedList;
2526
import java.util.List;
2627
import java.util.Set;
2728
import java.util.logging.Logger;
@@ -261,6 +262,48 @@ public void mainIsNoneOf(AnnotatedTypeMirror ty, AnnotationMirror[] mods, String
261262
}
262263
}
263264

265+
private void addDeepPreferenceImpl(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight,
266+
java.util.List<AnnotatedTypeMirror> visited, Tree node) {
267+
if (infer) {
268+
if (visited.contains(ty)) {
269+
return;
270+
}
271+
visited.add(ty);
272+
273+
final SlotManager slotManager = InferenceMain.getInstance().getSlotManager();
274+
Slot el = slotManager.getSlot(ty);
275+
276+
if (el == null) {
277+
logger.warning("InferenceVisitor::addDeepPreferenceImpl: no annotation in type: " + ty);
278+
} else {
279+
addPreference(ty, goal, weight);
280+
}
281+
282+
if (ty.getKind() == TypeKind.DECLARED) {
283+
AnnotatedDeclaredType declaredType = (AnnotatedDeclaredType) ty;
284+
for (AnnotatedTypeMirror typearg : declaredType.getTypeArguments()) {
285+
addDeepPreferenceImpl(typearg, goal, weight, visited, node);
286+
}
287+
} else if (ty.getKind() == TypeKind.ARRAY) {
288+
AnnotatedArrayType arrayType = (AnnotatedArrayType) ty;
289+
addDeepPreferenceImpl(arrayType.getComponentType(), goal, weight, visited, node);
290+
} else if (ty.getKind() == TypeKind.TYPEVAR) {
291+
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) ty;
292+
if (atv.getUpperBound()!=null) {
293+
addDeepPreferenceImpl(atv.getUpperBound(), goal, weight, visited, node);
294+
}
295+
if (atv.getLowerBound()!=null) {
296+
addDeepPreferenceImpl(atv.getLowerBound(), goal, weight, visited, node);
297+
}
298+
}
299+
}
300+
// Else, do nothing
301+
}
302+
303+
public void addDeepPreference(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight, Tree node) {
304+
addDeepPreferenceImpl(ty, goal, weight, new LinkedList<>(), node);
305+
}
306+
264307
public void addPreference(AnnotatedTypeMirror type, AnnotationMirror anno, int weight) {
265308
if (infer) {
266309
ConstraintManager cManager = InferenceMain.getInstance().getConstraintManager();

0 commit comments

Comments
 (0)