2

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

bool.dev
  • 17,508
  • 5
  • 69
  • 93
Ramya
  • 1,067
  • 6
  • 16
  • 29
  • http://stackoverflow.com/questions/4851937/codemodel-help-needed-for-right-hand-singleton-getinstance-assignment contains an example for imports – friedeas Jan 03 '13 at 09:59

1 Answers1

2

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.

honeybee
  • 21
  • 2