Jessie
Jessie

Reputation: 1105

generating import using Jcodemodel

I am trying to generate java code using Jcodemodel.

  1. How to generate required import statements using Jcodemodel?

  2. How to automatically generate the implementation of interface methods when a class implements the interface?

    eg:

    interface Act {
    
       void act();
    
    }
    

    using Jcodemodel, how to generate the interface method in implementation class? whether do I need to write method using JMethod? Is there any other way to auto generate the implementation methods?

  3. How to generate required imports for a class?

Kindly,guide me

Upvotes: 2

Views: 1957

Answers (1)

honeybee
honeybee

Reputation: 21

You should use the method

JClass importedClass= codeModel.ref("example.com.impl.MyClass");

And make sure example.com.impl.MyClass is in your classpath. In the generated java source, the import example.com.impl.MyClass statement will be automatically added for you.

Upvotes: 2

Related Questions