Implemented Module Configuration

This commit is contained in:
Speiger 2022-12-02 22:36:34 +01:00
parent 8e39acef45
commit 6722f399db
18 changed files with 1659 additions and 972 deletions

1082
ModulSettings.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,7 @@ configurations {
}
dependencies {
builderImplementation 'com.google.code.gson:gson:2.10'
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'

View File

@ -52,6 +52,11 @@ public enum ClassType
return classType;
}
public String getClassPath()
{
return this == OBJECT ? "Object" : classType;
}
public String getClassType(boolean value)
{
return value && this == OBJECT ? "V" : classType;

View File

@ -1,553 +0,0 @@
package speiger.src.builder;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
import speiger.src.builder.mappers.ArgumentMapper;
import speiger.src.builder.mappers.IMapper;
import speiger.src.builder.mappers.InjectMapper;
import speiger.src.builder.mappers.LineMapper;
import speiger.src.builder.mappers.SimpleMapper;
import speiger.src.builder.processor.TemplateProcess;
@SuppressWarnings("javadoc")
public class GlobalVariables
{
List<IMapper> operators = new ArrayList<>();
Set<String> flags = new LinkedHashSet<>();
ClassType type;
ClassType valueType;
public GlobalVariables(ClassType type, ClassType subType)
{
this.type = type;
valueType = subType;
}
public GlobalVariables createVariables()
{
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
addSimpleMapper("PACKAGE", type.getPathType());
addSimpleMapper("CLASS_TYPE", type.getClassType());
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
addSimpleMapper("KEY_TYPE", type.getKeyType());
addSimpleMapper("KEY_OBJECT_TYPE", type.isObject() ? "Object" : type.getKeyType());
addSimpleMapper("KEY_STRING_TYPE", type.isObject() ? "String" : type.getKeyType());
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
addSimpleMapper("CLASS_OBJECT_TYPE", type.getClassType());
addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType());
addSimpleMapper("CLASS_STRING_TYPE", type.isObject() ? "String" : type.getClassType());
addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType());
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType());
addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType());
addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
addSimpleMapper("KEY_JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("VALUE_JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
addSimpleMapper("INVALID_KEY_VALUE", type.getInvalidValue());
addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue());
addSimpleMapper(" KEY_STRING_GENERIC_TYPE", type.isObject() ? "<String>" : "");
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", type.isObject() ? "<"+type.getClassType()+">" : "");
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+type.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces();
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", type.isObject() ? "<? extends "+type.getKeyType()+">" : "");
addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : "");
addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? extends "+type.getKeyType()+", ? extends "+valueType.getValueType()+">" : "<? extends "+type.getKeyType()+">") : (valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", type.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" KSK_GENERIC_TYPE", type.isObject() ? "<%s, "+type.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" KKS_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" KSS_GENERIC_TYPE", type.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : "");
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
if(type.needsCustomJDKType())
{
addSimpleMapper("JAVA_TYPE", type.getCustomJDKType().getKeyType());
addSimpleMapper("SANITY_CAST", "castTo"+type.getFileType());
}
addSimpleMapper("JAVA_CLASS", type.getCustomJDKType().getClassType());
if(valueType.needsCustomJDKType())
{
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
}
addComment("@ArrayType", "@param <%s> the type of array that the operation should be applied");
addComment("@Type", "@param <%s> the type of elements maintained by this Collection");
addValueComment("@ValueArrayType", "@param <%s> the type of array that the operation should be applied");
addValueComment("@ValueType", "@param <%s> the type of elements maintained by this Collection");
addAnnontion("@PrimitiveOverride", "@Override");
addSimpleMapper("@PrimitiveDoc", "");
addAnnontion("@Primitive", "@Deprecated");
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
addValueAnnontion("@ValuePrimitive", "@Deprecated");
return this;
}
public GlobalVariables createHelperVariables()
{
createHelperVars(type, false, "KEY");
createHelperVars(valueType, true, "VALUE");
return this;
}
private void createHelperVars(ClassType type, boolean value, String fix)
{
addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces();
addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces();
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces();
addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType());
addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces();
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces();
else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
}
public GlobalVariables createPreFunctions()
{
addSimpleMapper("ENTRY_SET", type.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
return this;
}
public GlobalVariables createClassTypes()
{
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier");
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
//Final Classes
addClassMapper("ARRAY_LIST", "ArrayList");
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
addClassMapper("LINKED_LIST", "LinkedList");
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
addClassMapper("HEAP_PRIORITY_QUEUE", "HeapPriorityQueue");
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
addAbstractMapper("IMMUTABLE_HASH_SET", "Immutable%sOpenHashSet");
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
addClassMapper("HASH_SET", "OpenHashSet");
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");
addBiClassMapper("MUTABLE_PAIR", "MutablePair", "");
addClassMapper("RB_TREE_SET", "RBTreeSet");
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
addClassMapper("ARRAY_SET", "ArraySet");
addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2");
//Final UnitTest Classes
addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection");
addAbstractMapper("MINIMAL_SET", "Minimal%sSet");
addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester");
addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester");
addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester");
addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester");
addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester");
addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester");
addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester");
addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2");
addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester");
addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester");
addClassMapper("ITERATOR_TESTER", "IteratorTester");
addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder");
addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder");
addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder");
addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder");
addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder");
addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder");
addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder");
addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder");
addAbstractBiMapper("NAVIGABLE_MAP_TEST_BUILDER", "%sNavigableMapTestSuiteBuilder", "2");
addAbstractBiMapper("SORTED_MAP_TEST_BUILDER", "%sSortedMapTestSuiteBuilder", "2");
addAbstractBiMapper("ORDERED_MAP_TEST_BUILDER", "%sOrderedMapTestSuiteBuilder", "2");
addAbstractBiMapper("MAP_TEST_BUILDER", "%sMapTestSuiteBuilder", "2");
addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2");
addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests");
addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator");
addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator");
addClassMapper("LIST_TESTS", "ListTests");
addClassMapper("SET_TESTS", "SetTests");
addClassMapper("QUEUE_TESTS", "QueueTests");
addBiClassMapper("MAP_TESTS", "MapTests", "2");
//Abstract Classes
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
addClassMapper("SUB_LIST", "SubList");
addAbstractMapper("BASE_TASK", "Base%sTask");
//Helper Classes
addClassMapper("LISTS", "Lists");
addClassMapper("SETS", "Sets");
addClassMapper("COLLECTIONS", "Collections");
addClassMapper("ARRAYS", "Arrays");
addClassMapper("PRIORITY_QUEUES", "PriorityQueues");
addClassMapper("SPLIT_ITERATORS", "Splititerators");
addClassMapper("ITERATORS", "Iterators");
addClassMapper("ITERABLES", "Iterables");
addBiClassMapper("MAPS", "Maps", "2");
addClassMapper("SAMPLE_ELEMENTS", "Samples");
//UnitTest Helper Classes
addClassMapper("HELPERS", "Helpers");
addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator");
addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator");
addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator");
addAbstractMapper("TEST_NAVIGABLE_SET_GENERATOR", "Test%sNavigableSetGenerator");
addAbstractMapper("TEST_SORTED_SET_GENERATOR", "Test%sSortedSetGenerator");
addAbstractMapper("TEST_ORDERED_SET_GENERATOR", "Test%sOrderedSetGenerator");
addAbstractMapper("TEST_SET_GENERATOR", "Test%sSetGenerator");
addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator");
addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator");
addAbstractBiMapper("SIMPLE_MAP_TEST_GENERATOR", "Simple%sMapTestGenerator", "2");
addAbstractBiMapper("DERIVED_MAP_GENERATORS", "Derived%sMapGenerators", "2");
addAbstractBiMapper("TEST_ORDERED_MAP_GENERATOR", "Test%sOrderedMapGenerator", "2");
addAbstractBiMapper("TEST_SORTED_MAP_GENERATOR", "Test%sSortedMapGenerator", "2");
addAbstractBiMapper("TEST_MAP_GENERATOR", "Test%sMapGenerator", "2");
//Interfaces
addClassMapper("LIST_ITERATOR", "ListIterator");
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
addBiClassMapper("BI_CONSUMER", "Consumer", "");
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
addClassMapper("SPLIT_ITERATOR", "Splititerator");
addClassMapper("ITERATOR", "Iterator");
addClassMapper("ITERABLE", "Iterable");
addClassMapper("COLLECTION", "Collection");
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction");
addBiClassMapper("FUNCTION", "Function", "2");
addClassMapper("LIST_ITER", "ListIter");
addClassMapper("LIST", "List");
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
addBiClassMapper("MAP", "Map", "2");
addClassMapper("NAVIGABLE_SET", "NavigableSet");
addBiClassMapper("PAIR", "Pair", "");
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
addClassMapper("PREDICATE", "2BooleanFunction");
addClassMapper("SORTED_SET", "SortedSet");
addClassMapper("ORDERED_SET", "OrderedSet");
addClassMapper("SET", "Set");
addClassMapper("STRATEGY", "Strategy");
addClassMapper("STACK", "Stack");
addClassMapper("SUPPLIER", "Supplier");
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
addClassMapper("TASK", "Task");
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
if(type.isObject())
{
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
addSimpleMapper("CONSUMER", "Consumer");
addSimpleMapper("IARRAY", "IObjectArray");
}
else
{
if(valueType.isObject())
{
addSimpleMapper("VALUE_CONSUMER", "Consumer");
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
}
else addClassMapper("CONSUMER", "Consumer");
addFunctionMappers("IARRAY", "I%sArray");
}
addSimpleMapper("VALUE_COMPARATOR", valueType.isObject() ? "Comparator" : String.format("%sComparator", valueType.getNonFileType()));
addSimpleMapper("COMPARATOR", type.isObject() ? "Comparator" : String.format("%sComparator", type.getNonFileType()));
return this;
}
public GlobalVariables createFunctions()
{
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
addFunctionValueMapper("BULK_MERGE", "mergeAll");
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
addFunctionValueMapper("COMPUTE", "compute");
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
addFunctionMapper("DEQUEUE", "dequeue");
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
addFunctionMappers("POLL_LAST_ENTRY_KEY", "pollLast%sKey");
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
addFunctionMapper("POLL_LAST_KEY", "pollLast");
addFunctionMappers("FIRST_ENTRY_KEY", "first%sKey");
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
addFunctionMapper("FIRST_KEY", "first");
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
addFunctionMappers("ENTRY_KEY", "get%sKey");
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
addFunctionMappers("KEY_ENTRY", "set%sKey");
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
addFunctionMapper("GET_KEY", "get");
if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
else addSimpleMapper("GET_VALUE", "get");
addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType());
addFunctionMapper("LAST_KEY", "last");
addFunctionValueMapper("MERGE", "merge");
addFunctionMapper("NEXT", "next");
addFunctionMapper("PREVIOUS", "previous");
addFunctionMapper("REMOVE_SWAP", "swapRemove");
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
else addSimpleMapper("REMOVE_VALUE", "remove");
addFunctionMapper("REMOVE_KEY", "rem");
addFunctionMapper("REMOVE_LAST", "removeLast");
addFunctionMapper("REMOVE", "remove");
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
addFunctionMappers("SORT", "sort%ss");
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array");
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
addSimpleMapper("[SPACE]", " ");
operators.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
return this;
}
public GlobalVariables createFlags()
{
flags.add("TYPE_"+type.getCapType());
flags.add("VALUE_"+valueType.getCapType());
if(type == valueType) flags.add("SAME_TYPE");
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
if(!valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
return this;
}
public TemplateProcess create(String fileName, String splitter, boolean valueOnly)
{
TemplateProcess process = new TemplateProcess(String.format(fileName+".java", (splitter != null ? type.getFileType()+splitter+valueType.getFileType() : (valueOnly ? valueType : type).getFileType())));
process.setPathBuilder(new PathBuilder(type.getPathType()));
process.addFlags(flags);
process.addMappers(operators);
return process;
}
public void testComparason(List<String> keys, List<String> values) {
List<IMapper> copy = new ArrayList<>(operators);
Collections.shuffle(copy);
copy.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
operators.stream().map(IMapper::getSearchValue).forEach(keys::add);
copy.stream().map(IMapper::getSearchValue).forEach(values::add);
}
private int sort(String key, String value) {
if(value.contains(key)) return 1;
else if(key.contains(value)) return -1;
return 0;
}
public ClassType getType()
{
return type;
}
private void addClassMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+replacement));
operators.add(new SimpleMapper(pattern, pattern, type.getFileType()+replacement));
}
private void addBiClassMapper(String pattern, String replacement, String splitter)
{
operators.add(new SimpleMapper("KEY_"+pattern, "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement));
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
operators.add(new SimpleMapper(pattern, pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
}
private void addAbstractMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getFileType())));
}
private void addAbstractBiMapper(String pattern, String replacement, String splitter)
{
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getFileType()+splitter+valueType.getFileType())));
}
private void addFunctionMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, replacement+valueType.getNonFileType()));
operators.add(new SimpleMapper(pattern, pattern, replacement+type.getNonFileType()));
}
private void addFunctionValueMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, replacement+valueType.getNonFileType()));
}
private void addFunctionMappers(String pattern, String replacement)
{
operators.add(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, type.getNonFileType())));
}
private void addFunctionValueMappers(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, String.format(replacement, valueType.getNonFileType())));
}
private void addSimpleMapper(String pattern, String replacement)
{
operators.add(new SimpleMapper(pattern, pattern, replacement));
}
private void addAnnontion(String pattern, String value)
{
if(type == ClassType.OBJECT) operators.add(new LineMapper(pattern, pattern));
else operators.add(new SimpleMapper(pattern, pattern, value));
}
private void addValueAnnontion(String pattern, String value)
{
if(valueType == ClassType.OBJECT) operators.add(new LineMapper(pattern, pattern));
else operators.add(new SimpleMapper(pattern, pattern, value));
}
private void addComment(String pattern, String value)
{
if(type == ClassType.OBJECT) operators.add(new InjectMapper(pattern, pattern, value).removeBraces());
else operators.add(new LineMapper(pattern, pattern));
}
private void addValueComment(String pattern, String value)
{
if(valueType == ClassType.OBJECT) operators.add(new InjectMapper(pattern, pattern, value).removeBraces());
else operators.add(new LineMapper(pattern, pattern));
}
private InjectMapper addInjectMapper(String pattern, String replacement)
{
InjectMapper mapper = new InjectMapper(pattern, pattern, replacement);
operators.add(mapper);
return mapper;
}
private ArgumentMapper addArgumentMapper(String pattern, String replacement)
{
return addArgumentMapper(pattern, replacement, ", ");
}
private ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter)
{
ArgumentMapper mapper = new ArgumentMapper(pattern, pattern, replacement, splitter);
operators.add(mapper);
return mapper;
}
class PathBuilder implements UnaryOperator<Path>
{
String before;
public PathBuilder(String before)
{
this.before = before;
}
@Override
public Path apply(Path t)
{
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
}
}
}

View File

@ -1,122 +0,0 @@
package speiger.src.builder;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import speiger.src.builder.modules.AsyncModule;
import speiger.src.builder.modules.BaseModule;
import speiger.src.builder.modules.CollectionModule;
import speiger.src.builder.modules.FunctionModule;
import speiger.src.builder.modules.JavaModule;
import speiger.src.builder.modules.ListModule;
import speiger.src.builder.modules.MapModule;
import speiger.src.builder.modules.PairModule;
import speiger.src.builder.modules.PrioQueueModule;
import speiger.src.builder.modules.SetModule;
import speiger.src.builder.processor.TemplateProcess;
import speiger.src.builder.processor.TemplateProcessor;
@SuppressWarnings("javadoc")
public class ModuleBuilder extends TemplateProcessor
{
List<ModulePackage> simplePackages = new ArrayList<>();
List<ModulePackage> biPackages = new ArrayList<>();
List<ModulePackage> enumPackages = new ArrayList<>();
Map<String, RequiredType> requirements = new HashMap<>();
public static void main(String...args)
{
try
{
new ModuleBuilder(true).process(true);
}
catch(IOException e)
{
e.printStackTrace();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
public ModuleBuilder(boolean silencedSuccess)
{
super(silencedSuccess, Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
}
public ModuleBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
{
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
}
@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());
finishPackages();
}
public void addModule(BaseModule module)
{
biPackages.forEach(module::init);
module.cleanup();
}
private void finishPackages()
{
biPackages.forEach(ModulePackage::finish);
}
private void prepPackages()
{
for(ModulePackage entry : ModulePackage.createPackages())
{
entry.setRequirements(requirements::put);
biPackages.add(entry);
if(entry.isSame()) simplePackages.add(entry);
if(entry.isEnumValid()) enumPackages.add(entry);
}
}
@Override
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
{
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
for(int i = 0,m=packages.size();i<m;i++)
{
packages.get(i).process(fileName, process);
}
}
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
if(type == null) return simplePackages;
if(type == RequiredType.BI_CLASS) return biPackages;
if(type == RequiredType.ENUM) return enumPackages;
return Collections.emptyList();
}
@Override
protected boolean isFileValid(Path fileName) { return true; }
@Override
protected boolean relativePackages() { return true; }
@Override
protected boolean debugUnusedMappers() { return false; }
}

View File

@ -21,6 +21,7 @@ import speiger.src.builder.processor.TemplateProcess;
@SuppressWarnings("javadoc")
public class ModulePackage
{
private static final BiConsumer<String, RequiredType> VOID = (K, V) -> {};
public static final ClassType[] TYPE = ClassType.values();
final ClassType keyType;
final ClassType valueType;
@ -30,7 +31,7 @@ public class ModulePackage
List<Predicate<String>> blockedFilters = new ArrayList<>();
List<IMapper> mappers = new ArrayList<>();
Set<String> flags = new LinkedHashSet<>();
BiConsumer<String, RequiredType> requirements = (K, V) -> {};
BiConsumer<String, RequiredType> requirements = VOID;
public ModulePackage(ClassType keyType, ClassType valueType) {
this.keyType = keyType;
@ -38,6 +39,7 @@ public class ModulePackage
}
public void finish() {
requirements = VOID;
mappers.sort(Comparator.comparing(IMapper::getSearchValue, Comparator.comparingInt(String::length).reversed()));
mappers.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
}

View File

@ -7,8 +7,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -16,25 +15,34 @@ import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
import speiger.src.builder.modules.AsyncModule;
import speiger.src.builder.modules.BaseModule;
import speiger.src.builder.modules.CollectionModule;
import speiger.src.builder.modules.FunctionModule;
import speiger.src.builder.modules.JavaModule;
import speiger.src.builder.modules.ListModule;
import speiger.src.builder.modules.MapModule;
import speiger.src.builder.modules.PairModule;
import speiger.src.builder.modules.PrioQueueModule;
import speiger.src.builder.modules.SetModule;
import speiger.src.builder.processor.TemplateProcess;
import speiger.src.builder.processor.TemplateProcessor;
@SuppressWarnings("javadoc")
public class PrimitiveCollectionsBuilder extends TemplateProcessor
{
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
EnumMap<ClassType, List<Predicate<String>>> blockedPredicate = new EnumMap<>(ClassType.class);
Map<String, String> nameRemapper = new HashMap<>();
Map<String, String> biRequired = new HashMap<>();
Set<String> enumRequired = new HashSet<>();
public static final ClassType[] TYPE = ClassType.values();
List<GlobalVariables> variables = new ArrayList<>();
List<GlobalVariables> biVariables = new ArrayList<>();
List<GlobalVariables> enumVariables = new ArrayList<>();
boolean special = false;
private static final int SPECIAL = 0x1; //Detects if the Builder is generating tests
private static final int LOAD = 0x2; //If Configs should be loaded
private static final int ANTI_SAVE = SPECIAL | LOAD; //If save should be disabled since load/save shouldn't happen at the same time.
private static final int SAVE = 0x4; //if the configuration should be created
List<ModulePackage> simplePackages = new ArrayList<>();
List<ModulePackage> biPackages = new ArrayList<>();
List<ModulePackage> enumPackages = new ArrayList<>();
Map<String, RequiredType> requirements = new HashMap<>();
SettingsManager manager = new SettingsManager();
int flags;
public PrimitiveCollectionsBuilder()
{
@ -56,17 +64,26 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
}
private PrimitiveCollectionsBuilder setSpecial() {
special = true;
private PrimitiveCollectionsBuilder setFlags(int flags) {
this.flags = flags;
if((flags & ANTI_SAVE) != 0) {
this.flags &= ~SAVE;
}
return this;
}
private static PrimitiveCollectionsBuilder createTests(boolean silent) {
return new PrimitiveCollectionsBuilder(silent, Paths.get("src/builder/resources/speiger/assets/tests/templates/"), Paths.get("src/test/java/speiger/src/tests/"), Paths.get("src/builder/resources/speiger/assets/tests/")).setSpecial();
private static PrimitiveCollectionsBuilder createTests(boolean silent, int flags) {
return new PrimitiveCollectionsBuilder(silent,
Paths.get("src/builder/resources/speiger/assets/tests/templates/"),
Paths.get("src/test/java/speiger/src/tests/"),
Paths.get("src/builder/resources/speiger/assets/tests/")).setFlags(flags | SPECIAL);
}
private static PrimitiveCollectionsBuilder createTesters(boolean silent) {
return new PrimitiveCollectionsBuilder(silent, Paths.get("src/builder/resources/speiger/assets/testers/templates/"), Paths.get("src/test/java/speiger/src/testers/"), Paths.get("src/builder/resources/speiger/assets/testers/")).setSpecial();
private static PrimitiveCollectionsBuilder createTesters(boolean silent, int flags) {
return new PrimitiveCollectionsBuilder(silent,
Paths.get("src/builder/resources/speiger/assets/testers/templates/"),
Paths.get("src/test/java/speiger/src/testers/"),
Paths.get("src/builder/resources/speiger/assets/testers/")).setFlags(flags | SPECIAL);
}
@Override
@ -90,7 +107,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
@Override
protected void afterFinish()
{
if(!special && getVersion() > 8)
if((flags & SPECIAL) == 0 && getVersion() > 8)
{
Path basePath = Paths.get("src/main/java");
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
@ -107,168 +124,60 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
@Override
protected void init()
{
variables.clear();
for(ClassType clzType : TYPE)
{
for(ClassType subType : TYPE)
{
create(clzType, subType);
}
}
enumRequired.add("EnumMap");
enumRequired.add("LinkedEnumMap");
biRequired.put("BiConsumer", "");
biRequired.put("UnaryOperator", "");
biRequired.put("Pair", "");
biRequired.put("MutablePair", "");
biRequired.put("ImmutablePair", "");
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
nameRemapper.put("BiConsumer", "%sConsumer");
nameRemapper.put("IArray", "I%sArray");
nameRemapper.put("AbstractMap", "Abstract%sMap");
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
nameRemapper.put("AbstractSet", "Abstract%sSet");
nameRemapper.put("AbstractList", "Abstract%sList");
nameRemapper.put("EnumMap", "Enum2%sMap");
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
nameRemapper.put("ImmutableList", "Immutable%sList");
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
//UnitTesters
nameRemapper.put("AbstractIteratorTester", "Abstract%sIteratorTester");
nameRemapper.put("MinimalCollection", "Minimal%sCollection");
nameRemapper.put("MinimalSet", "Minimal%sSet");
nameRemapper.put("TestCollectionGenerator", "Test%sCollectionGenerator");
nameRemapper.put("TestQueueGenerator", "Test%sQueueGenerator");
nameRemapper.put("TestListGenerator", "Test%sListGenerator");
nameRemapper.put("TestNavigableSetGenerator", "Test%sNavigableSetGenerator");
nameRemapper.put("TestSortedSetGenerator", "Test%sSortedSetGenerator");
nameRemapper.put("TestOrderedSetGenerator", "Test%sOrderedSetGenerator");
nameRemapper.put("TestSetGenerator", "Test%sSetGenerator");
nameRemapper.put("AbstractContainerTester", "Abstract%sContainerTester");
nameRemapper.put("AbstractCollectionTester", "Abstract%sCollectionTester");
nameRemapper.put("AbstractQueueTester", "Abstract%sQueueTester");
nameRemapper.put("AbstractListTester", "Abstract%sListTester");
nameRemapper.put("AbstractListIndexOfTester", "Abstract%sListIndexOfTester");
nameRemapper.put("AbstractSetTester", "Abstract%sSetTester");
nameRemapper.put("SimpleTestGenerator", "Simple%sTestGenerator");
nameRemapper.put("SimpleQueueTestGenerator", "Simple%sQueueTestGenerator");
nameRemapper.put("TestMapGenerator", "Test%sMapGenerator");
nameRemapper.put("TestSortedMapGenerator", "Test%sSortedMapGenerator");
nameRemapper.put("TestOrderedMapGenerator", "Test%sOrderedMapGenerator");
nameRemapper.put("SimpleMapTestGenerator", "Simple%sMapTestGenerator");
nameRemapper.put("DerivedMapGenerators", "Derived%sMapGenerators");
nameRemapper.put("AbstractMapTester", "Abstract%sMapTester");
nameRemapper.put("TestMap", "Test%sMap");
biRequired.put("PairTester", "");
addBiClass("TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "OrderedMapTestSuiteBuilder", "MapTests", "MapConstructorTests", "TestMap");
addBiClass("MapAddToTester", "MapSubFromTester", "MapClearTester", "MapComputeIfAbsentTester", "MapComputeIfPresentTester", "MapComputeTester", "MapCopyTester", "MapContainsTester", "MapContainsKeyTester", "MapContainsValueTester", "MapCreatorTester", "MapEntrySetTester",
"MapEqualsTester", "MapForEachTester", "MapGetOrDefaultTester", "MapGetTester", "MapHashCodeTester", "MapIsEmptyTester", "MapMergeTester", "MapMergeBulkTester", "MapPutAllArrayTester", "MapPutAllTester", "MapPutIfAbsentTester", "MapPutTester",
"MapRemoveEntryTester", "MapRemoveOrDefaultTester", "MapRemoveTester", "MapReplaceAllTester", "MapReplaceEntryTester", "MapReplaceTester", "MapSizeTester", "MapSupplyIfAbsentTester", "MapToStringTester",
"NavigableMapNavigationTester", "SortedMapNavigationTester", "OrderedMapNavigationTester", "OrderedMapMoveTester", "MapConstructorTester");
addBlockage(ClassType.OBJECT, "CollectionStreamTester", "ListFillBufferTester");
addBlockage(ClassType.BOOLEAN, "TestOrderedSetGenerator", "TestSortedSetGenerator", "TestNavigableSetGenerator", "CollectionRemoveIfTester", "CollectionStreamTester", "ListFillBufferTester", "ListReplaceAllTester", "NavigableSetNavigationTester", "SetTests", "MapConstructorTests", "TestMap", "QueueTests");
addBlockage(ClassType.BOOLEAN, "OrderedSetMoveTester", "OrderedSetNavigationTester", "SortedSetNaviationTester", "SetTestSuiteBuilder", "OrderedSetTestSuiteBuilder", "SortedSetTestSuiteBuilder", "NavigableSetTestSuiteBuilder", "SortedSetSubsetTestSetGenerator", "OrderedMapNavigationTester", "OrderedMapTestSuiteBuilder", "OrderedSetIterationTester", "SortedSetIterationTester");
addBlockage(ClassType.BOOLEAN, "TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "MapTests");
addBlockage(ClassType.BOOLEAN, T -> T.endsWith("Tester") && (T.startsWith("Iterable") ||T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
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());
finishPackages();
}
protected void create(ClassType mainType, ClassType subType)
public void addModule(BaseModule module)
{
GlobalVariables type = new GlobalVariables(mainType, subType);
type.createFlags();
type.createHelperVariables();
type.createVariables();
type.createPreFunctions();
type.createClassTypes();
type.createFunctions();
if(mainType == subType) variables.add(type);
biVariables.add(type);
if(mainType.isObject()) enumVariables.add(type);
module.setManager(manager);
biPackages.forEach(module::init);
module.cleanup();
}
protected void addBiClass(String...classNames)
private void finishPackages()
{
for(String s : classNames)
{
biRequired.put(s, "2");
}
biPackages.forEach(ModulePackage::finish);
if((flags & SAVE) != 0) manager.save();
}
protected void addBlockage(ClassType type, Predicate<String> filter)
private void prepPackages()
{
blockedPredicate.computeIfAbsent(type, T -> new ArrayList<>()).add(filter);
}
protected void addBlockage(ClassType type, String...args)
if((flags & LOAD) != 0) manager.load();
for(ModulePackage entry : ModulePackage.createPackages())
{
for(String s : args)
{
EnumSet<ClassType> set = blocked.get(s);
if(set == null)
{
set = EnumSet.noneOf(ClassType.class);
blocked.put(s, set);
entry.setRequirements(requirements::put);
biPackages.add(entry);
if(entry.isSame()) simplePackages.add(entry);
if(entry.isEnumValid()) enumPackages.add(entry);
}
set.add(type);
}
}
public void test() throws InterruptedException, IOException
{
init();
List<String> keys = new ArrayList<>();
List<String> values = new ArrayList<>();
for(int i = 0,m=variables.size();i<m;i++) {
variables.get(i).testComparason(keys, values);
}
System.out.println("Original: "+keys);
System.out.println("Copy: "+values);
}
@Override
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
{
String splitter = biRequired.get(name);
boolean valueRequired = enumRequired.contains(name);
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
for(int i = 0,m=vars.size();i<m;i++)
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
for(int i = 0,m=packages.size();i<m;i++)
{
GlobalVariables type = vars.get(i);
if(isAllowed(type.getType(), name))
{
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
}
packages.get(i).process(fileName, process);
}
}
protected boolean isAllowed(ClassType type, String fileName)
{
EnumSet<ClassType> types = blocked.get(fileName);
if(types != null && types.contains(type)) return false;
List<Predicate<String>> list = blockedPredicate.get(type);
if(list != null) {
for(int i = 0,m=list.size();i<m;i++) {
if(list.get(i).test(fileName)) return false;
}
}
return true;
}
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
if(enumRequired.contains(name)) return enumVariables;
if(bi) return biVariables;
return variables;
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
if(type == null) return simplePackages;
if(type == RequiredType.BI_CLASS) return biPackages;
if(type == RequiredType.ENUM) return enumPackages;
return Collections.emptyList();
}
private String getModuleInfo(Path basePath) {
@ -326,14 +235,17 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
{
Set<String> flags = new HashSet<>(Arrays.asList(args));
boolean silent = flags.contains("silent");
boolean force = !flags.contains("force");
boolean force = flags.contains("force");
boolean tests = flags.contains("tests");
boolean forceTests = flags.contains("force-tests");
boolean load = flags.contains("load");
boolean save = !flags.contains("save");
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
// new PrimitiveCollectionsBuilder(silent).test();
new PrimitiveCollectionsBuilder(silent).process(force);
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);
if(tests) {
createTests(silent).process(force || forceTests);
createTesters(silent).process(force || forceTests);
createTests(silent, flag).process(force || forceTests);
createTesters(silent, flag).process(force || forceTests);
}
}
catch(InterruptedException | IOException e)

View File

@ -0,0 +1,105 @@
package speiger.src.builder;
import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Set;
import java.util.TreeSet;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import speiger.src.builder.modules.BaseModule;
@SuppressWarnings("javadoc")
public class SettingsManager
{
boolean loaded;
JsonObject data = new JsonObject();
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType, String entry)
{
if(!loaded) return true;
if(!isEnabled(data, base.getModuleName())) return false;
JsonObject result = getObject(data, keyType.getClassPath());
if(base.isBiModule()) result = getObject(result, valueType.getClassPath());
result = getObject(result, base.getModuleName());
return result.size() <= 0 || (isEnabled(result, "enabled") && isEnabled(result, entry));
}
public void addModule(BaseModule module) {
if(loaded) return;
String moduleName = module.getModuleName();
moduleNames.add(moduleName);
data.addProperty(moduleName, true);
if(module.isBiModule()) {
for(ClassType keyType : ModulePackage.TYPE) {
for(ClassType valueType : ModulePackage.TYPE) {
JsonObject obj = new JsonObject();
obj.addProperty("enabled", true);
for(String key : module.getModuleKeys(keyType, valueType)) {
obj.addProperty(key, true);
}
addModule(keyType, valueType, true, moduleName, obj);
}
}
return;
}
for(ClassType keyType : ModulePackage.TYPE) {
JsonObject obj = new JsonObject();
obj.addProperty("enabled", true);
for(String key : module.getModuleKeys(keyType, keyType)) {
obj.addProperty(key, true);
}
addModule(keyType, keyType, false, moduleName, obj);
}
}
public void load() {
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
data = JsonParser.parseReader(reader).getAsJsonObject();
loaded = true;
}
catch(Exception e) { e.printStackTrace(); }
}
public void save() {
data.asMap().keySet().removeAll(moduleNames);
JsonObject result = new JsonObject();
for(String s : moduleNames) {
result.addProperty(s, true);
}
result.asMap().putAll(data.asMap());
try(JsonWriter writer = new JsonWriter(Files.newBufferedWriter(Paths.get("ModulSettings.json")))) {
writer.setIndent("\t");
Streams.write(result, writer);
}
catch(Exception e) { e.printStackTrace(); }
}
private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
JsonObject result = getObject(data, keyType.getClassPath());
if(bi) {
result = getObject(result, valueType.getClassPath());
}
result.add(moduleName, obj);
}
private JsonObject getObject(JsonObject data, String name) {
JsonObject obj = data.getAsJsonObject(name);
if(obj == null) {
obj = new JsonObject();
data.add(name, obj);
}
return obj;
}
private boolean isEnabled(JsonObject obj, String key) {
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
return true;
}
}

View File

@ -4,18 +4,20 @@ package speiger.src.builder.modules;
public class AsyncModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadClasses();
}
public String getModuleName() { return "Async"; }
@Override
protected void loadVariables() {}
@Override
protected void loadRemappers() {}
@Override
protected void loadTestClasses() {}
@Override
protected void loadFunctions() {}
@Override
protected void loadFlags() {}
@Override
protected void loadFlags()
{
}
private void loadClasses()
protected void loadClasses()
{
//Abstract Classes
addAbstractMapper("BASE_TASK", "Base%sTask");

View File

@ -1,10 +1,13 @@
package speiger.src.builder.modules;
import java.util.Collections;
import java.util.Set;
import java.util.function.Predicate;
import speiger.src.builder.ClassType;
import speiger.src.builder.ModulePackage;
import speiger.src.builder.RequiredType;
import speiger.src.builder.SettingsManager;
import speiger.src.builder.mappers.ArgumentMapper;
import speiger.src.builder.mappers.InjectMapper;
import speiger.src.builder.mappers.LineMapper;
@ -13,16 +16,25 @@ import speiger.src.builder.mappers.SimpleMapper;
@SuppressWarnings("javadoc")
public abstract class BaseModule
{
SettingsManager manager;
ModulePackage entry;
protected ClassType keyType;
protected ClassType valueType;
public final void init(ModulePackage entry)
{
public final void setManager(SettingsManager manager) {
this.manager = manager;
manager.addModule(this);
}
public final void init(ModulePackage entry) {
this.entry = entry;
keyType = entry.getKeyType();
valueType = entry.getValueType();
loadVariables();
loadClasses();
loadTestClasses();
loadFunctions();
loadRemappers();
loadFlags();
}
@ -30,13 +42,26 @@ public abstract class BaseModule
entry = null;
keyType = null;
valueType = null;
manager = null;
}
protected abstract void loadVariables();
protected abstract void loadClasses();
protected abstract void loadTestClasses();
protected abstract void loadFunctions();
protected abstract void loadRemappers();
protected abstract void loadFlags();
protected void addFlag(String name)
{
public abstract String getModuleName();
public boolean isBiModule() { return false; }
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
protected boolean isModuleEnabled(String name) {
if(manager == null) return true;
return manager.isModuleEnabled(this, keyType, valueType, name);
}
protected void addFlag(String name) {
entry.addFlag(name);
}

View File

@ -1,34 +1,47 @@
package speiger.src.builder.modules;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class CollectionModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadClasses();
loadFunctions();
loadRemappers();
loadBlockades();
}
public String getModuleName() { return "Collection"; }
@Override
protected void loadFlags()
{
}
protected void loadVariables() { loadBlockades(); }
@Override
protected void loadFlags() {}
private void loadBlockades()
{
if(keyType.isObject()) addBlockedFiles("Stack");
if(keyType.isObject()) {
addBlockedFiles("Stack");
addBlockedFiles("CollectionStreamTester");
}
if(keyType == ClassType.BOOLEAN) {
addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester");
addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable"));
}
}
private void loadRemappers()
@Override
protected void loadRemappers()
{
//Main Classes
addRemapper("IArray", "I%sArray");
addRemapper("AbstractCollection", "Abstract%sCollection");
//Test Classes
addRemapper("AbstractIteratorTester", "Abstract%sIteratorTester");
addRemapper("MinimalCollection", "Minimal%sCollection");
addRemapper("TestCollectionGenerator", "Test%sCollectionGenerator");
addRemapper("AbstractContainerTester", "Abstract%sContainerTester");
addRemapper("AbstractCollectionTester", "Abstract%sCollectionTester");
addRemapper("SimpleTestGenerator", "Simple%sTestGenerator");
}
private void loadFunctions()
@Override
protected void loadFunctions()
{
addFunctionMapper("NEXT", "next");
addSimpleMapper("NEW_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getKeyType()+"Stream");
@ -38,7 +51,8 @@ public class CollectionModule extends BaseModule
addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Abstract Classes
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
@ -61,4 +75,25 @@ public class CollectionModule extends BaseModule
addClassMapper("STRATEGY", "Strategy");
}
@Override
protected void loadTestClasses()
{
//Implementation Classes
addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection");
addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester");
addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester");
addClassMapper("ITERATOR_TESTER", "IteratorTester");
addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder");
addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests");
//Abstract Classes
addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester");
addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester");
addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester");
//Helper Classes
addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator");
addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator");
}
}

View File

@ -4,26 +4,23 @@ package speiger.src.builder.modules;
public class FunctionModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadFunctions();
loadClasses();
loadRemappers();
loadBlockades();
}
public String getModuleName() { return "Function"; }
@Override
protected void loadFlags()
{
}
public boolean isBiModule() { return true; }
@Override
protected void loadVariables() { loadBlockades(); }
@Override
protected void loadFlags() {}
@Override
protected void loadTestClasses() {}
private void loadBlockades()
{
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
}
private void loadRemappers()
@Override
protected void loadRemappers()
{
addBiRequirement("BiConsumer", "");
addBiRequirement("UnaryOperator", "");
@ -31,13 +28,15 @@ public class FunctionModule extends BaseModule
addRemapper("BiConsumer", "%sConsumer");
}
private void loadFunctions()
@Override
protected void loadFunctions()
{
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
addSimpleMapper("TEST_VALUE", keyType.isObject() ? "getBoolean" : "get");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Interfaces
addBiClassMapper("BI_CONSUMER", "Consumer", "");

View File

@ -5,14 +5,14 @@ import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class JavaModule extends BaseModule
{
@Override
public String getModuleName() { return "Base"; }
@Override
protected void loadVariables()
{
createHelperVars(keyType, false, "KEY");
createHelperVars(valueType, true, "VALUE");
loadBaseVariables();
loadClasses();
loadFunctions();
}
@Override
@ -28,7 +28,11 @@ public class JavaModule extends BaseModule
if(valueType.needsCustomJDKType()) addFlag("JDK_VALUE");
}
private void loadFunctions()
@Override
protected void loadRemappers() {}
@Override
protected void loadFunctions()
{
addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType());
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
@ -42,7 +46,8 @@ public class JavaModule extends BaseModule
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
}
private void loadClasses()
@Override
protected void loadClasses()
{
addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate");
addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer");
@ -55,6 +60,13 @@ public class JavaModule extends BaseModule
addSimpleMapper("JAVA_BUFFER", keyType.getFileType()+"Buffer");
}
@Override
protected void loadTestClasses()
{
addClassMapper("HELPERS", "Helpers");
addClassMapper("SAMPLE_ELEMENTS", "Samples");
}
private void loadBaseVariables()
{
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());

View File

@ -1,31 +1,43 @@
package speiger.src.builder.modules;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class ListModule extends BaseModule
{
@Override
protected void loadVariables()
public String getModuleName() { return "List"; }
@Override
protected void loadVariables() { loadBlockedFiles(); }
@Override
protected void loadFlags() {}
private void loadBlockedFiles()
{
loadClasses();
loadFunctions();
loadRemappers();
if(keyType.isObject()) {
addBlockedFiles("ListFillBufferTester");
}
if(keyType == ClassType.BOOLEAN) {
addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
}
}
@Override
protected void loadFlags()
{
}
private void loadRemappers()
protected void loadRemappers()
{
//Main Classes
addRemapper("AbstractList", "Abstract%sList");
addRemapper("ImmutableList", "Immutable%sList");
addRemapper("CopyOnWriteList", "CopyOnWrite%sArrayList");
//Test Classes
addRemapper("AbstractListTester", "Abstract%sListTester");
addRemapper("AbstractListIndexOfTester", "Abstract%sListIndexOfTester");
addRemapper("TestListGenerator", "Test%sListGenerator");
}
private void loadFunctions()
@Override
protected void loadFunctions()
{
addFunctionMapper("GET_KEY", "get");
addFunctionMapper("REMOVE_LAST", "removeLast");
@ -34,7 +46,8 @@ public class ListModule extends BaseModule
addFunctionMappers("SORT", "sort%ss");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Implementation Classes
addClassMapper("ARRAY_LIST", "ArrayList");
@ -53,10 +66,22 @@ public class ListModule extends BaseModule
//Helper Classes
addClassMapper("LISTS", "Lists");
//Interfaces
addClassMapper("LIST", "List");
}
@Override
protected void loadTestClasses()
{
//Implementation Classes
addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder");
addClassMapper("LIST_TESTS", "ListTests");
//Abstract Classes
addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester");
addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester");
//Helper classes
addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator");
}
}

View File

@ -6,33 +6,36 @@ import speiger.src.builder.ClassType;
public class MapModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadFunctions();
loadClasses();
loadRemappers();
loadBlockades();
}
public String getModuleName() { return "Map"; }
@Override
protected void loadFlags()
{
}
public boolean isBiModule() { return true; }
@Override
protected void loadVariables() { loadBlockades(); }
@Override
protected void loadFlags() {}
private void loadBlockades()
{
if(keyType == ClassType.BOOLEAN)
{
//Main Classes
addBlockedFiles("SortedMap", "NavigableMap", "RBTreeMap", "AVLTreeMap");
addBlockedFiles("OrderedMap", "ArrayMap", "LinkedOpenHashMap", "LinkedOpenCustomHashMap");
addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
addBlockedFiles("ImmutableOpenHashMap", "OpenHashMap", "OpenCustomHashMap");
//Test Classes
addBlockedFiles("TestMap", "MapTests", "MapTestSuiteBuilder", "MapConstructorTests", "TestMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester");
addBlockedFiles("TestSortedMapGenerator", "NavigableMapTestSuiteBuilder", "SortedMapTestSuiteBuilder");
addBlockedFiles("TestOrderedMapGenerator");
addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
}
}
private void loadRemappers()
@Override
protected void loadRemappers()
{
//Main Classes
addBiRequirement("Map");
addBiRequirement("SortedMap");
addBiRequirement("OrderedMap");
@ -56,9 +59,71 @@ public class MapModule extends BaseModule
addRemapper("EnumMap", "Enum2%sMap");
addRemapper("LinkedEnumMap", "LinkedEnum2%sMap");
addRemapper("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
//Test Classes
addBiRequirement("TestMapGenerator");
addBiRequirement("TestSortedMapGenerator");
addBiRequirement("TestOrderedMapGenerator");
addBiRequirement("SimpleMapTestGenerator");
addBiRequirement("DerivedMapGenerators");
addBiRequirement("AbstractMapTester");
addBiRequirement("MapTestSuiteBuilder");
addBiRequirement("SortedMapTestSuiteBuilder");
addBiRequirement("NavigableMapTestSuiteBuilder");
addBiRequirement("OrderedMapTestSuiteBuilder");
addBiRequirement("MapTests");
addBiRequirement("MapConstructorTests");
addBiRequirement("TestMap");
addBiRequirement("MapAddToTester");
addBiRequirement("MapSubFromTester");
addBiRequirement("MapClearTester");
addBiRequirement("MapComputeIfAbsentTester");
addBiRequirement("MapComputeIfPresentTester");
addBiRequirement("MapComputeTester");
addBiRequirement("MapCopyTester");
addBiRequirement("MapContainsTester");
addBiRequirement("MapContainsKeyTester");
addBiRequirement("MapContainsValueTester");
addBiRequirement("MapCreatorTester");
addBiRequirement("MapEntrySetTester");
addBiRequirement("MapEqualsTester");
addBiRequirement("MapForEachTester");
addBiRequirement("MapGetOrDefaultTester");
addBiRequirement("MapGetTester");
addBiRequirement("MapHashCodeTester");
addBiRequirement("MapIsEmptyTester");
addBiRequirement("MapMergeTester");
addBiRequirement("MapMergeBulkTester");
addBiRequirement("MapPutAllArrayTester");
addBiRequirement("MapPutAllTester");
addBiRequirement("MapPutIfAbsentTester");
addBiRequirement("MapPutTester");
addBiRequirement("MapRemoveEntryTester");
addBiRequirement("MapRemoveOrDefaultTester");
addBiRequirement("MapRemoveTester");
addBiRequirement("MapReplaceAllTester");
addBiRequirement("MapReplaceEntryTester");
addBiRequirement("MapReplaceTester");
addBiRequirement("MapSizeTester");
addBiRequirement("MapSupplyIfAbsentTester");
addBiRequirement("MapToStringTester");
addBiRequirement("NavigableMapNavigationTester");
addBiRequirement("SortedMapNavigationTester");
addBiRequirement("OrderedMapNavigationTester");
addBiRequirement("OrderedMapMoveTester");
addBiRequirement("MapConstructorTester");
addRemapper("TestMapGenerator", "Test%sMapGenerator");
addRemapper("TestSortedMapGenerator", "Test%sSortedMapGenerator");
addRemapper("TestOrderedMapGenerator", "Test%sOrderedMapGenerator");
addRemapper("SimpleMapTestGenerator", "Simple%sMapTestGenerator");
addRemapper("DerivedMapGenerators", "Derived%sMapGenerators");
addRemapper("AbstractMapTester", "Abstract%sMapTester");
addRemapper("TestMap", "Test%sMap");
}
private void loadFunctions()
@Override
protected void loadFunctions()
{
addFunctionValueMapper("BULK_MERGE", "mergeAll");
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
@ -84,7 +149,8 @@ public class MapModule extends BaseModule
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Implementation Classes
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
@ -112,4 +178,27 @@ public class MapModule extends BaseModule
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
addBiClassMapper("MAP", "Map", "2");
}
@Override
protected void loadTestClasses()
{
//Implementation Classes
addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2");
addBiClassMapper("MAP_TESTS", "MapTests", "2");
addAbstractBiMapper("NAVIGABLE_MAP_TEST_BUILDER", "%sNavigableMapTestSuiteBuilder", "2");
addAbstractBiMapper("SORTED_MAP_TEST_BUILDER", "%sSortedMapTestSuiteBuilder", "2");
addAbstractBiMapper("ORDERED_MAP_TEST_BUILDER", "%sOrderedMapTestSuiteBuilder", "2");
addAbstractBiMapper("MAP_TEST_BUILDER", "%sMapTestSuiteBuilder", "2");
//Abstract Classes
addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2");
//Helper Classes
addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2");
addAbstractBiMapper("SIMPLE_MAP_TEST_GENERATOR", "Simple%sMapTestGenerator", "2");
addAbstractBiMapper("DERIVED_MAP_GENERATORS", "Derived%sMapGenerators", "2");
addAbstractBiMapper("TEST_ORDERED_MAP_GENERATOR", "Test%sOrderedMapGenerator", "2");
addAbstractBiMapper("TEST_SORTED_MAP_GENERATOR", "Test%sSortedMapGenerator", "2");
addAbstractBiMapper("TEST_MAP_GENERATOR", "Test%sMapGenerator", "2");
}
}

View File

@ -4,26 +4,32 @@ package speiger.src.builder.modules;
public class PairModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadClasses();
loadRemappers();
}
public String getModuleName() { return "Pair"; }
@Override
public boolean isBiModule() { return true; }
@Override
protected void loadVariables() {}
@Override
protected void loadFlags() {}
@Override
protected void loadFunctions() {}
@Override
protected void loadTestClasses() {}
@Override
protected void loadFlags()
{
}
private void loadRemappers()
protected void loadRemappers()
{
//Main Classes
addBiRequirement("Pair", "");
addBiRequirement("MutablePair", "");
addBiRequirement("ImmutablePair", "");
//Test Classes
addBiRequirement("PairTester", "");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Implementations
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");

View File

@ -1,27 +1,40 @@
package speiger.src.builder.modules;
import speiger.src.builder.ClassType;
@SuppressWarnings("javadoc")
public class PrioQueueModule extends BaseModule
{
@Override
protected void loadVariables()
public String getModuleName() { return "PriorityQueue"; }
@Override
protected void loadVariables() { loadBlockades(); }
@Override
protected void loadFlags() {}
@Override
protected void loadFunctions() {}
private void loadBlockades()
{
loadClasses();
loadReampper();
if(keyType == ClassType.BOOLEAN) {
addBlockedFiles("QueueTests");
}
}
@Override
protected void loadFlags()
{
}
private void loadReampper()
protected void loadRemappers()
{
//Main Classes
addRemapper("AbstractPriorityQueue", "Abstract%sPriorityQueue");
//Test Classes
addRemapper("TestQueueGenerator", "Test%sQueueGenerator");
addRemapper("AbstractQueueTester", "Abstract%sQueueTester");
addRemapper("SimpleQueueTestGenerator", "Simple%sQueueTestGenerator");
}
private void loadClasses()
@Override
protected void loadClasses()
{
//Implementation Classes
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
@ -37,6 +50,21 @@ public class PrioQueueModule extends BaseModule
//Interfaces
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
}
@Override
protected void loadTestClasses()
{
//Implementation Classes
addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder");
addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder");
addClassMapper("QUEUE_TESTS", "QueueTests");
//Abstract Classes
addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester");
//Helper Classes
addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator");
addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator");
}
}

View File

@ -6,37 +6,47 @@ import speiger.src.builder.ClassType;
public class SetModule extends BaseModule
{
@Override
protected void loadVariables()
{
loadClasses();
loadFunctions();
loadReamppers();
loadBlockades();
}
public String getModuleName() { return "Set"; }
@Override
protected void loadFlags()
{
}
protected void loadVariables() { loadBlockades(); }
@Override
protected void loadFlags() {}
private void loadBlockades()
{
if(keyType == ClassType.BOOLEAN)
{
//Main Classes
addBlockedFiles("SortedSet", "NavigableSet", "AVLTreeSet", "RBTreeSet");
addBlockedFiles("OrderedSet", "ArraySet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
addBlockedFiles("OpenHashSet", "OpenCustomHashSet", "ImmutableOpenHashSet");
//Test Classes
addBlockedFiles("SetTests", "SetTestSuiteBuilder");
addBlockedFiles("OrderedSetTestSuiteBuilder", "TestOrderedSetGenerator", "OrderedSetMoveTester", "OrderedSetNavigationTester", "OrderedMapNavigationTester", "OrderedMapTestSuiteBuilder", "OrderedSetIterationTester");
addBlockedFiles("SortedSetTestSuiteBuilder", "TestSortedSetGenerator", "SortedSetNaviationTester", "SortedSetSubsetTestSetGenerator", "SortedSetIterationTester", "SortedSetNaviationTester");
addBlockedFiles("NavigableSetTestSuiteBuilder", "TestNavigableSetGenerator", "NavigableSetNavigationTester");
}
}
private void loadReamppers()
@Override
protected void loadRemappers()
{
//Main Classes
addRemapper("AbstractSet", "Abstract%sSet");
addRemapper("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
//Test Classes
addRemapper("MinimalSet", "Minimal%sSet");
addRemapper("TestNavigableSetGenerator", "Test%sNavigableSetGenerator");
addRemapper("TestSortedSetGenerator", "Test%sSortedSetGenerator");
addRemapper("TestOrderedSetGenerator", "Test%sOrderedSetGenerator");
addRemapper("TestSetGenerator", "Test%sSetGenerator");
addRemapper("AbstractSetTester", "Abstract%sSetTester");
}
private void loadFunctions()
@Override
protected void loadFunctions()
{
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
addFunctionMapper("POLL_LAST_KEY", "pollLast");
@ -44,7 +54,31 @@ public class SetModule extends BaseModule
addFunctionMapper("LAST_KEY", "last");
}
private void loadClasses()
@Override
protected void loadTestClasses()
{
//Implementation Classes
addAbstractMapper("MINIMAL_SET", "Minimal%sSet");
addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder");
addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder");
addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder");
addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder");
addClassMapper("SET_TESTS", "SetTests");
//Abstract Classes
addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester");
//Helper Classes
addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator");
addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator");
addAbstractMapper("TEST_NAVIGABLE_SET_GENERATOR", "Test%sNavigableSetGenerator");
addAbstractMapper("TEST_SORTED_SET_GENERATOR", "Test%sSortedSetGenerator");
addAbstractMapper("TEST_ORDERED_SET_GENERATOR", "Test%sOrderedSetGenerator");
addAbstractMapper("TEST_SET_GENERATOR", "Test%sSetGenerator");
}
@Override
protected void loadClasses()
{
//Implementation Classes
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");