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,
"Function": true,
"List": true,
"Map": false,
"Map": true,
"Pair": true,
"PriorityQueue": true,
"Set": false,
"Set": true,
"Boolean": {
"Enabled": true,
"Base": {
@ -367,15 +367,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -638,15 +638,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -909,15 +909,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -1180,15 +1180,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -1451,15 +1451,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -1722,15 +1722,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -1993,15 +1993,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": true,
"RBTreeSet": true
},
@ -2264,15 +2264,15 @@
},
"Set": {
"Enabled": true,
"LinkedHashSet": false,
"LinkedCustomHashSet": false,
"LinkedHashSet": true,
"LinkedCustomHashSet": true,
"OrderedSet": true,
"ArraySet": true,
"AVLTreeSet": true,
"ImmutableSet": true,
"CustomHashSet": true,
"Sets": true,
"SortedSet": false,
"SortedSet": true,
"HashSet": 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
protected void init()
{
prepPackages();
//Init Modules here
addModule(new JavaModule());
addModule(new FunctionModule());
addModule(new CollectionModule());
addModule(new PrioQueueModule());
addModule(new ListModule());
addModule(new SetModule());
addModule(new MapModule());
addModule(new PairModule());
addModule(new AsyncModule());
addModules(createModules());
finishPackages();
}
public void addModule(BaseModule module)
public void addModules(List<BaseModule> modules)
{
module.setManager(manager);
biPackages.forEach(module::init);
module.cleanup();
if((flags & LOAD) != 0)
{
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()
@ -239,7 +256,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
boolean force = flags.contains("force");
boolean tests = flags.contains("tests");
boolean forceTests = flags.contains("force-tests");
boolean load = flags.contains("load");
boolean load = !flags.contains("load");
boolean save = flags.contains("save");
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);

View File

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

View File

@ -60,11 +60,23 @@ public abstract class BaseModule
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
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) {
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) {

View File

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

View File

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

View File

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

View File

@ -9,6 +9,8 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class ListModule extends BaseModule
{
public static final BaseModule INSTANCE = new ListModule();
@Override
public String getModuleName() { return "List"; }
@Override
@ -38,11 +40,15 @@ public class ListModule extends BaseModule
}
@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"));
}
@Override
protected boolean areDependenciesLoaded() {
return isDependencyLoaded(CollectionModule.INSTANCE);
}
@Override
protected void loadRemappers()
{

View File

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

View File

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

View File

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

View File

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