本文整理匯總了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;
}
示例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;
}
示例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());
}
}
}
}
示例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 + "()");
}
示例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;
}
示例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());
}
}
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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()]);
}
示例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()]);
}