MCPcopy Create free account
hub / github.com/PCGen/pcgen / allowArgs

Method allowArgs

code/src/java/plugin/function/LookupFunction.java:78–140  ·  view source on GitHub ↗
(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics)

Source from the content-addressed store, hash-verified

76 }
77
78 @Override
79 public FormatManager<?> allowArgs(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics)
80 {
81 int argCount = args.length;
82 if ((argCount < 3) || (argCount > 4))
83 {
84 throw new SemanticsFailureException("Function " + getFunctionName()
85 + " received incorrect # of arguments, expected: 3-4 got " + args.length + ' ' + Arrays.asList(args));
86 }
87
88 LoadContext context = semantics.get(ManagerKey.CONTEXT);
89 AbstractReferenceContext refContext = context.getReferenceContext();
90 //Table node (must be a DataTable)
91 Object format = args[0].jjtAccept(visitor,
92 semantics.getWith(FormulaSemantics.ASSERTED, Optional.of(refContext.getManufacturer(DATATABLE_CLASS))));
93 if (!(format instanceof TableFormatManager tableFormatManager))
94 {
95 throw new SemanticsFailureException("Parse Error: Invalid Object: " + format.getClass()
96 + " found in location requiring a TableFormatManager");
97 }
98 FormatManager<?> lookupFormat = tableFormatManager.getLookupFormat();
99
100 //Lookup value (at this point we enforce based on the Table Format)
101 FormatManager<?> luFormat = (FormatManager<?>) args[1].jjtAccept(visitor,
102 semantics.getWith(FormulaSemantics.ASSERTED, Optional.of(lookupFormat)));
103 if (!lookupFormat.equals(luFormat))
104 {
105 throw new SemanticsFailureException("Parse Error: Invalid Lookup Object: " + luFormat.getIdentifierType()
106 + " found in location the Table Format says is a " + lookupFormat.getIdentifierType());
107 }
108
109 //Result Column
110 Object resultColumn = args[2].jjtAccept(visitor,
111 semantics.getWith(FormulaSemantics.ASSERTED, Optional.of(refContext.getManufacturer(COLUMN_CLASS))));
112 if (!(resultColumn instanceof ColumnFormatManager<?> cf))
113 {
114 throw new SemanticsFailureException("Parse Error: Invalid Result Column Name: " + resultColumn.getClass()
115 + " found in location requiring a Column");
116 }
117 if (argCount == 4)
118 {
119 if (!(args[3] instanceof ASTQuotString typeNode))
120 {
121 throw new SemanticsFailureException("Parse Error: Invalid lookup type argument: Must be a String");
122 }
123 String lookupTypeName = typeNode.getText();
124 try
125 {
126 LookupType lookupType = DataTable.LookupType.valueOf(lookupTypeName);
127 if (lookupType.requiresSorting() && !(lookupFormat instanceof ComparableManager))
128 {
129 throw new SemanticsFailureException(
130 "Parse Error: Lookup type: " + lookupTypeName + " (which requries comparison) was requested on "
131 + "a format that is not Comparable: " + lookupFormat.getIdentifierType());
132 }
133 }
134 catch (IllegalArgumentException e)
135 {

Callers

nothing calls this directly

Calls 14

getFunctionNameMethod · 0.95
getReferenceContextMethod · 0.95
getManufacturerMethod · 0.95
requiresSortingMethod · 0.95
ofMethod · 0.80
getLookupFormatMethod · 0.80
getMethod · 0.65
equalsMethod · 0.65
getIdentifierTypeMethod · 0.65
getComponentManagerMethod · 0.65
jjtAcceptMethod · 0.45
getWithMethod · 0.45

Tested by

no test coverage detected