Utility method copying
This commit is contained in:
@@ -48,7 +48,14 @@ public class EntityProcess extends BaseProcessor{
|
|||||||
//getter
|
//getter
|
||||||
inter.addMethod(MethodSpec.methodBuilder("get" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(field.tname()).build());
|
inter.addMethod(MethodSpec.methodBuilder("get" + cname).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).returns(field.tname()).build());
|
||||||
//setter
|
//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);
|
write(inter);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.annotations.util;
|
package mindustry.annotations.util;
|
||||||
|
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import com.squareup.javapoet.*;
|
||||||
import com.sun.source.tree.*;
|
import com.sun.source.tree.*;
|
||||||
import mindustry.annotations.*;
|
import mindustry.annotations.*;
|
||||||
|
|
||||||
@@ -21,6 +22,10 @@ public class Smethod extends Selement<ExecutableElement>{
|
|||||||
return e.getReturnType();
|
return e.getReturnType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeName retn(){
|
||||||
|
return TypeName.get(ret());
|
||||||
|
}
|
||||||
|
|
||||||
public MethodTree tree(){
|
public MethodTree tree(){
|
||||||
return BaseProcessor.trees.getTree(e);
|
return BaseProcessor.trees.getTree(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.annotations.util;
|
package mindustry.annotations.util;
|
||||||
|
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import mindustry.annotations.*;
|
||||||
|
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.type.*;
|
import javax.lang.model.type.*;
|
||||||
@@ -12,6 +13,20 @@ public class Stype extends Selement<TypeElement>{
|
|||||||
super(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){
|
public <A extends Annotation> A annotation(Class<A> annotation){
|
||||||
return e.getAnnotation(annotation);
|
return e.getAnnotation(annotation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mindustry.entities.def;
|
|||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
import mindustry.net.*;
|
import mindustry.net.*;
|
||||||
|
|
||||||
public class EntityDefs{
|
public class EntityDefs{
|
||||||
@@ -24,7 +25,7 @@ public class EntityDefs{
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Vel extends Pos{
|
class Vel extends Pos{
|
||||||
Vec2 vel = new Vec2();
|
final Vec2 vel = new Vec2();
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
x += vel.x;
|
x += vel.x;
|
||||||
@@ -34,7 +35,7 @@ public class EntityDefs{
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Status{
|
class Status{
|
||||||
Statuses statuses = new Statuses();
|
final Statuses statuses = new Statuses();
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
statuses.update(null);
|
statuses.update(null);
|
||||||
@@ -45,4 +46,15 @@ public class EntityDefs{
|
|||||||
NetConnection connection;
|
NetConnection connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static <T extends Connectionc & Velc & Healthc & Posc> void doSomethingWithAConnection(T value){
|
||||||
|
value.setX(0);
|
||||||
|
value.setY(0);
|
||||||
|
value.getVel().set(100, 100f);
|
||||||
|
value.setDead(true);
|
||||||
|
value.getConnection().kick("you are dead");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test(){
|
||||||
|
doSomethingWithAConnection(new PlayerGen());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user