Skip to content

Commit

Permalink
Removed dead function call accessor code, since all items are now acc…
Browse files Browse the repository at this point in the history
…essed as a function.
  • Loading branch information
david-waltermire committed Dec 29, 2024
1 parent 3730786 commit 8a73918
Showing 1 changed file with 6 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,41 +72,13 @@ public ISequence<? extends IItem> 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
Expand Down

0 comments on commit 8a73918

Please sign in to comment.