From 8a73918c56511f7c9bc84f667356a9d18f16b8ec Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Sun, 29 Dec 2024 17:34:08 -0500 Subject: [PATCH] Removed dead function call accessor code, since all items are now accessed as a function. --- .../metapath/cst/FunctionCallAccessor.java | 47 +++---------------- 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java index 8e28455ce..c8eb87b9c 100644 --- a/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java +++ b/core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java @@ -6,17 +6,10 @@ package gov.nist.secauto.metaschema.core.metapath.cst; import gov.nist.secauto.metaschema.core.metapath.DynamicContext; -import gov.nist.secauto.metaschema.core.metapath.StaticMetapathException; import gov.nist.secauto.metaschema.core.metapath.function.IFunction; -import gov.nist.secauto.metaschema.core.metapath.function.library.ArrayGet; -import gov.nist.secauto.metaschema.core.metapath.function.library.MapGet; -import gov.nist.secauto.metaschema.core.metapath.item.ICollectionValue; import gov.nist.secauto.metaschema.core.metapath.item.IItem; import gov.nist.secauto.metaschema.core.metapath.item.ISequence; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem; -import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; -import gov.nist.secauto.metaschema.core.metapath.item.function.IArrayItem; -import gov.nist.secauto.metaschema.core.metapath.item.function.IMapItem; +import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import java.util.List; @@ -79,41 +72,13 @@ public ISequence accept(DynamicContext dynamicContext, ISequenc ISequence target = getBase().accept(dynamicContext, focus); IItem collection = target.getFirstItem(true); - if (collection instanceof AnonymousFunctionCall) { - return ((AnonymousFunctionCall) collection).execute( - ObjectUtils.notNull(getArguments().stream() - .map(expr -> expr.accept(dynamicContext, focus)) - .collect(Collectors.toUnmodifiableList())), - dynamicContext, - focus); - } - if (collection instanceof IFunction) { - return ((IFunction) collection).execute(ObjectUtils.notNull(getArguments().stream() - .map(expr -> expr.accept(dynamicContext, focus)) - .collect(Collectors.toUnmodifiableList())), dynamicContext, focus); - } - - // the value to find, which will be the key for a map or the index for an array - IExpression argument = getArguments().stream().findFirst() - .orElseThrow(() -> new StaticMetapathException( - StaticMetapathException.NO_FUNCTION_MATCH, - "No key provided for array or map lookup")); - - IAnyAtomicItem key = ISequence.of(argument.accept(dynamicContext, focus).atomize()) - .getFirstItem(false); - if (key == null) { - throw new StaticMetapathException(StaticMetapathException.NO_FUNCTION_MATCH, - "No key provided for functional call lookup"); - } - - ICollectionValue retval = null; - if (collection instanceof IArrayItem) { - retval = ArrayGet.get((IArrayItem) collection, IIntegerItem.cast(key)); - } else if (collection instanceof IMapItem) { - retval = MapGet.get((IMapItem) collection, key); + if (collection == null || !(collection instanceof IFunction)) { + throw new InvalidTypeMetapathException(collection, "The base expression did not evaluate to a function."); } - return retval == null ? ISequence.empty() : retval.toSequence(); + return ((IFunction) collection).execute(ObjectUtils.notNull(getArguments().stream() + .map(expr -> expr.accept(dynamicContext, focus)) + .collect(Collectors.toUnmodifiableList())), dynamicContext, focus); } @Override