Search in sources :

Example 6 with Constraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint 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 7 with Constraint

use of net.sourceforge.pmd.lang.java.typeresolution.typeinference.Constraint 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)

Example 8 with Constraint

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

the class TypeInferenceTest method testEqualityReduceNotPrimitiveVsVariable.

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

Example 9 with Constraint

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

the class TypeInferenceTest method testSubtypeReduceProperVsProper.

@Test
public void testSubtypeReduceProperVsProper() {
    // 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 a subtype of T (§4.10),
    // and false otherwise.
    List<BoundOrConstraint> result = new Constraint(integer, number, SUBTYPE).reduce();
    assertEquals(0, result.size());
    result = new Constraint(number, integer, SUBTYPE).reduce();
    assertNull(result);
// Otherwise, if S is the null type, the constraint reduces to true. TODO
// Otherwise, if T is the null type, the constraint reduces to false. 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 10 with Constraint

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

the class TypeInferenceTest method testEqualityReduceProperVsProper.

@Test
public void testEqualityReduceProperVsProper() {
    // If S and T are proper types, the constraint reduces to true if S is the same as T (§4.3.4), and false
    // otherwise.
    assertTrue(new Constraint(number, number, EQUALITY).reduce().isEmpty());
    assertNull(new Constraint(number, integer, EQUALITY).reduce());
// Otherwise, if S or T is the null type, the constraint reduces to false. TODO
}
Also used : 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