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

adding method for existing with CodeModel

I am trying to add abstract methods to my interfaces with CodeModel. Is this possible? JCodeModel cm = new JCodeModel(); JClass ref = cm.ref(Sample.class); After having a reference to actual class, I do not know to how I should add a method?…
Cemo
  • 5,370
  • 10
  • 50
  • 82
2
votes
2 answers

CodeModel How do i get value at specific index with com.sun.codemodel

I'm using com.sun.codemodel for generating my classes. I need to dynamically get array value depending on index argument. So i have an invocation that suppose to return an array JcodeModel model = new JCodeModel(); JPackage jPackage =…
Natta
  • 715
  • 1
  • 7
  • 15
2
votes
1 answer

How to type cast using Sun/Oracle CodeModel library?

I'm trying to use the Java CodeModel library to generate some code. In my generated code I need to perform a type cast. I want something like this... foo.setBar( ((TypeCastToThis)someVariable).getBar() ); The only support I've found in the…
Tansir1
  • 1,789
  • 2
  • 15
  • 28
1
vote
2 answers

CodeModel - How to define annotations with an enum value?

It seems that the java code generator framework CodeModel is not capable of creating annotations which only contain an enum value without a name - unfortunately a very common pattern (which JPA uses, for example): …
MRalwasser
  • 15,605
  • 15
  • 101
  • 147
1
vote
1 answer

NoClassDefFoundError: org/junit/AfterClass during annotation processing

I am generating code with CodeModel during annotation processing with maven. That code is for JUnit testing: JMethod tearDownClass = testClass.method( JMod.PUBLIC | JMod.STATIC, Void.class,…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
1
vote
1 answer

ternary operator support for code model?

Is it possible to use the ternary operator in code generated by com.sun.codemodel? I wish to generate the following statement: this((A==null)?A.getSomething:null)
Nacha
  • 107
  • 1
  • 5
1
vote
1 answer

Using Enum constant in switch with CodeModel

I am using the code model API to generate java source files. I have an enum defined through codemodel API and I want to use that in a switch block. In a switch statement, the enum constants should be used as unqualified. I have trouble in accessing…
Saravanan M
  • 4,697
  • 5
  • 35
  • 37
1
vote
1 answer

How can I create a simple assignment statement in codemodel?

I want to create a simple statement using codemodel like :- String text = element.getText(); I don't want to assign it to any block for now, rather just return it because I would be needing the name of the variable to refer later. How can I create…
Simar Singh
  • 415
  • 1
  • 7
  • 14
1
vote
0 answers

Make a CodeModel object implement/inherit a parent, before Having it been saved as an actual class on disk

I need to add an implementaion of an interface to a populated JCodeModel object, before saving it to a .java file using codeModel.build("FilePath");. I'm using jsonschema2pojo library to create JCodeModel object. The code is this: JCodeModel…
DummyBeginner
  • 411
  • 10
  • 34
1
vote
2 answers

CodeModel help needed for right-hand singleton.getinstance() assignment

I've been able to generate 99% of what I need with the CodeModel API, but I am stumped here... Using the various "directXX" methods does not add import statements to the generated code, and I can work without the "directXXX" type of methods except…
antarti
  • 11
  • 1
  • 2
1
vote
1 answer

JAXB, XJC: Generating field to Class Outline

My question concerns writing JAXB plugins, in particular ClassOutline internals. In com.sun.tools.xjc.outline.ClassOutline there are fields: target ref implClass implRef Code: /** * This {@link ClassOutline} holds information about this {@link…
jsosnowski
  • 1,560
  • 3
  • 26
  • 56
1
vote
2 answers

Extend inner class using code model

How can I extend my generated class from an inner static class? For instance, I have class Foo { static class Bar { } } And I want my generated class to be extended from Bar JCodeModel codeModel = new JCodeModel() JClass aClass =…
forcelain
  • 1,576
  • 3
  • 13
  • 16
1
vote
1 answer

How to generate Optional> in JCodeModel?

I want to create JCodeModel for the below method: private static Optional> getTypeOfId(String fieldName) { switch (fieldName.toLowerCase()) { case "IDFORCLASSX": { return…
1
vote
1 answer

Sun Codemodel generic method invocation

I'm using Codemodel library for java-class generation. Is there a way to generate a generic method invocation which looks like this: clazz.get(value) There is certainly a way of just casting a return result to a correct type using the…
Dmitry Smorzhok
  • 635
  • 11
  • 21
1
vote
1 answer

Cannot create abstract class in codemodel?

My code: JCodeModel cm = new JCodeModel(); cm._class(JMod.ABSTRACT, "TestClass", ClassType.CLASS); cm.build(new File(".")); no matter what I write to mods or ClassType parameter, the outcome is always a public class. How can I create an abstract…
Utku
  • 2,025
  • 22
  • 42