use of javassist.bytecode.AttributeInfo in project pinpoint by naver.
the class JavaAssistUtils method lookupLocalVariableAttribute.
/**
* get LocalVariableAttribute
*
* @param method
* @return null if the class is not compiled with debug option
*/
public static LocalVariableAttribute lookupLocalVariableAttribute(CtBehavior method) {
if (method == null) {
throw new NullPointerException("method must not be null");
}
MethodInfo methodInfo = method.getMethodInfo2();
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
if (codeAttribute == null) {
return null;
}
AttributeInfo localVariableTable = codeAttribute.getAttribute(LocalVariableAttribute.tag);
LocalVariableAttribute local = (LocalVariableAttribute) localVariableTable;
return local;
}
use of javassist.bytecode.AttributeInfo in project fakereplace by fakereplace.
the class FieldReplacementTransformer method copyFieldAttributes.
private static void copyFieldAttributes(FieldInfo oldField, FieldInfo newField) {
AnnotationsAttribute annotations = (AnnotationsAttribute) oldField.getAttribute(AnnotationsAttribute.visibleTag);
SignatureAttribute sigAt = (SignatureAttribute) oldField.getAttribute(SignatureAttribute.tag);
if (annotations != null) {
AttributeInfo newAnnotations = annotations.copy(newField.getConstPool(), Collections.EMPTY_MAP);
newField.addAttribute(newAnnotations);
}
if (sigAt != null) {
AttributeInfo newAnnotations = sigAt.copy(newField.getConstPool(), Collections.EMPTY_MAP);
newField.addAttribute(newAnnotations);
}
}
use of javassist.bytecode.AttributeInfo in project fakereplace by fakereplace.
the class MethodReplacementTransformer method copyMethodAttributes.
public static void copyMethodAttributes(MethodInfo oldMethod, MethodInfo newMethod) {
AnnotationsAttribute annotations = (AnnotationsAttribute) oldMethod.getAttribute(AnnotationsAttribute.visibleTag);
ParameterAnnotationsAttribute pannotations = (ParameterAnnotationsAttribute) oldMethod.getAttribute(ParameterAnnotationsAttribute.visibleTag);
ExceptionsAttribute exAt = (ExceptionsAttribute) oldMethod.getAttribute(ExceptionsAttribute.tag);
SignatureAttribute sigAt = (SignatureAttribute) oldMethod.getAttribute(SignatureAttribute.tag);
if (annotations != null) {
AttributeInfo newAnnotations = annotations.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
newMethod.addAttribute(newAnnotations);
}
if (pannotations != null) {
AttributeInfo newAnnotations = pannotations.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
newMethod.addAttribute(newAnnotations);
}
if (sigAt != null) {
AttributeInfo newAnnotations = sigAt.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
newMethod.addAttribute(newAnnotations);
}
if (exAt != null) {
AttributeInfo newAnnotations = exAt.copy(newMethod.getConstPool(), Collections.EMPTY_MAP);
newMethod.addAttribute(newAnnotations);
}
}
use of javassist.bytecode.AttributeInfo in project fakereplace by fakereplace.
the class FinalMethodManipulator method transformClass.
public boolean transformClass(ClassFile file, ClassLoader loader, boolean modifiableClass, final Set<MethodInfo> modifiedMethods) {
if (!modifiableClass) {
return false;
}
boolean modified = false;
for (Object i : file.getMethods()) {
MethodInfo m = (MethodInfo) i;
if ((m.getAccessFlags() & AccessFlag.FINAL) != 0) {
m.setAccessFlags(m.getAccessFlags() & ~AccessFlag.FINAL);
// ClassDataStore.addFinalMethod(file.getName(), m.getName(),
// m.getDescriptor());
AnnotationsAttribute at = (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag);
if (at == null) {
at = new AnnotationsAttribute(file.getConstPool(), AnnotationsAttribute.visibleTag);
m.addAttribute(at);
}
at.addAnnotation(new Annotation(ModifiedMethod.class.getName(), file.getConstPool()));
m.addAttribute(new AttributeInfo(file.getConstPool(), Constants.FINAL_METHOD_ATTRIBUTE, new byte[0]));
modified = true;
}
}
return modified;
}
use of javassist.bytecode.AttributeInfo in project powermock by powermock.
the class ClassFinalModifierMockTransformer method transform.
@Override
public CtClass transform(final CtClass clazz) {
if (clazz.isInterface()) {
return clazz;
}
if (getStrategy() != INST_REDEFINE) {
if (Modifier.isFinal(clazz.getModifiers())) {
clazz.setModifiers(clazz.getModifiers() ^ Modifier.FINAL);
}
ClassFile classFile = clazz.getClassFile2();
AttributeInfo attribute = classFile.getAttribute(InnerClassesAttribute.tag);
if (attribute != null && attribute instanceof InnerClassesAttribute) {
InnerClassesAttribute ica = (InnerClassesAttribute) attribute;
String name = classFile.getName();
int n = ica.tableLength();
for (int i = 0; i < n; ++i) {
if (name.equals(ica.innerClass(i))) {
int accessFlags = ica.accessFlags(i);
if (Modifier.isFinal(accessFlags)) {
ica.setAccessFlags(i, accessFlags ^ Modifier.FINAL);
}
}
}
}
}
return clazz;
}
Aggregations