當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInfo.getConstPool方法代碼示例

本文整理匯總了Java中javassist.bytecode.MethodInfo.getConstPool方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInfo.getConstPool方法的具體用法?Java MethodInfo.getConstPool怎麽用?Java MethodInfo.getConstPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javassist.bytecode.MethodInfo的用法示例。


在下文中一共展示了MethodInfo.getConstPool方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateClass

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static void updateClass(MethodInfo info, List<String> names) {
	
	// add the names to the class const pool
	ConstPool constPool = info.getConstPool();
	List<Integer> parameterNameIndices = new ArrayList<Integer>();
	for (String name : names) {
		if (name != null) {
			parameterNameIndices.add(constPool.addUtf8Info(name));
		} else {
			parameterNameIndices.add(0);
		}
	}
	
	// add the attribute to the method
	info.addAttribute(new MethodParametersAttribute(constPool, parameterNameIndices));
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:17,代碼來源:MethodParametersAttribute.java

示例2: buildExceptionInfo

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();

    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }

        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }

    return exceptions;
}
 
開發者ID:AndreJCL,項目名稱:JCL,代碼行數:21,代碼來源:Analyzer.java

示例3: updateClass

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static void updateClass(MethodInfo info, List<String> names) {

        // add the names to the class const pool
        ConstPool constPool = info.getConstPool();
        List<Integer> parameterNameIndices = new ArrayList<>();
        for (String name : names) {
            if (name != null) {
                parameterNameIndices.add(constPool.addUtf8Info(name));
            } else {
                parameterNameIndices.add(0);
            }
        }

        // add the attribute to the method
        info.addAttribute(new MethodParametersAttribute(constPool, parameterNameIndices));
    }
 
開發者ID:OpenModLoader,項目名稱:Enigma,代碼行數:17,代碼來源:MethodParametersAttribute.java

示例4: getBehaviourBytecode

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
 * This is basically the InstructionPrinter.getMethodBytecode but with a
 * CtBehaviour parameter instead of a CtMethod
 * 
 * @param behavior
 * @return
 */
public static String getBehaviourBytecode(CtBehavior behavior) {
    MethodInfo info = behavior.getMethodInfo2();
    CodeAttribute code = info.getCodeAttribute();
    if (code == null) {
        return "";
    }

    ConstPool pool = info.getConstPool();
    StringBuilder sb = new StringBuilder(1024);

    CodeIterator iterator = code.iterator();
    while (iterator.hasNext()) {
        int pos;
        try {
            pos = iterator.next();
        } catch (BadBytecode e) {
            throw new JVoidIntrumentationException("BadBytecoode", e);
        }

        sb.append(pos + ": " + InstructionPrinter.instructionString(iterator, pos, pool) + "\n");
    }
    return sb.toString();
}
 
開發者ID:jVoid,項目名稱:jVoid,代碼行數:31,代碼來源:JavassistUtils.java

示例5: updateClass

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static void updateClass(MethodInfo info, List<String> names)
{
	
	// add the names to the class const pool
	ConstPool constPool = info.getConstPool();
	List<Integer> parameterNameIndices = new ArrayList<Integer>();
	for(String name : names)
		if(name != null)
			parameterNameIndices.add(constPool.addUtf8Info(name));
		else
			parameterNameIndices.add(0);
	
	// add the attribute to the method
	info.addAttribute(new MethodParametersAttribute(constPool,
		parameterNameIndices));
}
 
開發者ID:Wurst-Imperium,項目名稱:Wurst-Enigma,代碼行數:17,代碼來源:MethodParametersAttribute.java

示例6: addEndpointMapping

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
@Override
protected void addEndpointMapping(CtMethod ctMethod, String method, String request) {
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	Annotation requestMapping = new Annotation(RequestMapping.class.getName(), constPool);

	ArrayMemberValue valueVals = new ArrayMemberValue(constPool);
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(request);
	valueVals.setValue(new MemberValue[]{valueVal});

	requestMapping.addMemberValue("value", valueVals);

	ArrayMemberValue methodVals = new ArrayMemberValue(constPool);
	EnumMemberValue methodVal = new EnumMemberValue(constPool);
	methodVal.setType(RequestMethod.class.getName());
	methodVal.setValue(method);
	methodVals.setValue(new MemberValue[]{methodVal});

	requestMapping.addMemberValue("method", methodVals);
	attr.addAnnotation(requestMapping);
	methodInfo.addAttribute(attr);
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:26,代碼來源:SpringMVCBinder.java

示例7: addMethodAnnotations

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static void addMethodAnnotations(CtMethod ctMethod, Method method) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
	if (method != null) {
		MethodInfo methodInfo = ctMethod.getMethodInfo();
		ConstPool constPool = methodInfo.getConstPool();
		AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
		methodInfo.addAttribute(attr);
		for(java.lang.annotation.Annotation anno : method.getAnnotations()) {

			// If it's a Transition skip
			// TODO : Make this a parameterized set of Filters instead of hardcoding
			//
			Annotation clone = null;
			if (anno instanceof Transitions || anno instanceof Transition) {
				// skip
			} else {
				clone = cloneAnnotation(constPool, anno);
				attr.addAnnotation(clone);
			}
		}
	}
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:22,代碼來源:JavassistUtils.java

示例8: addIdParameter

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
protected Annotation[] addIdParameter(
		CtMethod ctMethod, 
		Class<?> idType,
		ClassPool cp) throws NotFoundException, CannotCompileException {
	// Clone the parameter Class
	//
	CtClass ctParm = cp.get(idType.getName());
	
	// Add the parameter to the method
	//
	ctMethod.addParameter(ctParm);
	
	// Add the Parameter Annotations to the Method
	//
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();
	Annotation annot = new Annotation(getPathAnnotationClass().getName(), constPool);
	
	StringMemberValue valueVal = new StringMemberValue("id", constPool); 
	annot.addMemberValue("value", valueVal);
	
	return new Annotation[]{ annot };
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:24,代碼來源:AbstractRestfulBinder.java

示例9: analyze

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
/**
 * Performs data-flow analysis on a method and returns an array, indexed by
 * instruction position, containing the starting frame state of all reachable
 * instructions. Non-reachable code, and illegal code offsets are represented
 * as a null in the frame state array. This can be used to detect dead code.
 *
 * If the method does not contain code (it is either native or abstract), null
 * is returned.
 *
 * @param clazz the declaring class of the method
 * @param method the method to analyze
 * @return an array, indexed by instruction position, of the starting frame state,
 *         or null if this method doesn't have code
 * @throws BadBytecode if the bytecode does not comply with the JVM specification
 */
public Frame[] analyze(CtClass clazz, MethodInfo method) throws BadBytecode {
    this.clazz = clazz;
    CodeAttribute codeAttribute = method.getCodeAttribute();
    // Native or Abstract
    if (codeAttribute == null)
        return null;

    int maxLocals = codeAttribute.getMaxLocals();
    int maxStack = codeAttribute.getMaxStack();
    int codeLength = codeAttribute.getCodeLength();

    CodeIterator iter = codeAttribute.iterator();
    IntQueue queue = new IntQueue();

    exceptions = buildExceptionInfo(method);
    subroutines = scanner.scan(method);

    Executor executor = new Executor(clazz.getClassPool(), method.getConstPool());
    frames = new Frame[codeLength];
    frames[iter.lookAhead()] = firstFrame(method, maxLocals, maxStack);
    queue.add(iter.next());
    while (!queue.isEmpty()) {
        analyzeNextEntry(method, iter, queue, executor);
    }

    return frames;
}
 
開發者ID:AndreJCL,項目名稱:JCL,代碼行數:43,代碼來源:Analyzer.java

示例10: counterAdaptClass

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
byte[] counterAdaptClass(final InputStream is, final String name)
        throws Exception
{
    CtClass cc = pool.makeClass(is);
    if (!cc.isInterface()) {
        cc.addField(new CtField(CtClass.intType, "_counter", cc));
    }
    CtMethod[] ms = cc.getDeclaredMethods();
    for (int j = 0; j < ms.length; ++j) {
        CtMethod m = ms[j];
        int modifiers = m.getModifiers();
        if (!Modifier.isStatic(modifiers)
                && !Modifier.isAbstract(modifiers)
                && !Modifier.isNative(modifiers))
        {
            if (!m.isEmpty()) {
                MethodInfo info = m.getMethodInfo();
                Bytecode bc = new Bytecode(info.getConstPool(), 1, 0);
                bc.addAload(0);
                bc.addAload(0);
                bc.addGetfield(cc, "_counter", "I");
                bc.add(Opcode.ICONST_1);
                bc.add(Opcode.IADD);
                bc.addPutfield(cc, "_counter", "I");
                CodeIterator iter = info.getCodeAttribute().iterator();
                iter.begin();
                iter.insert(bc.get());
            }
        }
    }
    return cc.toBytecode();
}
 
開發者ID:typetools,項目名稱:annotation-tools,代碼行數:33,代碼來源:JavassistPerfTest.java

示例11: addConsumeAnnotation

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private void addConsumeAnnotation(CtMethod ctMethod, String uri) {
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	Annotation consume = new Annotation(Consume.class.getName(), constPool);
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(uri);
	consume.addMemberValue("uri", valueVal);

	AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	attr.addAnnotation(consume);
	methodInfo.addAttribute(attr);
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:14,代碼來源:CamelBinder.java

示例12: copyParameters

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
protected void copyParameters(CtMethod ctMethod, Method method, ClassPool cp) throws NotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, CannotCompileException {
	String[] parmNames = (method != null) ? parmDiscover.getParameterNames(method) : null;
		MethodInfo methodInfo = ctMethod.getMethodInfo();
	ParameterAnnotationsAttribute paramAtrributeInfo = 
			new ParameterAnnotationsAttribute(
					methodInfo.getConstPool(), 
					ParameterAnnotationsAttribute.visibleTag);
	
	Annotation[][] paramArrays = new Annotation[method.getParameterTypes().length][];
	java.lang.annotation.Annotation[][] parmAnnotations = method.getParameterAnnotations();
	int parmIndex = 0;
	for(Class<?> parm : method.getParameterTypes()) {
			
		// Clone the parameter Class
		//
		CtClass ctParm = cp.get(parm.getName());
		
		// Add the parameter to the method
		//
		ctMethod.addParameter(ctParm);
		
		// Add the Parameter Annotations to the Method
		//
		String parmName = (parmNames != null && parmNames.length > parmIndex) ? parmNames[parmIndex] : null;
		paramArrays[parmIndex] = createParameterAnnotations(
				parmName,
				ctMethod.getMethodInfo(),
				parmAnnotations[parmIndex],
				paramAtrributeInfo.getConstPool());
		parmIndex++;
	}
	paramAtrributeInfo.setAnnotations(paramArrays);
	methodInfo.addAttribute(paramAtrributeInfo);
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:35,代碼來源:AbstractRestfulBinder.java

示例13: addEndpointMapping

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
@Override
protected void addEndpointMapping(
		CtMethod ctMethod, 
		String method,
		String request) {
	
	// Add Path Annotation
	//
	MethodInfo methodInfo = ctMethod.getMethodInfo();
	ConstPool constPool = methodInfo.getConstPool();

	AnnotationsAttribute annoAttr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
	Annotation pathMapping = new Annotation(Path.class.getName(), constPool);
	
	StringMemberValue valueVal = new StringMemberValue(constPool);
	valueVal.setValue(request);
	
	pathMapping.addMemberValue("value", valueVal);
	
	annoAttr.addAnnotation(pathMapping);

	// Add Verb Annotation (GET|POST|PUT|DELETE)
	//
	String verbClassName = "javax.ws.rs." + method;
	Annotation verb = new Annotation(verbClassName, constPool);
	annoAttr.addAnnotation(verb);
	
	methodInfo.addAttribute(annoAttr);
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:30,代碼來源:JerseyBinder.java


注:本文中的javassist.bytecode.MethodInfo.getConstPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。