Fully implemente couldResolve

This commit is contained in:
Juan Martín Sotuyo Dodero
2016-10-14 19:34:39 -03:00
parent 565a9aa0d8
commit 8c82dae34c
2 changed files with 42 additions and 3 deletions

View File

@@ -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;
}
}
/**

View File

@@ -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)) {