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