Abstract component method support

This commit is contained in:
Anuken
2020-02-02 17:21:35 -05:00
parent ae6d33cad1
commit ad84329688
4 changed files with 28 additions and 10 deletions
@@ -1,6 +1,7 @@
package mindustry.annotations; package mindustry.annotations;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import com.squareup.javapoet.*; import com.squareup.javapoet.*;
import com.sun.source.util.*; import com.sun.source.util.*;
import mindustry.annotations.util.*; import mindustry.annotations.util.*;
@@ -86,10 +87,16 @@ public abstract class BaseProcessor extends AbstractProcessor{
public void err(String message){ public void err(String message){
messager.printMessage(Kind.ERROR, message); messager.printMessage(Kind.ERROR, message);
Log.err("[CODEGEN ERROR] " +message);
} }
public void err(String message, Element elem){ public void err(String message, Element elem){
messager.printMessage(Kind.ERROR, message, elem); messager.printMessage(Kind.ERROR, message, elem);
Log.err("[CODEGEN ERROR] " + message + ": " + elem);
}
public void err(String message, Selement elem){
err(message, elem.e);
} }
@Override @Override
@@ -137,7 +137,13 @@ public class EntityProcess extends BaseProcessor{
//only write the block if it's a void method with several entries //only write the block if it's a void method with several entries
boolean writeBlock = first.ret().toString().equals("void") && entry.value.size > 1; boolean writeBlock = first.ret().toString().equals("void") && entry.value.size > 1;
if(entry.value.first().is(Modifier.ABSTRACT) && entry.value.size == 1){
err(entry.value.first().up().getSimpleName() + " declares an abstract method. This method must be implemented in another component", entry.value.first());
}
for(Smethod elem : entry.value){ for(Smethod elem : entry.value){
if(elem.is(Modifier.ABSTRACT)) continue;
//get all statements in the method, copy them over //get all statements in the method, copy them over
MethodTree methodTree = elem.tree(); MethodTree methodTree = elem.tree();
BlockTree blockTree = methodTree.getBody(); BlockTree blockTree = methodTree.getBody();
@@ -14,6 +14,10 @@ public class Smethod extends Selement<ExecutableElement>{
super(executableElement); super(executableElement);
} }
public boolean is(Modifier mod){
return e.getModifiers().contains(mod);
}
public Array<TypeMirror> thrown(){ public Array<TypeMirror> thrown(){
return Array.with(e.getThrownTypes()).as(TypeMirror.class); return Array.with(e.getThrownTypes()).as(TypeMirror.class);
} }
@@ -30,8 +30,17 @@ public class EntityComps{
Entityc owner; Entityc owner;
} }
class TimedComp extends EntityComp implements Scaled{ @Depends({TimedComp.class})
float time, lifetime = 1f; class BulletComp{
BulletType bullet;
void init(){
bullet.init();
}
}
abstract class TimedComp extends EntityComp implements Scaled{
float time, lifetime;
void update(){ void update(){
time = Math.min(time + Time.delta(), lifetime); time = Math.min(time + Time.delta(), lifetime);
@@ -205,14 +214,6 @@ public class EntityComps{
} }
} }
class BulletComp{
BulletType bullet;
void init(){
bullet.init();
}
}
@BaseComponent @BaseComponent
class EntityComp{ class EntityComp{
int id; int id;