Merge branch 'pr-1123'
This commit is contained in:
commit
af7a8b3eb6
3 files changed
+62
-6
No files matched your search
+9
-6
@@ -100,7 +100,7 @@ import java.util.logging.Logger;
|
||||
@Override
|
||||
public JavaTypeDefinition getGenericType(final String parameterName) {
|
||||
for (JavaTypeDefinition currTypeDef = this; currTypeDef != null;
|
||||
currTypeDef = currTypeDef.getEnclosingClass()) {
|
||||
currTypeDef = currTypeDef.getEnclosingClass()) {
|
||||
|
||||
int paramIndex = getGenericTypeIndex(currTypeDef.getType().getTypeParameters(), parameterName);
|
||||
if (paramIndex != -1) {
|
||||
@@ -111,16 +111,16 @@ import java.util.logging.Logger;
|
||||
// throw because we could not find parameterName
|
||||
StringBuilder builder = new StringBuilder("No generic parameter by name ").append(parameterName);
|
||||
for (JavaTypeDefinition currTypeDef = this; currTypeDef != null;
|
||||
currTypeDef = currTypeDef.getEnclosingClass()) {
|
||||
currTypeDef = currTypeDef.getEnclosingClass()) {
|
||||
|
||||
builder.append("\n on class ");
|
||||
builder.append(clazz.getSimpleName());
|
||||
builder.append(currTypeDef.getType().getSimpleName());
|
||||
}
|
||||
|
||||
LOG.log(Level.FINE, builder.toString());
|
||||
// TODO: throw eventually
|
||||
//throw new IllegalArgumentException(builder.toString());
|
||||
return null;
|
||||
return forClass(Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,8 +282,11 @@ import java.util.logging.Logger;
|
||||
sb.append(jtd.shallowString()).append(", ");
|
||||
}
|
||||
|
||||
return sb.replace(sb.length() - 3, sb.length() - 1, "]") // last comma to bracket
|
||||
.append(", isGeneric=").append(isGeneric)
|
||||
if (!genericArgs.isEmpty()) {
|
||||
sb.replace(sb.length() - 3, sb.length() - 1, ""); // remove last comma
|
||||
}
|
||||
|
||||
return sb.append("], isGeneric=").append(isGeneric)
|
||||
.append("]\n").toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ import net.sourceforge.pmd.typeresolution.testdata.GenericsArrays;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.InnerClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.JavaTypeDefinitionToStringNPE;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Literals;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.LocalGenericClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodAccessibility;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodFirstPhase;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.MethodGenericExplicit;
|
||||
@@ -1829,6 +1830,11 @@ public class ClassTypeResolverTest {
|
||||
parseAndTypeResolveForClass(VarArgsMethodUseCase.class, "1.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalGenericClass() throws Exception {
|
||||
parseAndTypeResolveForClass(LocalGenericClass.class, "9");
|
||||
}
|
||||
|
||||
private JavaTypeDefinition getChildTypeDef(Node node, int childIndex) {
|
||||
return ((TypeNode) node.jjtGetChild(childIndex)).getTypeDefinition();
|
||||
}
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class LocalGenericClass {
|
||||
|
||||
public static <T> void localClassInGeneric() {
|
||||
class MyLocalClass implements MyCombiner<T, Optional<T>, MyLocalClass> {
|
||||
private T state;
|
||||
|
||||
@Override
|
||||
public void accept(T t) { }
|
||||
|
||||
@Override
|
||||
public Optional<T> get() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void combine(MyLocalClass other) {
|
||||
accept(other.state);
|
||||
}
|
||||
}
|
||||
|
||||
new MyLocalClass();
|
||||
}
|
||||
|
||||
private interface MyCombiner<R, S, T> extends MyConsumer<R>, MySupplier<S> {
|
||||
void combine(T t);
|
||||
}
|
||||
|
||||
private interface MyConsumer<R> {
|
||||
void accept(R r);
|
||||
}
|
||||
|
||||
private interface MySupplier<S> {
|
||||
S get();
|
||||
}
|
||||
|
||||
private static class Optional<T> {
|
||||
public static <T> Optional<T> empty() {
|
||||
return new Optional<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user