Comments (2)
Q : Why not do a list of script with parameters , eg new BeanScript().withClass(myJCMClass).apply(jcm) ?
A : first, for the reason of ordering : the order in which those scripts would be applied would impact the result. Secondly, because calling the script again in another par of the code could lead to issues, therefore the JCM must be used to ensure there is only one instance of each available.
from jcodemodel.
Another use case : the generation of a cached value from a generator method.
typically, either the method takes no argument, therefore one item is cached. Or the method takes an argument, and a map stores the cached generated items .
By applying the processor on those two methods :
private int makeNext(int value) {
return (value + 1);
}
private int make100() {
return 100;
}
It results in the following code being added :
private HashMap<Integer, Integer> next = new HashMap<Integer, Integer>();
private int hundred = null;
public int getNext(int value) {
int ret = next.get(value);
if (ret == null) {
ret = makeNext(value);
next.put(value, ret);
}
return ret;
}
public int getHundred() {
if (hundred == null) {
hundred = make100();
}
return hundred;
}
Still needs to be synchronized if required, to add comments, and to clean the code.
from jcodemodel.
Related Issues (20)
- How can I get the Java Class value for a generated param? HOT 4
- weird issue with snakeyaml HOT 11
- add direct enum ref in JCodemodel HOT 6
- Migrate off of jsr305 HOT 4
- [proposal] check packages names HOT 19
- [proposal] check class name against keywords and java.lang HOT 10
- https://github.com/eclipse-ee4j/jaxb-ri HOT 3
- create resource directory HOT 45
- in-memory and jar/zip platform HOT 3
- Missing qualification for inner classes in generic parameters of anonymous classes HOT 4
- Add a method to remove annotations from JDefinedClass or JFieldVar HOT 11
- Enum constant arg with class HOT 3
- Generate *.class HOT 5
- Inner Class HOT 8
- [feature] copying JCodeModel HOT 34
- [lib] use lombok ? HOT 3
- [feature] chaining blocks and instructions HOT 1
- java 16 record ? HOT 12
- memoryCodeWriter modifications HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jcodemodel.