Class SexprToModel
java.lang.Object
org.jfuncmachine.sexprlang.translate.SexprToModel
A utility to map S-expressions to an object model using the SexprMapper interface
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidconvertArrayTypes(Class[] paramTypes, Object[] params) Convert any Object arrays in a parameter list to objects of a specific component type.static booleanmatches(Constructor cons, Object[] params) Tests whether an array of parameters matches the parameters for a constructorstatic booleanmatches(Constructor cons, Object[] params, List<SexprItem> items, SexprMapper mapper) Test whether a list of S-expression items can be mapped to the arguments of a constructor, and place the mapped arguments into the params arraystatic booleanmatchesWithLocation(Constructor cons, Object[] params) Tests whether an array of parameters matches the parameters for a constructor, where the last two parameters of the constructor are a string and an int, which are expected to be a filename and line numberstatic booleanmatchesWithLocation(Constructor cons, Object[] params, List<SexprItem> items, SexprMapper mapper) Test whether a list of S-expression items can be mapped to the arguments of a constructor, where the constructor's last two parameters are a String and an int, which are expected to be a filename and line number, and place the mapped arguments into the params arraystatic ObjectsexprListToItemList(SexprList list, SexprMapper mapper) Map an S-expression list to a model item using a mapperstatic ObjectsexprListToModel(Class clazz, SexprList list, SexprMapper mapper) Map an S-expression list to an instance of a specific classstatic Object[]sexprsToModel(SexprList sexprs, SexprMapper mapper, Class targetClass) Map a list of S-expressions to model objectsstatic ObjectsexprToModel(SexprItem item, SexprMapper mapper, Class targetClass) Map an S-expression item to a model objectstatic ObjecttrySimpleConversion(Class paramType, SexprItem item)
-
Method Details
-
sexprsToModel
public static Object[] sexprsToModel(SexprList sexprs, SexprMapper mapper, Class targetClass) throws MappingException Map a list of S-expressions to model objects- Parameters:
sexprs- The list of S-expressions to mapmapper- The mapper to usetargetClass- The (super-)class that each expression is supposed to map to, or null if there is no expectation- Returns:
- An array of the mapped objects
- Throws:
MappingException- If there is an error performing the mapping
-
sexprToModel
public static Object sexprToModel(SexprItem item, SexprMapper mapper, Class targetClass) throws MappingException Map an S-expression item to a model object- Parameters:
item- The S-expression item to mapmapper- The mapper to usetargetClass- The (super-)class that the object is supposed to map to, or null if there is no expectation- Returns:
- The mapped object
- Throws:
MappingException- If there is an error performing the mapping
-
sexprListToItemList
public static Object sexprListToItemList(SexprList list, SexprMapper mapper) throws MappingException Map an S-expression list to a model item using a mapper- Parameters:
list- The S-expression to mapmapper- The mapper to use- Returns:
- The object the list maps to
- Throws:
MappingException- If there is an error performing the mapping
-
sexprListToModel
public static Object sexprListToModel(Class clazz, SexprList list, SexprMapper mapper) throws MappingException Map an S-expression list to an instance of a specific class- Parameters:
clazz- The class the list should map tolist- The list to mapmapper- The mapper to use- Returns:
- An instance of the class that the list has been mapped to
- Throws:
MappingException- If there is an error performing the mapping
-
convertArrayTypes
Convert any Object arrays in a parameter list to objects of a specific component type. This is used when invoking constructors, which may take a specific type of object, but the parameters have all been generated as arrays of type Object (Object[]).- Parameters:
paramTypes- The types of each parameterparams- The parameters to convert
-
matches
public static boolean matches(Constructor cons, Object[] params, List<SexprItem> items, SexprMapper mapper) throws MappingException Test whether a list of S-expression items can be mapped to the arguments of a constructor, and place the mapped arguments into the params array- Parameters:
cons- The constructor to match againstparams- An array of constructor parameters to be populated during the matching processitems- The list of S-expression items to match to the constructormapper- The mapper to use- Returns:
- True if the items can be mapped to the constructor params
- Throws:
MappingException- If there is an error performing the mapping
-
matchesWithLocation
public static boolean matchesWithLocation(Constructor cons, Object[] params, List<SexprItem> items, SexprMapper mapper) throws MappingException Test whether a list of S-expression items can be mapped to the arguments of a constructor, where the constructor's last two parameters are a String and an int, which are expected to be a filename and line number, and place the mapped arguments into the params array- Parameters:
cons- The constructor to match againstparams- An array of constructor parameters to be populated during the matching processitems- The list of S-expression items to match to the constructormapper- The mapper to use- Returns:
- True if the items can be mapped to the constructor params
- Throws:
MappingException- If there is an error performing the mapping
-
matches
Tests whether an array of parameters matches the parameters for a constructor- Parameters:
cons- The constructor to testparams- The parameters to test against the constructor parameters- Returns:
- True if the params match the constructor parameters
-
matchesWithLocation
Tests whether an array of parameters matches the parameters for a constructor, where the last two parameters of the constructor are a string and an int, which are expected to be a filename and line number- Parameters:
cons- The constructor to testparams- The parameters to test against the constructor parameters- Returns:
- True if the params match the constructor parameters
-
trySimpleConversion
-