All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlassian.code.transforms.add.annotation.FlakyAnnotationAdder Maven / Gradle / Ivy

package com.atlassian.code.transforms.add.annotation;

import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.reference.CtPackageReference;
import spoon.reflect.reference.CtTypeReference;

import java.lang.annotation.Annotation;

public class FlakyAnnotationAdder extends AbstractProcessor {

    private final String className;
    private final String methodName;

    public FlakyAnnotationAdder(String className, String methodName) {
        this.className = className;
        this.methodName = methodName;
    }

    @Override
    public void process(CtMethod ctMethod) {
        if (methodName.equals(ctMethod.getSimpleName())
                && ctMethod.getParent((CtClass c) -> className.equals(c.getQualifiedName())) != null) {


            CtPackageReference pkgRef = getFactory().Core().createPackageReference().setSimpleName("com.atlassian.test.rules");
            CtTypeReference flakyRef = getFactory().Core().createTypeReference();
            flakyRef.setSimpleName("Flaky");
            flakyRef.setPackage(pkgRef);

            CtAnnotation flaky = getFactory().Code().createAnnotation(flakyRef);
            ctMethod.addAnnotation(flaky);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy