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

View File

@ -1,6 +1,7 @@
package mindustry.annotations;
import arc.struct.*;
import arc.util.*;
import com.squareup.javapoet.*;
import com.sun.source.util.*;
import mindustry.annotations.util.*;
@ -86,10 +87,16 @@ public abstract class BaseProcessor extends AbstractProcessor{
public void err(String message){
messager.printMessage(Kind.ERROR, message);
Log.err("[CODEGEN ERROR] " +message);
}
public void err(String message, Element 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

View File

@ -137,7 +137,13 @@ public class EntityProcess extends BaseProcessor{
//only write the block if it's a void method with several entries
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){
if(elem.is(Modifier.ABSTRACT)) continue;
//get all statements in the method, copy them over
MethodTree methodTree = elem.tree();
BlockTree blockTree = methodTree.getBody();

View File

@ -14,6 +14,10 @@ public class Smethod extends Selement<ExecutableElement>{
super(executableElement);
}
public boolean is(Modifier mod){
return e.getModifiers().contains(mod);
}
public Array<TypeMirror> thrown(){
return Array.with(e.getThrownTypes()).as(TypeMirror.class);
}

View File

@ -30,8 +30,17 @@ public class EntityComps{
Entityc owner;
}
class TimedComp extends EntityComp implements Scaled{
float time, lifetime = 1f;
@Depends({TimedComp.class})
class BulletComp{
BulletType bullet;
void init(){
bullet.init();
}
}
abstract class TimedComp extends EntityComp implements Scaled{
float time, lifetime;
void update(){
time = Math.min(time + Time.delta(), lifetime);
@ -205,14 +214,6 @@ public class EntityComps{
}
}
class BulletComp{
BulletType bullet;
void init(){
bullet.init();
}
}
@BaseComponent
class EntityComp{
int id;