Skip to content

Commit 2845af8

Browse files
committed
Allow runnables/callables to be generated independently from methods
1 parent 8e10c08 commit 2845af8

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

JavaProjectGenerator/src/de/loskutov/jpg/Clazz.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ String generateMethods(String type) {
7575
"\t public void set" + suffix + "(Object element) {\n" +
7676
"\t \t this.element = ("+type+")element;\n" +
7777
"\t \t " + extend + ".getInstance" + suffix + "().set" + suffix + "(this.element);\n" +
78-
"\t }\n\n" +
79-
"\t public void run" + suffix + "() {\n" +
78+
"\t }\n\n";
79+
sb.append(result);
80+
}
81+
if(methodCounts > 0) {
82+
for (int i = 0; i < runnablesAndCallablesCounts; i++) {
83+
String suffix = i == 0? "" : "" + i;
84+
String result = "\t public void run" + suffix + "() {\n" +
8085
"\t \t try {\n" +
8186
"\t \t \t this.call" + suffix + "();\n" +
8287
"\t \t } catch (Exception e) {}\n" +
@@ -91,20 +96,25 @@ String generateMethods(String type) {
9196
"\t \t " + "r = " + extend + ".instance::run;\n" +
9297
"\t \t " + "r.run();\n" +
9398
"\t \t " + extend + ".getInstance" + suffix + "().run();\n" +
94-
"\t }\n\n" +
95-
"\t public "+type+" call" + suffix + "() throws Exception {\n" +
96-
"\t \t " + extend + ".getInstance" + suffix + "().call();\n" +
97-
"\t \t " + "java.util.concurrent.Callable<?> c = () -> {\n" +
98-
"\t \t " + " call" + suffix + "();\n" +
99-
"\t \t " + " set(this);\n" +
100-
"\t \t " + " return get();\n" +
101-
"\t \t " + "};\n" +
102-
"\t \t " + "c.call();\n" +
103-
"\t \t " + "c = " + extend + ".getInstance" + suffix + "()::call;\n" +
104-
"\t \t " + "c.call();\n" +
105-
"\t \t return ("+type+")" + extend + ".getInstance" + suffix + "().call" + suffix + "();\n" +
106-
"\t }\n";
107-
sb.append(result);
99+
"\t }\n\n";
100+
sb.append(result);
101+
}
102+
for (int i = 0; i < runnablesAndCallablesCounts; i++) {
103+
String suffix = i == 0? "" : "" + i;
104+
String result = "\t public "+type+" call" + suffix + "() throws Exception {\n" +
105+
"\t \t " + extend + ".getInstance" + suffix + "().call();\n" +
106+
"\t \t " + "java.util.concurrent.Callable<?> c = () -> {\n" +
107+
"\t \t " + " call" + suffix + "();\n" +
108+
"\t \t " + " set(this);\n" +
109+
"\t \t " + " return get();\n" +
110+
"\t \t " + "};\n" +
111+
"\t \t " + "c.call();\n" +
112+
"\t \t " + "c = " + extend + ".getInstance" + suffix + "()::call;\n" +
113+
"\t \t " + "c.call();\n" +
114+
"\t \t return ("+type+")" + extend + ".getInstance" + suffix + "().call" + suffix + "();\n" +
115+
"\t }\n\n";
116+
sb.append(result);
117+
}
108118
}
109119
return sb.toString();
110120
}

JavaProjectGenerator/src/de/loskutov/jpg/JavaElement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public abstract class JavaElement {
2020
static int commentsCount = 3;
2121
static int seeCount = 3;
2222
static int methodCounts = 1;
23+
static int runnablesAndCallablesCounts = 1;
2324
static boolean useExtend = true;
2425

2526
static final List<String> IMPORTS = Arrays.asList(

JavaProjectGenerator/src/de/loskutov/jpg/Main.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static void main(String[] args) throws IOException {
2727
int imports = 3;
2828
int comments = 3;
2929
int see = 3;
30-
int methods = 1;
30+
int methods = 1; // result method count will be (methods x 6 + runnablesAndCallables x 2)
31+
int runnablesAndCallables = 1;
3132
boolean extend = true;
3233

3334
if(args.length == 0) {
@@ -44,6 +45,7 @@ public static void main(String[] args) throws IOException {
4445
comments = Integer.parseUnsignedInt(args[argc++]);
4546
see = Integer.parseUnsignedInt(args[argc++]);
4647
methods = Integer.parseUnsignedInt(args[argc++]);
48+
runnablesAndCallables = Integer.parseUnsignedInt(args[argc++]);
4749
} catch(Exception e) {
4850
//
4951
}
@@ -61,6 +63,7 @@ public static void main(String[] args) throws IOException {
6163
JavaElement.commentsCount = comments;
6264
JavaElement.seeCount = see;
6365
JavaElement.methodCounts = methods;
66+
JavaElement.runnablesAndCallablesCounts = runnablesAndCallables;
6467
JavaElement.useExtend = extend;
6568

6669
new JavaBuilder(depth, roots, classes, root).build();

0 commit comments

Comments
 (0)