javassist.bytecode.ParameterAnnotationsAttribute Java Examples
The following examples show how to use
javassist.bytecode.ParameterAnnotationsAttribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavassistAdapter.java From panda with Apache License 2.0 | 6 votes |
@Override public List<String> getParameterAnnotationNames(MethodInfo method, int parameterIndex) { List<String> result = new ArrayList<>(); List<ParameterAnnotationsAttribute> parameterAnnotationsAttributes = Arrays.asList((ParameterAnnotationsAttribute) method.getAttribute(ParameterAnnotationsAttribute.visibleTag), (ParameterAnnotationsAttribute) method.getAttribute(ParameterAnnotationsAttribute.invisibleTag)); for (ParameterAnnotationsAttribute parameterAnnotationsAttribute : parameterAnnotationsAttributes) { if (parameterAnnotationsAttribute == null) { continue; } Annotation[][] annotations = parameterAnnotationsAttribute.getAnnotations(); if (parameterIndex < annotations.length) { Annotation[] annotation = annotations[parameterIndex]; result.addAll(getAnnotationNames(annotation)); } } return result; }
Example #2
Source File: JavaAssistClass.java From smart-testing with Apache License 2.0 | 5 votes |
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); } }
Example #3
Source File: JavaAssistClass.java From smart-testing with Apache License 2.0 | 5 votes |
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()); } } } }
Example #4
Source File: MapperAnnotationEnhancer.java From tsharding with MIT License | 5 votes |
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; }
Example #5
Source File: AbstractRestfulBinder.java From statefulj with Apache License 2.0 | 5 votes |
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); }
Example #6
Source File: Javassists.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
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); }
Example #7
Source File: DefaultRepositoryGenerator.java From business with Mozilla Public License 2.0 | 4 votes |
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); }
Example #8
Source File: AbstractRestfulBinder.java From statefulj with Apache License 2.0 | 4 votes |
protected void addRequestParameters( boolean referencesId, Class<?> idType, boolean isDomainEntity, CtMethod ctMethod, Method method, ClassPool cp) throws NotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, CannotCompileException { int fixedParmCnt = (isDomainEntity) ? 1 : 2; String[] parmNames = (method != null) ? parmDiscover.getParameterNames(method) : null; MethodInfo methodInfo = ctMethod.getMethodInfo(); ParameterAnnotationsAttribute paramAtrributeInfo = new ParameterAnnotationsAttribute( methodInfo.getConstPool(), ParameterAnnotationsAttribute.visibleTag); Annotation[][] paramArrays = null; if (method != null) { int parmIndex = 0; // Does this event reference the stateful object? // int additionalParmCnt = (referencesId) ? 2 : 1; int annotationCnt = method.getParameterTypes().length + additionalParmCnt - fixedParmCnt; annotationCnt = Math.max(annotationCnt, additionalParmCnt); // Pull the Parameter Annotations from the StatefulController - we're going to skip // over the first one (DomainEntity) or two (Controller) - but then we're going to // add a parameter for the HttpServletRequest and "id" parameter // java.lang.annotation.Annotation[][] parmAnnotations = method.getParameterAnnotations(); paramArrays = new Annotation[annotationCnt][]; // Add an Id parameter at the beginning of the method - this will be // used by the Harness to fetch the object // if (referencesId) { paramArrays[parmIndex] = addIdParameter(ctMethod, idType, cp); parmIndex++; } // Add an HttpServletRequest - this will be passed in as a context to the finder/factory methods // paramArrays[parmIndex] = addHttpRequestParameter(ctMethod, cp); parmIndex++; int parmCnt = 0; for(Class<?> parm : method.getParameterTypes()) { // Skip first two parameters - they are the Stateful Object and event String. // if (parmCnt < fixedParmCnt) { parmCnt++; continue; } // 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 > parmCnt) ? parmNames[parmCnt] : null; paramArrays[parmIndex] = createParameterAnnotations( parmName, ctMethod.getMethodInfo(), parmAnnotations[parmCnt], paramAtrributeInfo.getConstPool()); parmCnt++; parmIndex++; } } else { // NOOP transitions always a require an object Id // paramArrays = new Annotation[2][]; paramArrays[0] = addIdParameter(ctMethod, idType, cp); paramArrays[1] = addHttpRequestParameter(ctMethod, cp); } paramAtrributeInfo.setAnnotations(paramArrays); methodInfo.addAttribute(paramAtrributeInfo); }
Example #9
Source File: JavassistAnnotationsHelper.java From jadira with Apache License 2.0 | 3 votes |
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()]); }