[java] typeresolution: don't throw if the type variables couldn't be resolved

This commit is contained in:
Andreas Dangel
2017-10-06 20:09:26 +02:00
parent ece871c2f7
commit e84866aa8d
3 changed files with 17 additions and 1 deletions

View File

@ -21,6 +21,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/* default */ class JavaTypeDefinitionSimple extends JavaTypeDefinition {
@ -32,6 +34,8 @@ import java.util.Set;
private final boolean isRawType;
private final JavaTypeDefinition enclosingClass;
private static final Logger log = Logger.getLogger(JavaTypeDefinitionSimple.class.getName());
protected JavaTypeDefinitionSimple(Class<?> clazz, JavaTypeDefinition... boundGenerics) {
super(EXACT);
this.clazz = clazz;
@ -112,7 +116,10 @@ import java.util.Set;
builder.append(clazz.getSimpleName());
}
throw new IllegalArgumentException(builder.toString());
log.log(Level.FINE, builder.toString());
// TODO: throw eventually
//throw new IllegalArgumentException(builder.toString());
return null;
}
@Override

View File

@ -1341,6 +1341,9 @@ public class ClassTypeResolverTest {
// Set<String> set = new HashSet<>();
assertEquals(HashSet.class, expressions.get(index++).getType());
// List<String> myList = new ArrayList<>();
assertEquals(ArrayList.class, expressions.get(index++).getType());
// Make sure we got them all
assertEquals("All expressions not tested", index, expressions.size());
}

View File

@ -4,8 +4,11 @@
package net.sourceforge.pmd.typeresolution.testdata;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MethodFirstPhase {
@ -18,6 +21,9 @@ public class MethodFirstPhase {
Set<String> set = new HashSet<>();
set.addAll(Arrays.asList("a", "b")); // TODO: return type of method call Arrays.asList is missing
List<String> myList = new ArrayList<>();
Collections.sort(myList); // TODO: generic type variables on methods
}
String vararg(Number... a) {