1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package com.github.javaparser.symbolsolver.resolution.typeinference.constraintformulas;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.resolution.typeinference.BoundSet;
import com.github.javaparser.symbolsolver.resolution.typeinference.ConstraintFormula;
import static com.github.javaparser.symbolsolver.resolution.typeinference.TypeHelper.isProperType;
/**
* A type argument S is contained by a type argument T
*
* @author Federico Tomassetti
*/
public class TypeContainedByType extends ConstraintFormula {
private ResolvedType S;
private ResolvedType T;
@Override
public ReductionResult reduce(BoundSet currentBoundSet) {
// A constraint formula of the form ‹S <= T›, where S and T are type arguments (§4.5.1), is reduced as follows:
//
// - If T is a type:
if (isProperType(T) && !T.isWildcard()) {
// - If S is a type, the constraint reduces to ‹S = T›.
//
// - If S is a wildcard, the constraint reduces to false.
throw new UnsupportedOperationException();
}
// - If T is a wildcard of the form ?, the constraint reduces to true.
if (T.isWildcard() && !T.asWildcard().isBounded()) {
return ReductionResult.trueResult();
}
// - If T is a wildcard of the form ? extends T':
if (T.isWildcard() && T.asWildcard().isExtends()) {
// - If S is a type, the constraint reduces to ‹S <: T'›.
//
// - If S is a wildcard of the form ?, the constraint reduces to ‹Object <: T'›.
//
// - If S is a wildcard of the form ? extends S', the constraint reduces to ‹S' <: T'›.
//
// - If S is a wildcard of the form ? super S', the constraint reduces to ‹Object = T'›.
throw new UnsupportedOperationException();
}
// - If T is a wildcard of the form ? super T':
if (T.isWildcard() && T.asWildcard().isSuper()) {
// - If S is a type, the constraint reduces to ‹T' <: S›.
//
// - If S is a wildcard of the form ? super S', the constraint reduces to ‹T' <: S'›.
//
// - Otherwise, the constraint reduces to false.
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TypeContainedByType that = (TypeContainedByType) o;
if (!S.equals(that.S)) return false;
return T.equals(that.T);
}
@Override
public int hashCode() {
int result = S.hashCode();
result = 31 * result + T.hashCode();
return result;
}
@Override
public String toString() {
return "TypeContainedByType{" +
"S=" + S +
", T=" + T +
'}';
}
}
|