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


Java MethodInfo.getAttribute方法代碼示例

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


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

示例1: getParameterNames

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private String[] getParameterNames(final CtBehavior behavior) throws NotFoundException {
    final MethodInfo methodInfo = behavior.getMethodInfo();
    final ParameterAnnotationsAttribute attribute =
            (ParameterAnnotationsAttribute) methodInfo.getAttribute(ParameterAnnotationsAttribute.visibleTag);
    if (attribute == null) {
        return null;
    }
    final int numParameters = behavior.getParameterTypes().length;
    final String[] parameterNames = new String[numParameters];
    final Annotation[][] annotationsArray = attribute.getAnnotations();
    if (annotationsArray == null || annotationsArray.length != numParameters) {
        return null;
    }
    for (int i = 0; i < numParameters; ++i) {
        final String parameterName = getParameterName(annotationsArray[i]);
        if (parameterName == null) {
            return null;
        }
        parameterNames[i] = parameterName;
    }
    return parameterNames;
}
 
開發者ID:lastaflute,項目名稱:lasta-di,代碼行數:23,代碼來源:BeanDescImpl.java

示例2: copyAttribute

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static @Nullable AttributeInfo copyAttribute(MethodInfo from, MethodInfo to, String attributeName) {
    final AttributeInfo attr = from.getAttribute(attributeName);
    if(attr != null) {
        addAttribute(to, attr);
    }
    return attr;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:8,代碼來源:Javassists.java

示例3: addParameterAnnotationsFor

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private void addParameterAnnotationsFor(Collection<String> imports, MethodInfo methodInfo, String tag) {
    AttributeInfo attribute = methodInfo.getAttribute(tag);
    ParameterAnnotationsAttribute annotationAttribute = (ParameterAnnotationsAttribute) attribute;
    if (annotationAttribute != null) {
        Annotation[][] parameters = annotationAttribute.getAnnotations();
        for (Annotation[] annotations : parameters) {
            for (Annotation annotation : annotations) {
                imports.add(annotation.getTypeName());
            }
        }
    }
}
 
開發者ID:arquillian,項目名稱:smart-testing,代碼行數:13,代碼來源:JavaAssistClass.java

示例4: getDefault

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private Object getDefault(String name, Method method)
    throws ClassNotFoundException, RuntimeException
{
    String classname = annotation.getTypeName();
    if (pool != null) {
        try {
            CtClass cc = pool.get(classname);
            ClassFile cf = cc.getClassFile2();
            MethodInfo minfo = cf.getMethod(name);
            if (minfo != null) {
                AnnotationDefaultAttribute ainfo
                    = (AnnotationDefaultAttribute)
                      minfo.getAttribute(AnnotationDefaultAttribute.tag);
                if (ainfo != null) {
                    MemberValue mv = ainfo.getDefaultValue();
                    return mv.getValue(classLoader, pool, method);
                }
            }
        }
        catch (NotFoundException e) {
            throw new RuntimeException("cannot find a class file: "
                                       + classname);
        }
    }

    throw new RuntimeException("no default value: " + classname + "."
                               + name + "()");
}
 
開發者ID:AndreJCL,項目名稱:JCL,代碼行數:29,代碼來源:AnnotationImpl.java

示例5: isAnnotationPresent

import javassist.bytecode.MethodInfo; //導入方法依賴的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.MethodInfo; //導入方法依賴的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: getMethodGenericSignatureType

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
@Override
public String getMethodGenericSignatureType(Signature methodSignature) throws MethodNotFoundException {
    final MethodInfo m = findMethodDeclaration(methodSignature);
    if (m == null) {
        throw new MethodNotFoundException(methodSignature.toString());
    }
    final SignatureAttribute sa
        = (SignatureAttribute) m.getAttribute(SignatureAttribute.tag);
    return sa == null ? null : sa.getSignature();
}
 
開發者ID:pietrobraione,項目名稱:jbse,代碼行數:11,代碼來源:ClassFileJavassist.java

示例8: getMethodAnnotationsRaw

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
@Override
public byte[] getMethodAnnotationsRaw(Signature methodSignature) 
throws MethodNotFoundException {
    final MethodInfo m = findMethodDeclaration(methodSignature);
    if (m == null) {
        throw new MethodNotFoundException(methodSignature.toString());
    }
    final AttributeInfo attrVisible = m.getAttribute(AnnotationsAttribute.visibleTag);
    final AttributeInfo attrInvisible = m.getAttribute(AnnotationsAttribute.invisibleTag);
    return mergeVisibleAndInvisibleAttributes(attrVisible, attrInvisible);
}
 
開發者ID:pietrobraione,項目名稱:jbse,代碼行數:12,代碼來源:ClassFileJavassist.java

示例9: toParameterAnnotationsAttribute

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
private static ParameterAnnotationsAttribute toParameterAnnotationsAttribute(CtBehavior ctBehavior) {
    MethodInfo minfo = ctBehavior.getMethodInfo();
    ParameterAnnotationsAttribute attr = (ParameterAnnotationsAttribute) minfo
            .getAttribute(ParameterAnnotationsAttribute.visibleTag);
    return attr;
}
 
開發者ID:mnip91,項目名稱:proactive-component-monitoring,代碼行數:7,代碼來源:Method.java

示例10: grabMethodandParameterAnnotation

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public void grabMethodandParameterAnnotation(CtBehavior ctBehavior) {

        MethodInfo minfo = ctBehavior.getMethodInfo();
        AnnotationsAttribute methodattr = (AnnotationsAttribute) minfo
                .getAttribute(AnnotationsAttribute.visibleTag);

        if (methodattr != null) {
            Annotation[] methodAnn = methodattr.getAnnotations();

            for (Annotation object : methodAnn) {
                JavassistByteCodeStubBuilder.logger.debug("adding annotation " + object.getTypeName() +
                    " to " + ctBehavior.getLongName());
                methodAnnotation.add(object);
            }
        }

        // get parameter annotations

        ParameterAnnotationsAttribute attr = toParameterAnnotationsAttribute(ctBehavior);
        if (attr == null) {
            return;
        }

        javassist.bytecode.annotation.Annotation[][] parametersAnnotations = attr.getAnnotations();

        //        if (listMethodParameters.size() > 0) {

        for (int paramIndex = 0; paramIndex < parametersAnnotations.length; paramIndex++) {

            javassist.bytecode.annotation.Annotation[] paramAnnotations = parametersAnnotations[paramIndex];
            for (javassist.bytecode.annotation.Annotation parameterAnnotation : paramAnnotations) {

                MethodParameter mp = listMethodParameters.get(paramIndex);
                if (mp == null) {
                    mp = new MethodParameter();
                    listMethodParameters.set(paramIndex, mp);
                }
                JavassistByteCodeStubBuilder.logger.debug("adding annotation " +
                    parameterAnnotation.getTypeName() + " to param " + paramIndex + " of " +
                    ctBehavior.getLongName());
                mp.getAnnotations().add(parameterAnnotation);
            }
        }
    }
 
開發者ID:mnip91,項目名稱:proactive-component-monitoring,代碼行數:45,代碼來源:Method.java

示例11: getAnnotationsForMethod

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static Annotation[] getAnnotationsForMethod(MethodInfo methodInfo) {

		AnnotationsAttribute visible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.visibleTag);
		AnnotationsAttribute invisible = (AnnotationsAttribute) methodInfo.getAttribute(AnnotationsAttribute.invisibleTag);

		Set<Annotation> retVal = new HashSet<Annotation>();

		retVal.addAll(findAnnotationsForAnnotationsAttribute(visible));
		retVal.addAll(findAnnotationsForAnnotationsAttribute(invisible));

		return retVal.toArray(new Annotation[retVal.size()]);
	}
 
開發者ID:JadiraOrg,項目名稱:jadira,代碼行數:13,代碼來源:JavassistAnnotationsHelper.java

示例12: getAnnotationsForMethodParameter

import javassist.bytecode.MethodInfo; //導入方法依賴的package包/類
public static Annotation[] getAnnotationsForMethodParameter(MethodInfo methodInfo, int index) {

		ParameterAnnotationsAttribute visible = (ParameterAnnotationsAttribute) methodInfo.getAttribute(ParameterAnnotationsAttribute.visibleTag);
		ParameterAnnotationsAttribute invisible = (ParameterAnnotationsAttribute) methodInfo.getAttribute(ParameterAnnotationsAttribute.invisibleTag);

		Set<Annotation> retVal = new HashSet<Annotation>();

		retVal.addAll(findAnnotationsForAnnotationsArray(visible.getAnnotations()[index]));
		retVal.addAll(findAnnotationsForAnnotationsArray(invisible.getAnnotations()[index]));

		return retVal.toArray(new Annotation[retVal.size()]);
	}
 
開發者ID:JadiraOrg,項目名稱:jadira,代碼行數:13,代碼來源:JavassistAnnotationsHelper.java


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