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
9
votes
5 answers

A better way of code generator in Java?

I have a class with a graph inside. I iterate the graph and create a string that builds the graph, and then I just write that string into a Java file. Is there a better way of doing this, i read about JDT and CodeModel but I really am needing some…
sm13294
  • 563
  • 7
  • 23
8
votes
1 answer

Sun CodeModel generic method

Does anyone know how to generate the following generic method declaration using CodeModel? public T getValue(Class clazz){...} usage: ValueType value = getValue(ValueType.class); Seems not to be handled by the existing implementation. I…
John Ericksen
  • 10,995
  • 4
  • 45
  • 75
8
votes
2 answers

What is the role of ClassOutline / JClass / CClass in CodeModel?

My question concerns writing JAXB plugins, in particular JAXB codemodel. What is the role of ClassOutline (and it's companions) and JClass (and companions) and CClass (and companions)? When looking at the list of classes in corresponding packages it…
dma_k
  • 10,431
  • 16
  • 76
  • 128
4
votes
1 answer

Extends AbstractEntity with codemodel

Does anyone know how to generate this with CodeModel ?? ... public class MyClass extends AbstractEntity { ... I already have something like this.. almost there.. JCodeModel jCodeModel = new JCodeModel(); ... JDefinedClass jClass =…
3
votes
0 answers

Does CodeModel support importing classes from unspecified packages?

I want to generate a file containing a reference to a class without knowing which package it actually comes from. E.g. the user supplies import foo.* import blah.* Button("press me") and I need to generate import foo.*; import blah.*; public…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
3
votes
1 answer

Using generics with com.sun.codemodel

Using com.sun.codemodel, I would like to generate a generic LinkedList field. I can create a raw field using this code: JDefinedClass masterClass; String detailName; JDefinedClass detailClass; JFieldVar detailField = masterClass.field(JMod.PRIVATE,…
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
3
votes
1 answer

How to remove an annotation on a JDefinedClass

I am writing an custom annotator in jsonschema2pojo in order to tweak how this code generator annotates generated class with Jackson annotations. To simplify the usecase, I have a JClass at hand that is already annotation with JsonInclude(…
Samuel Kerrien
  • 6,965
  • 2
  • 29
  • 32
3
votes
1 answer

codemodel narrow for generics

I would like to generate a new class as follows: public class QueryBuilder_QueryField extends AbstractQueryBuilder and i tried this but it doesn't narrow the extends... JCodeModel model = new JCodeModel(); String fqcn =…
Adam Morgan
  • 425
  • 1
  • 3
  • 17
3
votes
1 answer

Java: Generate Annotation with default value using Codemodel

I use the Sun CodeModel code generator for my project. During this I came to the point to generate an annotation class. This class would have an array member which takes an empty array as default values. See the following example: public class…
smeyersdev
  • 103
  • 7
3
votes
2 answers

JCodeModel - How to chain invoke methods

I am trying to figure out how to use a loop to build a JExpression that I can use in an .assign() call. I know that you can do something like JExpr.invoke("methodA").invoke("methodB") with JCodeModel, but I want to be able to add each .invoke()…
kriegh13
  • 33
  • 5
3
votes
1 answer

How to generate loops and conditionals using the codemodel library

I've been trying to learn how to use Suns codemodel library and I'm absolutely stumped with generating for loops and if-else blocks. I'm struggling with how to generate the conditions for the if-else blocks and the for loops, but also on how to…
3
votes
5 answers

Java Codemodel - Annotate a method or class

I am using CodeModel to programmatically generate .java files. This is a snippet of code to create a method: JCodeModel jCodeModel = new JCodeModel(); JDefinedClass definedClass = jCodeModel._class("Foo"); //To generate method JMethod method =…
Pradeep Simha
  • 17,683
  • 18
  • 56
  • 107
3
votes
2 answers

Java source code generation: Eclipse JDT AST vs CodeModel

I am writing an eclipse plugin which lets the user write java code using a drag and drop kind of UI. I have came across these two java source code generation libraries. Eclipse JDT AST and Code Model. I would like to understand the pros and cons of…
3
votes
3 answers

Create JCodeModel from existing source file(s)

I want to create Java source code with code snippets that are possibly syntactically invalid. That's possible with com.sun.codemodel.JBlock#directStatement() method. My problem is, that I want to modify existing (syntactically valid) source files…
Morrandir
  • 595
  • 1
  • 4
  • 19
3
votes
1 answer

How to create with JCodeModel?

I've used JClass.narrow on JCodeModel to create the necessary generics for types, but I can't figure out how to generate something like this. private Class dataType; How does one generate the ? extends part? Any help would…
James
  • 121
  • 5
1
2 3 4 5 6