Search in sources :

Example 11 with Constraint

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

the class TypeInferenceTest method testLooseInvocationRightBoxing.

@Test
public void testLooseInvocationRightBoxing() {
    // Otherwise, if T is a primitive type, let T' be the result of applying boxing conversion (§5.1.7) to T.
    // Then the constraint reduces to ‹S = T'›.
    List<BoundOrConstraint> result = new Constraint(number, primitiveInt, LOOSE_INVOCATION).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), number, integer, EQUALITY, Constraint.class);
// Otherwise, if T is a parameterized type of the form G<T1, ..., Tn>, and there exists no type of the
// form G<...> that is a supertype of S, but the raw type G is a supertype of S, then the constraint
// reduces to true. TODO
// Otherwise, if T is an array type of the form G<T1, ..., Tn>[]k, and there exists no type of the form
// G<...>[]k that is a supertype of S, but the raw type G[]k is a supertype of S, then the constraint
// reduces to true. (The notation []k indicates an array type of k dimensions.) 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 12 with Constraint

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

the class TypeInferenceTest method testLooseInvocationProperVsProper.

@Test
public void testLooseInvocationProperVsProper() {
    // A constraint formula of the form ‹S → T› is reduced as follows:
    // If S and T are proper types, the constraint reduces to true if S is compatible in a loose invocation
    // context with T (§5.3), and false otherwise.
    List<BoundOrConstraint> result = new Constraint(number, integer, LOOSE_INVOCATION).reduce();
    assertNull(result);
    result = new Constraint(integer, number, LOOSE_INVOCATION).reduce();
    assertEquals(0, result.size());
}
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 13 with Constraint

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

the class TypeInferenceTest method testEqualityReduceSameErasure.

@Test
public void testEqualityReduceSameErasure() {
    // Otherwise, if S and T are class or interface types with the same erasure, where S has type
    // arguments B1, ..., Bn and T has type arguments A1, ..., An, the constraint reduces to the
    // following new constraints: for all i (1 ≤ i ≤ n), ‹Bi = Ai›.
    List<BoundOrConstraint> result = new Constraint(generic, generic, EQUALITY).reduce();
    assertEquals(2, result.size());
    testBoundOrConstraint(result.get(0), number, number, EQUALITY, Constraint.class);
    testBoundOrConstraint(result.get(1), integer, 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)

Example 14 with Constraint

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

the class TypeInferenceTest method testSubtypeReduceVariableVsAny.

@Test
public void testSubtypeReduceVariableVsAny() {
    // Otherwise, if S is an inference variable, α, the constraint reduces to the bound α <: T.
    List<BoundOrConstraint> result = new Constraint(alpha, integer, SUBTYPE).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), alpha, integer, 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 15 with Constraint

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

the class TypeInferenceTest method testEqualityReduceVariableVsNotPrimitive.

@Test
public void testEqualityReduceVariableVsNotPrimitive() {
    // Otherwise, if S is an inference variable, α, and T is not a primitive type, the constraint reduces to
    // the bound α = T.
    List<BoundOrConstraint> result = new Constraint(alpha, number, EQUALITY).reduce();
    assertEquals(1, result.size());
    testBoundOrConstraint(result.get(0), alpha, number, EQUALITY, 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)

Aggregations

Constraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint)15 Test (org.junit.Test)14 BoundOrConstraint (net.sourceforge.pmd.lang.java.typeresolution.typeinference.BoundOrConstraint)13 ArrayList (java.util.ArrayList)2 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 ASTArgumentList (net.sourceforge.pmd.lang.java.ast.ASTArgumentList)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 AbstractJavaNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaNode)1 TypeNode (net.sourceforge.pmd.lang.java.ast.TypeNode)1 Variable (net.sourceforge.pmd.lang.java.typeresolution.typeinference.Variable)1 SuperClassA (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassA)1 SuperClassAOther (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther)1 SuperClassAOther2 (net.sourceforge.pmd.typeresolution.testdata.dummytypes.SuperClassAOther2)1