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
1
vote
2 answers

Create a method which returns the class that i want to generate in Codemodel

I need to generate a class which must have a method that returns an object of the same class. I want to generate something like this public class A{ public A method1(){ ... } } The problem is that I have to pass the Class object of…
theAsker
  • 527
  • 3
  • 14
1
vote
1 answer

How do I force-enclose a CodeModel expression in brackets?

I want to generate some very common code using Sun's CodeModel while ((sbt = reader.readLine()) != null) { } However when I write: JWhileLoop whileJsonBuilder = block._while(JExpr …
druk
  • 553
  • 6
  • 16
1
vote
2 answers

How to assign a value to a specific index of an array with Java codeModel

How do you employ com.sun.codemodel to generate this java statement? constructorArgs[constructorArgIndex] = null; I tried using com.sun.codemodel.JArrayCompRef via component() however i get com.sun.codemodel.JArrayCompRef is not visible when trying…
Hector
  • 4,016
  • 21
  • 112
  • 211
1
vote
1 answer

Codemodel does not generate static import

JCodeModel generates an import statement in place of an import static. For example I have a class that has import nz.co.cloudm.cloudserv.api.pojos.core.file.attachment.Attachment.Status instead of import static…
Juampa
  • 2,035
  • 2
  • 25
  • 35
1
vote
2 answers

CodeModel / Jinvocation with JMethod.body()

I have the next JInvocation: JInvocation jInvoke = JExpr.invoke(anotherPageInstance, method); where anotherPageInstance is JVar and method is JMethod. I do some actions on this JInvocation, and then I want to add it to test.body().invoke where test…
Or Smith
  • 3,556
  • 13
  • 42
  • 69
1
vote
1 answer

override annotation with CodeModel Java API

How i can add @Override annotation to my method using codeModel? JMethod update = classe.method(JMod.PUBLIC, void.class,"update"); update.annotate(?); i didn't find the @Override Class.
user2602584
  • 737
  • 2
  • 7
  • 25
1
vote
1 answer

Codemodel: how to check if I need to generate a generic type?

I am browsing through methods in the class and then generate methods in another place with a different name - the parameters and return types are the same, I check them by method.getParameters(), method.isGeneric() etc. So with a definition in…
kch
  • 57
  • 1
  • 8
1
vote
1 answer

Custom formatter for Sun Codemodel

I'm using Java Sun Codemodel to generate java classes on the fly, and it works pretty well for me. Now I have an additional challenge: How do I control how the code is formatted? Is there any way at all? In particular, I'd like to have all curly…
mac
  • 2,672
  • 4
  • 31
  • 43
1
vote
1 answer

CodeModel How do i add @Pattern.List annotations com.sun.codemodel

I'm using com.sun.codemodel for generating my classes and adding JSR303 annotations. This is working fine, except when I want to add @Pattern.List annotations. field.annotate(Pattern.class).param("regexp", "some_expression"); This is currently what…
user2270781
  • 11
  • 1
  • 2
1
vote
1 answer

JCodeModel and elseif

I'm generating Java source code with JCodeModel and want to get an "if-elseif" block like this: if (foo){ } else if (bar) { } As far as I understand the according code would be something like this (where m is a JMethod): JConditional cond =…
Morrandir
  • 595
  • 1
  • 4
  • 19
0
votes
1 answer

How to obtain the Assert JClass in CodeModel?

The org.junit package defines the Assert class for JUnit testing. How can I retrieve this static class as a JClass in the CodeModel framework?
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
0
votes
1 answer

How can I pass enum values as an argument to an invoke in codemodel?

I am trying to create a JInvocation like :- driver.manage().timeouts().implicitlyWait(10L, (TimeUnit.SECONDS)); This is the block of code that I use to generate the same :- public static JInvocation implicitWait(JVar driverJVar, Long…
Simar Singh
  • 415
  • 1
  • 7
  • 14
0
votes
1 answer

How to initialise a 2D array using CodeModel

I need to initialise a 2d array like below Object[][] someName = { {"param1","param2","param3"}, {"param4","param5","param6"} }; I tried like …
Monis Majeed
  • 1,358
  • 14
  • 21
0
votes
2 answers

How to use any field of parent class using codemodel

I have a class Parent and a class Derived like class Parent { SomeClass obj = new SomeClass(); } Now below class i want to generate using CodeModel class Derived extends Parent { String s = obj.invoke(); } I tried below but not…
Monis Majeed
  • 1,358
  • 14
  • 21
0
votes
1 answer

Exception message in JCodemodel

I am using JCodemodel to generate java classes dynamically. Below is the code for creating a switch statement whose the default case would be to throw an Exception. JSwitch valueswitch; AbstractJClass exception =…
Sneha
  • 317
  • 4
  • 15