|
1 | 1 | package liquidjava.utils; |
2 | 2 |
|
| 3 | +import java.util.Map; |
3 | 4 | import java.util.Set; |
| 5 | +import java.util.stream.Stream; |
4 | 6 |
|
5 | 7 | import liquidjava.utils.constants.Types; |
6 | 8 | import spoon.reflect.cu.SourcePosition; |
| 9 | +import spoon.reflect.declaration.CtAnnotation; |
7 | 10 | import spoon.reflect.declaration.CtElement; |
8 | 11 | import spoon.reflect.factory.Factory; |
9 | 12 | import spoon.reflect.reference.CtTypeReference; |
@@ -35,9 +38,19 @@ public static String qualifyName(String prefix, String name) { |
35 | 38 | return String.format("%s.%s", prefix, name); |
36 | 39 | } |
37 | 40 |
|
38 | | - public static SourcePosition getAnnotationPosition(CtElement element) { |
| 41 | + public static SourcePosition getAnnotationPosition(CtElement element, String refinement) { |
39 | 42 | return element.getAnnotations().stream() |
40 | | - .filter(a -> a.getAnnotationType().getQualifiedName().startsWith("liquidjava.specification")) |
41 | | - .findFirst().map(CtElement::getPosition).orElse(element.getPosition()); |
| 43 | + .filter(a -> isLiquidJavaAnnotation(a) && hasRefinementValue(a, "\"" + refinement + "\"")).findFirst() |
| 44 | + .map(CtElement::getPosition).orElse(element.getPosition()); |
| 45 | + } |
| 46 | + |
| 47 | + private static boolean isLiquidJavaAnnotation(CtAnnotation<?> annotation) { |
| 48 | + return annotation.getAnnotationType().getQualifiedName().startsWith("liquidjava.specification"); |
| 49 | + } |
| 50 | + |
| 51 | + private static boolean hasRefinementValue(CtAnnotation<?> annotation, String refinement) { |
| 52 | + Map<String, ?> values = annotation.getValues(); |
| 53 | + return Stream.of("value", "to", "from") |
| 54 | + .anyMatch(key -> refinement.equals(String.valueOf(values.get(key)))); |
42 | 55 | } |
43 | 56 | } |
0 commit comments