use of com.github.javaparser.symbolsolver.resolution.typeinference.InferenceVariable in project javaparser by javaparser.
the class ConstraintFormulaTest method testExpressionCompatibleWithTypeReduce1.
/**
* From JLS 18.1.2
*
* From Collections.singleton("hi"), we have the constraint formula ‹"hi" → α›.
* Through reduction, this will become the constraint formula: ‹String <: α›.
*/
@Test
public void testExpressionCompatibleWithTypeReduce1() {
ResolvedTypeParameterDeclaration tp = mock(ResolvedTypeParameterDeclaration.class);
Expression e = new StringLiteralExpr("hi");
InferenceVariable inferenceVariable = new InferenceVariable("α", tp);
ExpressionCompatibleWithType formula = new ExpressionCompatibleWithType(typeSolver, e, inferenceVariable);
ConstraintFormula.ReductionResult res1 = formula.reduce(BoundSet.empty());
assertEquals(ConstraintFormula.ReductionResult.empty().withConstraint(new TypeCompatibleWithType(typeSolver, stringType, inferenceVariable)), res1);
assertEquals(ConstraintFormula.ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, stringType, inferenceVariable)), res1.getConstraint(0).reduce(BoundSet.empty()));
}
use of com.github.javaparser.symbolsolver.resolution.typeinference.InferenceVariable in project javaparser by javaparser.
the class SameAsBoundTest method recognizeInstantiation.
@Test
public void recognizeInstantiation() {
// { α = String } contains a single bound, instantiating α as String.
InferenceVariable inferenceVariable = new InferenceVariable("α", null);
Bound bound1 = new SameAsBound(inferenceVariable, stringType);
Bound bound2 = new SameAsBound(stringType, inferenceVariable);
assertEquals(Optional.of(new Instantiation(inferenceVariable, stringType)), bound1.isAnInstantiation());
assertEquals(Optional.of(new Instantiation(inferenceVariable, stringType)), bound2.isAnInstantiation());
}
Aggregations