From 53e47ba2d8ef18619f3a883ec5b06f14119b9e50 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 31 Jul 2024 11:27:14 -0400 Subject: [PATCH] parser refactor --- .../main/core/btree/BehaviorTree.java | 13 +- .../main/project/ProjectStructure.java | 217 ++---------------- .../main/project/parsers/BTreeParser.java | 111 +++++++++ .../main/project/parsers/EnumParser.java | 66 ++++++ .../main/project/parsers/FieldParser.java | 115 ++++++++++ .../main/project/parsers/MainParser.java | 140 +++++++++++ .../main/source/VirtualClass.java | 26 +++ .../main/source/VirtualField.java | 14 ++ .../main/source/VirtualMethod.java | 21 ++ .../main/targets/NetcodeGenTarget.java | 43 ---- 10 files changed, 516 insertions(+), 250 deletions(-) create mode 100644 src/main/java/electrosphere/main/project/parsers/BTreeParser.java create mode 100644 src/main/java/electrosphere/main/project/parsers/EnumParser.java create mode 100644 src/main/java/electrosphere/main/project/parsers/FieldParser.java create mode 100644 src/main/java/electrosphere/main/project/parsers/MainParser.java create mode 100644 src/main/java/electrosphere/main/source/VirtualClass.java create mode 100644 src/main/java/electrosphere/main/source/VirtualField.java create mode 100644 src/main/java/electrosphere/main/source/VirtualMethod.java delete mode 100644 src/main/java/electrosphere/main/targets/NetcodeGenTarget.java diff --git a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java index c06fff1..41fd156 100644 --- a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java +++ b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java @@ -1,5 +1,6 @@ package electrosphere.main.core.btree; +import java.util.LinkedList; import java.util.List; import electrosphere.main.core.syncfield.SynchronizedField; @@ -27,7 +28,7 @@ public class BehaviorTree { boolean isServer; //The synchronized fields within this tree - List synchronizedFields; + List synchronizedFields = new LinkedList(); //The file this type appears in TargetFile targetFile; @@ -47,7 +48,6 @@ public class BehaviorTree { String className, String correspondingTreeName, boolean isServer, - List synchronizedFields, TargetFile targetFile ){ this.id = id; @@ -55,7 +55,6 @@ public class BehaviorTree { this.className = className; this.correspondingTreeName = correspondingTreeName; this.isServer = isServer; - this.synchronizedFields = synchronizedFields; this.targetFile = targetFile; } @@ -107,6 +106,14 @@ public class BehaviorTree { return synchronizedFields; } + /** + * Adds a synchronized field to this behavior tree + * @param field The synchronized field + */ + public void addSynchronizedField(SynchronizedField field){ + this.synchronizedFields.add(field); + } + /** * Gets the target file associated with this behavior tree * @return The target file diff --git a/src/main/java/electrosphere/main/project/ProjectStructure.java b/src/main/java/electrosphere/main/project/ProjectStructure.java index 89b958b..26b5406 100644 --- a/src/main/java/electrosphere/main/project/ProjectStructure.java +++ b/src/main/java/electrosphere/main/project/ProjectStructure.java @@ -1,18 +1,8 @@ package electrosphere.main.project; import java.io.File; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; import java.util.List; -import java.util.Map; -import org.jboss.forge.roaster.model.source.AnnotationSource; -import org.jboss.forge.roaster.model.source.EnumConstantSource; -import org.jboss.forge.roaster.model.source.FieldSource; -import org.jboss.forge.roaster.model.source.JavaClassSource; -import org.jboss.forge.roaster.model.source.JavaEnumSource; -import org.jboss.forge.roaster.model.source.JavaSource; import electrosphere.main.Main; import electrosphere.main.client.ClientSynchronizationManager; @@ -21,6 +11,7 @@ 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; import electrosphere.main.targets.TargetFile; import electrosphere.main.util.ClassSourceUtils; @@ -31,32 +22,14 @@ public class ProjectStructure { //The root folder of the project File rootFolder; - //The list of files to parse List targetFiles; - //The list of behavior trees to synchronize - List behaviorTrees = new LinkedList(); - - //All fields that are to be synchronized - List synchronizedFields = new LinkedList(); - - //All types (enums) that can be synchronized - List synchronizedTypes = new LinkedList(); - - //the client synchronization manager - TargetFile clientSynchronizationManager; - - //the file that has the enum of all behavior tree ids - TargetFile behaviorTreeIdEnums; - int behaviorTreeIdIterator = 0; //used to generate unique ids for new trees - Map existingTreeNameToIdMap; //the id map associated with the behaviorTreeIdEnums file - - //the file that contains the enum of all synced fields to their ids - TargetFile fieldIdEnums; - int fieldIdIterator = 0; //used to generate unique ids for new fields - Map existingFieldNameToIdMap; //the map of existing field names to their ids + /** + * The main parser + */ + MainParser mainParser = new MainParser(); /** * Constructor @@ -73,87 +46,7 @@ public class ProjectStructure { * Parses the target files in this project into rich data to generate off of */ public void parseRichStructure(){ - int typeIterator = 0; - for(TargetFile target : targetFiles){ - AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); - - //parse btrees - if(mainAnnotation != null){ - String bTreeName = mainAnnotation.getStringValue("name"); - String bTreeCorrespondingName = mainAnnotation.getStringValue("correspondingTree"); - boolean isServer = Boolean.parseBoolean(mainAnnotation.getStringValue("isServer")); - - - //parse sync'd fields - List syncedFields = new LinkedList(); - for(FieldSource fieldSource : target.getSource().getFields()){ - AnnotationSource syncAnnotation = fieldSource.getAnnotation("SyncedField"); - if(syncAnnotation != null){ - String fieldName = fieldSource.getName(); - String typeName = fieldSource.getType().getName(); - int fieldId = getFieldId(bTreeName,fieldName); - SynchronizedField field = new SynchronizedField(fieldId,fieldName,typeName,target); - this.synchronizedFields.add(field); - syncedFields.add(field); - } - } - - //parse sync'd enum types - for(JavaSource fieldSource : target.getSource().getNestedTypes()){ - if(fieldSource instanceof JavaEnumSource){ - JavaEnumSource enumSource = (JavaEnumSource)fieldSource; - AnnotationSource annotation = enumSource.getAnnotation("SynchronizableEnum"); - if(annotation != null){ - List values = new LinkedList(); - for(EnumConstantSource constants: enumSource.getEnumConstants()){ - values.add(constants.getName()); - } - SynchronizedType type = new SynchronizedType(typeIterator, enumSource.getName(), values,target); - synchronizedTypes.add(type); - typeIterator++; - } - } - } - - BehaviorTree newBehaviorTree = new BehaviorTree( - getBTreeId(bTreeName), - bTreeName, - target.getSource().getName(), - bTreeCorrespondingName, - isServer, - syncedFields, - target - ); - behaviorTrees.add(newBehaviorTree); - - //push behavior tree to each field - for(SynchronizedField field : syncedFields){ - field.setParent(newBehaviorTree); - } - } - - // - //specific cases - - //client synchronization manager - if(target.getName().contains("ClientSynchronizationManager")){ - this.clientSynchronizationManager = target; - } - - //currently defined behavior tree ids - //this is guaranteed to be parsed before the regular behavior trees that are discovered in the recursive file parser - if(target.getName().contains("BehaviorTreeIdEnums")){ - this.behaviorTreeIdEnums = target; - pushExistingTreeIds(); - } - - //class storing all current field's ids - if(target.getName().contains("FieldIdEnums")){ - this.fieldIdEnums = target; - pushExistingFieldIds(); - } - } - + this.mainParser.parse(targetFiles); } @@ -162,7 +55,7 @@ public class ProjectStructure { */ public void generate(){ //generate in-class functions for btrees - for(BehaviorTree tree : behaviorTrees){ + for(BehaviorTree tree : this.getBehaviorTrees()){ if(Main.LOG){ System.out.println("Generating for " + tree.getClassName()); } @@ -217,14 +110,14 @@ public class ProjectStructure { ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings"); } //generate enums for all synchronized types - for(SynchronizedType type : synchronizedTypes){ + for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){ ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent()); ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent()); } BTreeIdEnum.generate(this); FieldIdEnum.generate(this); //client sync manager - ClientSynchronizationManager.update(this, clientSynchronizationManager); + ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager()); } /** @@ -254,12 +147,7 @@ public class ProjectStructure { * @return The synchronized type if it exists, null otherwise */ public SynchronizedType getType(String typeName){ - for(SynchronizedType type : this.synchronizedTypes){ - if(type.getName().equals(typeName)){ - return type; - } - } - return null; + return mainParser.getType(typeName); } /** @@ -268,86 +156,7 @@ public class ProjectStructure { * @return The tree if it exists, null otherwise */ public BehaviorTree getTree(String typeName){ - for(BehaviorTree tree : this.behaviorTrees){ - if(tree.getName().equals(typeName)){ - return tree; - } - } - return null; - } - - /** - * Updates the behavior tree objects with the behavior tree ids that are already defined - */ - private void pushExistingTreeIds(){ - existingTreeNameToIdMap = new HashMap(); - for(FieldSource fieldSource : this.behaviorTreeIdEnums.getSource().getFields()){ - int value = Integer.parseInt(fieldSource.getLiteralInitializer()); - String fieldName = fieldSource.getName(); - String capitalizedBTreeName = fieldName.split("_")[1]; - existingTreeNameToIdMap.put(capitalizedBTreeName,value); - } - } - - /** - * Updates the field objects with the field ids that are already defined - */ - private void pushExistingFieldIds(){ - existingFieldNameToIdMap = new HashMap(); - if(this.fieldIdEnums != null){ - for(FieldSource fieldSource : this.fieldIdEnums.getSource().getFields()){ - int value = Integer.parseInt(fieldSource.getLiteralInitializer()); - String fieldName = fieldSource.getName(); - String capitalizedFieldName = fieldName.split("_")[1] + "_" + fieldName.split("_")[3]; - existingFieldNameToIdMap.put(capitalizedFieldName,value); - } - } - } - - /** - * Gets the id for a given btree - * @param bTreeName the name of the btree - * @return the id - */ - private int getBTreeId(String bTreeName){ - String capitalizedName = bTreeName.toUpperCase(); - if(existingTreeNameToIdMap.containsKey(capitalizedName)){ - return existingTreeNameToIdMap.get(capitalizedName); - } else { - Collection existingIds = existingTreeNameToIdMap.values(); - //increment ids until we hit an available one - while(existingIds.contains(behaviorTreeIdIterator)){ - behaviorTreeIdIterator++; - } - existingTreeNameToIdMap.put(capitalizedName,behaviorTreeIdIterator); - return behaviorTreeIdIterator; - } - } - - /** - * Gets the id for a given field - * @param bTreeName the name of the btree that the field is inside of - * @param fieldName the name of the field - * @return the id - */ - private int getFieldId(String bTreeName, String fieldName){ - //init the map if it doesn't already exist (ie the file doesn't exist) - if(existingFieldNameToIdMap == null){ - existingFieldNameToIdMap = new HashMap(); - } - //get the id - String qualifiedName = bTreeName.toUpperCase() + "_" + fieldName.toUpperCase(); - if(existingFieldNameToIdMap.containsKey(qualifiedName)){ - return existingFieldNameToIdMap.get(qualifiedName); - } else { - Collection existingIds = existingFieldNameToIdMap.values(); - //increment ids until we hit an available one - while(existingIds.contains(fieldIdIterator)){ - fieldIdIterator++; - } - existingFieldNameToIdMap.put(qualifiedName,fieldIdIterator); - return fieldIdIterator; - } + return mainParser.getTree(typeName); } /** @@ -355,7 +164,7 @@ public class ProjectStructure { * @return The list of synchronized fields */ public List getSynchronizedFields(){ - return this.synchronizedFields; + return mainParser.getSynchronizedFields(); } /** @@ -363,7 +172,7 @@ public class ProjectStructure { * @return The list of all behavior trees */ public List getBehaviorTrees(){ - return this.behaviorTrees; + return mainParser.getBehaviorTrees(); } } diff --git a/src/main/java/electrosphere/main/project/parsers/BTreeParser.java b/src/main/java/electrosphere/main/project/parsers/BTreeParser.java new file mode 100644 index 0000000..1dc3e38 --- /dev/null +++ b/src/main/java/electrosphere/main/project/parsers/BTreeParser.java @@ -0,0 +1,111 @@ +package electrosphere.main.project.parsers; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jboss.forge.roaster.model.source.AnnotationSource; +import org.jboss.forge.roaster.model.source.FieldSource; +import org.jboss.forge.roaster.model.source.JavaClassSource; + +import electrosphere.main.core.btree.BehaviorTree; +import electrosphere.main.targets.TargetFile; + +/** + * Parses behavior trees from the project structure + */ +public class BTreeParser { + + //The list of behavior trees to synchronize + List behaviorTrees = new LinkedList(); + + //the file that has the enum of all behavior tree ids + TargetFile behaviorTreeIdEnums; + int behaviorTreeIdIterator = 0; //used to generate unique ids for new trees + Map existingTreeNameToIdMap = new HashMap(); //the id map associated with the behaviorTreeIdEnums file + + + + /** + * Gets the list of all parsed behavior trees + * @return The list of all parsed behavior trees + */ + public List getBehaviorTrees(){ + return this.behaviorTrees; + } + + /** + * Parses a target file + * @param target The target file + * @return The behavior tree that was parsed or null if no behavior tree was parsed + */ + public BehaviorTree parse(TargetFile target){ + BehaviorTree rVal = null; + + AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); + //parse btrees + if(mainAnnotation != null){ + String bTreeName = mainAnnotation.getStringValue("name"); + String bTreeCorrespondingName = mainAnnotation.getStringValue("correspondingTree"); + boolean isServer = Boolean.parseBoolean(mainAnnotation.getStringValue("isServer")); + + rVal = new BehaviorTree( + getBTreeId(bTreeName), + bTreeName, + target.getSource().getName(), + bTreeCorrespondingName, + isServer, + target + ); + behaviorTrees.add(rVal); + } + + // + //specific cases + + //currently defined behavior tree ids + //this is guaranteed to be parsed before the regular behavior trees that are discovered in the recursive file parser + if(target.getName().contains("BehaviorTreeIdEnums")){ + this.behaviorTreeIdEnums = target; + pushExistingTreeIds(); + } + + return rVal; + } + + /** + * Updates the behavior tree objects with the behavior tree ids that are already defined + */ + private void pushExistingTreeIds(){ + existingTreeNameToIdMap = new HashMap(); + for(FieldSource fieldSource : this.behaviorTreeIdEnums.getSource().getFields()){ + int value = Integer.parseInt(fieldSource.getLiteralInitializer()); + String fieldName = fieldSource.getName(); + String capitalizedBTreeName = fieldName.split("_")[1]; + existingTreeNameToIdMap.put(capitalizedBTreeName,value); + } + } + + /** + * Gets the id for a given btree + * @param bTreeName the name of the btree + * @return the id + */ + private int getBTreeId(String bTreeName){ + String capitalizedName = bTreeName.toUpperCase(); + if(existingTreeNameToIdMap.containsKey(capitalizedName)){ + return existingTreeNameToIdMap.get(capitalizedName); + } else { + Collection existingIds = existingTreeNameToIdMap.values(); + //increment ids until we hit an available one + while(existingIds.contains(behaviorTreeIdIterator)){ + behaviorTreeIdIterator++; + } + existingTreeNameToIdMap.put(capitalizedName,behaviorTreeIdIterator); + return behaviorTreeIdIterator; + } + } + +} diff --git a/src/main/java/electrosphere/main/project/parsers/EnumParser.java b/src/main/java/electrosphere/main/project/parsers/EnumParser.java new file mode 100644 index 0000000..81cf92d --- /dev/null +++ b/src/main/java/electrosphere/main/project/parsers/EnumParser.java @@ -0,0 +1,66 @@ +package electrosphere.main.project.parsers; + +import java.util.LinkedList; +import java.util.List; + +import org.jboss.forge.roaster.model.source.AnnotationSource; +import org.jboss.forge.roaster.model.source.EnumConstantSource; +import org.jboss.forge.roaster.model.source.JavaClassSource; +import org.jboss.forge.roaster.model.source.JavaEnumSource; +import org.jboss.forge.roaster.model.source.JavaSource; + +import electrosphere.main.core.syncfield.SynchronizedType; +import electrosphere.main.targets.TargetFile; + +/** + * Parses synchronized enums from a target file + */ +public class EnumParser { + + //All types (enums) that can be synchronized + List synchronizedTypes = new LinkedList(); + + + + /** + * Parses a target file + * @param target The target file + * @return The list of types parsed from this target file + */ + public List parse(TargetFile target, int typeIterator){ + List rVal = new LinkedList(); + + AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); + //parse btrees + if(mainAnnotation != null){ + //parse sync'd enum types + for(JavaSource fieldSource : target.getSource().getNestedTypes()){ + if(fieldSource instanceof JavaEnumSource){ + JavaEnumSource enumSource = (JavaEnumSource)fieldSource; + AnnotationSource annotation = enumSource.getAnnotation("SynchronizableEnum"); + if(annotation != null){ + List values = new LinkedList(); + for(EnumConstantSource constants: enumSource.getEnumConstants()){ + values.add(constants.getName()); + } + SynchronizedType type = new SynchronizedType(typeIterator, enumSource.getName(), values,target); + synchronizedTypes.add(type); + rVal.add(type); + typeIterator++; + } + } + } + } + return rVal; + } + + + /** + * Gets the list of synchronized types + * @return The list of synchronized types + */ + public List getSynchronizedTypes(){ + return this.synchronizedTypes; + } + +} diff --git a/src/main/java/electrosphere/main/project/parsers/FieldParser.java b/src/main/java/electrosphere/main/project/parsers/FieldParser.java new file mode 100644 index 0000000..429f0f3 --- /dev/null +++ b/src/main/java/electrosphere/main/project/parsers/FieldParser.java @@ -0,0 +1,115 @@ +package electrosphere.main.project.parsers; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jboss.forge.roaster.model.source.AnnotationSource; +import org.jboss.forge.roaster.model.source.FieldSource; +import org.jboss.forge.roaster.model.source.JavaClassSource; + +import electrosphere.main.core.syncfield.SynchronizedField; +import electrosphere.main.targets.TargetFile; + +/** + * Parses synchronized fields from a target file + */ +public class FieldParser { + + //All fields that are to be synchronized + List synchronizedFields = new LinkedList(); + + //the file that contains the enum of all synced fields to their ids + TargetFile fieldIdEnums; + int fieldIdIterator = 0; //used to generate unique ids for new fields + Map existingFieldNameToIdMap = new HashMap(); //the map of existing field names to their ids + + + /** + * Parses a given target file + * @param target The target file + * @return The list of fields parsed from this file + */ + public List parse(TargetFile target){ + List rVal = new LinkedList(); + + + AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); + //parse btrees + if(mainAnnotation != null){ + String bTreeName = mainAnnotation.getStringValue("name"); + //parse sync'd fields + for(FieldSource fieldSource : target.getSource().getFields()){ + AnnotationSource syncAnnotation = fieldSource.getAnnotation("SyncedField"); + if(syncAnnotation != null){ + String fieldName = fieldSource.getName(); + String typeName = fieldSource.getType().getName(); + int fieldId = getFieldId(bTreeName,fieldName); + SynchronizedField field = new SynchronizedField(fieldId,fieldName,typeName,target); + this.synchronizedFields.add(field); + rVal.add(field); + } + } + } + + //class storing all current field's ids + if(target.getName().contains("FieldIdEnums")){ + this.fieldIdEnums = target; + pushExistingFieldIds(); + } + + return rVal; + } + + /** + * Gets the list of synchronized fields + * @return The list of synchronized fields + */ + public List getSynchronizedFields(){ + return this.synchronizedFields; + } + + /** + * Updates the field objects with the field ids that are already defined + */ + private void pushExistingFieldIds(){ + existingFieldNameToIdMap = new HashMap(); + if(this.fieldIdEnums != null){ + for(FieldSource fieldSource : this.fieldIdEnums.getSource().getFields()){ + int value = Integer.parseInt(fieldSource.getLiteralInitializer()); + String fieldName = fieldSource.getName(); + String capitalizedFieldName = fieldName.split("_")[1] + "_" + fieldName.split("_")[3]; + existingFieldNameToIdMap.put(capitalizedFieldName,value); + } + } + } + + /** + * Gets the id for a given field + * @param bTreeName the name of the btree that the field is inside of + * @param fieldName the name of the field + * @return the id + */ + private int getFieldId(String bTreeName, String fieldName){ + //init the map if it doesn't already exist (ie the file doesn't exist) + if(existingFieldNameToIdMap == null){ + existingFieldNameToIdMap = new HashMap(); + } + //get the id + String qualifiedName = bTreeName.toUpperCase() + "_" + fieldName.toUpperCase(); + if(existingFieldNameToIdMap.containsKey(qualifiedName)){ + return existingFieldNameToIdMap.get(qualifiedName); + } else { + Collection existingIds = existingFieldNameToIdMap.values(); + //increment ids until we hit an available one + while(existingIds.contains(fieldIdIterator)){ + fieldIdIterator++; + } + existingFieldNameToIdMap.put(qualifiedName,fieldIdIterator); + return fieldIdIterator; + } + } + +} diff --git a/src/main/java/electrosphere/main/project/parsers/MainParser.java b/src/main/java/electrosphere/main/project/parsers/MainParser.java new file mode 100644 index 0000000..28cb6b5 --- /dev/null +++ b/src/main/java/electrosphere/main/project/parsers/MainParser.java @@ -0,0 +1,140 @@ +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.btree.BehaviorTree; +import electrosphere.main.core.syncfield.SynchronizedField; +import electrosphere.main.core.syncfield.SynchronizedType; +import electrosphere.main.targets.TargetFile; + +/** + * The top level parser object + */ +public class MainParser { + + /** + * The behavior tree parser + */ + BTreeParser bTreeParser = new BTreeParser(); + + /** + * The enum parser + */ + EnumParser enumParser = new EnumParser(); + + /** + * The field parser + */ + FieldParser fieldParser = new FieldParser(); + + //the client synchronization manager + TargetFile clientSynchronizationManager; + + /** + * Parses all the target files + * @param targetFiles The list of target files + */ + public void parse(List targetFiles){ + 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); + } + + // + //specific cases + + //client synchronization manager + if(target.getName().contains("ClientSynchronizationManager")){ + this.clientSynchronizationManager = target; + } + } + } + + /** + * Links all the values gathered from a behavior tree file + * @param tree The tree + * @param fields The list of fields + * @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); + } + } + + + /** + * Gets a synchronized type from a name + * @param typeName The name of the type + * @return The synchronized type if it exists, null otherwise + */ + public SynchronizedType getType(String typeName){ + for(SynchronizedType type : this.enumParser.getSynchronizedTypes()){ + if(type.getName().equals(typeName)){ + return type; + } + } + return null; + } + + /** + * Gets a behavior tree from its name + * @param typeName The name of the tree + * @return The tree if it exists, null otherwise + */ + public BehaviorTree getTree(String typeName){ + for(BehaviorTree tree : this.bTreeParser.getBehaviorTrees()){ + if(tree.getName().equals(typeName)){ + return tree; + } + } + return null; + } + + /** + * Gets the list of synchronized fields + * @return The list of synchronized fields + */ + public List getSynchronizedFields(){ + return this.fieldParser.getSynchronizedFields(); + } + + /** + * Gets the list of all behavior trees + * @return The list of all behavior trees + */ + public List getBehaviorTrees(){ + return this.bTreeParser.getBehaviorTrees(); + } + + /** + * Gets the list of all synchronized types + * @return The list of all synchronized types + */ + public List getSynchronizedTypes(){ + return this.enumParser.getSynchronizedTypes(); + } + + /** + * Gets the client synchronization manager target file + * @return The target file + */ + public TargetFile getClientSynchronizationManager(){ + return this.clientSynchronizationManager; + } + +} diff --git a/src/main/java/electrosphere/main/source/VirtualClass.java b/src/main/java/electrosphere/main/source/VirtualClass.java new file mode 100644 index 0000000..200ab14 --- /dev/null +++ b/src/main/java/electrosphere/main/source/VirtualClass.java @@ -0,0 +1,26 @@ +package electrosphere.main.source; + +import java.util.List; + +/** + * Represents the contents of a class + */ +public abstract class VirtualClass { + + /** + * All the imports in this virtual class + */ + List imports; + + /** + * All the fields in this class + */ + List fields; + + /** + * All the methods in this class + */ + List methods; + + +} diff --git a/src/main/java/electrosphere/main/source/VirtualField.java b/src/main/java/electrosphere/main/source/VirtualField.java new file mode 100644 index 0000000..9cc853c --- /dev/null +++ b/src/main/java/electrosphere/main/source/VirtualField.java @@ -0,0 +1,14 @@ +package electrosphere.main.source; + +/** + * Represents a field in a class + */ +public interface VirtualField { + + /** + * Gets the name of the field + * @return The name of the field + */ + public String getName(); + +} diff --git a/src/main/java/electrosphere/main/source/VirtualMethod.java b/src/main/java/electrosphere/main/source/VirtualMethod.java new file mode 100644 index 0000000..4907287 --- /dev/null +++ b/src/main/java/electrosphere/main/source/VirtualMethod.java @@ -0,0 +1,21 @@ +package electrosphere.main.source; + +/** + * Represents a method in a class + */ +public interface VirtualMethod { + + /** + * Gets the name of the method + * @return The name of the method + */ + public String getName(); + + + /** + * Gets the content of this method + * @return The content + */ + public String getContent(); + +} diff --git a/src/main/java/electrosphere/main/targets/NetcodeGenTarget.java b/src/main/java/electrosphere/main/targets/NetcodeGenTarget.java deleted file mode 100644 index e142ae1..0000000 --- a/src/main/java/electrosphere/main/targets/NetcodeGenTarget.java +++ /dev/null @@ -1,43 +0,0 @@ -package electrosphere.main.targets; - -import org.jboss.forge.roaster.model.source.AnnotationSource; -import org.jboss.forge.roaster.model.source.FieldSource; -import org.jboss.forge.roaster.model.source.JavaClassSource; - -public class NetcodeGenTarget { - - int id; - String name; - String typeName; - FieldSource field; - AnnotationSource annotation; - - public NetcodeGenTarget(int id, String name, String typeName, FieldSource field, AnnotationSource annotation){ - this.id = id; - this.name = name; - this.typeName = typeName; - this.field = field; - this.annotation = annotation; - } - - public int getId(){ - return id; - } - - public String getName(){ - return name; - } - - public String getTypeName(){ - return typeName; - } - - public FieldSource getField(){ - return field; - } - - public AnnotationSource getAnnotation(){ - return annotation; - } - -}