Annotation -> Variable
This commit is contained in:
parent
cc6142562b
commit
af3481fd4d
4 changed files with 63 additions and 20 deletions
|
@ -26,11 +26,14 @@ public class Annotation extends JavaElement{
|
|||
return matcher.group(1).length();
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(ArrayBuffer<String> buffer, int tab) throws Exception {
|
||||
super.build(buffer, tab);
|
||||
buffer.append((s) -> s+="@"+type+(param == null ? "":param));
|
||||
buffer.add("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -120,7 +120,10 @@ public class Class extends JavaElement{
|
|||
|
||||
@Override
|
||||
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||
for(Annotation annotation : this.annotations) annotation.build(buffer, tab);
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(buffer, tab);
|
||||
buffer.add("");
|
||||
}
|
||||
|
||||
super.build(buffer, tab);
|
||||
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+this.name+"{");
|
||||
|
|
|
@ -29,6 +29,8 @@ public class Function extends OperationContainer{
|
|||
}
|
||||
|
||||
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
|
||||
local = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS", '(', ')'));
|
||||
content = local.unzipOne(local.clean(content), (s,p) -> s);
|
||||
Matcher matcher = PATTERN.matcher(content);
|
||||
matcher.matches();
|
||||
|
||||
|
@ -36,17 +38,16 @@ public class Function extends OperationContainer{
|
|||
parameters(matcher.group(3)+";", global, local);
|
||||
this.exceptions = matcher.group(4).trim();
|
||||
|
||||
local = new CleanerPool(
|
||||
new Cleaner("GENERIC_FUNCTION", '{', '}'),
|
||||
new Cleaner("GENERIC_PARENTHESIS", '(', ')'));
|
||||
local = local.group(new CleanerPool(new Cleaner("GENERIC_FUNCTION", '{', '}')));
|
||||
|
||||
|
||||
String zip = local.clean("{"+matcher.group(5));
|
||||
String body = local.unzipOne(zip, (s,p) -> s);
|
||||
String unzip = body.substring(1, body.indexOf('}'));
|
||||
|
||||
super.parse(local.clean(unzip), global, local);
|
||||
|
||||
|
||||
return matcher.group(1).length()+local.unzip(unzip, ((s,p) -> s)).length()+1;
|
||||
return local.unzip(matcher.group(1), (s,p) -> s).length()+local.unzip(unzip, ((s,p) -> s)).length()+1;
|
||||
}
|
||||
|
||||
private static Pattern UNZIP_STICK = Pattern.compile("\\s+(?<e>[<|(|\\[|\"|'])");
|
||||
|
@ -104,17 +105,28 @@ public class Function extends OperationContainer{
|
|||
|
||||
@Override
|
||||
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||
for(Annotation annotation : this.annotations) annotation.build(buffer, tab);
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(buffer, tab);
|
||||
buffer.add("");
|
||||
}
|
||||
|
||||
String param = "";
|
||||
for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+"";
|
||||
if(!param.isEmpty()) param = param.substring(1);
|
||||
|
||||
final String paramMod = param;
|
||||
boolean empty = getChilds().size() == 0;
|
||||
|
||||
super.build(buffer, tab);
|
||||
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+paramMod+") "+exceptions+"{"+((empty ? "}":"")));
|
||||
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"(");
|
||||
boolean first = true;
|
||||
for(Variable variable : this.parameters){
|
||||
for(Annotation annotation : variable.getAnnotations()){
|
||||
annotation.build(buffer, 0);
|
||||
buffer.append((s) -> s+=" ");
|
||||
}
|
||||
if(first) first = false;
|
||||
else{
|
||||
buffer.append((s) -> s+=",");
|
||||
}
|
||||
buffer.append((s) -> s+=variable.getType()+" "+variable.getName());
|
||||
}
|
||||
buffer.append((s) -> s+=") "+exceptions+"{"+((empty ? "}":"")));
|
||||
buffer.add("");
|
||||
|
||||
if(empty) return;
|
||||
|
|
|
@ -14,14 +14,19 @@ public class Variable extends JavaElement{
|
|||
|
||||
private static Pattern PATTERN = Pattern.compile("^(\\s*)(.*)$");
|
||||
|
||||
private List<Annotation> annotations;
|
||||
|
||||
private int modifier;
|
||||
private String name;
|
||||
private String type;
|
||||
private Variable value; //Change into operation or JavaElement
|
||||
|
||||
public Variable(){}
|
||||
public Variable(){
|
||||
this.annotations = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Variable(int modifier, String type){
|
||||
this();
|
||||
this.modifier = modifier;
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -57,7 +62,7 @@ public class Variable extends JavaElement{
|
|||
return offset+local.unzipOne(body, (s,p) -> (p.equals("^GENERIC_TYPE") || p.equals("^GENERIC_ARRAY")) ? s : null).length();
|
||||
}
|
||||
|
||||
private void assigment(String content, CleanerPool cleaner){
|
||||
private void assigment(String content, CleanerPool cleaner) throws Exception{
|
||||
Iterator<String> values = onlyDefine(content, cleaner);
|
||||
if(!values.hasNext()) return;
|
||||
values.next();
|
||||
|
@ -67,13 +72,26 @@ public class Variable extends JavaElement{
|
|||
this.value = new Value(spacesValue);
|
||||
}
|
||||
|
||||
private Iterator<String> onlyDefine(String content, CleanerPool cleaner){
|
||||
private Iterator<String> onlyDefine(String content, CleanerPool cleaner) throws Exception{
|
||||
content = generiqueTypes(content, cleaner);
|
||||
Iterator<String> values = new ArrayIterator<>(content.split("\\s+"));
|
||||
|
||||
CleanerPool tmp = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS",'(',')'));
|
||||
content = tmp.clean(content);
|
||||
|
||||
String[] array = content.split("\\s+");
|
||||
// for(int i = 0; i < array.length; i++) array[i] = tmp.unzip(array[i], (s,p) -> s);
|
||||
Iterator<String> values = new ArrayIterator<>(array);
|
||||
String value = null;
|
||||
int modifier;
|
||||
while(values.hasNext() && (modifier = JavaParser.getModifier(value = values.next())) > 0){
|
||||
this.modifier+=modifier;
|
||||
while(values.hasNext() && ((value = values.next()).charAt(0) == '@')){
|
||||
Annotation annotation = new Annotation();
|
||||
annotation.parse(value, cleaner, tmp);
|
||||
this.annotations.add(annotation);
|
||||
}
|
||||
if((modifier = JavaParser.getModifier(value)) > 0){
|
||||
do{
|
||||
this.modifier+=modifier;
|
||||
}while(values.hasNext() && (modifier = JavaParser.getModifier(value = values.next())) > 0);
|
||||
}
|
||||
if(this.type == null){
|
||||
this.type = value;
|
||||
|
@ -126,10 +144,17 @@ public class Variable extends JavaElement{
|
|||
return this.value;
|
||||
}
|
||||
|
||||
public List<Annotation> getAnnotations(){
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||
super.build(buffer, tab);
|
||||
for(Annotation annotation : this.annotations){
|
||||
annotation.build(buffer, 0);
|
||||
buffer.append((s) -> s+=" ");
|
||||
}
|
||||
buffer.append((s) -> s+=Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
|
||||
buffer.add("");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue