mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-04 07:17:19 +07:00
Utility method copying
This commit is contained in:
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package mindustry.entities.def;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.net.*;
|
||||
|
||||
public class EntityDefs{
|
||||
@ -24,7 +25,7 @@ public class EntityDefs{
|
||||
}
|
||||
|
||||
class Vel extends Pos{
|
||||
Vec2 vel = new Vec2();
|
||||
final Vec2 vel = new Vec2();
|
||||
|
||||
void update(){
|
||||
x += vel.x;
|
||||
@ -34,7 +35,7 @@ public class EntityDefs{
|
||||
}
|
||||
|
||||
class Status{
|
||||
Statuses statuses = new Statuses();
|
||||
final Statuses statuses = new Statuses();
|
||||
|
||||
void update(){
|
||||
statuses.update(null);
|
||||
@ -45,4 +46,15 @@ public class EntityDefs{
|
||||
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