Utility method copying

This commit is contained in:
Anuken
2020-02-02 00:39:29 -05:00
parent da2aee7d31
commit 7ddfcbfabd
4 changed files with 42 additions and 3 deletions

View File

@@ -48,7 +48,14 @@ public class EntityProcess extends BaseProcessor{
//getter
inter.addMethod(MethodSpec.methodBuilder("get" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(field.tname()).build());
//setter
inter.addMethod(MethodSpec.methodBuilder("set" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).addParameter(field.tname(), field.name()).build());
if(!field.is(Modifier.FINAL)) inter.addMethod(MethodSpec.methodBuilder("set" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).addParameter(field.tname(), field.name()).build());
}
//add utility methods to interface
for(Smethod method : component.methods()){
inter.addMethod(MethodSpec.methodBuilder(method.name()).returns(method.ret().toString().equals("void") ? TypeName.VOID : method.retn())
.addParameters(method.params().map(v -> ParameterSpec.builder(v.tname(), v.name())
.build())).addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT).build());
}
write(inter);

View File

@@ -1,6 +1,7 @@
package mindustry.annotations.util;
import arc.struct.*;
import com.squareup.javapoet.*;
import com.sun.source.tree.*;
import mindustry.annotations.*;
@@ -21,6 +22,10 @@ public class Smethod extends Selement<ExecutableElement>{
return e.getReturnType();
}
public TypeName retn(){
return TypeName.get(ret());
}
public MethodTree tree(){
return BaseProcessor.trees.getTree(e);
}

View File

@@ -1,6 +1,7 @@
package mindustry.annotations.util;
import arc.struct.*;
import mindustry.annotations.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
@@ -12,6 +13,20 @@ public class Stype extends Selement<TypeElement>{
super(typeElement);
}
public Array<Stype> superclasses(){
Array<Stype> out = new Array<>();
Stype sup = superclass();
while(!sup.superclass().name().equals("java.lang.Object")){
out.add(sup);
sup = superclass();
}
return out;
}
public Stype superclass(){
return new Stype((TypeElement)BaseProcessor.typeu.asElement(BaseProcessor.typeu.directSupertypes(mirror()).get(0)));
}
public <A extends Annotation> A annotation(Class<A> annotation){
return e.getAnnotation(annotation);
}