forked from phoedos/pmd
Fully implemente couldResolve
This commit is contained in:
@@ -98,9 +98,9 @@ public class TypeSet {
|
||||
public boolean couldResolve(final String name) {
|
||||
/*
|
||||
* Resolvers based on this one, will attempt to load the class from
|
||||
* the class loader yields no real gain
|
||||
* the class loader, so ask him
|
||||
*/
|
||||
return true;
|
||||
return pmdClassLoader.couldResolve(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,11 @@ public class TypeSet {
|
||||
public Class<?> resolve(String name) throws ClassNotFoundException {
|
||||
return pmdClassLoader.loadClass(pkg + '.' + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldResolve(String name) {
|
||||
return super.couldResolve(pkg + '.' + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,6 +213,11 @@ public class TypeSet {
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldResolve(String name) {
|
||||
return super.couldResolve("java.lang." + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,6 +255,23 @@ public class TypeSet {
|
||||
}
|
||||
throw new ClassNotFoundException("Type " + name + " not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldResolve(String name) {
|
||||
boolean couldResolve = false;
|
||||
for (String importStmt : importStmts) {
|
||||
if (importStmt.endsWith("*")) {
|
||||
String fqClassName = new StringBuilder(importStmt.length() + name.length())
|
||||
.append(importStmt)
|
||||
.replace(importStmt.length() - 1, importStmt.length(), name)
|
||||
.toString();
|
||||
// can any class be resolved / was never attempted?
|
||||
couldResolve |= super.couldResolve(fqClassName);
|
||||
}
|
||||
}
|
||||
|
||||
return couldResolve;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -47,7 +47,7 @@ public final class PMDASMClassLoader extends ClassLoader {
|
||||
private PMDASMClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A new PMDASMClassLoader is created for each compilation unit, this method
|
||||
* allows to reuse the same PMDASMClassLoader across all the compilation
|
||||
@@ -80,6 +80,18 @@ public final class PMDASMClassLoader extends ClassLoader {
|
||||
throw new ClassNotFoundException(name, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the class loader could resolve a given class name
|
||||
* (ie: it doesn't know for sure it will fail).
|
||||
* Notice, that the ability to resolve a class does not imply
|
||||
* that the class will actually be found and resolved.
|
||||
* @param name the name of the class
|
||||
* @return whether the class can be resolved
|
||||
*/
|
||||
public boolean couldResolve(String name) {
|
||||
return !dontBother.containsKey(name);
|
||||
}
|
||||
|
||||
public synchronized Map<String, String> getImportedClasses(String name) throws ClassNotFoundException {
|
||||
if (dontBother.containsValue(name)) {
|
||||
|
Reference in New Issue
Block a user