本文整理汇总了Java中javassist.bytecode.ClassFile.getMethods方法的典型用法代码示例。如果您正苦于以下问题:Java ClassFile.getMethods方法的具体用法?Java ClassFile.getMethods怎么用?Java ClassFile.getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.ClassFile
的用法示例。
在下文中一共展示了ClassFile.getMethods方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformInvokevirtualsIntoPutAndGetfields
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile) throws CannotCompileException, BadBytecode {
for ( Object o : classfile.getMethods() ) {
final MethodInfo methodInfo = (MethodInfo) o;
final String methodName = methodInfo.getName();
if ( methodName.startsWith( EACH_READ_METHOD_PREFIX )
|| methodName.startsWith( EACH_WRITE_METHOD_PREFIX )
|| methodName.equals( GETFIELDHANDLER_METHOD_NAME )
|| methodName.equals( SETFIELDHANDLER_METHOD_NAME ) ) {
continue;
}
final CodeAttribute codeAttr = methodInfo.getCodeAttribute();
if ( codeAttr == null ) {
continue;
}
final CodeIterator iter = codeAttr.iterator();
while ( iter.hasNext() ) {
int pos = iter.next();
pos = transformInvokevirtualsIntoGetfields( classfile, iter, pos );
transformInvokevirtualsIntoPutfields( classfile, iter, pos );
}
final StackMapTable smt = MapMaker.make( classPool, methodInfo );
codeAttr.setAttribute( smt );
}
}
示例2: instrument
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public void instrument(CodeConverter converter)
throws CannotCompileException
{
checkModify();
ClassFile cf = getClassFile2();
ConstPool cp = cf.getConstPool();
List<MethodInfo> 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);
}
}
示例3: modifyConstructors
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void modifyConstructors(ClassFile cf)
throws CannotCompileException, NotFoundException
{
if (fieldInitializers == null)
return;
ConstPool cp = cf.getConstPool();
List<MethodInfo> list = cf.getMethods();
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo)list.get(i);
if (minfo.isConstructor()) {
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr != null)
try {
Bytecode init = new Bytecode(cp, 0,
codeAttr.getMaxLocals());
CtClass[] params
= Descriptor.getParameterTypes(
minfo.getDescriptor(),
classPool);
int stacksize = makeFieldInitializer(init, params);
insertAuxInitializer(codeAttr, init, stacksize);
minfo.rebuildStackMapIf6(classPool, cf);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
示例4: transformInvokevirtualsIntoPutAndGetfields
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
throws CannotCompileException {
List methods = classfile.getMethods();
for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
MethodInfo minfo = (MethodInfo) method_iter.next();
String methodName = minfo.getName();
if (methodName.startsWith(EACH_READ_METHOD_PREFIX)
|| methodName.startsWith(EACH_WRITE_METHOD_PREFIX)
|| methodName.equals(GETFIELDHANDLER_METHOD_NAME)
|| methodName.equals(SETFIELDHANDLER_METHOD_NAME)) {
continue;
}
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null) {
return;
}
CodeIterator iter = codeAttr.iterator();
while (iter.hasNext()) {
try {
int pos = iter.next();
pos = transformInvokevirtualsIntoGetfields(classfile, iter,
pos);
pos = transformInvokevirtualsIntoPutfields(classfile, iter,
pos);
} catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
示例5: isAnnotationPresent
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
protected boolean isAnnotationPresent(ClassFile cf) {
List<MethodInfo> methods = cf.getMethods();
for (MethodInfo info : methods) {
AnnotationsAttribute attr = (AnnotationsAttribute) info
.getAttribute(AnnotationsAttribute.visibleTag);
if (isAnnotationPresent(attr))
return true;
}
return false;
}
示例6: discoverAndIntimateForMethodAnnotations
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
/**
* Discovers Method Annotations
*
* @param classFile
*/
private void discoverAndIntimateForMethodAnnotations(ClassFile classFile) {
@SuppressWarnings("unchecked")
List<MethodInfo> methods = classFile.getMethods();
if (methods == null) {
return;
}
for (MethodInfo methodInfo : methods) {
Set<Annotation> annotations = new HashSet<Annotation>();
AnnotationsAttribute visible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.visibleTag);
AnnotationsAttribute invisible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.invisibleTag);
if (visible != null) {
annotations.addAll(Arrays.asList(visible.getAnnotations()));
}
if (invisible != null) {
annotations.addAll(Arrays.asList(invisible.getAnnotations()));
}
// now tell listeners
for (Annotation annotation : annotations) {
Set<MethodAnnotationDiscoveryListener> listeners = methodAnnotationListeners.get(annotation.getTypeName());
if (null == listeners) {
continue;
}
for (MethodAnnotationDiscoveryListener listener : listeners) {
listener.discovered(classFile.getName(), methodInfo.getName(), methodInfo.getDescriptor(), annotation.getTypeName());
}
}
}
}
示例7: hasMainMethod
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static boolean hasMainMethod(ClassFile cls) {
int flags = cls.getAccessFlags();
if (Modifier.isInterface(flags)
|| Modifier.isAnnotation(flags)
|| Modifier.isEnum(flags)) return false;
for (Object m : cls.getMethods()) {
if (m instanceof MethodInfo) {
if (isMainMethod((MethodInfo) m)) return true;
}
}
return false;
}
示例8: instrument
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
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);
}
}
示例9: modifyConstructors
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void modifyConstructors(ClassFile cf)
throws CannotCompileException, NotFoundException
{
if (fieldInitializers == null)
return;
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);
if (minfo.isConstructor()) {
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr != null)
try {
Bytecode init = new Bytecode(cp, 0,
codeAttr.getMaxLocals());
CtClass[] params
= Descriptor.getParameterTypes(
minfo.getDescriptor(),
classPool);
int stacksize = makeFieldInitializer(init, params);
insertAuxInitializer(codeAttr, init, stacksize);
minfo.rebuildStackMapIf6(classPool, cf);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
示例10: renameClasses
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void renameClasses(CtClass c, ClassNameReplacer replacer) {
// sadly, we can't use CtClass.renameClass() because SignatureAttribute.renameClass() is extremely buggy =(
ReplacerClassMap map = new ReplacerClassMap(replacer);
ClassFile classFile = c.getClassFile();
// rename the constant pool (covers ClassInfo, MethodTypeInfo, and NameAndTypeInfo)
ConstPool constPool = c.getClassFile().getConstPool();
constPool.renameClass(map);
// rename class attributes
renameAttributes(classFile.getAttributes(), map, SignatureType.Class);
// rename methods
for (MethodInfo methodInfo : (List<MethodInfo>)classFile.getMethods()) {
methodInfo.setDescriptor(Descriptor.rename(methodInfo.getDescriptor(), map));
renameAttributes(methodInfo.getAttributes(), map, SignatureType.Method);
}
// rename fields
for (FieldInfo fieldInfo : (List<FieldInfo>)classFile.getFields()) {
fieldInfo.setDescriptor(Descriptor.rename(fieldInfo.getDescriptor(), map));
renameAttributes(fieldInfo.getAttributes(), map, SignatureType.Field);
}
// rename the class name itself last
// NOTE: don't use the map here, because setName() calls the buggy SignatureAttribute.renameClass()
// we only want to replace exactly this class name
String newName = renameClassName(c.getName(), map);
if (newName != null) {
c.setName(newName);
}
// replace simple names in the InnerClasses attribute too
InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute(InnerClassesAttribute.tag);
if (attr != null) {
for (int i = 0; i < attr.tableLength(); i++) {
// get the inner class full name (which has already been translated)
ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(attr.innerClass(i)));
if (attr.innerNameIndex(i) != 0) {
// update the inner name
attr.setInnerNameIndex(i, constPool.addUtf8Info(classEntry.getInnermostClassName()));
}
/* DEBUG
System.out.println(String.format("\tDEOBF: %s-> ATTR: %s,%s,%s", classEntry, attr.outerClass(i), attr.innerClass(i), attr.innerName(i)));
*/
}
}
}