forked from Speiger/Primitive-Collections
Start of the Modularization
-Added: Base code to modularize the project. -Added: Javas Base Module.
This commit is contained in:
parent
25a7cd060a
commit
b065ebe9ba
|
@ -0,0 +1,159 @@
|
||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
import speiger.src.builder.mappers.ArgumentMapper;
|
||||||
|
import speiger.src.builder.mappers.InjectMapper;
|
||||||
|
import speiger.src.builder.mappers.LineMapper;
|
||||||
|
import speiger.src.builder.mappers.SimpleMapper;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class BaseModule
|
||||||
|
{
|
||||||
|
ModulePackage entry;
|
||||||
|
protected ClassType keyType;
|
||||||
|
protected ClassType valueType;
|
||||||
|
|
||||||
|
public final void init(ModulePackage entry)
|
||||||
|
{
|
||||||
|
this.entry = entry;
|
||||||
|
keyType = entry.getKeyType();
|
||||||
|
valueType = entry.getValueType();
|
||||||
|
loadVariables();
|
||||||
|
loadFlags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void cleanup() {
|
||||||
|
entry = null;
|
||||||
|
keyType = null;
|
||||||
|
valueType = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void loadVariables();
|
||||||
|
protected abstract void loadFlags();
|
||||||
|
|
||||||
|
protected void addFlag(String name)
|
||||||
|
{
|
||||||
|
entry.addFlag(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBiRequirement(String fileName) {
|
||||||
|
entry.addRequirement(fileName, RequiredType.BI_CLASS);
|
||||||
|
entry.addSplitter(fileName, "%1$s2%2$s");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBiRequirement(String fileName, String splitter) {
|
||||||
|
entry.addRequirement(fileName, RequiredType.BI_CLASS);
|
||||||
|
entry.addSplitter(fileName, "%1$s"+splitter+"%2$s");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addRequirement(String fileName, String splitter, RequiredType type) {
|
||||||
|
entry.addRequirement(fileName, type);
|
||||||
|
entry.addSplitter(fileName, splitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBlockedFile(String name)
|
||||||
|
{
|
||||||
|
entry.addBlockedFile(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBlockedFilter(Predicate<String> filter)
|
||||||
|
{
|
||||||
|
entry.addBlockedFilter(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addClassMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+replacement));
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, keyType.getFileType()+replacement));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBiClassMapper(String pattern, String replacement, String splitter)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper("KEY_"+pattern, "KEY_"+pattern, keyType.getFileType()+splitter+keyType.getFileType()+replacement));
|
||||||
|
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, keyType.getFileType()+splitter+valueType.getFileType()+replacement));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addAbstractMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getFileType())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addAbstractBiMapper(String pattern, String replacement, String splitter)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getFileType()+splitter+valueType.getFileType())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addFunctionMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, replacement+valueType.getNonFileType()));
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, replacement+keyType.getNonFileType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addFunctionValueMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, replacement+valueType.getNonFileType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addFunctionMappers(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper("VALUE_"+pattern, "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, keyType.getNonFileType())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addFunctionValueMappers(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, String.format(replacement, valueType.getNonFileType())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addSimpleMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
entry.addMapper(new SimpleMapper(pattern, pattern, replacement));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addAnnontion(String pattern, String value)
|
||||||
|
{
|
||||||
|
if(keyType == ClassType.OBJECT) entry.addMapper(new LineMapper(pattern, pattern));
|
||||||
|
else entry.addMapper(new SimpleMapper(pattern, pattern, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addValueAnnontion(String pattern, String value)
|
||||||
|
{
|
||||||
|
if(valueType == ClassType.OBJECT) entry.addMapper(new LineMapper(pattern, pattern));
|
||||||
|
else entry.addMapper(new SimpleMapper(pattern, pattern, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addComment(String pattern, String value)
|
||||||
|
{
|
||||||
|
if(keyType == ClassType.OBJECT) entry.addMapper(new InjectMapper(pattern, pattern, value).removeBraces());
|
||||||
|
else entry.addMapper(new LineMapper(pattern, pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addValueComment(String pattern, String value)
|
||||||
|
{
|
||||||
|
if(valueType == ClassType.OBJECT) entry.addMapper(new InjectMapper(pattern, pattern, value).removeBraces());
|
||||||
|
else entry.addMapper(new LineMapper(pattern, pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InjectMapper addInjectMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
InjectMapper mapper = new InjectMapper(pattern, pattern, replacement);
|
||||||
|
entry.addMapper(mapper);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArgumentMapper addArgumentMapper(String pattern, String replacement)
|
||||||
|
{
|
||||||
|
return addArgumentMapper(pattern, replacement, ", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter)
|
||||||
|
{
|
||||||
|
ArgumentMapper mapper = new ArgumentMapper(pattern, pattern, replacement, splitter);
|
||||||
|
entry.addMapper(mapper);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,178 @@
|
||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class JavaModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void loadVariables()
|
||||||
|
{
|
||||||
|
loadBaseVariables();
|
||||||
|
createHelperVars(keyType, false, "KEY");
|
||||||
|
createHelperVars(valueType, true, "VALUE");
|
||||||
|
loadClasses();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags()
|
||||||
|
{
|
||||||
|
addFlag("TYPE_"+keyType.getCapType());
|
||||||
|
addFlag("VALUE_"+valueType.getCapType());
|
||||||
|
if(keyType == valueType) addFlag("SAME_TYPE");
|
||||||
|
if(keyType.hasFunction(valueType)) addFlag("JDK_FUNCTION");
|
||||||
|
if(!keyType.needsCustomJDKType()) addFlag("JDK_TYPE");
|
||||||
|
if(!keyType.isPrimitiveBlocking()) addFlag("PRIMITIVES");
|
||||||
|
if(!valueType.isPrimitiveBlocking()) addFlag("VALUE_PRIMITIVES");
|
||||||
|
if(valueType.needsCustomJDKType()) addFlag("JDK_VALUE");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFunctions()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadClasses()
|
||||||
|
{
|
||||||
|
addSimpleMapper("JAVA_PREDICATE", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Predicate");
|
||||||
|
addSimpleMapper("JAVA_CONSUMER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Consumer");
|
||||||
|
addSimpleMapper("JAVA_SUPPLIER", keyType.isPrimitiveBlocking() ? "" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"Supplier");
|
||||||
|
addSimpleMapper("JAVA_FUNCTION", keyType.getFunctionClass(valueType));
|
||||||
|
addSimpleMapper("JAVA_BINARY_OPERATOR", keyType == ClassType.BOOLEAN ? "" : (keyType.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+keyType.getCustomJDKType().getFileType()+"BinaryOperator"));
|
||||||
|
addSimpleMapper("JAVA_UNARY_OPERATOR", keyType.isObject() ? "BinaryOperator" : keyType == ClassType.BOOLEAN ? "" : keyType.getCustomJDKType().getFileType()+"UnaryOperator");
|
||||||
|
addSimpleMapper("JAVA_SPLIT_ITERATOR", keyType.isPrimitiveBlocking() ? "Spliterator" : "Of"+keyType.getCustomJDKType().getFileType());
|
||||||
|
addSimpleMapper("JAVA_STREAM", keyType.isPrimitiveBlocking() ? "" : keyType.getCustomJDKType().getFileType()+"Stream");
|
||||||
|
addSimpleMapper("JAVA_BUFFER", keyType.getFileType()+"Buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadBaseVariables()
|
||||||
|
{
|
||||||
|
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
|
||||||
|
addSimpleMapper("PACKAGE", keyType.getPathType());
|
||||||
|
addSimpleMapper("CLASS_TYPE", keyType.getClassType());
|
||||||
|
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||||
|
addSimpleMapper("KEY_TYPE", keyType.getKeyType());
|
||||||
|
addSimpleMapper("KEY_OBJECT_TYPE", keyType.isObject() ? "Object" : keyType.getKeyType());
|
||||||
|
addSimpleMapper("KEY_STRING_TYPE", keyType.isObject() ? "String" : keyType.getKeyType());
|
||||||
|
addSimpleMapper("KEY_SPECIAL_TYPE", keyType.isObject() ? "E" : keyType.getKeyType());
|
||||||
|
addSimpleMapper("CLASS_OBJECT_TYPE", keyType.getClassType());
|
||||||
|
addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType());
|
||||||
|
addSimpleMapper("CLASS_STRING_TYPE", keyType.isObject() ? "String" : keyType.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", keyType.getCustomJDKType().getKeyType());
|
||||||
|
addSimpleMapper("VALUE_JAVA_TYPE", keyType.getCustomJDKType().getKeyType());
|
||||||
|
|
||||||
|
addSimpleMapper("EMPTY_KEY_VALUE", keyType.getEmptyValue());
|
||||||
|
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||||
|
|
||||||
|
addSimpleMapper("INVALID_KEY_VALUE", keyType.getInvalidValue());
|
||||||
|
addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue());
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_STRING_GENERIC_TYPE", keyType.isObject() ? "<String>" : "");
|
||||||
|
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
|
||||||
|
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
|
||||||
|
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", "+keyType.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.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", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||||
|
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
||||||
|
addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+keyType.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces();
|
||||||
|
|
||||||
|
addSimpleMapper(" NO_GENERIC_TYPE", keyType.isObject() ? "<?>" : "");
|
||||||
|
addSimpleMapper(" NO_KV_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
||||||
|
addSimpleMapper(" KEY_COMPAREABLE_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+" extends Comparable<T>>" : "");
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", keyType.isObject() ? "<? super "+keyType.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<? super "+keyType.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+keyType.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? "<? extends "+keyType.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<? extends "+keyType.getKeyType()+", ? extends "+valueType.getValueType()+">" : "<? extends "+keyType.getKeyType()+">") : (valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : ""));
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : "<"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
||||||
|
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", keyType.isObject() ? (valueType.isObject() ? "<"+keyType.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+keyType.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
|
||||||
|
|
||||||
|
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", keyType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||||
|
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
||||||
|
addInjectMapper(" KSK_GENERIC_TYPE", keyType.isObject() ? "<%s, "+keyType.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
||||||
|
addInjectMapper(" KKS_GENERIC_TYPE", keyType.isObject() ? "<"+keyType.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
||||||
|
addArgumentMapper(" KSS_GENERIC_TYPE", keyType.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", keyType.isObject() ? " <"+keyType.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||||
|
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", keyType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||||
|
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||||
|
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">, "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+" extends Enum<"+keyType.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||||
|
|
||||||
|
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||||
|
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||||
|
|
||||||
|
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", keyType.isObject() ? (valueType.isObject() ? " <"+keyType.getKeyType()+", "+valueType.getValueType()+">" : " <"+keyType.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||||
|
addSimpleMapper(" COMPAREABLE_KEY_BRACES", keyType.isObject() ? " <"+keyType.getKeyType()+" extends Comparable<T>>" : "");
|
||||||
|
addSimpleMapper("KV_BRACES", keyType.isObject() || valueType.isObject() ? "<>" : "");
|
||||||
|
addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : "");
|
||||||
|
addSimpleMapper("BRACES", keyType.isObject() ? "<>" : "");
|
||||||
|
if(keyType.needsCustomJDKType())
|
||||||
|
{
|
||||||
|
addSimpleMapper("JAVA_TYPE", keyType.getCustomJDKType().getKeyType());
|
||||||
|
addSimpleMapper("SANITY_CAST", "castTo"+keyType.getFileType());
|
||||||
|
}
|
||||||
|
addSimpleMapper("JAVA_CLASS", keyType.getCustomJDKType().getClassType());
|
||||||
|
if(valueType.needsCustomJDKType())
|
||||||
|
{
|
||||||
|
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
|
||||||
|
}
|
||||||
|
addComment("@ArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||||
|
addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection");
|
||||||
|
addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||||
|
addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection");
|
||||||
|
addAnnontion("@PrimitiveOverride", "@Override");
|
||||||
|
addSimpleMapper("@PrimitiveDoc", "");
|
||||||
|
addAnnontion("@Primitive", "@Deprecated");
|
||||||
|
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
|
||||||
|
addValueAnnontion("@ValuePrimitive", "@Deprecated");
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
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.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 ModuleBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||||
|
{
|
||||||
|
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init()
|
||||||
|
{
|
||||||
|
prepPackages();
|
||||||
|
//Init Modules here
|
||||||
|
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; }
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
import speiger.src.builder.mappers.IMapper;
|
||||||
|
import speiger.src.builder.processor.TemplateProcess;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ModulePackage
|
||||||
|
{
|
||||||
|
public static final ClassType[] TYPE = ClassType.values();
|
||||||
|
final ClassType keyType;
|
||||||
|
final ClassType valueType;
|
||||||
|
Set<String> blocked = new HashSet<>();
|
||||||
|
Map<String, String> nameRemapper = new HashMap<>();
|
||||||
|
Map<String, String> splitters = new HashMap<>();
|
||||||
|
List<Predicate<String>> blockedFilters = new ArrayList<>();
|
||||||
|
List<IMapper> mappers = new ArrayList<>();
|
||||||
|
Set<String> flags = new LinkedHashSet<>();
|
||||||
|
BiConsumer<String, RequiredType> requirements = (K, V) -> {};
|
||||||
|
|
||||||
|
public ModulePackage(ClassType keyType, ClassType valueType) {
|
||||||
|
this.keyType = keyType;
|
||||||
|
this.valueType = valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish() {
|
||||||
|
mappers.sort(Comparator.comparing(IMapper::getSearchValue, this::sort));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequirements(BiConsumer<String, RequiredType> requirements) {
|
||||||
|
this.requirements = requirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSame() {
|
||||||
|
return keyType == valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnumValid() {
|
||||||
|
return keyType == ClassType.OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassType getKeyType() {
|
||||||
|
return keyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassType getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFlag(String flag) {
|
||||||
|
flags.add(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRequirement(String fileName, RequiredType type) {
|
||||||
|
requirements.accept(fileName, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMapper(IMapper mapper) {
|
||||||
|
mappers.add(mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBlockedFilter(Predicate<String> filter) {
|
||||||
|
blockedFilters.add(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBlockedFile(String name) {
|
||||||
|
blocked.add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSplitter(String fileName, String splitter) {
|
||||||
|
splitters.put(fileName, splitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRemapper(String fileName, String actualName) {
|
||||||
|
nameRemapper.put(fileName, actualName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(String fileName, Consumer<TemplateProcess> result) {
|
||||||
|
if(isBlocked(fileName)) return;
|
||||||
|
String splitter = String.format(splitters.getOrDefault(fileName, keyType.getFileType()), keyType.getFileType(), valueType.getFileType());
|
||||||
|
String newName = String.format(nameRemapper.getOrDefault(fileName, "%s"+fileName), splitter);
|
||||||
|
TemplateProcess process = new TemplateProcess(newName);
|
||||||
|
process.setPathBuilder(new PathBuilder(keyType.getPathType()));
|
||||||
|
process.addFlags(flags);
|
||||||
|
process.addMappers(mappers);
|
||||||
|
result.accept(process);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlocked(String fileName) {
|
||||||
|
if(blocked.contains(fileName)) return true;
|
||||||
|
for(int i = 0,m=blockedFilters.size();i<m;i++) {
|
||||||
|
if(blockedFilters.get(i).test(fileName)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ModulePackage> createPackages() {
|
||||||
|
List<ModulePackage> list = new ArrayList<>();
|
||||||
|
for(ClassType key : TYPE) {
|
||||||
|
for(ClassType value : TYPE) {
|
||||||
|
list.add(new ModulePackage(key, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int sort(String key, String value) {
|
||||||
|
if(key.equals(value)) return 0;
|
||||||
|
if(value.contains(key)) return 1;
|
||||||
|
else if(key.contains(value)) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public enum RequiredType
|
||||||
|
{
|
||||||
|
BI_CLASS,
|
||||||
|
ENUM
|
||||||
|
}
|
Loading…
Reference in New Issue