|
22 | 22 | import java.lang.annotation.Annotation; |
23 | 23 | import java.util.Arrays; |
24 | 24 | import java.util.HashSet; |
| 25 | +import java.util.LinkedList; |
25 | 26 | import java.util.List; |
26 | 27 | import java.util.Set; |
27 | 28 | import java.util.logging.Logger; |
@@ -261,6 +262,48 @@ public void mainIsNoneOf(AnnotatedTypeMirror ty, AnnotationMirror[] mods, String |
261 | 262 | } |
262 | 263 | } |
263 | 264 |
|
| 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 | + |
264 | 307 | public void addPreference(AnnotatedTypeMirror type, AnnotationMirror anno, int weight) { |
265 | 308 | if (infer) { |
266 | 309 | ConstraintManager cManager = InferenceMain.getInstance().getConstraintManager(); |
|
0 commit comments