mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 01:37:36 +07:00
Cleanup
This commit is contained in:
@ -87,6 +87,14 @@ public class Annotations{
|
|||||||
//endregion
|
//endregion
|
||||||
//region misc. utility
|
//region misc. utility
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
public @interface Multiline {
|
||||||
|
boolean trim() default true;
|
||||||
|
boolean merge() default false;
|
||||||
|
char mergeChar() default ' ';
|
||||||
|
}
|
||||||
|
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface StyleDefaults{
|
public @interface StyleDefaults{
|
||||||
|
@ -3,9 +3,14 @@ package mindustry.annotations;
|
|||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.struct.Array;
|
import arc.struct.Array;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.Log;
|
||||||
import arc.util.Log.*;
|
import arc.util.Log.*;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import com.sun.source.util.*;
|
import com.sun.source.util.*;
|
||||||
|
import com.sun.tools.javac.model.*;
|
||||||
|
import com.sun.tools.javac.processing.*;
|
||||||
|
import com.sun.tools.javac.tree.*;
|
||||||
|
import com.sun.tools.javac.util.*;
|
||||||
import mindustry.annotations.util.*;
|
import mindustry.annotations.util.*;
|
||||||
|
|
||||||
import javax.annotation.processing.*;
|
import javax.annotation.processing.*;
|
||||||
@ -19,6 +24,7 @@ import java.io.*;
|
|||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||||
public abstract class BaseProcessor extends AbstractProcessor{
|
public abstract class BaseProcessor extends AbstractProcessor{
|
||||||
@ -36,6 +42,10 @@ public abstract class BaseProcessor extends AbstractProcessor{
|
|||||||
protected RoundEnvironment env;
|
protected RoundEnvironment env;
|
||||||
protected Fi rootDirectory;
|
protected Fi rootDirectory;
|
||||||
|
|
||||||
|
protected Context context;
|
||||||
|
protected JavacElements elementUtils;
|
||||||
|
protected TreeMaker maker;
|
||||||
|
|
||||||
public static String getMethodName(Element element){
|
public static String getMethodName(Element element){
|
||||||
return ((TypeElement)element.getEnclosingElement()).getQualifiedName().toString() + "." + element.getSimpleName();
|
return ((TypeElement)element.getEnclosingElement()).getQualifiedName().toString() + "." + element.getSimpleName();
|
||||||
}
|
}
|
||||||
@ -185,6 +195,11 @@ public abstract class BaseProcessor extends AbstractProcessor{
|
|||||||
elementu = env.getElementUtils();
|
elementu = env.getElementUtils();
|
||||||
filer = env.getFiler();
|
filer = env.getFiler();
|
||||||
messager = env.getMessager();
|
messager = env.getMessager();
|
||||||
|
context = ((JavacProcessingEnvironment)env).getContext();
|
||||||
|
|
||||||
|
JavacProcessingEnvironment javacProcessingEnv = (JavacProcessingEnvironment)env;
|
||||||
|
this.elementUtils = javacProcessingEnv.getElementUtils();
|
||||||
|
this.maker = TreeMaker.instance(javacProcessingEnv.getContext());
|
||||||
|
|
||||||
Log.setLogLevel(LogLevel.info);
|
Log.setLogLevel(LogLevel.info);
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package mindustry.annotations.mutate;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.annotations.*;
|
||||||
|
|
||||||
|
import javax.annotation.processing.*;
|
||||||
|
import javax.lang.model.element.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
//currently unused
|
||||||
|
@SupportedAnnotationTypes({"mindustry.annotations.Annotations.Multiline"})
|
||||||
|
public final class MultilineProcessor extends BaseProcessor{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(RoundEnvironment env){
|
||||||
|
Set<? extends Element> fields = env.getElementsAnnotatedWith(Multiline.class);
|
||||||
|
for(Element field : fields){
|
||||||
|
String docComment = elementUtils.getDocComment(field);
|
||||||
|
if(null != docComment){
|
||||||
|
JCVariableDecl fieldNode = (JCVariableDecl)elementUtils.getTree(field);
|
||||||
|
fieldNode.init = maker.Literal(toString(docComment, field.getAnnotation(Multiline.class)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String toString(String value, Multiline annotation){
|
||||||
|
if(!annotation.merge() && !annotation.trim()){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
String crnl = System.getProperty("line.separator");
|
||||||
|
try{
|
||||||
|
BufferedReader reader = new BufferedReader(new StringReader(value));
|
||||||
|
StringBuilder buf = new StringBuilder();
|
||||||
|
String line = reader.readLine();
|
||||||
|
while(line != null){
|
||||||
|
if(annotation.trim()){
|
||||||
|
line = line.trim();
|
||||||
|
}
|
||||||
|
if(annotation.merge() && buf.length() > 0){
|
||||||
|
if(annotation.mergeChar() != '\0'){
|
||||||
|
buf.append(annotation.mergeChar());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf.append(line);
|
||||||
|
if(!annotation.merge()){
|
||||||
|
buf.append(crnl);
|
||||||
|
}
|
||||||
|
|
||||||
|
line = reader.readLine();
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}catch(IOException ex){
|
||||||
|
throw new RuntimeException("checked exceptions are disgusting", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,29 +7,27 @@ import mindustry.gen.*;
|
|||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
|
||||||
public class UnitTypes implements ContentList{
|
public class UnitTypes implements ContentList{
|
||||||
//TODO reimplement - DO NOT USE
|
|
||||||
public static UnitType
|
|
||||||
ghoul, revenant, lich,
|
|
||||||
crawler, fortress, eruptor, chaosArray, eradicator;
|
|
||||||
|
|
||||||
//TODO this is awful
|
//ground
|
||||||
public static @EntityDef({Unitc.class, Legsc.class}) UnitType titan;
|
public static @EntityDef({Unitc.class, Legsc.class}) UnitType titan, dagger, crawler, fortress, eruptor, chaosArray, eradicator;
|
||||||
public static @EntityDef({Unitc.class, Legsc.class}) UnitType dagger;
|
|
||||||
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
|
//air
|
||||||
|
public static @EntityDef({Unitc.class}) UnitType wraith, reaper, ghoul, revenant, lich;
|
||||||
|
|
||||||
|
//mining
|
||||||
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
|
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
|
||||||
public static @EntityDef({Unitc.class, Trailc.class}) UnitType wraith;
|
|
||||||
public static @EntityDef({Unitc.class}) UnitType reaper;
|
|
||||||
public static @EntityDef({Unitc.class}) UnitType spirit;
|
|
||||||
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
|
|
||||||
|
|
||||||
//TODO remove
|
//building
|
||||||
public static UnitType alpha, delta, tau, omega, dart, javelin, trident, glaive;
|
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom, spirit;
|
||||||
public static UnitType starter;
|
|
||||||
|
//water
|
||||||
|
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
|
|
||||||
dagger = new UnitType("dagger"){{
|
dagger = new UnitType("dagger"){{
|
||||||
|
|
||||||
speed = 0.5f;
|
speed = 0.5f;
|
||||||
drag = 0.3f;
|
drag = 0.3f;
|
||||||
hitsize = 8f;
|
hitsize = 8f;
|
||||||
|
@ -3,40 +3,12 @@ package mindustry.entities;
|
|||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
class GroupDefs{
|
class GroupDefs<G>{
|
||||||
|
@GroupDef(value = Entityc.class, mapping = true) G all;
|
||||||
@GroupDef(value = Entityc.class, mapping = true)
|
@GroupDef(value = Playerc.class, mapping = true) G player;
|
||||||
class gall{
|
@GroupDef(value = Bulletc.class, spatial = true, collide = true) G bullet;
|
||||||
|
@GroupDef(value = Unitc.class, spatial = true, mapping = true) G unit;
|
||||||
}
|
@GroupDef(value = Tilec.class) G tile;
|
||||||
|
@GroupDef(value = Syncc.class, mapping = true) G sync;
|
||||||
@GroupDef(value = Playerc.class, mapping = true)
|
@GroupDef(value = Drawc.class) G draw;
|
||||||
class gplayer{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GroupDef(value = Bulletc.class, spatial = true, collide = true)
|
|
||||||
class gbullet{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GroupDef(value = Unitc.class, spatial = true, mapping = true)
|
|
||||||
class gunit{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GroupDef(Tilec.class)
|
|
||||||
class gtile{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GroupDef(value = Syncc.class, mapping = true)
|
|
||||||
class gsync{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GroupDef(Drawc.class)
|
|
||||||
class gdraw{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user