/** * Internal-use only. * <code>CtClass.getRefClasses()</code> calls this method. */ public final void getRefClasses(Map classnames) { constPool.renameClass(classnames); AttributeInfo.getRefClasses(attributes, classnames); ArrayList list = methods; int n = list.size(); for (int i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo)list.get(i); String desc = minfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(minfo.getAttributes(), classnames); } list = fields; n = list.size(); for (int i = 0; i < n; ++i) { FieldInfo finfo = (FieldInfo)list.get(i); String desc = finfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(finfo.getAttributes(), classnames); } }
+ " " + minfo.getName() + "\t" + minfo.getDescriptor()); printAttributes(minfo.getAttributes(), out, 'm'); out.println();
String desc = minfo.getDescriptor(); minfo.setDescriptor(Descriptor.rename(desc, oldname, newname)); AttributeInfo.renameClass(minfo.getAttributes(), oldname, newname);
String desc = minfo.getDescriptor(); minfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(minfo.getAttributes(), classnames);
+ " " + minfo.getName() + "\t" + minfo.getDescriptor()); printAttributes(minfo.getAttributes(), out, 'm'); out.println();
/** * Internal-use only. * <code>CtClass.getRefClasses()</code> calls this method. */ public final void getRefClasses(Map<String,String> classnames) { constPool.renameClass(classnames); AttributeInfo.getRefClasses(attributes, classnames); for (MethodInfo minfo:methods) { String desc = minfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(minfo.getAttributes(), classnames); } for (FieldInfo finfo:fields) { String desc = finfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(finfo.getAttributes(), classnames); } }
String desc = minfo.getDescriptor(); minfo.setDescriptor(Descriptor.rename(desc, oldname, newname)); AttributeInfo.renameClass(minfo.getAttributes(), oldname, newname);
/** * Replaces all occurrences of several class names in the class file. * * @param classnames * specifies which class name is replaced with which new name. * Class names must be described with the JVM-internal * representation like <code>java/lang/Object</code>. * @see #renameClass(String,String) */ public final void renameClass(Map<String,String> classnames) { String jvmNewThisName = classnames.get(Descriptor .toJvmName(thisclassname)); if (jvmNewThisName != null) thisclassname = Descriptor.toJavaName(jvmNewThisName); constPool.renameClass(classnames); AttributeInfo.renameClass(attributes, classnames); for (MethodInfo minfo:methods) { String desc = minfo.getDescriptor(); minfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(minfo.getAttributes(), classnames); } for (FieldInfo finfo:fields) { String desc = finfo.getDescriptor(); finfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(finfo.getAttributes(), classnames); } }
for (Object attr : method.getMethodInfo().getAttributes()) { if (attr instanceof SignatureAttribute) { newMethod.getMethodInfo().addAttribute((SignatureAttribute) attr);
private boolean isJUnit5TestMethod(CtMethod ctMethod) { final List<?> attributes = ctMethod.getMethodInfo2().getAttributes(); return attributes.stream() .filter(clazz -> clazz instanceof AnnotationsAttribute) .map(attribute -> (AnnotationsAttribute) attribute) .map(AnnotationsAttribute::getAnnotations) .flatMap(Arrays::stream) .map(Annotation::getTypeName) .anyMatch(org.junit.jupiter.api.Test.class.getName()::equals); }
private List<AnnotationMetadata> annotationsFor( MethodInfo method ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : method.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return annotations; }
private List<AnnotationMetadata> annotationsFor( MethodInfo method ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : method.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return annotations; }
private List<AnnotationMetadata> annotationsFor( MethodInfo method ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : method.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return annotations; }
private boolean isJUnit4TestMethod(CtMethod ctMethod) { MethodInfo methodInfo = ctMethod.getMethodInfo2(); List<?> attributes = methodInfo.getAttributes(); for (Object attribute : attributes) { if (attribute instanceof AnnotationsAttribute) { AnnotationsAttribute annotations = (AnnotationsAttribute) attribute; for (Annotation each : annotations.getAnnotations()) { if (org.junit.Test.class.getName().equals(each.getTypeName())) { return true; } } } } return false; }
private boolean isTestNGTestMethod(CtMethod ctMethod) { MethodInfo methodInfo = ctMethod.getMethodInfo2(); List<?> attributes = methodInfo.getAttributes(); for (Object attribute : attributes) { if (attribute instanceof AnnotationsAttribute) { AnnotationsAttribute annotations = (AnnotationsAttribute) attribute; for (Annotation each : annotations.getAnnotations()) { if (org.testng.annotations.Test.class.getName().equals(each.getTypeName())) { return true; } } } } return false; }
private static SignatureAttribute copyConstructorGenericsSignature( final ConstPool constPool, final CtClass[] params, final CtClass source, final CtClass anchor) throws Exception { final CtConstructor ctConstructor = source.getConstructor(Descriptor.ofConstructor(params)); String signature = null; for (Object attr : ctConstructor.getMethodInfo().getAttributes()) { if (attr instanceof SignatureAttribute) { signature = ((SignatureAttribute) attr).getSignature(); break; } } if (signature != null && anchor != null) { // add anchor to generics signature final String type = "L" + (anchor.getName().replaceAll("\\.", "/")) + ";"; final int idx = signature.lastIndexOf(')'); signature = signature.substring(0, idx) + type + signature.substring(idx); } return signature == null ? null : new SignatureAttribute(constPool, signature); } }
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); } }
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); } }
@Override public boolean matches(CtBehavior ctBehavior) { List attributes = ctBehavior.getMethodInfo().getAttributes(); boolean hasAnnotation = hasAnnotation(attributes); if (!hasAnnotation) { CtClass declaringClass = ctBehavior.getDeclaringClass(); hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); if (!hasAnnotation) { try { declaringClass = declaringClass.getDeclaringClass(); if (declaringClass != null) { hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); } } catch (NotFoundException e) { LOGGER.log(Level.FINE, "Failed to load class '" + declaringClass.getName() + "': " + e.getLocalizedMessage(), e); } } } return hasAnnotation; }
@Override public boolean matches(CtBehavior ctBehavior) { List attributes = ctBehavior.getMethodInfo().getAttributes(); boolean hasAnnotation = hasAnnotation(attributes); if (!hasAnnotation) { CtClass declaringClass = ctBehavior.getDeclaringClass(); hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); if (!hasAnnotation) { try { declaringClass = declaringClass.getDeclaringClass(); if (declaringClass != null) { hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); } } catch (NotFoundException e) { LOGGER.log(Level.FINE, "Failed to load class '" + declaringClass.getName() + "': " + e.getLocalizedMessage(), e); } } } return hasAnnotation; }