Example #1
0
  @Override
  public void add(MethodInfo method) {
    MethodDeclaration methodDeclaration;

    if (method instanceof MethodDeclarationWrapper) {
      val wrapper = (MethodDeclarationWrapper) method;
      methodDeclaration = (MethodDeclaration) wrapper.declaration.clone();
      methodDeclaration.setAnnotations(Collections.emptyList());
      wrapper
          .getClassInfo()
          .changeTypeContext(wrapper.getContext(), getContext(), methodDeclaration);
    } else {
      methodDeclaration = new MethodDeclaration();
      new MethodDeclarationWrapper(methodDeclaration).setAll(method);
    }

    addMember(methodDeclaration);
  }
Example #2
0
  @Override
  public void add(FieldInfo field) {
    FieldDeclaration fieldDeclaration;

    if (field instanceof FieldDeclarationWrapper) {
      val wrapper = (FieldDeclarationWrapper) field;
      fieldDeclaration = (FieldDeclaration) wrapper.declaration.clone();
      fieldDeclaration.setAnnotations(Collections.emptyList());
      changeTypeContext(wrapper.getContext(), getContext(), fieldDeclaration);
    } else {
      fieldDeclaration = new FieldDeclaration();
      val vars = new ArrayList<VariableDeclarator>();
      vars.add(new VariableDeclarator(new VariableDeclaratorId("unknown")));
      fieldDeclaration.setVariables(vars);
      new FieldDeclarationWrapper(fieldDeclaration).setAll(field);
    }

    addMember(fieldDeclaration);

    val result = new FieldDeclarationWrapper(fieldDeclaration);
    if (!field.similar(result))
      throw new TransformationException(
          "After adding to class, didn't match. added: " + field + " result: " + result);
  }