本文整理汇总了Java中javassist.bytecode.ParameterAnnotationsAttribute类的典型用法代码示例。如果您正苦于以下问题:Java ParameterAnnotationsAttribute类的具体用法?Java ParameterAnnotationsAttribute怎么用?Java ParameterAnnotationsAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterAnnotationsAttribute类属于javassist.bytecode包,在下文中一共展示了ParameterAnnotationsAttribute类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameterNames
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的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: addMethodAnnotationDependencies
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的package包/类
private void addMethodAnnotationDependencies(CtClass ctClass, Collection<String> imports) {
for (CtMethod ctMethod : ctClass.getDeclaredMethods()) {
MethodInfo methodInfo = ctMethod.getMethodInfo2();
List<?> attributes = methodInfo.getAttributes();
addAnnotationsForAttributes(imports, attributes);
addParameterAnnotationsFor(imports, methodInfo, ParameterAnnotationsAttribute.visibleTag);
addParameterAnnotationsFor(imports, methodInfo, ParameterAnnotationsAttribute.invisibleTag);
}
}
示例3: addParameterAnnotationsFor
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的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: duplicateParameterAnnotationsAttribute
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的package包/类
public static ParameterAnnotationsAttribute duplicateParameterAnnotationsAttribute(ConstPool cp, Method method) {
ParameterAnnotationsAttribute oldAns = new ParameterAnnotationsAttribute(cp, ParameterAnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation[][] anAr = new javassist.bytecode.annotation.Annotation[method.getParameterAnnotations().length][];
for (int i = 0; i < anAr.length; ++i) {
anAr[i] = new javassist.bytecode.annotation.Annotation[method.getParameterAnnotations()[i].length];
for (int j = 0; j < anAr[i].length; ++j) {
anAr[i][j] = createJavassistAnnotation(method.getParameterAnnotations()[i][j], cp);
}
}
oldAns.setAnnotations(anAr);
return oldAns;
}
示例5: copyParameters
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的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);
}
示例6: copyAnnotations
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的package包/类
public static void copyAnnotations(MethodInfo from, MethodInfo to) {
copyAttribute(from, to, AnnotationsAttribute.invisibleTag);
copyAttribute(from, to, AnnotationsAttribute.visibleTag);
copyAttribute(from, to, ParameterAnnotationsAttribute.invisibleTag);
copyAttribute(from, to, ParameterAnnotationsAttribute.visibleTag);
}
示例7: addAssistedAnnotation
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的package包/类
private void addAssistedAnnotation(ConstPool constPool, CtConstructor cc) {
ParameterAnnotationsAttribute attribute = new ParameterAnnotationsAttribute(constPool,
ParameterAnnotationsAttribute.visibleTag);
attribute.setAnnotations(new Annotation[][]{{createAnnotation(constPool, Assisted.class)}});
cc.getMethodInfo().addAttribute(attribute);
}
示例8: toParameterAnnotationsAttribute
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的package包/类
private static ParameterAnnotationsAttribute toParameterAnnotationsAttribute(CtBehavior ctBehavior) {
MethodInfo minfo = ctBehavior.getMethodInfo();
ParameterAnnotationsAttribute attr = (ParameterAnnotationsAttribute) minfo
.getAttribute(ParameterAnnotationsAttribute.visibleTag);
return attr;
}
示例9: grabMethodandParameterAnnotation
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的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);
}
}
}
示例10: getAnnotationsForMethodParameter
import javassist.bytecode.ParameterAnnotationsAttribute; //导入依赖的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()]);
}