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
0
votes
1 answer

How can I generate/declare annotation field inside of Annotation?

I want to get something like this: public @interface Unfinished { String value(); String value() default "someVal"; } The problem is I cannot use JFieldVar because it looks like this: String value; //no parentheses String value = "someVal";…
aderesh
  • 927
  • 10
  • 22
0
votes
1 answer

Add a comment in the beginning of a class when using jsonschema2pojo or com.sun.codemodel

I'm trying to create POJOs using jsonSchema. I've found a project called jsonschema2pojo which seems suitable except for a couple of issues. I'm willing to fork the project and add some customizations (such as custom annotations and perhaps…
Slava
  • 160
  • 2
  • 11
0
votes
2 answers

Add JExpression (JOp.cond()) to JBlock (JMethod body)

I want to refactor an if - else statement into a Ternary Operator. if ((variable) == null) { ... do something } else { ... do something else } Creating a Ternary Operator with Codemodel is quite simple, as with JOp.cond() we can pass in…
coderwurst
  • 161
  • 3
  • 14
0
votes
1 answer

JExpression add String value as property in an if statement

I am working on a plugin to create toString statements in my project, using CodeModel. The resulting code should look like this: if (variable == null) { out.append(" " + "variable = null").append("\n"); } (out in the code above is a simple…
coderwurst
  • 161
  • 3
  • 14
0
votes
2 answers

How do I add a generic type parameter to a class which I extend with JCodeModel?

I am playing with JCodeModel and trying to generate a class; thanks to this link I was able to come up with this: public final class CodeModelTest { private CodeModelTest() { throw new Error("no instantiation is permitted"); } …
fge
  • 119,121
  • 33
  • 254
  • 329
0
votes
1 answer

Java sun CodeModel math operations

Does anybody know how to perform math operations in codeModel? I've been everywhere and can't figure it out. I have my generated class and I want e.g. add 2 variables(I've done it using Long.staticInvoke("sum"), but what I mean is…
kcdsh
  • 59
  • 2
  • 11
0
votes
1 answer

Sun CodeModel using Class with JInvocation.arg

I'm using sun's code model (2.4.1) classes to generate code. How do I pass a Class to JInvocation.arg? The code I am trying to generate is: JAXBContext jc; jc = JAXBContext.newInstance(NaturalLanguageUsage.class); The code I am running is: JClass…
EGHM
  • 2,144
  • 23
  • 37
0
votes
1 answer

How to assign method with multiple argument in Java CodeModel API

I want to generate a code like below example with Java CodeModel API package com.testcase.myPackage; package com.aaa.abc; package com.bbb.b; import org.testng.annotations.Test; public class TestCode { private int a; private int…
joy87
  • 25
  • 4
0
votes
1 answer

Add import using code model

I am trying to import a class in my code using code model. This is my code. JCodeModel model = new JCodeModel(); JClass mapper = model.directClass("com.another.Mapper"); JDefinedClass dc = model._class("com.example.Something"); JMethod method =…
Arun M R Nair
  • 653
  • 7
  • 30
0
votes
1 answer

How to narrow a anonymous class?

i want to generate some code like below: AbstractSomeClass someClassObj = new AbstractSomeClass { ... } I tried the following: JDefinedClass anonymousSomeClass =…
Cheng
  • 572
  • 8
  • 12
0
votes
1 answer

How can you wait until com.sun.codemodel.JCodeModel.build() has completed

I am using com.sun.codemodel.JCodeModel to generate almost 1000 classes with associated JUnits for each one. I also generate a JUnit Test Suite that executes the individual JUnit test cases. To complete this code generation project i want to execute…
Hector
  • 4,016
  • 21
  • 112
  • 211
0
votes
1 answer

make ForEach final with CodeModel

I am using com.sun.codemodel to generate some java entity objects i want to generate a for loop as follows:- for (final Field field : classFields) {} However i can only manage this for (Field field : classFields) {} is it possible to add final…
Hector
  • 4,016
  • 21
  • 112
  • 211
0
votes
1 answer

Save Jcodemodel Object after exit

I have a issue with JCodeModel (SUN). My program is running every day, and I want to add some function to classes which was created before the current running. JcodeModel support this? If not, there is any option to save the JCodemodel Object in…
Or Smith
  • 3,556
  • 13
  • 42
  • 69
0
votes
2 answers

Codemodel Java Library - Initializing 2D Array

Just trying to declare and initialize a 2D array using the codemodel library by Sun but I'm having some issues. I've tried: JBlock.decl(model.LONG.array().array(), "arrayName", JExpr.newArray(model.LONG, n)); which outputs: long[][] arrayName = new…
s990x
  • 1
  • 2
0
votes
1 answer

Code model / Quotation mark (") in arg parameter

I try to create the next expression in codemodel(Sun): driver.findElement(By.xpath("//div[text()=\""+whatToclick+"\"]/parent::span/parent::span")).click(); so whatToclick would be a parameter in my function. So I wrote the next: …
Or Smith
  • 3,556
  • 13
  • 42
  • 69