当前位置: 首页>>代码示例>>Java>>正文


Java ClassFile.getMethods方法代码示例

本文整理汇总了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 );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:FieldTransformer.java

示例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);
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:14,代码来源:CtClassType.java

示例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);
                }
        }
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:32,代码来源:CtClassType.java

示例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);
			}
		}
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:32,代码来源:FieldTransformer.java

示例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;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:11,代码来源:CheckForAnnotation.java

示例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());
			}
		}
	}	
}
 
开发者ID:guci314,项目名称:playorm,代码行数:39,代码来源:Discoverer.java

示例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;
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:16,代码来源:AbstractRapidoidMojo.java

示例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);
    }
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:14,代码来源:CtClassType.java

示例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);
                }
        }
    }
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:32,代码来源:CtClassType.java

示例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)));
			*/
		}
	}
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:55,代码来源:ClassRenamer.java


注:本文中的javassist.bytecode.ClassFile.getMethods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。