コード例 #1
0
  public static CtMethod cloneMethodTest(CtMethod method, String suffix, int timeOut) {
    CtMethod cloned_method = cloneMethod(method, suffix);
    CtAnnotation testAnnotation =
        cloned_method
            .getAnnotations()
            .stream()
            .filter(annotation -> annotation.toString().contains("Test"))
            .findFirst()
            .orElse(null);

    if (testAnnotation != null) {
      cloned_method.removeAnnotation(testAnnotation);
    }

    testAnnotation = method.getFactory().Core().createAnnotation();
    CtTypeReference<Object> ref = method.getFactory().Core().createTypeReference();
    ref.setSimpleName("Test");

    CtPackageReference refPackage = method.getFactory().Core().createPackageReference();
    refPackage.setSimpleName("org.junit");
    ref.setPackage(refPackage);
    testAnnotation.setAnnotationType(ref);

    Map<String, Object> elementValue = new HashMap<>();
    elementValue.put("timeout", timeOut);
    testAnnotation.setElementValues(elementValue);

    cloned_method.addAnnotation(testAnnotation);

    return cloned_method;
  }
コード例 #2
0
ファイル: PackageFactory.java プロジェクト: revaultch/spoon
 /**
  * Creates a reference to a package.
  *
  * @param name full name of the package to reference
  */
 public CtPackageReference createReference(String name) {
   CtPackageReference ref = factory.Core().createPackageReference();
   ref.setSimpleName(name);
   return ref;
 }