1 package com.github.javaparser.symbolsolver.resolution.typeinference; 2 3 import com.github.javaparser.symbolsolver.resolution.typeinference.bounds.FalseBound; 4 5 import java.util.Optional; 6 import java.util.Set; 7 8 /** 9 * Bounds are defined for Inference Variables. 10 * 11 * @author Federico Tomassetti 12 */ 13 public abstract class Bound { 14 15 /// 16 /// Creation of bounds 17 /// 18 falseBound()19 static Bound falseBound() { 20 return FalseBound.getInstance(); 21 } 22 23 /// 24 /// Satisfiability 25 /// 26 27 /** 28 * A bound is satisfied by an inference variable substitution if, after applying the substitution, 29 * the assertion is true. 30 */ isSatisfied(InferenceVariableSubstitution inferenceVariableSubstitution)31 public abstract boolean isSatisfied(InferenceVariableSubstitution inferenceVariableSubstitution); 32 33 /// 34 /// Classification of bounds 35 /// 36 37 /** 38 * Given a bound of the form α = T or T = α, we say T is an instantiation of α. 39 * 40 * Return empty if it is not an instantiation. Otherwise it returns the variable of which this is an 41 * instantiation. 42 */ isAnInstantiation()43 public Optional<Instantiation> isAnInstantiation() { 44 return Optional.empty(); 45 } 46 isAnInstantiationFor(InferenceVariable v)47 boolean isAnInstantiationFor(InferenceVariable v) { 48 return isAnInstantiation().isPresent() && isAnInstantiation().get().getInferenceVariable().equals(v); 49 } 50 51 /** 52 * Given a bound of the form α <: T, we say T is a proper upper bound of α. 53 * 54 * Return empty if it is not a proper upper bound. Otherwise it returns the variable of which this is an 55 * proper upper bound. 56 */ isProperUpperBound()57 public Optional<ProperUpperBound> isProperUpperBound() { 58 return Optional.empty(); 59 } 60 61 /** 62 * Given a bound of the form T <: α, we say T is a proper lower bound of α. 63 * 64 * Return empty if it is not a proper lower bound. Otherwise it returns the variable of which this is an 65 * proper lower bound. 66 */ isProperLowerBound()67 public Optional<ProperLowerBound> isProperLowerBound() { 68 return Optional.empty(); 69 } 70 isProperLowerBoundFor(InferenceVariable inferenceVariable)71 Optional<ProperLowerBound> isProperLowerBoundFor(InferenceVariable inferenceVariable) { 72 Optional<ProperLowerBound> partial = isProperLowerBound(); 73 if (partial.isPresent() && partial.get().getInferenceVariable().equals(inferenceVariable)) { 74 return partial; 75 } else { 76 return Optional.empty(); 77 } 78 } 79 isProperUpperBoundFor(InferenceVariable inferenceVariable)80 Optional<ProperUpperBound> isProperUpperBoundFor(InferenceVariable inferenceVariable) { 81 Optional<ProperUpperBound> partial = isProperUpperBound(); 82 if (partial.isPresent() && partial.get().getInferenceVariable().equals(inferenceVariable)) { 83 return partial; 84 } else { 85 return Optional.empty(); 86 } 87 } 88 89 /** 90 * Other bounds relate two inference variables, or an inference variable to a type that contains inference 91 * variables. Such bounds, of the form S = T or S <: T, are called dependencies. 92 */ isADependency()93 public boolean isADependency() { 94 return false; 95 } 96 isThrowsBoundOn(InferenceVariable inferenceVariable)97 boolean isThrowsBoundOn(InferenceVariable inferenceVariable) { 98 return false; 99 } 100 101 /// 102 /// Other methods 103 /// 104 usedInferenceVariables()105 public abstract Set<InferenceVariable> usedInferenceVariables(); 106 } 107