1

If I have a class

@GenerateInterface
public class _FooImpl {}

I want to generate an interface

public interface Foo {}

that basically contains all the methods of _FooImpl (i.e. getters and setters).

Also if I have inheritance, like

@GenerateInterface
public class _ParentImpl {}

@GenerateInterface
public class _ChildImpl extends _ParentImpl {}

this should result in interface inheritance as well

public interface Parent {}

public interface Child extends Parent {}

I have a rough idea how to do that. But what if _ParentImpl is part of a library? That library also has to contain Parent.

In the annotation processor, how do I handle this? I can't generate the Parent interface again because then I'd have the same interface twice. Can I somehow detect that it already exists but distinguish it from files that do also already exist but are not part of the library and can thus be overriden?

I actually only need this for one class/interface that is extended by anything else. Thus I could remove @GenerateInterface from _ParentImpl and hardcode the inheritance of the Parent interface. This would be my last resort though. Edit: Or instead of removing the interface altogether, I could set @Retention(RetentionPolicy.SOURCE), right?

9
  • An interface can't be extend a class. For inheritance among interfaces, you have to use implements. For ex: Interface_Child implements Interface_Parent Commented Aug 16, 2016 at 8:05
  • @DheerajRoy no that is not true. Interfaces can extend each other... Commented Aug 16, 2016 at 8:08
  • Yes Interface can extend each other, but interface cant extend a class Commented Aug 16, 2016 at 8:24
  • 1
    @DheerajRoy that's true. I do, however, not try to do that anywhere O.o Commented Aug 16, 2016 at 8:27
  • Your issue is not clear. Can you simplify what exactly you are trying to do? Commented Aug 16, 2016 at 9:47

1 Answer 1

1

Already compiled classes are not processed again.

I created a complete test set-up and explored the issue myself. Turns out, only files that actually have to be compiled are run through annotation processing. This means I can safely include _ParentImpl and Parent in the library. _ParentImpl can keep the annotation, it is then possible to use @Retention(RetentionPolicy.CLASS) in connection with @Inherited to apply the annotation to subclasses in a very convenient manner.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.