Java, typeres: add vararg tests for method resolution
This commit is contained in:
@ -18,6 +18,7 @@ import java.util.StringTokenizer;
|
||||
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodFirstPhase;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodMostSpecific;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodThirdPhase;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodSecondPhase;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jaxen.JaxenException;
|
||||
@ -1302,6 +1303,34 @@ public class ClassTypeResolverTest {
|
||||
assertEquals("All expressions not tested", index, expressions.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodThirdPhase() throws JaxenException {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass15(MethodThirdPhase.class);
|
||||
|
||||
List<AbstractJavaTypeNode> expressions = convertList(
|
||||
acu.findChildNodesWithXPath("//VariableInitializer/Expression/PrimaryExpression"),
|
||||
AbstractJavaTypeNode.class);
|
||||
|
||||
int index = 0;
|
||||
|
||||
// Exception a = vararg(10, (Number) null, (Number) null);
|
||||
assertEquals(Exception.class, expressions.get(index).getType());
|
||||
assertEquals(Exception.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(Exception.class, getChildType(expressions.get(index++), 1));
|
||||
// Exception b = vararg(10);
|
||||
assertEquals(Exception.class, expressions.get(index).getType());
|
||||
assertEquals(Exception.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(Exception.class, getChildType(expressions.get(index++), 1));
|
||||
// int c = vararg(10, "", "", "");
|
||||
assertEquals(int.class, expressions.get(index).getType());
|
||||
assertEquals(int.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(int.class, getChildType(expressions.get(index++), 1));
|
||||
|
||||
// Make sure we got them all
|
||||
assertEquals("All expressions not tested", index, expressions.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Class<?> getChildType(Node node, int childIndex) {
|
||||
|
21
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodThirdPhase.java
vendored
Normal file
21
pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/testdata/MethodThirdPhase.java
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class MethodThirdPhase {
|
||||
void test() {
|
||||
// more args than parameters
|
||||
Exception a = vararg(10, (Number) null, (Number) null);
|
||||
|
||||
// less args than parameters
|
||||
Exception b = vararg(10);
|
||||
|
||||
// component type determined properly
|
||||
int c = vararg(10, "", "", "");
|
||||
|
||||
// TODO: add most specific tests among vararg conversion
|
||||
|
||||
}
|
||||
|
||||
Exception vararg(int a, Number... b) { return null; }
|
||||
|
||||
int vararg(int a, String c, String... b) {return 0; }
|
||||
}
|
Reference in New Issue
Block a user