(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics)
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public FormatManager<?> allowArgs(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics) |
| 63 | { |
| 64 | if (args.length != 3) |
| 65 | { |
| 66 | throw new SemanticsFailureException("Function " + getFunctionName() |
| 67 | + " received incorrect # of arguments, expected: 3 got " + args.length + " " + Arrays.asList(args)); |
| 68 | } |
| 69 | |
| 70 | //Turn scope node into a scope name |
| 71 | Node scopeNode = args[0]; |
| 72 | if (!(scopeNode instanceof ASTQuotString)) |
| 73 | { |
| 74 | throw new SemanticsFailureException("Parse Error: Invalid Format Node: " + scopeNode.getClass().getName() |
| 75 | + " found in location requiring a" + " Static String (class cannot be evaluated)"); |
| 76 | } |
| 77 | String formatName = ((ASTQuotString) scopeNode).getText(); |
| 78 | LoadContext context = semantics.get(ManagerKey.CONTEXT); |
| 79 | FormatManager<?> formatManager = context.getManufacturer(formatName); |
| 80 | FormatManager<?> objectFormat = (FormatManager<?>) args[1].jjtAccept(visitor, |
| 81 | semantics.getWith(FormulaSemantics.ASSERTED, Optional.of(formatManager))); |
| 82 | |
| 83 | if (!formatManager.equals(objectFormat)) |
| 84 | { |
| 85 | throw new SemanticsFailureException( |
| 86 | "Parse Error: Invalid Object Format: " + objectFormat.getIdentifierType() |
| 87 | + " found in a getFact call that asserted " + formatManager.getIdentifierType()); |
| 88 | } |
| 89 | if (!CDOMOBJECT_CLASS.isAssignableFrom(objectFormat.getManagedClass())) |
| 90 | { |
| 91 | throw new SemanticsFailureException( |
| 92 | "Parse Error: Invalid Object Format: " + objectFormat + " is not capable of holding a Fact"); |
| 93 | } |
| 94 | Node factNode = args[2]; |
| 95 | if (!(factNode instanceof ASTQuotString)) |
| 96 | { |
| 97 | throw new SemanticsFailureException("Parse Error: Invalid Fact Node: " + factNode.getClass().getName() |
| 98 | + " found in location requiring a" + " Static String (class cannot be evaluated)"); |
| 99 | } |
| 100 | String factName = ((ASTQuotString) factNode).getText(); |
| 101 | FactDefinition<?, ?> factDef = context.getReferenceContext() |
| 102 | .silentlyGetConstructedCDOMObject(FactDefinition.class, formatName + " " + factName); |
| 103 | if (factDef == null) |
| 104 | { |
| 105 | throw new SemanticsFailureException("Parse Error: Invalid Fact: " + factName + " is not a valid FACT name"); |
| 106 | } |
| 107 | Class<?> usable = factDef.getUsableLocation(); |
| 108 | if (!usable.isAssignableFrom(objectFormat.getManagedClass())) |
| 109 | { |
| 110 | throw new SemanticsFailureException("Parse Error: Invalid Fact: " + factDef.getDisplayName() + " works on " |
| 111 | + usable + " but formula asserted it was in " + objectFormat.getIdentifierType()); |
| 112 | } |
| 113 | return factDef.getFormatManager(); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) |
nothing calls this directly
no test coverage detected