Skip to content

Commit f4defea

Browse files
add bi and side variance
1 parent 86bedbd commit f4defea

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/main/java/io/github/bldl/annotationProcessing/VarianceProcessor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ private void checkVariance(String className, MyVariance annotation, String packa
127127
cu.accept(new ReturnTypeCollector(), types);
128128
else if (annotation.variance() == VarianceType.COVARIANT)
129129
cu.accept(new ParameterTypeCollector(), types);
130+
else if (annotation.variance() == VarianceType.BIVARIANT) {
131+
cu.accept(new ReturnTypeCollector(), types);
132+
cu.accept(new ParameterTypeCollector(), types);
133+
}
130134

131135
for (Type type : types) {
132136
if (TypeHandler.containsType(type, typeOfInterest)) {
@@ -136,7 +140,8 @@ else if (annotation.variance() == VarianceType.COVARIANT)
136140
"%s is declared as %s, but does not conform to constraints: contains T in %s position",
137141
className,
138142
annotation.variance(),
139-
annotation.variance() == VarianceType.COVARIANT ? "IN" : "OUT"));
143+
annotation.variance() == VarianceType.COVARIANT ? "IN"
144+
: annotation.variance() == VarianceType.BIVARIANT ? "OUT" : "IN/OUT"));
140145
}
141146
}
142147
}

src/main/java/io/github/bldl/annotationProcessing/VarianceType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public enum VarianceType {
44
INVARIANT,
55
COVARIANT,
66
CONTRAVARIANT,
7-
SIDE
7+
BIVARIANT,
8+
SIDEVARIANT
89
}

src/main/java/io/github/bldl/astParsing/visitors/SubtypingCheckVisitor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@ private boolean isValidSubtype(ClassOrInterfaceType assigneeType, ClassOrInterfa
197197
return classHierarchy.isDescendant(
198198
((ClassOrInterfaceType) assignedArgs.get(i)).getNameAsString(),
199199
((ClassOrInterfaceType) assigneeArgs.get(i)).getNameAsString(), mp.get(i).depth());
200-
case SIDE:
200+
case BIVARIANT:
201+
return classHierarchy.isDescendant(
202+
((ClassOrInterfaceType) assigneeArgs.get(i)).getNameAsString(),
203+
((ClassOrInterfaceType) assignedArgs.get(i)).getNameAsString(), mp.get(i).depth())
204+
|| classHierarchy.isDescendant(
205+
((ClassOrInterfaceType) assignedArgs.get(i)).getNameAsString(),
206+
((ClassOrInterfaceType) assigneeArgs.get(i)).getNameAsString(),
207+
mp.get(i).depth());
208+
case SIDEVARIANT:
201209
return classHierarchy.sameLevel(((ClassOrInterfaceType) assignedArgs.get(i)).getNameAsString(),
202210
((ClassOrInterfaceType) assigneeArgs.get(i)).getNameAsString());
203211
default:

0 commit comments

Comments
 (0)