use of net.sourceforge.pmd.lang.java.ast.ASTExpression in project pmd by pmd.
the class ClassTypeResolverTest method testUnaryNumericPromotion.
@Test
public void testUnaryNumericPromotion() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = " + "'unaryNumericPromotion']]//Expression[UnaryExpression]"), ASTExpression.class);
int index = 0;
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// Make sure we got them all.
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTExpression in project pmd by pmd.
the class ClassTypeResolverTest method testBinaryNumericOperators.
@Test
public void testBinaryNumericOperators() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression"), ASTExpression.class);
int index = 0;
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
// Make sure we got them all.
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTExpression in project pmd by pmd.
the class ClassTypeResolverTest method testBinaryNumericPromotion.
@Test
public void testBinaryNumericPromotion() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = " + "'binaryNumericPromotion']]//Expression[AdditiveExpression]"), ASTExpression.class);
int index = 0;
// LHS = byte
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = short
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = char
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = int
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Integer.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = long
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Long.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = float
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Float.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// LHS = double
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
assertEquals(Double.TYPE, expressions.get(index++).getType());
// Make sure we got them all.
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTExpression in project pmd by pmd.
the class ClassTypeResolverTest method testBinaryLogicalOperators.
@Test
public void testBinaryLogicalOperators() throws JaxenException {
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression"), ASTExpression.class);
int index = 0;
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
// Make sure we got them all.
assertEquals("All expressions not tested", index, expressions.size());
}
use of net.sourceforge.pmd.lang.java.ast.ASTExpression in project pmd by pmd.
the class StatementAndBraceFinderTest method testIfStmtHasCorrectTypes.
@Test
public void testIfStmtHasCorrectTypes() {
ASTExpression exp = getOrderedNodes(ASTExpression.class, TEST3).get(0);
DataFlowNode dfn = exp.getDataFlowNode().getFlow().get(2);
assertTrue(dfn.isType(NodeType.IF_EXPR));
assertTrue(dfn.isType(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE));
}
Aggregations