use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method getEnclosingBehavior.
public CtBehavior getEnclosingBehavior() throws NotFoundException {
ClassFile cf = getClassFile2();
EnclosingMethodAttribute ema = (EnclosingMethodAttribute) cf.getAttribute(EnclosingMethodAttribute.tag);
if (ema == null)
return null;
else {
CtClass enc = classPool.get(ema.className());
String name = ema.methodName();
if (MethodInfo.nameInit.equals(name))
return enc.getConstructor(ema.methodDescriptor());
else if (MethodInfo.nameClinit.equals(name))
return enc.getClassInitializer();
else
return enc.getMethod(name, ema.methodDescriptor());
}
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method setGenericSignature.
public void setGenericSignature(String sig) {
ClassFile cf = getClassFile();
SignatureAttribute sa = new SignatureAttribute(cf.getConstPool(), sig);
cf.addAttribute(sa);
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method instrument.
public void instrument(CodeConverter converter) throws CannotCompileException {
checkModify();
ClassFile cf = getClassFile2();
ConstPool cp = cf.getConstPool();
List list = cf.getMethods();
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo) list.get(i);
converter.doit(this, minfo, cp);
}
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method setModifiers.
public void setModifiers(int mod) {
checkModify();
updateInnerEntry(mod, getName(), this, true);
ClassFile cf = getClassFile2();
cf.setAccessFlags(AccessFlag.of(mod & ~Modifier.STATIC));
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method updateInnerEntry.
private static void updateInnerEntry(int newMod, String name, CtClass clazz, boolean outer) {
ClassFile cf = clazz.getClassFile2();
InnerClassesAttribute ica = (InnerClassesAttribute) cf.getAttribute(InnerClassesAttribute.tag);
if (ica != null) {
// If the class is a static inner class, its modifier
// does not contain the static bit. Its inner class attribute
// contains the static bit.
int mod = newMod & ~Modifier.STATIC;
int i = ica.find(name);
if (i >= 0) {
int isStatic = ica.accessFlags(i) & AccessFlag.STATIC;
if (isStatic != 0 || !Modifier.isStatic(newMod)) {
clazz.checkModify();
ica.setAccessFlags(i, AccessFlag.of(mod) | isStatic);
String outName = ica.outerClass(i);
if (outName != null && outer)
try {
CtClass parent = clazz.getClassPool().get(outName);
updateInnerEntry(mod, name, parent, false);
} catch (NotFoundException e) {
throw new RuntimeException("cannot find the declaring class: " + outName);
}
return;
}
}
}
if (Modifier.isStatic(newMod))
throw new RuntimeException("cannot change " + Descriptor.toJavaName(name) + " into a static class");
}
Aggregations