2020-11-11 21:33:59 +01:00
package speiger.src.builder.example ;
2020-11-12 02:13:54 +01:00
import java.nio.file.Path ;
2020-11-11 21:33:59 +01:00
import java.util.ArrayList ;
import java.util.LinkedHashSet ;
import java.util.List ;
import java.util.Set ;
import java.util.function.UnaryOperator ;
2020-11-16 02:55:33 +01:00
import speiger.src.builder.mappers.ArgumentMapper ;
2021-01-20 04:29:08 +01:00
import speiger.src.builder.mappers.IMapper ;
2020-11-12 02:13:54 +01:00
import speiger.src.builder.mappers.InjectMapper ;
2020-11-30 00:11:40 +01:00
import speiger.src.builder.mappers.LineMapper ;
2020-11-11 21:33:59 +01:00
import speiger.src.builder.mappers.SimpleMapper ;
import speiger.src.builder.processor.TemplateProcess ;
public class GlobalVariables
{
2021-01-20 04:29:08 +01:00
List < IMapper > operators = new ArrayList < > ( ) ;
2020-11-11 21:33:59 +01:00
Set < String > flags = new LinkedHashSet < > ( ) ;
2020-11-12 02:13:54 +01:00
ClassType type ;
2021-01-21 21:35:23 +01:00
ClassType valueType ;
2020-11-11 21:33:59 +01:00
2021-01-21 21:35:23 +01:00
public GlobalVariables ( ClassType type , ClassType subType )
2020-11-11 21:33:59 +01:00
{
2020-11-12 02:13:54 +01:00
this . type = type ;
2021-01-21 21:35:23 +01:00
valueType = subType ;
2020-11-11 21:33:59 +01:00
}
2020-11-12 02:13:54 +01:00
public GlobalVariables createVariables ( )
2020-11-11 21:33:59 +01:00
{
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " VALUE_PACKAGE " , valueType . getPathType ( ) ) ;
2020-11-13 03:01:13 +01:00
addSimpleMapper ( " PACKAGE " , type . getPathType ( ) ) ;
addSimpleMapper ( " CLASS_TYPE " , type . getClassType ( ) ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " CLASS_VALUE_TYPE " , valueType . getClassValueType ( ) ) ;
2020-11-13 03:01:13 +01:00
addSimpleMapper ( " KEY_TYPE " , type . getKeyType ( ) ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " VALUE_TYPE " , valueType . getValueType ( ) ) ;
addSimpleMapper ( " EMPTY_KEY_VALUE " , type . getEmptyValue ( ) ) ;
addSimpleMapper ( " EMPTY_VALUE " , valueType . getEmptyValue ( ) ) ;
2020-11-30 00:11:40 +01:00
addSimpleMapper ( " KEY_GENERIC_TYPE " , type . isObject ( ) ? " < " + type . getKeyType ( ) + " > " : " " ) ;
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " KEY_KEY_GENERIC_TYPE " , type . isObject ( ) ? " < " + type . getKeyType ( ) + " , " + type . getKeyType ( ) + " > " : " " ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " VALUE_GENERIC_TYPE " , valueType . isObject ( ) ? " < " + valueType . getValueType ( ) + " > " : " " ) ;
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " VALUE_VALUE_GENERIC_TYPE " , valueType . isObject ( ) ? " < " + valueType . getValueType ( ) + " , " + valueType . getValueType ( ) + " > " : " " ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " KEY_VALUE_GENERIC_TYPE " , type . isObject ( ) ? ( valueType . isObject ( ) ? " < " + type . getKeyType ( ) + " , " + valueType . getValueType ( ) + " > " : " < " + type . getKeyType ( ) + " > " ) : ( valueType . isObject ( ) ? " < " + valueType . getValueType ( ) + " > " : " " ) ) ;
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " KEY_VALUE_VALUE_GENERIC_TYPE " , type . isObject ( ) ? ( valueType . isObject ( ) ? " < " + type . getKeyType ( ) + " , " + valueType . getValueType ( ) + " , " + valueType . getValueType ( ) + " > " : " < " + type . getKeyType ( ) + " > " ) : ( valueType . isObject ( ) ? " < " + valueType . getValueType ( ) + " , " + valueType . getValueType ( ) + " > " : " " ) ) ;
2020-12-01 02:43:13 +01:00
addSimpleMapper ( " NO_GENERIC_TYPE " , type . isObject ( ) ? " <?> " : " " ) ;
2020-11-30 00:11:40 +01:00
addSimpleMapper ( " KEY_COMPAREABLE_TYPE " , type . isObject ( ) ? " < " + type . getKeyType ( ) + " extends Comparable<T>> " : " " ) ;
2020-12-01 02:43:13 +01:00
addSimpleMapper ( " KEY_SUPER_GENERIC_TYPE " , type . isObject ( ) ? " <? super " + type . getKeyType ( ) + " > " : " " ) ;
2021-01-28 20:42:29 +01:00
addSimpleMapper ( " VALUE_SUPER_GENERIC_TYPE " , valueType . isObject ( ) ? " <? super " + valueType . getValueType ( ) + " > " : " " ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " KEY_VALUE_SUPER_GENERIC_TYPE " , type . isObject ( ) ? ( valueType . isObject ( ) ? " <? super " + type . getKeyType ( ) + " , ? super " + valueType . getValueType ( ) + " > " : " <? super " + type . getKeyType ( ) + " > " ) : ( valueType . isObject ( ) ? " <? super " + valueType . getValueType ( ) + " > " : " " ) ) ;
2021-01-28 20:42:29 +01:00
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 ( ) + " >> " : " " ) ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " GENERIC_KEY_BRACES " , type . isObject ( ) ? " < " + type . getKeyType ( ) + " > " : " " ) ;
addSimpleMapper ( " GENERIC_VALUE_BRACES " , type . isObject ( ) ? " < " + valueType . getValueType ( ) + " > " : " " ) ;
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>> " : " " ) ;
2021-01-28 20:42:29 +01:00
addSimpleMapper ( " KV_BRACES " , type . isObject ( ) | | valueType . isObject ( ) ? " <> " : " " ) ;
2020-11-30 00:11:40 +01:00
addSimpleMapper ( " BRACES " , type . isObject ( ) ? " <> " : " " ) ;
2020-11-12 02:13:54 +01:00
if ( type . needsCustomJDKType ( ) )
{
2020-11-13 03:01:13 +01:00
addSimpleMapper ( " JAVA_TYPE " , type . getCustomJDKType ( ) . getKeyType ( ) ) ;
addSimpleMapper ( " SANITY_CAST " , " castTo " + type . getFileType ( ) ) ;
2020-11-12 02:13:54 +01:00
}
2021-01-25 05:48:14 +01:00
if ( valueType . needsCustomJDKType ( ) )
{
addSimpleMapper ( " SANITY_CAST_VALUE " , " castTo " + valueType . getFileType ( ) ) ;
}
2021-01-20 04:29:08 +01:00
addAnnontion ( " @PrimitiveOverride " , " @Override " ) ;
2020-12-06 09:32:22 +01:00
addSimpleMapper ( " @PrimitiveDoc " , " " ) ;
2021-01-20 04:29:08 +01:00
addAnnontion ( " @Primitive " , " @Deprecated " ) ;
2020-11-16 02:55:33 +01:00
return this ;
}
public GlobalVariables createHelperVariables ( )
{
2021-01-25 05:48:14 +01:00
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 ( ) ;
2021-01-21 21:35:23 +01:00
2021-01-25 05:48:14 +01:00
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 ( ) ;
2021-01-21 21:35:23 +01:00
2021-01-25 05:48:14 +01:00
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 ( ) ;
2021-01-28 20:42:29 +01:00
addInjectMapper ( " CLASS_TO_ " + fix , type . isObject ( ) ? " ( " + type . getKeyType ( value ) + " )%s " : " (( " + type . getClassType ( value ) + " )%s). " + type . getKeyType ( value ) + " Value() " ) . removeBraces ( ) ;
2021-01-21 21:35:23 +01:00
2021-01-25 05:48:14 +01:00
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 ( ) ;
2021-01-21 21:35:23 +01:00
2021-01-25 05:48:14 +01:00
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_CLASS " + ( value ? " _VALUE " : " " ) + " _ARRAY " , type . isObject ( ) ? " (CLASS_TYPE[])new Object[%s] " : " new CLASS_TYPE[%s] " ) . removeBraces ( ) ;
2020-11-11 21:33:59 +01:00
}
2021-01-24 07:39:13 +01:00
public GlobalVariables createPreFunctions ( )
{
addSimpleMapper ( " ENTRY_SET " , type . getFileType ( ) . toLowerCase ( ) + " 2 " + valueType . getFileType ( ) + " EntrySet " ) ;
return this ;
}
2020-11-12 02:13:54 +01:00
public GlobalVariables createClassTypes ( )
2020-11-11 21:33:59 +01:00
{
2020-11-13 03:01:13 +01:00
addSimpleMapper ( " JAVA_PREDICATE " , type . isPrimitiveBlocking ( ) ? " " : type . getCustomJDKType ( ) . getFileType ( ) + " Predicate " ) ;
addSimpleMapper ( " JAVA_CONSUMER " , type . isPrimitiveBlocking ( ) ? " " : " java.util.function. " + type . getCustomJDKType ( ) . getFileType ( ) + " Consumer " ) ;
2021-01-21 21:35:23 +01:00
addSimpleMapper ( " JAVA_FUNCTION " , type . getFunctionClass ( valueType ) ) ;
2021-01-24 07:39:13 +01:00
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 " ) ;
2020-12-13 20:14:22 +01:00
//Final Classes
addClassMapper ( " ARRAY_LIST " , " ArrayList " ) ;
2021-01-20 04:29:08 +01:00
addClassMapper ( " ARRAY_FIFO_QUEUE " , " ArrayFIFOQueue " ) ;
addClassMapper ( " ARRAY_PRIORITY_QUEUE " , " ArrayPriorityQueue " ) ;
addClassMapper ( " HEAP_PRIORITY_QUEUE " , " HeapPriorityQueue " ) ;
2020-12-13 23:41:09 +01:00
addClassMapper ( " LINKED_CUSTOM_HASH_SET " , " LinkedOpenCustomHashSet " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " LINKED_HASH_SET " , " LinkedOpenHashSet " ) ;
2020-12-13 23:41:09 +01:00
addClassMapper ( " CUSTOM_HASH_SET " , " OpenCustomHashSet " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " HASH_SET " , " OpenHashSet " ) ;
2021-01-28 20:42:29 +01:00
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 ( " ENUM_MAP " , valueType . isObject ( ) ? " Enum2ObjectMap " : " Enum2%sMap " ) ;
addBiClassMapper ( " HASH_MAP " , " OpenHashMap " , " 2 " ) ;
addBiClassMapper ( " ARRAY_MAP " , " ArrayMap " , " 2 " ) ;
2020-12-19 21:11:21 +01:00
addClassMapper ( " RB_TREE_SET " , " RBTreeSet " ) ;
2020-12-20 05:45:16 +01:00
addClassMapper ( " AVL_TREE_SET " , " AVLTreeSet " ) ;
2020-12-13 23:41:09 +01:00
addClassMapper ( " ARRAY_SET " , " ArraySet " ) ;
2020-12-13 20:14:22 +01:00
//Abstract Classes
2020-12-13 23:41:09 +01:00
addAbstractMapper ( " ABSTRACT_COLLECTION " , " Abstract%sCollection " ) ;
addAbstractMapper ( " ABSTRACT_SET " , " Abstract%sSet " ) ;
addAbstractMapper ( " ABSTRACT_LIST " , " Abstract%sList " ) ;
2021-01-25 05:48:14 +01:00
addAbstractBiMapper ( " ABSTRACT_MAP " , " Abstract%sMap " , " 2 " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " SUB_LIST " , " SubList " ) ;
//Helper Classes
addClassMapper ( " LISTS " , " Lists " ) ;
2020-12-20 05:45:16 +01:00
addClassMapper ( " SETS " , " Sets " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " COLLECTIONS " , " Collections " ) ;
addClassMapper ( " ARRAYS " , " Arrays " ) ;
addClassMapper ( " ITERATORS " , " Iterators " ) ;
2021-01-24 07:39:13 +01:00
addBiClassMapper ( " MAPS " , " Maps " , " 2 " ) ;
2020-12-13 20:14:22 +01:00
//Interfaces
addClassMapper ( " LIST_ITERATOR " , " ListIterator " ) ;
addClassMapper ( " BI_ITERATOR " , " BidirectionalIterator " ) ;
2021-01-21 21:35:23 +01:00
addBiClassMapper ( " BI_CONSUMER " , " Consumer " , " " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " ITERATOR " , " Iterator " ) ;
addClassMapper ( " ITERABLE " , " Iterable " ) ;
addClassMapper ( " COLLECTION " , " Collection " ) ;
2021-01-21 21:35:23 +01:00
addBiClassMapper ( " FUNCTION " , " Function " , " 2 " ) ;
2020-12-13 23:41:09 +01:00
addClassMapper ( " LIST_ITER " , " ListIter " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " LIST " , " List " ) ;
2021-01-28 20:42:29 +01:00
addBiClassMapper ( " NAVIGABLE_MAP " , " NavigableMap " , " 2 " ) ;
addBiClassMapper ( " SORTED_MAP " , " SortedMap " , " 2 " ) ;
2021-01-24 07:39:13 +01:00
addBiClassMapper ( " MAP " , " Map " , " 2 " ) ;
2020-12-19 21:11:21 +01:00
addClassMapper ( " NAVIGABLE_SET " , " NavigableSet " ) ;
2021-01-20 04:29:08 +01:00
addClassMapper ( " PRIORITY_QUEUE " , " PriorityQueue " ) ;
addClassMapper ( " PRIORITY_DEQUEUE " , " PriorityDequeue " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " SORTED_SET " , " SortedSet " ) ;
addClassMapper ( " SET " , " Set " ) ;
2020-12-13 23:41:09 +01:00
addClassMapper ( " STRATEGY " , " Strategy " ) ;
2020-12-13 20:14:22 +01:00
addClassMapper ( " STACK " , " Stack " ) ;
2021-01-24 07:39:13 +01:00
addBiClassMapper ( " UNARY_OPERATOR " , " UnaryOperator " , " " ) ;
2020-11-30 00:11:40 +01:00
if ( type . isObject ( ) )
{
2021-01-28 20:42:29 +01:00
if ( ! valueType . isObject ( ) )
{
addSimpleMapper ( " VALUE_CONSUMER " , valueType . getFileType ( ) + " Consumer " ) ;
}
2020-11-30 00:11:40 +01:00
addSimpleMapper ( " CONSUMER " , " Consumer " ) ;
addSimpleMapper ( " COMPARATOR " , " Comparator " ) ;
2020-12-01 02:43:13 +01:00
addSimpleMapper ( " IARRAY " , " IObjectArray " ) ;
2020-11-30 00:11:40 +01:00
}
else
{
addClassMapper ( " CONSUMER " , " Consumer " ) ;
addClassMapper ( " COMPARATOR " , " Comparator " ) ;
2020-12-01 02:43:13 +01:00
addFunctionMappers ( " IARRAY " , " I%sArray " ) ;
2020-11-30 00:11:40 +01:00
}
2020-11-12 02:13:54 +01:00
return this ;
}
public GlobalVariables createFunctions ( )
{
2021-01-25 05:48:14 +01:00
addSimpleMapper ( " APPLY_VALUE " , valueType . isObject ( ) ? " apply " : " applyAs " + valueType . getNonFileType ( ) ) ;
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " APPLY_CAST " , " applyAs " + type . getCustomJDKType ( ) . getNonFileType ( ) ) ;
2021-01-25 05:48:14 +01:00
addSimpleMapper ( " APPLY " , type . isObject ( ) ? " apply " : " applyAs " + type . getNonFileType ( ) ) ;
2021-01-24 07:39:13 +01:00
addFunctionValueMappers ( " COMPUTE_IF_ABSENT " , " compute%sIfAbsent " ) ;
addFunctionValueMappers ( " COMPUTE_IF_PRESENT " , " compute%sIfPresent " ) ;
addFunctionValueMapper ( " COMPUTE " , " compute " ) ;
2021-01-20 04:29:08 +01:00
addFunctionMapper ( " ENQUEUE_FIRST " , " enqueueFirst " ) ;
addFunctionMapper ( " ENQUEUE " , " enqueue " ) ;
addFunctionMapper ( " DEQUEUE_LAST " , " dequeueLast " ) ;
addFunctionMapper ( " DEQUEUE " , " dequeue " ) ;
2021-01-28 20:42:29 +01:00
addFunctionMappers ( " POLL_FIRST_ENTRY_KEY " , " pollFirst%sKey " ) ;
addFunctionMappers ( " POLL_LAST_ENTRY_KEY " , " pollLast%sKey " ) ;
2021-01-24 07:39:13 +01:00
addFunctionMapper ( " POLL_FIRST_KEY " , " pollFirst " ) ;
addFunctionMapper ( " POLL_LAST_KEY " , " pollLast " ) ;
2021-01-28 20:42:29 +01:00
addFunctionMappers ( " FIRST_ENTRY_KEY " , " first%sKey " ) ;
addFunctionValueMappers ( " FIRST_ENTRY_VALUE " , " first%sValue " ) ;
2021-01-24 07:39:13 +01:00
addFunctionMapper ( " FIRST_KEY " , " first " ) ;
2021-01-28 20:42:29 +01:00
addFunctionMappers ( " LAST_ENTRY_KEY " , " last%sKey " ) ;
addFunctionValueMappers ( " LAST_ENTRY_VALUE " , " last%sValue " ) ;
addFunctionMappers ( " ENTRY_KEY " , " get%sKey " ) ;
addFunctionValueMappers ( " ENTRY_VALUE " , " get%sValue " ) ;
2021-01-24 07:39:13 +01:00
addFunctionMapper ( " GET_KEY " , " get " ) ;
2021-01-28 20:42:29 +01:00
addFunctionValueMapper ( " GET_VALUE " , valueType . isObject ( ) ? " getObject " : " get " ) ;
2021-01-24 07:39:13 +01:00
addFunctionMapper ( " LAST_KEY " , " last " ) ;
addFunctionValueMapper ( " MERGE " , " merge " ) ;
addFunctionMapper ( " NEXT " , " next " ) ;
2020-11-16 02:55:33 +01:00
addFunctionMapper ( " PREVIOUS " , " previous " ) ;
2020-11-28 15:05:28 +01:00
addFunctionMapper ( " PEEK " , " peek " ) ;
addFunctionMapper ( " POP " , " pop " ) ;
addFunctionMapper ( " PUSH " , " push " ) ;
2021-01-24 07:39:13 +01:00
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 " ) ;
2020-12-01 02:43:13 +01:00
addFunctionMappers ( " SORT " , " sort%ss " ) ;
2021-01-24 07:39:13 +01:00
addSimpleMapper ( " TO_ARRAY " , " to " + type . getNonFileType ( ) + " Array " ) ;
addFunctionMapper ( " TOP " , " top " ) ;
2020-11-12 02:13:54 +01:00
return this ;
}
public GlobalVariables createFlags ( )
{
flags . add ( " TYPE_ " + type . getCapType ( ) ) ;
2021-01-21 21:35:23 +01:00
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 " ) ;
2021-01-24 07:39:13 +01:00
if ( ! valueType . isPrimitiveBlocking ( ) ) flags . add ( " VALUE_PRIMITIVES " ) ;
2021-01-21 21:35:23 +01:00
if ( valueType . needsCustomJDKType ( ) ) flags . add ( " JDK_VALUE " ) ;
2020-11-11 21:33:59 +01:00
return this ;
}
2021-01-28 20:42:29 +01:00
public TemplateProcess create ( String fileName , String splitter , boolean valueOnly )
2021-01-21 21:35:23 +01:00
{
2021-01-28 20:42:29 +01:00
TemplateProcess process = new TemplateProcess ( String . format ( fileName + " .java " , ( splitter ! = null ? type . getFileType ( ) + splitter + valueType . getFileType ( ) : ( valueOnly ? valueType : type ) . getFileType ( ) ) ) ) ;
2021-01-21 21:35:23 +01:00
process . setPathBuilder ( new PathBuilder ( type . getPathType ( ) ) ) ;
process . addFlags ( flags ) ;
process . addMappers ( operators ) ;
return process ;
}
2020-11-12 02:13:54 +01:00
public ClassType getType ( )
{
return type ;
}
2020-11-16 02:55:33 +01:00
private void addClassMapper ( String pattern , String replacement )
{
2021-01-21 21:35:23 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [VALUE_ " + pattern + " ] " , " VALUE_ " + pattern , valueType . getFileType ( ) + replacement ) ) ;
2021-01-24 07:39:13 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , type . getFileType ( ) + replacement ) ) ;
2021-01-21 21:35:23 +01:00
}
private void addBiClassMapper ( String pattern , String replacement , String splitter )
{
2021-01-24 07:39:13 +01:00
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 ) ) ;
2021-01-21 21:35:23 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , type . getFileType ( ) + splitter + valueType . getFileType ( ) + replacement ) ) ;
2020-11-16 02:55:33 +01:00
}
2020-12-13 23:41:09 +01:00
private void addAbstractMapper ( String pattern , String replacement )
{
2021-01-25 05:48:14 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [VALUE_ " + pattern + " ] " , " VALUE_ " + pattern , String . format ( replacement , valueType . getFileType ( ) ) ) ) ;
2021-01-20 04:29:08 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , String . format ( replacement , type . getFileType ( ) ) ) ) ;
2020-12-13 23:41:09 +01:00
}
2021-01-25 05:48:14 +01:00
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 ( ) ) ) ) ;
}
2020-11-16 02:55:33 +01:00
private void addFunctionMapper ( String pattern , String replacement )
{
2021-01-25 05:48:14 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [VALUE_ " + pattern + " ] " , " VALUE_ " + pattern , replacement + valueType . getNonFileType ( ) ) ) ;
2021-01-20 04:29:08 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , replacement + type . getNonFileType ( ) ) ) ;
2020-11-16 02:55:33 +01:00
}
2021-01-21 21:35:23 +01:00
private void addFunctionValueMapper ( String pattern , String replacement )
{
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , replacement + valueType . getNonFileType ( ) ) ) ;
}
2020-11-30 00:11:40 +01:00
private void addFunctionMappers ( String pattern , String replacement )
{
2021-01-25 05:48:14 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [VALUE_ " + pattern + " ] " , " VALUE_ " + pattern , String . format ( replacement , valueType . getNonFileType ( ) ) ) ) ;
2021-01-20 04:29:08 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , String . format ( replacement , type . getNonFileType ( ) ) ) ) ;
2020-11-30 00:11:40 +01:00
}
2021-01-24 07:39:13 +01:00
private void addFunctionValueMappers ( String pattern , String replacement )
{
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , String . format ( replacement , valueType . getNonFileType ( ) ) ) ) ;
}
2020-11-13 03:01:13 +01:00
private void addSimpleMapper ( String pattern , String replacement )
{
2021-01-20 04:29:08 +01:00
operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , replacement ) ) ;
2020-11-13 03:01:13 +01:00
}
2021-01-20 04:29:08 +01:00
private void addAnnontion ( String pattern , String value )
2020-11-30 00:11:40 +01:00
{
2021-01-20 04:29:08 +01:00
if ( type = = ClassType . OBJECT ) operators . add ( new LineMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern ) ) ;
else operators . add ( new SimpleMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , value ) ) ;
2020-11-30 00:11:40 +01:00
}
2020-11-13 03:01:13 +01:00
private InjectMapper addInjectMapper ( String pattern , String replacement )
{
2021-01-20 04:29:08 +01:00
InjectMapper mapper = new InjectMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , replacement ) ;
2020-11-13 03:01:13 +01:00
operators . add ( mapper ) ;
return mapper ;
}
2020-11-16 02:55:33 +01:00
private ArgumentMapper addArgumentMapper ( String pattern , String replacement )
{
return addArgumentMapper ( pattern , replacement , " , " ) ;
}
private ArgumentMapper addArgumentMapper ( String pattern , String replacement , String splitter )
{
2021-01-20 04:29:08 +01:00
ArgumentMapper mapper = new ArgumentMapper ( type . name ( ) + " [ " + pattern + " ] " , pattern , replacement , splitter ) ;
2020-11-16 02:55:33 +01:00
operators . add ( mapper ) ;
return mapper ;
}
2020-11-12 02:13:54 +01:00
class PathBuilder implements UnaryOperator < Path >
{
String before ;
public PathBuilder ( String before )
{
this . before = before ;
}
2020-11-11 21:33:59 +01:00
2020-11-12 02:13:54 +01:00
@Override
public Path apply ( Path t )
{
return t . subpath ( 0 , 6 ) . resolve ( before ) . resolve ( t . subpath ( 6 , t . getNameCount ( ) ) ) ;
}
2020-11-11 21:33:59 +01:00
}
}