So the idea is to support #Macro in java. Not only in the final result but also during compile time. So all the injections and code completion will work properly.
To add the macro functionality to java we can use CPP.
src/Test.java
:
#define READINT (new java.util.Scanner(System.in).nextInt())
class Test {
public static void main(String[] args) {
int i = READINT;
}
}
cpp
command:
$ cpp -P src/Test.java preprocessed/Test.java
Result:
class Test {
public static void main(String[] args) {
int i = (new java.util.Scanner(System.in).nextInt());
}
}
Compile:
$ javac preprocessed/Test.java
Tnx to aioobe for the original idea.
How ever this will only allows us to compile macros, we need a way to use it in code time, so if I do some thing like this:
#define PASTE2(a, b) a##b
#define PASTE(a, b) PASTE2(a, b)
#define setParameter(type,name) private type name;public type PAST(get,name)(){return name;}
Usage:
setParameter(int, value)
Will produce:
int value;public int getvalue(){return value;}
I want the compile to autocomplete this method. So it will know the class contains a getter getvalue() from type int
Also there are java annotations that can work in compile time, but I am not sure that it's possible with them.