Questions tagged [sun-codemodel]

CodeModel is a Java library for code generators.

CodeModel provides a way to generate Java programs in a way much nicer than PrintStream.println().

This project is a spin-off from the Reference Implementation for its schema compiler to generate Java source files. http://codemodel.java.net/

81 questions
2
votes
1 answer

How to "generate source code" create and initialise of a hashMap inside a method using CodeModel

Source Code to generate class SomeClass{ public void someMethod(){ HashMap map = new HashMap(); } } Able to create as a global variable but i need to create it inside a method …
Monis Majeed
  • 1,358
  • 14
  • 21
2
votes
1 answer

How to call a method of another class using codemodel

I have a java class say Class A with some methods already present, I am generating a class using code model say classB and while generating using code model I am trying to call one the method of that classA. i tried below method .body() …
Monis Majeed
  • 1,358
  • 14
  • 21
2
votes
1 answer

Using com.sun.codemodel; how to write class as String instead of to a File

I am investigating com.sun.codemodel to generate Java classes. // https://mvnrepository.com/artifact/com.sun.codemodel/codemodel compile group: 'com.sun.codemodel', name: 'codemodel', version: '2.6' The JCodeModel class has multiple build methods…
Hector
  • 4,016
  • 21
  • 112
  • 211
2
votes
0 answers

Codemodel: how to implement method reference

I have a interface having getter methods like below public interface IAddress { AddressId getId(); String getCity(); String getCountry(); } I want to create another class where I want to reference the getter methods of IAddress like…
Sneha
  • 317
  • 4
  • 15
2
votes
1 answer

Create abstract method implementation using sun-codemodel?

I am trying to create the following using sun-codemodel. JavaRDD activityBatchDailyRDDs = activityBatchDailyFunction.cassandraTable("test", "tbl") .map(new Function() { public…
Arun M R Nair
  • 653
  • 7
  • 30
2
votes
1 answer

Cannot find exception classes in CodeModel in XJC plugin

I'm generating custom Java code from a WSDL provided by PeopleSoft. I've written several XJC plugins to try to clean up the generated code to be easier to use – adding interfaces and custom methods, etc. However, I'd like to add a common interface…
Akido
  • 176
  • 2
  • 5
2
votes
1 answer

how to define java codeModel generated class within another generatede class WITHOUT fully qualifuied name

I am using java codeModel to generate hibernate entity classes. Where tables have compound keys, i am generating an @Embeddable class that i then need to define a field for in my entity class. currently this compound key class is being defined as a…
Hector
  • 4,016
  • 21
  • 112
  • 211
2
votes
1 answer

How to generate type List?

Sun's CodeModel is able to generate List by using model.ref(List.class).narrow(model.ref(Number.class).wildcard()). However, I've searched the documentation and couldn't find a way to generate List. Any help would…
user1698814
  • 184
  • 3
  • 7
2
votes
1 answer

How to use CodeModel to invoke a method from a 2nd-level, abstract superclass?

I am using CodeModel 2.6. How would I generate this instruction, when the getType( ) method is inherited from an abstract superclass, two levels above the JDefinedClass? assertEquals(GeneraldocumenMetadata.TYPE,…
Mark
  • 139
  • 1
  • 9
2
votes
1 answer

Sun CodeModel - How to create enum with multiple parameters

I want to create an enum class similar to the following code snippet using Sun's codemodel public enum REPORT_COLUMNS { MONTH("month", true, false), DAY("day", false, true); private final String column; private final boolean…
Anand
  • 1,791
  • 5
  • 23
  • 41
2
votes
2 answers

How to get generic type "T" of class when reused in method

I am building a code generator for Fluent API. I want to create a new class for every existing (POJO)-class. I dont have the existing classes under my control. I parse the existing methods via reflection and if I encounter a setter or an "add"…
Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
2
votes
1 answer

Codemodel: generic types generation in a loop .narrow()?

I am using sun-codemodel to generate code. I have problem with generics. I know that to generate something like LinkedList, I need to use JType jtype = jCodeModel.ref("LinkedList").narrow(jCodeModel.ref("String")); However, how do I create…
kch
  • 57
  • 1
  • 8
2
votes
1 answer

How to generate an anonymous class using sun-codemodel?

I'm trying to generate the code below using codemodel, but I have no idea how to create the anonymous class syntax. I can't find it in the codemodel documentation…
Pedro Pinheiro
  • 1,059
  • 14
  • 32
2
votes
1 answer

Codemodel array

I use CodeModel to generate Java code. I expect output like this: public static final String[] COLUMNS = {ID, CODE, NAME}; I tried: definedClass.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL, String[].class, fieldName,…
2
votes
2 answers

CodeModel: manually insert import statement

How do I manually insert an import statement using CodeModel? I'd like to use Arrays.toString(...) in a direct statement. Context: I'm generating a toString() method in the generated code just like Eclipse does. The Arrays class is used to avoid…
AndrewBourgeois
  • 2,634
  • 7
  • 41
  • 58