Search in sources :

Example 1 with BoundOrConstraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint in project pmd by pmd.

the class TypeInferenceTest method testContainmentReduceTypeVsType.

@Test
public void testContainmentReduceTypeVsType() {
    // 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 S is a type, the constraint reduces to ‹S = T›.
    List<BoundOrConstraint> result = new Constraint(number, integer, CONTAINS).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), number, integer, EQUALITY, Constraint.class);
// If T is a type: // If S is a wildcard, the constraint reduces to false. TODO
// If T is a wildcard of the form ?, the constraint reduces to true. TODO
// If T is a wildcard of the form ? extends T': TODO
// If T is a wildcard of the form ? super T': TODO
}
Also used : BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Example 2 with BoundOrConstraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint in project pmd by pmd.

the class TypeInferenceTest method testSubtypeReduceAnyVsVariable.

@Test
public void testSubtypeReduceAnyVsVariable() {
    // Otherwise, if T is an inference variable, α, the constraint reduces to the bound S <: α.
    List<BoundOrConstraint> result = new Constraint(integer, alpha, SUBTYPE).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), integer, alpha, SUBTYPE, Bound.class);
    result = new Constraint(alpha, beta, SUBTYPE).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), alpha, beta, SUBTYPE, Bound.class);
}
Also used : BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Example 3 with BoundOrConstraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint in project pmd by pmd.

the class TypeInferenceTest method testLooseInvocationAnythingElse.

@Test
public void testLooseInvocationAnythingElse() {
    // Otherwise, the constraint reduces to ‹S<:T›.
    List<BoundOrConstraint> result = new Constraint(number, alpha, LOOSE_INVOCATION).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), number, alpha, SUBTYPE, Constraint.class);
    result = new Constraint(alpha, number, LOOSE_INVOCATION).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), alpha, number, SUBTYPE, Constraint.class);
}
Also used : BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Example 4 with BoundOrConstraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint in project pmd by pmd.

the class TypeInferenceTest method testLooseInvocationLeftBoxing.

@Test
public void testLooseInvocationLeftBoxing() {
    // Otherwise, if S is a primitive type, let S' be the result of applying boxing conversion (§5.1.7) to S.
    // Then the constraint reduces to ‹S' → T›.
    List<BoundOrConstraint> result = new Constraint(primitiveInt, number, LOOSE_INVOCATION).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), integer, number, LOOSE_INVOCATION, Constraint.class);
}
Also used : BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Example 5 with BoundOrConstraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint in project pmd by pmd.

the class TypeInferenceTest method testEqualityReduceArrayTypes.

@Test
public void testEqualityReduceArrayTypes() {
    // Otherwise, if S and T are array types, S'[] and T'[], the constraint reduces to ‹S' = T'›.
    List<BoundOrConstraint> result = new Constraint(JavaTypeDefinition.forClass(Number[].class), JavaTypeDefinition.forClass(Integer[].class), EQUALITY).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), number, integer, EQUALITY, Constraint.class);
}
Also used : BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) BoundOrConstraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint) Constraint(net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint) Test(org.junit.Test)

Aggregations

BoundOrConstraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint)12 Constraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)12 Test (org.junit.Test)12