use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class ScopedClassPool method getCached.
/**
* Get the cached class
*
* @param classname
* the class name
* @return the class
*/
protected CtClass getCached(String classname) {
CtClass clazz = getCachedLocally(classname);
if (clazz == null) {
boolean isLocal = false;
ClassLoader dcl = getClassLoader0();
if (dcl != null) {
final int lastIndex = classname.lastIndexOf('$');
String classResourceName = null;
if (lastIndex < 0) {
classResourceName = classname.replaceAll("[\\.]", "/") + ".class";
} else {
classResourceName = classname.substring(0, lastIndex).replaceAll("[\\.]", "/") + classname.substring(lastIndex) + ".class";
}
isLocal = dcl.getResource(classResourceName) != null;
}
if (!isLocal) {
Map registeredCLs = repository.getRegisteredCLs();
synchronized (registeredCLs) {
Iterator it = registeredCLs.values().iterator();
while (it.hasNext()) {
ScopedClassPool pool = (ScopedClassPool) it.next();
if (pool.isUnloadedClassLoader()) {
repository.unregisterClassLoader(pool.getClassLoader());
continue;
}
clazz = pool.getCachedLocally(classname);
if (clazz != null) {
return clazz;
}
}
}
}
}
// *NOTE* NEED TO TEST WHEN SUPERCLASS IS IN ANOTHER UCL!!!!!!
return clazz;
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class ScopedClassPool method getLocally.
/**
* Get any local copy of the class
*
* @param classname
* the class name
* @return the class
* @throws NotFoundException
* when the class is not found
*/
public synchronized CtClass getLocally(String classname) throws NotFoundException {
softcache.remove(classname);
CtClass clazz = (CtClass) classes.get(classname);
if (clazz == null) {
clazz = createCtClass(classname, true);
if (clazz == null)
throw new NotFoundException(classname);
super.cacheCtClass(classname, clazz, false);
}
return clazz;
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class CtClassSignature method getParams.
private String getParams(CtClass[] ctClasses) {
StringBuilder strBuilder = new StringBuilder("(");
boolean first = true;
for (CtClass ctClass : ctClasses) {
if (!first)
strBuilder.append(",");
else
first = false;
strBuilder.append(getName(ctClass));
}
strBuilder.append(")");
return strBuilder.toString();
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class SignatureTest method testInterfaceSignature.
@Test
public void testInterfaceSignature() throws Exception {
CtClass makeClass = ClassPool.getDefault().get(TestSignatures.class.getName());
String expected = ClassSignatureComparerHelper.getJavaClassSignature(TestSignatures.class, SIGNATURE_ELEMENTS);
String actual = ClassSignatureComparerHelper.getCtClassSignature(makeClass, SIGNATURE_ELEMENTS);
assertEquals("Signatures not equal", expected, actual);
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class AnnotationHelperTest method testHasAnnotationJavassist.
@Test
public void testHasAnnotationJavassist() throws Exception {
ClassPool ctPool = ClassPool.getDefault();
CtClass ctClass = ctPool.getCtClass(AnonymousClassPatchPlugin.class.getName());
assertTrue(AnnotationHelper.hasAnnotation(ctClass, "org.hotswap.agent.annotation.Plugin"));
assertFalse(AnnotationHelper.hasAnnotation(ctClass, "xxxx"));
}
Aggregations