diff --git a/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java b/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java index 2a7c86c..3f26b6a 100644 --- a/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java +++ b/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java @@ -1,7 +1,7 @@ package electrosphere.main.client; import electrosphere.main.core.btree.BehaviorTree; -import electrosphere.main.core.enums.BTreeIdEnum; +import electrosphere.main.core.statics.btreeenum.BTreeIdEnum; import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedType; import electrosphere.main.project.ProjectStructure; diff --git a/src/main/java/electrosphere/main/core/VirtualProject.java b/src/main/java/electrosphere/main/core/VirtualProject.java new file mode 100644 index 0000000..4f3106a --- /dev/null +++ b/src/main/java/electrosphere/main/core/VirtualProject.java @@ -0,0 +1,34 @@ +package electrosphere.main.core; + +import electrosphere.main.core.statics.btreeenum.BTreeIdEnum; +import electrosphere.main.core.statics.fieldenum.FieldIdEnum; + +/** + * The rich data on all the classes in the project + */ +public class VirtualProject { + + //The BTree id enum file + BTreeIdEnum bTreeIdEnum = new BTreeIdEnum(); + + //field id enum + FieldIdEnum fieldIdEnum = new FieldIdEnum(); + + + /** + * Gets the BTree id enum file's class + * @return The class + */ + public BTreeIdEnum getBTreeIdEnum(){ + return bTreeIdEnum; + } + + /** + * Gets the field id enum's class + * @return The field id enum class + */ + public FieldIdEnum getFieldIdEnum(){ + return this.fieldIdEnum; + } + +} diff --git a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java index 41fd156..9d768c6 100644 --- a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java +++ b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java @@ -40,7 +40,6 @@ public class BehaviorTree { * @param className * @param correspondingTreeName * @param isServer - * @param synchronizedFields */ public BehaviorTree( int id, diff --git a/src/main/java/electrosphere/main/core/enums/BTreeIdEnum.java b/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java similarity index 59% rename from src/main/java/electrosphere/main/core/enums/BTreeIdEnum.java rename to src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java index 418b2dd..178bae8 100644 --- a/src/main/java/electrosphere/main/core/enums/BTreeIdEnum.java +++ b/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java @@ -1,4 +1,4 @@ -package electrosphere.main.core.enums; +package electrosphere.main.core.statics.btreeenum; import java.io.File; import java.io.IOException; @@ -7,46 +7,33 @@ import com.google.common.io.Files; import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.project.ProjectStructure; +import electrosphere.main.source.VirtualClass; import electrosphere.main.util.ClassSourceUtils; /** * A class that is a list of every behavior tree and its associated id */ -public class BTreeIdEnum { - - //The class name of this class - public static final String CLASSNAME = "BehaviorTreeIdEnums"; - - //The location of the file - public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java"; +public class BTreeIdEnum extends VirtualClass { /** - * Gets the qualified path for the b tree id enum - * @param structure The project structure - * @return The qualified path + * Constructor */ - public static String getQualifiedPath(ProjectStructure structure){ - File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); - return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME; - } - - /** - * Gets the import declaration for this class - * @param structure The project structure - * @return The import declaration - */ - public static String getImport(ProjectStructure structure){ - return "import " + getQualifiedPath(structure) + ";"; + public BTreeIdEnum() { + super( + "src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java", + "BehaviorTreeIdEnums" + ); } /** * Generates a b tree id enum file * @param structure The project structure */ - public static void generate(ProjectStructure structure){ + @Override + public void generate(ProjectStructure structure){ String source = ""; - File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); + File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile(); source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile)); source = source + "\n"; source = source + ClassSourceUtils.generateClassHeader("BehaviorTreeIdEnums", "List of enums for each automatically synchronized behavior tree.", true); diff --git a/src/main/java/electrosphere/main/core/enums/FieldIdEnum.java b/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java similarity index 60% rename from src/main/java/electrosphere/main/core/enums/FieldIdEnum.java rename to src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java index b614ab9..7de096c 100644 --- a/src/main/java/electrosphere/main/core/enums/FieldIdEnum.java +++ b/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java @@ -1,4 +1,4 @@ -package electrosphere.main.core.enums; +package electrosphere.main.core.statics.fieldenum; import java.io.File; import java.io.IOException; @@ -7,47 +7,34 @@ import com.google.common.io.Files; import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.project.ProjectStructure; +import electrosphere.main.source.VirtualClass; import electrosphere.main.util.ClassSourceUtils; /** * A class that has an enum of all fields and their associated ids */ -public class FieldIdEnum { +public class FieldIdEnum extends VirtualClass { - - //The class name of this class - public static final String CLASSNAME = "FieldIdEnums"; - - //The location of the file - public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/FieldIdEnums.java"; - /** - * Gets the qualified path for the b tree id enum - * @param structure The project structure - * @return The qualified path + * Constructor */ - public static String getQualifiedPath(ProjectStructure structure){ - File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); - return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME; - } - - /** - * Gets the import declaration for this class - * @param structure The project structure - * @return The import declaration - */ - public static String getImport(ProjectStructure structure){ - return "import " + getQualifiedPath(structure) + ";"; + public FieldIdEnum() { + super( + "src/main/java/electrosphere/net/synchronization/FieldIdEnums.java", + "FieldIdEnums" + ); + //TODO Auto-generated constructor stub } /** * Generates a b tree id enum file * @param structure The project structure */ - public static void generate(ProjectStructure structure){ + @Override + public void generate(ProjectStructure structure){ String source = ""; - File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); + File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile(); source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile)); source = source + "\n"; source = source + ClassSourceUtils.generateClassHeader("FieldIdEnums", "List of enums of all fields and their associated ids.", true); diff --git a/src/main/java/electrosphere/main/project/ProjectStructure.java b/src/main/java/electrosphere/main/project/ProjectStructure.java index 26b5406..d08a6ec 100644 --- a/src/main/java/electrosphere/main/project/ProjectStructure.java +++ b/src/main/java/electrosphere/main/project/ProjectStructure.java @@ -6,9 +6,8 @@ import java.util.List; import electrosphere.main.Main; import electrosphere.main.client.ClientSynchronizationManager; +import electrosphere.main.core.VirtualProject; import electrosphere.main.core.btree.BehaviorTree; -import electrosphere.main.core.enums.BTreeIdEnum; -import electrosphere.main.core.enums.FieldIdEnum; import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedType; import electrosphere.main.project.parsers.MainParser; @@ -31,6 +30,11 @@ public class ProjectStructure { */ MainParser mainParser = new MainParser(); + /** + * The virtual project + */ + VirtualProject virtualProject; + /** * Constructor * @param targetFiles The target files to iterate on @@ -46,7 +50,7 @@ public class ProjectStructure { * Parses the target files in this project into rich data to generate off of */ public void parseRichStructure(){ - this.mainParser.parse(targetFiles); + this.virtualProject = this.mainParser.parse(targetFiles); } @@ -106,7 +110,7 @@ public class ProjectStructure { //guarantee entity fetch method ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent()); //guarantee imports of required files (btree enum, etc) - ClassSourceUtils.importClass(this, tree.getTargetFile(), BTreeIdEnum.getQualifiedPath(this)); + ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this)); ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings"); } //generate enums for all synchronized types @@ -114,8 +118,8 @@ public class ProjectStructure { ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent()); ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent()); } - BTreeIdEnum.generate(this); - FieldIdEnum.generate(this); + this.virtualProject.getBTreeIdEnum().generate(this); + this.virtualProject.getFieldIdEnum().generate(this); //client sync manager ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager()); } diff --git a/src/main/java/electrosphere/main/project/parsers/MainParser.java b/src/main/java/electrosphere/main/project/parsers/MainParser.java index 28cb6b5..ae214e5 100644 --- a/src/main/java/electrosphere/main/project/parsers/MainParser.java +++ b/src/main/java/electrosphere/main/project/parsers/MainParser.java @@ -2,9 +2,7 @@ package electrosphere.main.project.parsers; import java.util.List; -import org.jboss.forge.roaster.model.source.AnnotationSource; -import org.jboss.forge.roaster.model.source.JavaClassSource; - +import electrosphere.main.core.VirtualProject; import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedType; @@ -37,19 +35,22 @@ public class MainParser { * Parses all the target files * @param targetFiles The list of target files */ - public void parse(List targetFiles){ + public VirtualProject parse(List targetFiles){ + VirtualProject rVal = new VirtualProject(); + + // + // + // MAIN PARSING LOOP + // + // int typeIterator = 0; for(TargetFile target : targetFiles){ - AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); //parse btrees - if(mainAnnotation != null){ - BehaviorTree bTree = this.bTreeParser.parse(target); - List types = this.enumParser.parse(target, typeIterator); - List fields = this.fieldParser.parse(target); - - linkData(bTree, fields, types); - } + BehaviorTree bTree = this.bTreeParser.parse(target); + List types = this.enumParser.parse(target, typeIterator); + List fields = this.fieldParser.parse(target); + linkData(bTree, fields, types); // //specific cases @@ -59,6 +60,8 @@ public class MainParser { this.clientSynchronizationManager = target; } } + + return rVal; } /** @@ -68,11 +71,12 @@ public class MainParser { * @param types The list of types */ private void linkData(BehaviorTree tree, List fields, List types){ - - //link fields - for(SynchronizedField field : fields){ - field.setParent(tree); - tree.addSynchronizedField(field); + if(tree != null){ + //link fields + for(SynchronizedField field : fields){ + field.setParent(tree); + tree.addSynchronizedField(field); + } } } diff --git a/src/main/java/electrosphere/main/source/VirtualClass.java b/src/main/java/electrosphere/main/source/VirtualClass.java index 200ab14..acb0546 100644 --- a/src/main/java/electrosphere/main/source/VirtualClass.java +++ b/src/main/java/electrosphere/main/source/VirtualClass.java @@ -1,11 +1,20 @@ package electrosphere.main.source; +import java.io.File; import java.util.List; +import electrosphere.main.project.ProjectStructure; +import electrosphere.main.util.ClassSourceUtils; + /** * Represents the contents of a class */ public abstract class VirtualClass { + + //the location of the file + private String LOCATION; + //the class's name + private String CLASSNAME; /** * All the imports in this virtual class @@ -22,5 +31,58 @@ public abstract class VirtualClass { */ List methods; + /** + * Constructor + * @param location The location of the file + * @param name The name of the class + */ + public VirtualClass(String location, String name){ + this.LOCATION = location; + this.CLASSNAME = name; + } + + /** + * Gets the qualified path for the b tree id enum + * @param structure The project structure + * @return The qualified path + */ + public String getQualifiedPath(ProjectStructure structure){ + File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); + return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME; + } + + /** + * Gets the import declaration for this class + * @param structure The project structure + * @return The import declaration + */ + public String getImport(ProjectStructure structure){ + return "import " + getQualifiedPath(structure) + ";"; + } + + /** + * Gets the location of this file + * @return The location + */ + public String getLocation(){ + return this.LOCATION; + } + + /** + * Generates the file from scratch + * @param structure The project + */ + public void generate(ProjectStructure structure){ + throw new UnsupportedOperationException("Not yet implemented!"); + } + + /** + * Updates the existing file with the new contents of specific methods + * @param structure The project + */ + public void update(ProjectStructure structure){ + throw new UnsupportedOperationException("Not yet implemented!"); + } + } diff --git a/src/main/java/electrosphere/main/source/VirtualMethod.java b/src/main/java/electrosphere/main/source/VirtualMethod.java index 4907287..323271a 100644 --- a/src/main/java/electrosphere/main/source/VirtualMethod.java +++ b/src/main/java/electrosphere/main/source/VirtualMethod.java @@ -1,5 +1,7 @@ package electrosphere.main.source; +import java.util.List; + /** * Represents a method in a class */ @@ -18,4 +20,10 @@ public interface VirtualMethod { */ public String getContent(); + /** + * Gets the list of imports required for this method + * @return The list of imports + */ + public List getImports(); + }