Java, typres: Add simple method type resolution
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
package net.sourceforge.pmd.lang.java.typeresolution;
|
||||
|
||||
|
||||
import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is really just a POJO.
|
||||
*/
|
||||
|
||||
public class MethodType {
|
||||
private JavaTypeDefinition returnType;
|
||||
private List<JavaTypeDefinition> argTypes;
|
||||
private Method method;
|
||||
|
||||
public MethodType(JavaTypeDefinition returnType, List<JavaTypeDefinition> argTypes, Method method) {
|
||||
this.returnType = returnType;
|
||||
this.argTypes = argTypes;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public JavaTypeDefinition getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public List<JavaTypeDefinition> getArgTypes() {
|
||||
return argTypes;
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return method;
|
||||
}
|
||||
}
|
@ -1144,12 +1144,12 @@ public class ClassTypeResolverTest {
|
||||
|
||||
int index = 0;
|
||||
|
||||
// int a = vararg("", "");
|
||||
// int a = vararg("");
|
||||
assertEquals(int.class, expressions.get(index).getType());
|
||||
assertEquals(int.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(int.class, getChildType(expressions.get(index++), 1));
|
||||
|
||||
// int b = vararg("", "", 10);
|
||||
// int b = 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));
|
||||
@ -1164,6 +1164,15 @@ public class ClassTypeResolverTest {
|
||||
assertEquals(Number.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(Number.class, getChildType(expressions.get(index++), 1));
|
||||
|
||||
// Number e = field.noArguments();
|
||||
assertEquals(Number.class, expressions.get(index).getType());
|
||||
assertEquals(Number.class, getChildType(expressions.get(index), 0));
|
||||
assertEquals(Number.class, getChildType(expressions.get(index++), 1));
|
||||
|
||||
// int f = this.vararg("");
|
||||
assertEquals(int.class, expressions.get(index).getType());
|
||||
assertEquals(int.class, getChildType(expressions.get(index), 1));
|
||||
assertEquals(int.class, getChildType(expressions.get(index++), 2));
|
||||
|
||||
// Make sure we got them all
|
||||
assertEquals("All expressions not tested", index, expressions.size());
|
||||
|
@ -2,16 +2,32 @@ package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class MethodPotentialApplicability {
|
||||
void test() {
|
||||
int a = vararg("", "");
|
||||
int b = vararg("", "", 10);
|
||||
MethodPotentialApplicability field;
|
||||
field = this; // initialize like this to simplify XPath expr. in tests
|
||||
|
||||
// Suffix/ASTName cases
|
||||
|
||||
int a = vararg("");
|
||||
int b = vararg("", 10);
|
||||
|
||||
String c = notVararg(0, 0);
|
||||
|
||||
Number d = noArguments();
|
||||
|
||||
// TODO: add test for: if there are type parameters then method is either non-generic or type arg airty matches
|
||||
Number e = field.noArguments();
|
||||
|
||||
// PrimaryPrefix cases
|
||||
|
||||
int f = this.vararg("");
|
||||
|
||||
// TODO: add test for: if there are type parameters then method is either non-generic or type arg arity matches
|
||||
}
|
||||
|
||||
// test if variable arity with arity n -> then call arity >= n-1
|
||||
int vararg(String b, int... a) { return 0;}
|
||||
|
||||
Exception vararg(String a, String b, String c, int... d) {return null;}
|
||||
|
||||
// test no arguments
|
||||
Number noArguments() {return null;}
|
||||
|
||||
@ -19,9 +35,4 @@ public class MethodPotentialApplicability {
|
||||
String notVararg(int a, int b) {return null;}
|
||||
|
||||
Exception notVararg(int a) {return null;}
|
||||
|
||||
// test if variable arity with arity n -> then call arity >= n-1
|
||||
int vararg(String b, String c, int... a) { return 0;}
|
||||
|
||||
Exception vararg(int... b) {return null;}
|
||||
}
|
||||
|
Reference in New Issue
Block a user