當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。