package speiger.src.builder; import java.nio.file.Path; import java.util.ArrayList; 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 operators = new ArrayList<>(); Set 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_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType()); addSimpleMapper("VALUE_TYPE", valueType.getValueType()); addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType()); addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue()); addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : ""); addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : ""); addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : ""); addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""); 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()+">" : "")); 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>" : ""); addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "" : ""); addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); 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("<>"); 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>" : ""); addSimpleMapper("KV_BRACES", type.isObject() || 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(); 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() ? "%s.hashCode()" : type.getClassType(value)+".hashCode(%s)").removeBraces(); addInjectMapper(fix+"_TO_STRING", type.isObject() ? "%s.toString()" : 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(); addInjectMapper("NEW_CLASS"+(value ? "_VALUE" : "")+"_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_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"); //Final Classes addClassMapper("ARRAY_LIST", "ArrayList"); 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("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"); //Abstract Classes addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection"); addAbstractMapper("ABSTRACT_SET", "Abstract%sSet"); addAbstractMapper("ABSTRACT_LIST", "Abstract%sList"); addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2"); addClassMapper("SUB_LIST", "SubList"); //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"); //Interfaces addClassMapper("LIST_ITERATOR", "ListIterator"); addClassMapper("BI_ITERATOR", "BidirectionalIterator"); addBiClassMapper("BI_CONSUMER", "Consumer", ""); addClassMapper("BI_OBJECT_CONSUMER", "ObjectConsumer"); 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("SORTED_MAP", "SortedMap", "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("SET", "Set"); addClassMapper("STRATEGY", "Strategy"); addClassMapper("STACK", "Stack"); 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("COMPARATOR", "Comparator"); addSimpleMapper("IARRAY", "IObjectArray"); } else { if(valueType.isObject()) { addSimpleMapper("VALUE_CONSUMER", "Consumer"); addSimpleMapper("CONSUMER", type.getFileType()+"Consumer"); } else addClassMapper("CONSUMER", "Consumer"); addClassMapper("COMPARATOR", "Comparator"); addFunctionMappers("IARRAY", "I%sArray"); } return this; } public GlobalVariables createFunctions() { 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"); addFunctionMapper("LAST_KEY", "last"); addFunctionValueMapper("MERGE", "merge"); addFunctionMapper("NEXT", "next"); addFunctionMapper("PREVIOUS", "previous"); 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"); 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("TO_ARRAY", "to"+type.getNonFileType()+"Array"); addSimpleMapper("[SPACE]", " "); 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 ClassType getType() { return type; } private void addClassMapper(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement)); operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement)); } private void addBiClassMapper(String pattern, String replacement, String splitter) { operators.add(new SimpleMapper(type.name()+"[KEY_"+pattern+"]", "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement)); operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement)); operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement)); } private void addAbstractMapper(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getFileType()))); operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType()))); } private void addAbstractBiMapper(String pattern, String replacement, String splitter) { operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType()+splitter+valueType.getFileType()))); } private void addFunctionMapper(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, replacement+valueType.getNonFileType())); operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+type.getNonFileType())); } private void addFunctionValueMapper(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+valueType.getNonFileType())); } private void addFunctionMappers(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType()))); operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType()))); } private void addFunctionValueMappers(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, valueType.getNonFileType()))); } private void addSimpleMapper(String pattern, String replacement) { operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement)); } private void addAnnontion(String pattern, String value) { if(type == ClassType.OBJECT) operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern)); else operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, value)); } private void addValueAnnontion(String pattern, String value) { if(valueType == ClassType.OBJECT) operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern)); else operators.add(new SimpleMapper(valueType.name()+"["+pattern+"]", pattern, value)); } private void addComment(String pattern, String value) { if(type == ClassType.OBJECT) operators.add(new InjectMapper(type.name()+"["+pattern+"]", pattern, value).removeBraces()); else operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern)); } private void addValueComment(String pattern, String value) { if(valueType == ClassType.OBJECT) operators.add(new InjectMapper(valueType.name()+"["+pattern+"]", pattern, value).removeBraces()); else operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern)); } private InjectMapper addInjectMapper(String pattern, String replacement) { InjectMapper mapper = new InjectMapper(type.name()+"["+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(type.name()+"["+pattern+"]", pattern, replacement, splitter); operators.add(mapper); return mapper; } class PathBuilder implements UnaryOperator { 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())); } } }