Refractor -> ClassBase has now mod & name of the class + [base] Builder, using builder pattern to provide a easy way to create domain elements
This commit is contained in:
parent
1c44d143e9
commit
dd899da348
23 changed files with 608 additions and 65 deletions
|
@ -81,7 +81,7 @@ public class Annotation extends JavaElement{
|
|||
}
|
||||
|
||||
private Token name;
|
||||
private Map<Token, Value> values;
|
||||
private Map<Token, Value> values; //TODO works with key null ?
|
||||
|
||||
public Annotation(Token name){
|
||||
this.name = name;
|
||||
|
|
|
@ -9,15 +9,12 @@ import dev.peerat.parser.visitor.VisitorBag;
|
|||
|
||||
public class AnnotationClass extends ClassBase{
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
private Token extend; //TODO verify?
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public AnnotationClass(List<Annotation> annotations, Token name){
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
public AnnotationClass(List<Annotation> annotations, int mod, Token name){
|
||||
super(annotations, mod, name);
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -36,10 +33,6 @@ public class AnnotationClass extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Token getExtension(){
|
||||
return this.extend;
|
||||
}
|
||||
|
@ -53,7 +46,7 @@ public class AnnotationClass extends ClassBase{
|
|||
super.build(builder);
|
||||
|
||||
builder.append("@interface");
|
||||
builder.append(name);
|
||||
builder.append(getName());
|
||||
if(extend != null){
|
||||
builder.append(" extends ");
|
||||
builder.append(extend);
|
||||
|
|
|
@ -9,21 +9,18 @@ import dev.peerat.parser.visitor.VisitorBag;
|
|||
|
||||
public class Class extends ClassBase{
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
private Token implement;
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public Class(List<Annotation> annotations, Token name){
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
public Class(List<Annotation> annotations, int mod, Token name){
|
||||
super(annotations, mod, name);
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Class(List<Annotation> annotations, Token name, Token extend, Token implement){
|
||||
this(annotations, name);
|
||||
public Class(List<Annotation> annotations, int mod, Token name, Token extend, Token implement){
|
||||
this(annotations, mod, name);
|
||||
this.extend = extend;
|
||||
this.implement = implement;
|
||||
}
|
||||
|
@ -43,10 +40,6 @@ public class Class extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Token getExtension(){
|
||||
return this.extend;
|
||||
}
|
||||
|
@ -64,7 +57,7 @@ public class Class extends ClassBase{
|
|||
super.build(builder);
|
||||
|
||||
builder.append("class ");
|
||||
builder.append(name);
|
||||
builder.append(getName());
|
||||
if(extend != null){
|
||||
builder.append(" extends ");
|
||||
builder.append(extend);
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.peerat.parser.java;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.Annotation.Annotable;
|
||||
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
||||
import dev.peerat.parser.java.Function.FunctionContainer;
|
||||
|
@ -13,12 +14,24 @@ import dev.peerat.parser.visitor.VisitorBag;
|
|||
|
||||
public abstract class ClassBase extends Annotable implements AnnotableBuffer, ClassContainer, FunctionContainer, VariableContainer{
|
||||
|
||||
//Why not name and modifier here ?
|
||||
|
||||
private List<Annotation> annotationBuffer;
|
||||
|
||||
private int mod;
|
||||
private Token name;
|
||||
|
||||
public ClassBase(List<Annotation> annotations){
|
||||
public ClassBase(List<Annotation> annotations, int mod, Token name){
|
||||
super(annotations);
|
||||
this.mod = mod;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getModifier(){
|
||||
return this.mod;
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,20 +9,17 @@ import dev.peerat.parser.visitor.VisitorBag;
|
|||
|
||||
public class Enumeration extends ClassBase{
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public Enumeration(List<Annotation> annotations, Token name){
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
public Enumeration(List<Annotation> annotations, int mod, Token name){
|
||||
super(annotations, mod, name);
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Enumeration(List<Annotation> annotations, Token name, Token extend){
|
||||
this(annotations, name);
|
||||
public Enumeration(List<Annotation> annotations, int mod, Token name, Token extend){
|
||||
this(annotations, mod, name);
|
||||
this.extend = extend;
|
||||
}
|
||||
|
||||
|
@ -41,10 +38,6 @@ public class Enumeration extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Token getExtension(){
|
||||
return this.extend;
|
||||
}
|
||||
|
@ -58,7 +51,7 @@ public class Enumeration extends ClassBase{
|
|||
super.build(builder);
|
||||
|
||||
builder.append("enum");
|
||||
builder.append(name);
|
||||
builder.append(getName());
|
||||
if(extend != null){
|
||||
builder.append(" extends ");
|
||||
builder.append(extend);
|
||||
|
|
|
@ -9,20 +9,17 @@ import dev.peerat.parser.visitor.VisitorBag;
|
|||
|
||||
public class Interface extends ClassBase{
|
||||
|
||||
//where mod ????
|
||||
private Token name;
|
||||
private Token extend;
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public Interface(List<Annotation> annotations, Token name){
|
||||
super(annotations);
|
||||
this.name = name;
|
||||
public Interface(List<Annotation> annotations, int mod, Token name){
|
||||
super(annotations, mod, name);
|
||||
this.elements = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Interface(List<Annotation> annotations, Token name, Token extend){
|
||||
this(annotations, name);
|
||||
public Interface(List<Annotation> annotations, int mod, Token name, Token extend){
|
||||
this(annotations, mod, name);
|
||||
this.extend = extend;
|
||||
}
|
||||
|
||||
|
@ -41,10 +38,6 @@ public class Interface extends ClassBase{
|
|||
this.elements.add(clazz);
|
||||
}
|
||||
|
||||
public Token getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Token getExtension(){
|
||||
return this.extend;
|
||||
}
|
||||
|
@ -58,7 +51,7 @@ public class Interface extends ClassBase{
|
|||
super.build(builder);
|
||||
|
||||
builder.append("interface");
|
||||
builder.append(name);
|
||||
builder.append(getName());
|
||||
if(extend != null){
|
||||
builder.append(" extends ");
|
||||
builder.append(extend);
|
||||
|
|
|
@ -24,14 +24,12 @@ public class JavaFile extends JavaElement implements ClassContainer, AnnotableBu
|
|||
this.subClazz = new ArrayList<>();
|
||||
}
|
||||
|
||||
JavaFile setPackage(Bag bag){
|
||||
this.pack = bag.<Token>get();
|
||||
return this;
|
||||
public void setPackage(Token token){
|
||||
this.pack = token;
|
||||
}
|
||||
|
||||
JavaFile addImport(Import value){
|
||||
public void addImport(Import value){
|
||||
this.imports.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,18 @@ public class JavaParser extends Parser<JavaElement>{
|
|||
* Bind correctement tout (déplacer les noms & modifiers des classes dans ClassBase)
|
||||
*
|
||||
*
|
||||
*
|
||||
* Find a way to simplify the way of using the Tree, like Value..., without the need of casting, checking,... A Easy Way to Walk And Build.
|
||||
* Benchmark, check how to optimise. Like changing node order, capturing Token,...
|
||||
* Builder package -> look to only load what is needed ! (same for the whole program)
|
||||
*
|
||||
* Review choice of implementation, is ArrayList a good choice for all case needed ? (spoiler : no), is null a good idea for some cases ? review it.
|
||||
* Check thr whole tree, match with current Java Version
|
||||
* Complete SwitchOperation
|
||||
* Do Generic interface for case, like a generic interface for Class, for exemple, InstanceValue can contains class, annotation, method, variable,...
|
||||
* Remove Value.ValueContainer class
|
||||
* Do All build, find and visitor for all JavaElement
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -118,7 +130,7 @@ public class JavaParser extends Parser<JavaElement>{
|
|||
InitialStateTree<JavaElement> base = new InitialStateTree<>();
|
||||
main = base;
|
||||
|
||||
StateTree<JavaElement> pack = main.then((validator) -> {
|
||||
StateTree<JavaElement> pack = main.then((validator) -> {
|
||||
if(validator.validate(
|
||||
(token) -> token.getValue().equals("package"))){
|
||||
|
||||
|
@ -134,7 +146,7 @@ public class JavaParser extends Parser<JavaElement>{
|
|||
}
|
||||
return false;
|
||||
}).end((parent, bag) -> {
|
||||
((JavaFile)parent).setPackage(bag);
|
||||
((JavaFile)parent).setPackage(bag.get());
|
||||
return parent;
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.Annotation;
|
||||
import dev.peerat.parser.java.value.Value;
|
||||
|
||||
public class JavaAnnotationBuilder extends JavaBuilder<Annotation>{
|
||||
|
||||
private String name;
|
||||
private Map<String, Value> values;
|
||||
|
||||
public JavaAnnotationBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaAnnotationBuilder parameter(String key, Value value){
|
||||
if(this.values == null) this.values = new HashMap<>();
|
||||
this.values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaAnnotationBuilder uniqueParameter(Value value){
|
||||
return parameter(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Annotation build(){
|
||||
Map<Token, Value> map = null;
|
||||
if(values != null){
|
||||
map = new HashMap<>();
|
||||
for(Entry<String, Value> entry : values.entrySet()){
|
||||
map.put(entry.getKey() == null ? null : new Token(0,0,entry.getKey(), null), entry.getValue());
|
||||
}
|
||||
}
|
||||
return new Annotation(new Token(0,0,name, null), map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
81
src/dev/peerat/parser/java/builder/JavaBuilder.java
Normal file
81
src/dev/peerat/parser/java/builder/JavaBuilder.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
import dev.peerat.parser.java.Operation;
|
||||
import dev.peerat.parser.java.value.Value;
|
||||
|
||||
public abstract class JavaBuilder<T extends JavaElement>{
|
||||
|
||||
//TODO WHEN TAKE BUILDER, TAKE ALSO BUILDED TYPE
|
||||
|
||||
public static JavaFileBuilder ofFile(){
|
||||
return new JavaFileBuilder();
|
||||
}
|
||||
|
||||
public static JavaFileBuilder ofFile(String pack){
|
||||
return ofFile().setPackage(pack);
|
||||
}
|
||||
|
||||
public static JavaClassBuilder ofClass(){
|
||||
return new JavaClassBuilder();
|
||||
}
|
||||
|
||||
public static JavaClassBuilder ofClass(String name){
|
||||
return ofClass().setName(name);
|
||||
}
|
||||
|
||||
public static JavaAnnotationBuilder ofAnnotation(){
|
||||
return new JavaAnnotationBuilder();
|
||||
}
|
||||
|
||||
public static JavaAnnotationBuilder ofAnnotation(String name){
|
||||
return ofAnnotation().setName(name);
|
||||
}
|
||||
|
||||
public static JavaAnnotationBuilder ofAnnotation(String name, Value paramter){
|
||||
return ofAnnotation(name).uniqueParameter(paramter);
|
||||
}
|
||||
|
||||
public static JavaVariableBuilder ofVariable(){
|
||||
return new JavaVariableBuilder();
|
||||
}
|
||||
|
||||
public static JavaVariableBuilder ofVariable(String type, String name){
|
||||
return ofVariable().setType(type).setName(name);
|
||||
}
|
||||
|
||||
public static JavaVariableBuilder ofVariable(String type, String name, Value value){
|
||||
return ofVariable(type, name).setValue(value);
|
||||
}
|
||||
|
||||
public static JavaFunctionBuilder ofFunction(){
|
||||
return new JavaFunctionBuilder();
|
||||
}
|
||||
|
||||
public static JavaFunctionBuilder ofFunction(String type, String name){
|
||||
return ofFunction().setType(type).setName(name);
|
||||
}
|
||||
|
||||
public static JavaFunctionBuilder ofFunction(String generic, String type, String name){
|
||||
return ofFunction(type, name).setGeneric(generic);
|
||||
}
|
||||
|
||||
public static Operation ofOperation(String operation){
|
||||
try{
|
||||
return new JavaOperationBuilder(operation).build();
|
||||
}catch(Exception e){
|
||||
throw new IllegalArgumentException("Failed to parse Operation "+operation, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Value ofValue(String value){
|
||||
try{
|
||||
return new JavaValueBuilder(value).build();
|
||||
}catch(Exception e){
|
||||
throw new IllegalArgumentException("Failed to parse Value "+value, e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract T build();
|
||||
|
||||
}
|
55
src/dev/peerat/parser/java/builder/JavaClassBuilder.java
Normal file
55
src/dev/peerat/parser/java/builder/JavaClassBuilder.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.Annotation;
|
||||
import dev.peerat.parser.java.Class;
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
|
||||
public class JavaClassBuilder extends JavaModifiableBuilder<JavaClassBuilder, dev.peerat.parser.java.Class>{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
private String name;
|
||||
private String extend;
|
||||
private String implement;
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public JavaClassBuilder annotate(JavaAnnotationBuilder annotation){
|
||||
if(this.annotations == null) this.annotations = new ArrayList<>();
|
||||
this.annotations.add(annotation.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaClassBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaClassBuilder extend(String type){
|
||||
this.extend = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaClassBuilder implement(String type){
|
||||
if(implement == null) this.implement = type;
|
||||
else this.implement+=","+type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends JavaElement> JavaClassBuilder element(JavaBuilder<T> builder){
|
||||
if(this.elements == null) this.elements = new ArrayList<>();
|
||||
this.elements.add(builder.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class build(){
|
||||
dev.peerat.parser.java.Class result = new dev.peerat.parser.java.Class(this.annotations, this.mod, new Token(0,0,name, null), extend == null ? null : new Token(0,0,extend, null), implement == null ? null : new Token(0,0, implement, null));
|
||||
if(elements != null) result.getElements().addAll(elements);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
51
src/dev/peerat/parser/java/builder/JavaFileBuilder.java
Normal file
51
src/dev/peerat/parser/java/builder/JavaFileBuilder.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.ClassBase;
|
||||
import dev.peerat.parser.java.Import;
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
import dev.peerat.parser.java.JavaFile;
|
||||
|
||||
public class JavaFileBuilder extends JavaBuilder<JavaFile>{
|
||||
|
||||
private String pack;
|
||||
private List<Import> imports;
|
||||
private List<ClassBase> classes;
|
||||
|
||||
public JavaFileBuilder setPackage(String value){
|
||||
this.pack = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFileBuilder doImport(String value, boolean isStatic){
|
||||
if(this.imports == null) this.imports = new ArrayList<>();
|
||||
this.imports.add(new Import(isStatic, new Token(0,0, value, null)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends ClassBase> JavaFileBuilder clazz(JavaBuilder<T> builder){
|
||||
if(this.classes == null) this.classes = new ArrayList<>();
|
||||
this.classes.add(builder.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JavaFile build(){
|
||||
JavaFile result = new JavaFile();
|
||||
result.setPackage(new Token(0,0, this.pack, null));
|
||||
if(this.imports != null)
|
||||
for(Import imp : this.imports){
|
||||
result.addImport(imp);
|
||||
}
|
||||
if(this.classes != null)
|
||||
for(ClassBase clazz : this.classes){
|
||||
result.addClass(clazz);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
79
src/dev/peerat/parser/java/builder/JavaFunctionBuilder.java
Normal file
79
src/dev/peerat/parser/java/builder/JavaFunctionBuilder.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.Annotation;
|
||||
import dev.peerat.parser.java.Function;
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
import dev.peerat.parser.java.Variable;
|
||||
|
||||
public class JavaFunctionBuilder extends JavaModifiableBuilder<JavaFunctionBuilder, Function>{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
private String generic;
|
||||
private String type;
|
||||
private String name;
|
||||
private List<Variable> parameters;
|
||||
private List<Token> throwables;
|
||||
|
||||
private List<JavaElement> elements;
|
||||
|
||||
public JavaFunctionBuilder annotate(JavaAnnotationBuilder annotation){
|
||||
if(this.annotations == null) this.annotations = new ArrayList<>();
|
||||
this.annotations.add(annotation.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder setGeneric(String generic){
|
||||
this.generic = generic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder setType(String type){
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder parameter(JavaVariableBuilder builder){
|
||||
if(this.parameters == null) this.parameters = new ArrayList<>();
|
||||
this.parameters.add(builder.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder throwable(String throwable){
|
||||
if(this.throwables == null) this.throwables = new ArrayList<>();
|
||||
this.throwables.add(new Token(0,0,throwable, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaFunctionBuilder element(JavaElement element){
|
||||
if(this.elements == null) this.elements = new ArrayList<>();
|
||||
this.elements.add(element);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function build(){
|
||||
Function result = new Function(
|
||||
this.annotations,
|
||||
this.mod,
|
||||
new Token(0,0, this.generic, null),
|
||||
new Token(0,0, this.type, null),
|
||||
new Token(0,0, this.name, null),
|
||||
this.parameters,
|
||||
this.throwables
|
||||
);
|
||||
result.getElements().addAll(elements);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
|
||||
public abstract class JavaModifiableBuilder<T, E extends JavaElement> extends JavaBuilder<E>{
|
||||
|
||||
//TODO TO TEST
|
||||
protected int mod;
|
||||
|
||||
public T setPublic(){
|
||||
this.mod += 0x1;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setPrivate(){
|
||||
this.mod += 0x2;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setProtected(){
|
||||
this.mod += 0x4;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setStatic(){
|
||||
this.mod += 0x8;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setFinal(){
|
||||
this.mod += 0x10;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setSynchronized(){
|
||||
this.mod += 0x20;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setVolatile(){
|
||||
this.mod += 0x40;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setTransient(){
|
||||
this.mod += 0x80;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setNative(){
|
||||
this.mod += 0x100;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setAbstract(){
|
||||
this.mod += 0x400;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setStrict(){
|
||||
this.mod += 0x800;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T setPackageLevel(){
|
||||
// this.mod += 0x1;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
}
|
58
src/dev/peerat/parser/java/builder/JavaOperationBuilder.java
Normal file
58
src/dev/peerat/parser/java/builder/JavaOperationBuilder.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import dev.peerat.parser.Parser;
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
import dev.peerat.parser.java.JavaParser;
|
||||
import dev.peerat.parser.java.Operation;
|
||||
import dev.peerat.parser.java.Operation.OperationContainer;
|
||||
import dev.peerat.parser.java.tree.JavaTreeType;
|
||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||
import dev.peerat.parser.visitor.VisitorBag;
|
||||
|
||||
public class JavaOperationBuilder extends JavaBuilder<Operation>{
|
||||
|
||||
private static Parser<JavaElement> PARSER = new JavaParser(JavaTreeType.OPERATION);
|
||||
|
||||
private Operation operation;
|
||||
|
||||
public JavaOperationBuilder(String operation) throws Exception{
|
||||
PARSER.parse(operation, new Container());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation build(){
|
||||
return this.operation;
|
||||
}
|
||||
|
||||
class Container extends JavaElement implements OperationContainer{
|
||||
|
||||
@Override
|
||||
public void addOperation(Operation operation){
|
||||
JavaOperationBuilder.this.operation = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitorBag visit(JavaVisitor<?> visitor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
58
src/dev/peerat/parser/java/builder/JavaValueBuilder.java
Normal file
58
src/dev/peerat/parser/java/builder/JavaValueBuilder.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import dev.peerat.parser.Parser;
|
||||
import dev.peerat.parser.java.JavaElement;
|
||||
import dev.peerat.parser.java.JavaParser;
|
||||
import dev.peerat.parser.java.tree.JavaTreeType;
|
||||
import dev.peerat.parser.java.value.Value;
|
||||
import dev.peerat.parser.java.value.Value.ValueContainer;
|
||||
import dev.peerat.parser.java.visitor.JavaVisitor;
|
||||
import dev.peerat.parser.visitor.VisitorBag;
|
||||
|
||||
public class JavaValueBuilder extends JavaBuilder<Value>{
|
||||
|
||||
private static Parser<JavaElement> PARSER = new JavaParser(JavaTreeType.VALUE);
|
||||
|
||||
private Value value;
|
||||
|
||||
public JavaValueBuilder(String value) throws Exception{
|
||||
PARSER.parse(value, new Container());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value build(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
class Container extends JavaElement implements ValueContainer{
|
||||
|
||||
@Override
|
||||
public void addValue(Value value) {
|
||||
JavaValueBuilder.this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Builder builder) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitorBag visit(JavaVisitor<?> visitor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
45
src/dev/peerat/parser/java/builder/JavaVariableBuilder.java
Normal file
45
src/dev/peerat/parser/java/builder/JavaVariableBuilder.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package dev.peerat.parser.java.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import dev.peerat.parser.Token;
|
||||
import dev.peerat.parser.java.Annotation;
|
||||
import dev.peerat.parser.java.Variable;
|
||||
import dev.peerat.parser.java.value.Value;
|
||||
|
||||
public class JavaVariableBuilder extends JavaModifiableBuilder<JavaVariableBuilder, Variable>{
|
||||
|
||||
private List<Annotation> annotations;
|
||||
private String type;
|
||||
private String name;
|
||||
private boolean elipse;
|
||||
private Value value;
|
||||
|
||||
public JavaVariableBuilder annotate(JavaAnnotationBuilder annotation){
|
||||
if(this.annotations == null) this.annotations = new ArrayList<>();
|
||||
this.annotations.add(annotation.build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaVariableBuilder setType(String type){
|
||||
this.type = type;
|
||||
this.elipse = type.endsWith("...");
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaVariableBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavaVariableBuilder setValue(Value value){
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Variable build(){
|
||||
return new Variable(annotations, mod, new Token(0,0, type, null), new Token(0,0, name, null), elipse, value);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ public class AnnotationClassTree extends SyntaxTree<JavaElement> {
|
|||
def_anno_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
AnnotationClass current = new AnnotationClass((((AnnotableBuffer) parent).getAnnotationBuffer()),
|
||||
bag.get("modifier") == null ? 0 : bag.get("modifier"),
|
||||
bag.get("name"));
|
||||
if (parent instanceof ClassContainer)
|
||||
((ClassContainer) parent).addClass(current);
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ClassTree extends SyntaxTree<JavaElement> {
|
|||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("name", local.get())));
|
||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()), bag.get("name"));
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()), bag.get("modifier") == null ? 0 : bag.get("modifier"),bag.get("name"));
|
||||
if (parent instanceof ClassContainer)
|
||||
((ClassContainer) parent).addClass(current);
|
||||
return current;
|
||||
|
@ -52,7 +52,9 @@ public class ClassTree extends SyntaxTree<JavaElement> {
|
|||
.then(clazz_implement_name);
|
||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()), bag.get("name"),
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()),
|
||||
bag.get("modifier") == null ? 0 : bag.get("modifier"),
|
||||
bag.get("name"),
|
||||
bag.get("extend"), bag.get("implement"));
|
||||
if (parent instanceof ClassContainer)
|
||||
((ClassContainer) parent).addClass(current);
|
||||
|
@ -64,7 +66,9 @@ public class ClassTree extends SyntaxTree<JavaElement> {
|
|||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("extend", local.get())));
|
||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()), bag.get("name"),
|
||||
Class current = new Class((((AnnotableBuffer) parent).getAnnotationBuffer()),
|
||||
bag.get("modifier") == null ? 0 : bag.get("modifier"),
|
||||
bag.get("name"),
|
||||
bag.get("extend"), bag.get("implement"));
|
||||
if (parent instanceof ClassContainer)
|
||||
((ClassContainer) parent).addClass(current);
|
||||
|
|
|
@ -24,7 +24,7 @@ public class FunctionContainerTree extends SyntaxTree<JavaElement> {
|
|||
|
||||
function_container.then(variable);
|
||||
function_container.then(operation);
|
||||
function_container.then((v) -> { System.out.println("then its just a value ?"); return true;}).then(value);
|
||||
function_container.then(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ValueTree extends SyntaxTree<JavaElement> { //TODO order tree by mo
|
|||
global.<ValueChainBuilder>get().right(local.get());
|
||||
});
|
||||
|
||||
//TODO -> Array and dot after a new Instance...event with {}
|
||||
StateTree<JavaElement> value_instance = unary_value.equals("new");
|
||||
StateTree<JavaElement> value_instance_type = value_instance.redirect(type, (global, local) -> global.set("type", local.get()));
|
||||
StateTree<JavaElement> value_instance_params = value_instance_type.equals("(");
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ClassTests{
|
|||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("name", local.get())));
|
||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"));
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),bag.get("modifier") == null ? 0 : bag.get("modifier"), bag.get("name"));
|
||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||
return current;
|
||||
})
|
||||
|
@ -40,7 +40,7 @@ public class ClassTests{
|
|||
(bag, token) -> bag.set("implement", bag.<Token>get("implement").concat(token)))).then(clazz_implement_name);
|
||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),bag.get("modifier") == null ? 0 : bag.get("modifier"),bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||
return current;
|
||||
})
|
||||
|
@ -51,7 +51,7 @@ public class ClassTests{
|
|||
.then(new RedirectStateTree<>(TypeTests.get(), (global, local) -> global.set("extend", local.get())));
|
||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.<JavaElement>end((parent, bag) -> {
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()), bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||
Class current = new Class((((AnnotableBuffer)parent).getAnnotationBuffer()),bag.get("modifier") == null ? 0 : bag.get("modifier"), bag.get("name"), bag.get("extend"), bag.get("implements"));
|
||||
if(parent instanceof ClassContainer) ((ClassContainer)parent).addClass(current);
|
||||
return current;
|
||||
})
|
||||
|
|
|
@ -81,7 +81,7 @@ public class VariableTests{
|
|||
TokenValidator.TOKENS = 0;
|
||||
TokenValidator.MAX_VALIDATE = 0;
|
||||
|
||||
JavaElement result = new Class(null, new Token(0, 0, "Test", TokenType.NAME));
|
||||
JavaElement result = new Class(null, 0,new Token(0, 0, "Test", TokenType.NAME));
|
||||
|
||||
parser.parse(value, result);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue