Added Dependency Checks into the Module System.

Why a Dependency Check system was added?
This commit is contained in:
Speiger 2022-12-07 03:23:19 +01:00
parent 8d8c30c9a7
commit cc92ef953a
12 changed files with 107 additions and 52 deletions

View File

@ -4,10 +4,10 @@
"Collection": true, "Collection": true,
"Function": true, "Function": true,
"List": true, "List": true,
"Map": false, "Map": true,
"Pair": true, "Pair": true,
"PriorityQueue": true, "PriorityQueue": true,
"Set": false, "Set": true,
"Boolean": { "Boolean": {
"Enabled": true, "Enabled": true,
"Base": { "Base": {
@ -367,15 +367,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -638,15 +638,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -909,15 +909,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -1180,15 +1180,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -1451,15 +1451,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -1722,15 +1722,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -1993,15 +1993,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },
@ -2264,15 +2264,15 @@
}, },
"Set": { "Set": {
"Enabled": true, "Enabled": true,
"LinkedHashSet": false, "LinkedHashSet": true,
"LinkedCustomHashSet": false, "LinkedCustomHashSet": true,
"OrderedSet": true, "OrderedSet": true,
"ArraySet": true, "ArraySet": true,
"AVLTreeSet": true, "AVLTreeSet": true,
"ImmutableSet": true, "ImmutableSet": true,
"CustomHashSet": true, "CustomHashSet": true,
"Sets": true, "Sets": true,
"SortedSet": false, "SortedSet": true,
"HashSet": true, "HashSet": true,
"RBTreeSet": true "RBTreeSet": true
}, },

View File

@ -122,28 +122,45 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
} }
} }
public List<BaseModule> createModules()
{
List<BaseModule> modules = new ArrayList<>();
modules.add(JavaModule.INSTANCE);
modules.add(FunctionModule.INSTANCE);
modules.add(CollectionModule.INSTANCE);
modules.add(PrioQueueModule.INSTANCE);
modules.add(ListModule.INSTANCE);
modules.add(SetModule.INSTANCE);
modules.add(MapModule.INSTANCE);
modules.add(PairModule.INSTANCE);
modules.add(AsyncModule.INSTANCE);
return modules;
}
@Override @Override
protected void init() protected void init()
{ {
prepPackages(); prepPackages();
//Init Modules here //Init Modules here
addModule(new JavaModule()); addModules(createModules());
addModule(new FunctionModule());
addModule(new CollectionModule());
addModule(new PrioQueueModule());
addModule(new ListModule());
addModule(new SetModule());
addModule(new MapModule());
addModule(new PairModule());
addModule(new AsyncModule());
finishPackages(); finishPackages();
} }
public void addModule(BaseModule module) public void addModules(List<BaseModule> modules)
{ {
module.setManager(manager); if((flags & LOAD) != 0)
biPackages.forEach(module::init); {
module.cleanup(); for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).setManager(manager);
}
}
for(int i = 0,m=modules.size();i<m;i++) {
biPackages.forEach(modules.get(i)::init);
}
for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).cleanup();
}
} }
private void finishPackages() private void finishPackages()
@ -239,7 +256,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
boolean force = flags.contains("force"); boolean force = flags.contains("force");
boolean tests = flags.contains("tests"); boolean tests = flags.contains("tests");
boolean forceTests = flags.contains("force-tests"); boolean forceTests = flags.contains("force-tests");
boolean load = flags.contains("load"); boolean load = !flags.contains("load");
boolean save = flags.contains("save"); boolean save = flags.contains("save");
int flag = (load ? LOAD : 0) | (save ? SAVE : 0); int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force); new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);

View File

@ -3,6 +3,8 @@ package speiger.src.builder.modules;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class AsyncModule extends BaseModule public class AsyncModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new AsyncModule();
@Override @Override
public String getModuleName() { return "Async"; } public String getModuleName() { return "Async"; }
@Override @Override
@ -14,6 +16,8 @@ public class AsyncModule extends BaseModule
@Override @Override
protected void loadFunctions() {} protected void loadFunctions() {}
@Override @Override
protected boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
@Override
protected void loadBlockades() { protected void loadBlockades() {
if(!isModuleEnabled()) { if(!isModuleEnabled()) {
addBlockedFiles("AsyncBuilder"); addBlockedFiles("AsyncBuilder");

View File

@ -60,11 +60,23 @@ public abstract class BaseModule
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; } public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
protected boolean isModuleEnabled() { protected boolean isModuleEnabled() {
return manager == null || manager.isModuleEnabled(this, keyType, valueType); return manager == null || (manager.isModuleEnabled(this, keyType, valueType) && areDependenciesLoaded());
} }
protected boolean isModuleEnabled(String name) { protected boolean isModuleEnabled(String name) {
return manager == null || manager.isModuleEnabled(this, keyType, valueType, name); return manager == null || (manager.isModuleEnabled(this, keyType, valueType, name) && areDependenciesLoaded());
}
protected boolean isDependencyLoaded(BaseModule module) {
return isDependencyLoaded(module, true);
}
protected boolean isDependencyLoaded(BaseModule module, boolean key) {
return manager == null || (module.isBiModule() ? manager.isModuleEnabled(module, keyType, valueType) : (key ? manager.isModuleEnabled(module, keyType, keyType) : manager.isModuleEnabled(module, valueType, valueType)));
}
protected boolean areDependenciesLoaded() {
return true;
} }
protected void addFlag(String name) { protected void addFlag(String name) {

View File

@ -5,6 +5,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class CollectionModule extends BaseModule public class CollectionModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new CollectionModule();
@Override @Override
public String getModuleName() { return "Collection"; } public String getModuleName() { return "Collection"; }
@Override @Override

View File

@ -3,6 +3,8 @@ package speiger.src.builder.modules;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class FunctionModule extends BaseModule public class FunctionModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new FunctionModule();
@Override @Override
public String getModuleName() { return "Function"; } public String getModuleName() { return "Function"; }
@Override @Override

View File

@ -5,6 +5,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class JavaModule extends BaseModule public class JavaModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new JavaModule();
@Override @Override
public String getModuleName() { return "Base"; } public String getModuleName() { return "Base"; }
@Override @Override

View File

@ -9,6 +9,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class ListModule extends BaseModule public class ListModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new ListModule();
@Override @Override
public String getModuleName() { return "List"; } public String getModuleName() { return "List"; }
@Override @Override
@ -38,11 +40,15 @@ public class ListModule extends BaseModule
} }
@Override @Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
{
return new HashSet<>(Arrays.asList("Lists", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList")); return new HashSet<>(Arrays.asList("Lists", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList"));
} }
@Override
protected boolean areDependenciesLoaded() {
return isDependencyLoaded(CollectionModule.INSTANCE);
}
@Override @Override
protected void loadRemappers() protected void loadRemappers()
{ {

View File

@ -9,6 +9,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class MapModule extends BaseModule public class MapModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new MapModule();
@Override @Override
public String getModuleName() { return "Map"; } public String getModuleName() { return "Map"; }
@Override @Override
@ -32,6 +34,11 @@ public class MapModule extends BaseModule
return sets; return sets;
} }
@Override
protected boolean areDependenciesLoaded() {
return isDependencyLoaded(SetModule.INSTANCE) && isDependencyLoaded(CollectionModule.INSTANCE, false);
}
@Override @Override
protected void loadFlags() protected void loadFlags()
{ {

View File

@ -3,6 +3,7 @@ package speiger.src.builder.modules;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class PairModule extends BaseModule public class PairModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new PairModule();
@Override @Override
public String getModuleName() { return "Pair"; } public String getModuleName() { return "Pair"; }
@Override @Override

View File

@ -5,6 +5,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class PrioQueueModule extends BaseModule public class PrioQueueModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new PrioQueueModule();
@Override @Override
public String getModuleName() { return "PriorityQueue"; } public String getModuleName() { return "PriorityQueue"; }
@Override @Override
@ -13,7 +15,8 @@ public class PrioQueueModule extends BaseModule
protected void loadFlags() {} protected void loadFlags() {}
@Override @Override
protected void loadFunctions() {} protected void loadFunctions() {}
@Override
protected boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
@Override @Override
protected void loadBlockades() protected void loadBlockades()
{ {

View File

@ -9,20 +9,19 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class SetModule extends BaseModule public class SetModule extends BaseModule
{ {
public static final BaseModule INSTANCE = new SetModule();
@Override @Override
public String getModuleName() { return "Set"; } public String getModuleName() { return "Set"; }
@Override @Override
protected void loadVariables() {} protected void loadVariables() {}
@Override @Override
public boolean isModuleValid(ClassType keyType, ClassType valueType) public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
{
return keyType != ClassType.BOOLEAN;
}
@Override @Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) protected boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
{ @Override
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
Set<String> sets = new HashSet<>(); Set<String> sets = new HashSet<>();
sets.add("Sets"); sets.add("Sets");
sets.addAll(Arrays.asList("OrderedSet", "SortedSet")); sets.addAll(Arrays.asList("OrderedSet", "SortedSet"));