Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a Metapath execution stack #336

Conversation

david-waltermire
Copy link
Contributor

@david-waltermire david-waltermire commented Jan 4, 2025

Committer Notes

Added support for an execution stack on the DynamicContext that tracks the expressions entered and exited during Metapath evaluation. This will be useful context for debugging and error reporting.

This approach adds minimal overhead to processing, due to the stack-based approach which guarantees amortized constant time for push and pop operations.

All Submissions:

By submitting a pull request, you are agreeing to provide this contribution under the CC0 1.0 Universal public domain dedication.

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you included examples of how to use your new feature(s)?
  • Have you updated all website and readme documentation affected by the changes you made?

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced expression management with a new execution stack tracking mechanism.
    • Improved dynamic context handling for expressions.
  • Improvements

    • Refactored method signatures across multiple expression classes.
    • Standardized expression evaluation with evaluate method.
    • Consolidated IExpression interface imports.
    • Renamed toASTString() methods to toCSTString().
  • Changes

    • Modified method access levels from public to protected for expression evaluation methods.
    • Updated package structure for IExpression interface.
    • Simplified generic type parameters in literal expression classes.
  • Internal Refactoring

    • Reorganized package imports.
    • Enhanced type handling in expression classes.
    • Improved code clarity and consistency.

Copy link

coderabbitai bot commented Jan 4, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The pull request introduces a comprehensive refactoring of the Metaschema Core Metapath expression handling system. The primary changes involve renaming methods from accept to evaluate, modifying method visibilities from public to protected, and consolidating the IExpression interface imports to a more general package. These modifications aim to enhance the clarity and encapsulation of expression evaluation across multiple classes in the Metapath framework.

Changes

File/Group Change Summary
DynamicContext.java Added execution stack management with methods pushExecutionStack, popExecutionStack, and getExecutionStack.
IExpression.java Renamed toASTString() to toCSTString(), updated package declaration, and added import for IExpressionVisitor.
MetapathExpression.java Renamed getASTNode() to getCSTNode() and updated relevant documentation.
AbstractBinaryExpression.java, AbstractCSTVisitorBase.java, AbstractExpression.java, AbstractExpressionVisitor.java, AbstractNAryExpression.java, AbstractUnaryExpression.java, AnonymousFunctionCall.java, BuildCSTVisitor.java, CSTPrinter.java, DynamicFunctionCall.java, ExpressionUtils.java, For.java, FunctionCallAccessor.java, ICstExpressionFactory.java, Let.java, NamedFunctionReference.java, StaticFunctionCall.java, VariableReference.java, AbstractFilterExpression.java, AbstractLiteralExpression.java, ArraySequenceConstructor.java, ArraySquareConstructor.java, DecimalLiteral.java, EmptySequence.java, Except.java, ILiteralExpression.java, IntegerLiteral.java, Intersect.java, MapConstructor.java, PostfixLookup.java, Quantified.java, Range.java, SequenceExpression.java, SimpleMap.java, StringConcat.java, StringLiteral.java, UnaryLookup.java, Union.java, AbstractComparison.java, And.java, GeneralComparison.java, IBooleanLogicExpression.java, If.java, Or.java, PredicateExpression.java, ValueComparison.java, AbstractArithmeticExpression.java, AbstractBasicArithmeticExpression.java, Addition.java, Division.java, IntegerDivision.java, Modulo.java, Multiplication.java, Negate.java, Subtraction.java, AbstractRelativePathExpression.java, AbstractRootPathExpression.java, AbstractSearchPathExpression.java, AbstractStepExpression.java, ContextItem.java, INodeTestExpression.java, KindNodeTest.java, NameNodeTest.java, RelativeDoubleSlashPath.java, RelativeSlashPath.java, RootDoubleSlashPath.java, RootSlashOnlyPath.java, RootSlashPath.java, Step.java, WildcardNodeTest.java, AbstractCastingExpression.java, Cast.java, Castable.java, InstanceOf.java, Treat.java, AbstractKeySpecifier.java Replaced accept methods with evaluate methods, changing visibility from public to protected and renaming methods where applicable.
ExpressionUtilsTest.java, BuildCstVisitorTest.java, CSTLogicalExpressionsTest.java, PredicateExpressionTest.java, ValueComparisonTest.java Updated import statements for IExpression to reflect changes in package structure.

Sequence Diagram

sequenceDiagram
    participant DC as DynamicContext
    participant E as Expression
    participant CS as ChildExpression

    DC->>E: pushExecutionStack(expression)
    E->>CS: evaluate(dynamicContext, focus)
    CS-->>E: return result
    E->>DC: popExecutionStack(expression)
Loading

Possibly related PRs

  • /metaschema-java#290: Modifications to AbstractFunction execution method, potentially related to expression state management

Poem

🐰 Hop, hop, through the syntax tree,
Refactoring code with metapath glee!
From accept to evaluate we dance,
Expressions now have a clearer stance.
🌈 CodeRabbit's magic, clean and bright! 🌈


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@david-waltermire david-waltermire changed the title Support a Metapath execution stack Jan 4, 2025
@david-waltermire david-waltermire added this to the v2.2.0 milestone Jan 4, 2025
@david-waltermire david-waltermire self-assigned this Jan 4, 2025
@david-waltermire
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jan 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (2)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Union.java (1)

Line range hint 57-66: Consider pushing and popping the current expression to the DynamicContext’s execution stack for improved debugging.

Since this PR aims to provide an execution stack for expression evaluation, it’s recommended to wrap child evaluations in push/pop calls for the current Union expression. This ensures that all entered and exited expressions are tracked consistently, enhancing both debugging context and error reporting.

Below is a potential approach:

  @Override
  protected ISequence<?> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+    dynamicContext.pushExecutionStack(this);
+    try {
      @NonNull
      Stream<? extends IItem> retval = ObjectUtils.notNull(getChildren().stream()
          .flatMap(child -> {
            ISequence<?> result = child.accept(
                dynamicContext,
                focus.reusable());
            return result.stream();
          }).distinct());
      return ISequence.of(retval);
+    } finally {
+      dynamicContext.popExecutionStack();
+    }
  }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (1)

Line range hint 69-79: Consider renaming .accept(...) to .evaluate(...) in the base expression call.
The newly introduced evaluate(...) method replaces accept(...) for expression evaluation, yet the base expression call still uses .accept(...). If the base expression is also updated to support .evaluate(...), align these method names for consistency.

-    ISequence<?> base = getBase().accept(dynamicContext, focus);
+    ISequence<?> base = getBase().evaluate(dynamicContext, focus);
🧹 Nitpick comments (25)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (1)

53-57: Method rename and visibility change aligns with broader refactoring pattern

The change from public accept() to protected evaluate() is part of a broader refactoring pattern that:

  1. Better encapsulates the evaluation logic by making it protected
  2. Uses more descriptive method naming ('evaluate' vs 'accept')
  3. Supports the new execution stack feature for debugging and error reporting

The implementation maintains the existing functionality while improving the design.

This change follows good design principles by:

  • Improving encapsulation through proper visibility modifiers
  • Using more meaningful method names that better describe their purpose
  • Maintaining consistency across the codebase as part of a larger refactoring effort
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/If.java (1)

89-89: Align sub-expression calls with the renamed method.
While this evaluate method replaces the old accept logic, it still invokes accept on sub-expressions (getTestExpression().accept(...), etc.). If your intent is to rename all expression processing methods to evaluate, you should update these calls accordingly throughout the sub-expressions to prevent confusion and maintain consistent naming. Otherwise, confirm that it is intentional to retain the accept method for sub-expressions.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringLiteral.java (1)

30-30: Validate string length before stripping quotes.

Currently, removeQuotes(value) assumes the string is at least two characters long and properly enclosed in quotes. Consider adding a defensive check to avoid potential IndexOutOfBoundsException for malformed strings.

private static String removeQuotes(@NonNull String value) {
+  if (value.length() < 2) {
+    throw new IllegalArgumentException("String not enclosed in quotes: " + value);
+  }
  return value.substring(1, value.length() - 1);
}
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java (1)

Line range hint 16-22: Correct the Javadoc to refer to “intersect” rather than “except.”

The constructor Javadoc appears to be a copy-paste artifact referring to “Metapath except expression.” For clarity and consistency with the class name Intersect, consider updating the doc comment as follows:

- * Construct a new Metapath except expression CST node.
+ * Construct a new Metapath intersect expression CST node.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java (1)

48-48: Consider adding a Javadoc comment for the evaluate method.

The method’s purpose is clear from context, but providing a brief Javadoc block clarifying the evaluation approach and details of how the input focus is transformed would enhance maintainability.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java (1)

64-64: Use generics to ensure type safety.

While switching from public ISequence<? extends IItem> to protected ISequence<?> provides flexibility, it may be beneficial to use generics or a more specific return type to avoid type erasure and maintain stricter compile-time checks. If the method usage must remain this generic, consider adding documentation explaining why.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/MapConstructor.java (2)

Line range hint 55-64: Ensure robust error reporting.

The switch to toCSTString() for the key expression in the error message is helpful for diagnosing parsing-level issues. However, consider also including context about the current evaluation stack if available, to pinpoint the failing expression more precisely during debugging.


132-132: Refine exception logic or message.

Throwing UnsupportedOperationException indicates that evaluate is intentionally delegated to the parent class. Consider adding a clarifying message or a Javadoc comment explaining that this method is deliberately unimplemented because the map entry logic is rolled up into the parent’s evaluate method.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringConcat.java (1)

71-71: Consider renaming the child calls from accept to evaluate for consistency.
This evaluate method relies on calling child.accept(...) on each child expression. To enhance consistency and clarity throughout the codebase, consider refactoring these calls to child.evaluate(...) if feasible.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (1)

79-79: Maintain consistent naming across calls.
While the method is now named evaluate, you still invoke accept(dynamicContext, focus) on the base expression. This might introduce confusion or hamper discoverability. Consider renaming the child's accept method to evaluate to align with the broader refactoring.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Let.java (1)

85-85: Promote internal consistency by renaming child calls to evaluate.
Similarly, this evaluate method calls getReturnExpression().accept(...). For clarity, consider renaming the child's method to evaluate(...), so that handling is consistent across the entire codebase.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1)

58-58: Consider clarifying the toCSTString() method name in comments or docstrings.

Renaming to toCSTString() is consistent with representing "Concrete Syntax Tree," but adding a short explanation may help future maintainers distinguish this method from any toASTString() usage in other classes.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java (1)

Line range hint 28-35: Consider optimizing the filter operation to avoid O(n²) complexity.

Currently, using items.contains(item) in a stream filter runs in O(n) per item. If items is large, this approach can significantly degrade performance. Converting items to a Set before filtering can reduce the overall complexity to O(n).

Below is one way to implement this change:

protected ISequence<?> applyFilterTo(@NonNull List<? extends IItem> source,
                                     @NonNull List<? extends IItem> items) {
+  Set<IItem> filterSet = new HashSet<>(items);
  return ISequence.of(ObjectUtils.notNull(
    source.stream()
-         .filter(item -> !items.contains(item))
+         .filter(item -> !filterSet.contains(item))
          ));
}
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ContextItem.java (1)

69-69: Handle null focus to avoid potential NPE.

Currently, only an empty focus is checked. While your higher-level code may guarantee that focus is never null, guarding against a null pointer would make this method more robust.

One possible fix:

 protected ISequence<?> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+  if (focus == null) {
+    throw new DynamicMetapathException(DynamicMetapathException.DYNAMIC_CONTEXT_ABSENT, "The context is null");
+  }
   if (focus.isEmpty()) {
     throw new DynamicMetapathException(DynamicMetapathException.DYNAMIC_CONTEXT_ABSENT, "The context is empty");
   }
   return focus;
 }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (1)

63-63: Consider adding debug instrumentation for consistency with the new execution stack feature.

If other expressions in this PR push/pop from the dynamicContext to track the current expression in the stack, you may want to do the same here, even though the sequence is empty. This ensures consistent behavior and debugging.

  @Override
  protected ISequence<RESULT_TYPE> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+    // Optionally track expression for debugging and error reporting
+    dynamicContext.push(this);
    ISequence<RESULT_TYPE> retval = ISequence.empty();
+    dynamicContext.pop();
    return retval;
  }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpression.java (1)

112-112: Review type-safety and possible performance implications.

Using asInteger() on the IntegerLiteral for indexing is acceptable; however, consider adding checks to ensure the integer value is within expected bounds. Large values could potentially degrade performance or lead to unexpected results.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Quantified.java (1)

Line range hint 136-196: Consider unifying naming and enhancing type safety.

  1. Method Renaming Consistency
    The class-level method changed from accept(...) to evaluate(...), but this block still calls accept(...) on sub-expressions (e.g., entry.getValue().accept(...)). If your intent is to standardize evaluation method names, consider renaming or delegating these calls through a similarly named method to maintain consistency.

  2. Return Type Specificity
    Since this expression always produces a boolean result, changing the return type from ISequence<?> to ISequence<IBooleanItem> could provide stronger type safety, facilitating clearer expectations when calling evaluate(...).

  3. Logic Review

    • The “SOME”/“EVERY” evaluation logic is correct and short-circuits as expected on the first definitive result.
    • The cartesian product iteration is suitably encapsulated in the inner class.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (1)

47-50: Concise evaluation method.
The evaluate implementation properly wraps the literal in an ISequence.
Optional enhancement: If feasible in the overall design, consider returning ISequence<RESULT_TYPE> instead of ISequence<?> for stricter typing.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java (1)

80-80: Renaming toASTString() to toCSTString()
Renaming this method to “CST” terminology is consistent with other refactorings. Verify references in downstream classes or tests to ensure proper usage.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java (1)

87-87: Public toCSTString() method
Renaming from toASTString() to toCSTString() aligns with the rest of the code’s naming convention. Adding public visibility is acceptable, but verify this method is not inadvertently exposed outside the intended scope.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (1)

311-320: Added pushExecutionStack().
Properly stores the current expression for debugging or introspection. Consider adding unit tests to confirm stack behavior under concurrent or nested expression scenarios.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java (1)

53-65: Consider unifying generics for improved consistency.

accept returns ISequence<?>, whereas evaluate returns ISequence<? extends IItem>. If feasible, unify these generics to maintain a consistent API boundary and avoid potential identity casting or typed usage confusion.

Potential approach:

-protected abstract ISequence<? extends IItem> evaluate(
+protected abstract <T extends IItem> ISequence<T> evaluate(
    @NonNull DynamicContext dynamicContext,
    @NonNull ISequence<?> focus);
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (1)

Line range hint 69-79: Replace or handle assert item != null more robustly.
Assertions may be disabled at runtime, so consider throwing a dedicated exception if a null item truly indicates an error case.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (2)

63-63: Consider adding JavaDoc to clarify the evaluation approach.

The new evaluate() method introduces core logic for retrieving the root document node, but its behavior and potential edge cases (e.g., empty focus) could be more transparent if documented in JavaDoc, especially given this is a key method for resolving the root context in Metapath evaluation.


Line range hint 64-70: Refactor the chained stream operations for clarity.

This stream chain is functional, but it can be harder to follow. Consider extracting sub-steps into local variables or a small helper method, which might improve readability without sacrificing performance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2e2409 and 9281a76.

📒 Files selected for processing (84)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (14 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractBinaryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractNAryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/DynamicFunctionCall.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/For.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Let.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/StaticFunctionCall.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySequenceConstructor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySquareConstructor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/DecimalLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ILiteralExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/IntegerLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/MapConstructor.java (4 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Quantified.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Range.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SequenceExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SimpleMap.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringConcat.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/UnaryLookup.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Union.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/And.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/GeneralComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/IBooleanLogicExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/If.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/Or.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractArithmeticExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractBasicArithmeticExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Addition.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/IntegerDivision.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Modulo.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Negate.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRelativePathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRootPathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractSearchPathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractStepExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ContextItem.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/INodeTestExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameNodeTest.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeDoubleSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootDoubleSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/WildcardNodeTest.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/AbstractCastingExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Cast.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Castable.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ExpressionUtilsTest.java (0 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/CSTLogicalExpressionsTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpressionTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparisonTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ExpressionUtilsTest.java
✅ Files skipped from review due to trivial changes (8)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Addition.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRelativePathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractSearchPathExpression.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpressionTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractArithmeticExpression.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparisonTest.java
🧰 Additional context used
📓 Learnings (13)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractBinaryExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/IBooleanLogicExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#245
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java:86-104
Timestamp: 2024-11-14T18:19:40.200Z
Learning: In the file `core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/atomic/IBooleanItem.java`, the 3-step approach in the `cast` method is consistent with the XPath 3.1 specification.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractNAryExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/AbstractCastingExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#266
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/FunctionCallAccessor.java:82-89
Timestamp: 2024-11-28T04:47:39.173Z
Learning: In `FunctionCallAccessor.java`, the `accept` method must continue executing after handling `AnonymousFunctionCall` to properly process other collection types. Adding an `else` block that bypasses the remaining code is incorrect.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
🔇 Additional comments (136)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java (1)

9-9: Consistent interface placement is beneficial.

Switching to gov.nist.secauto.metaschema.core.metapath.IExpression helps ensure that the IExpression interface is referenced from its more general location, promoting consistent package organization. Nice work!

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/WildcardNodeTest.java (2)

54-54: Maintain consistent method signature in refactored classes.

The new evaluate method aligns with the renaming convention from accept to evaluate used elsewhere. Making it protected is consistent with limiting external access, and the usage of streams ensures efficient processing. Overall, this change appears structurally sound.


97-97: Renaming to toCSTString() is consistent with the shift from AST to CST.

The updated method name clearly indicates that the returned string represents the concrete syntax tree, which improves clarity and consistency across the refactored codebase.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (1)

9-9: Verify import statement consistency across codebase

The import statement has been moved to a more general package, which aligns with the consolidation of the IExpression interface imports.

Let's verify this change is consistent across the codebase:

✅ Verification successful

Import change is consistent across codebase

The search results confirm that all files are using the new import path gov.nist.secauto.metaschema.core.metapath.IExpression consistently. There are no remaining references to the old package-specific import path containing .cst.IExpression. This change aligns with the broader refactoring effort to consolidate the IExpression interface imports.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining imports from the old package
rg "import.*\.cst\.IExpression;" -g '*.java'

# Search for imports from the new package
rg "import.*\.metapath\.IExpression;" -g '*.java'

Length of output: 11246

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/DecimalLiteral.java (2)

22-22: Confirm the correctness of the generic type signature.
Switching from a multi-generic signature to AbstractLiteralExpression<IDecimalItem> is consistent with the refactor but ensure that any code relying on a second type parameter (e.g., BigDecimal) no longer needs it.


33-33: Validate the IDecimalItem.valueOf(...) usage.
The call to IDecimalItem.valueOf(value) is appropriate and streamlines the instantiation. Just confirm that valueOf(...) handles large decimal inputs and edge cases (e.g., negative or extremely large values) as expected.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (3)

9-9: Import references updated for clarity
The new import statement correctly references IExpression in the metaschema.core.metapath package, which aligns with the broader refactoring changes and enhances consistency.


Line range hint 110-130: Visibility change and method name refactor
Changing the method from a public accept to a protected evaluate aligns with the encapsulation of internal logic while retaining the existing functionality. The usage of axis.execute(item).distinct() is appropriate here, ensuring duplicates are removed, although you should confirm that discarding duplicates is the intended behavior for all use cases. Other than that, the method appears coherent and maintains readability.


131-131: Renamed 'toASTString()' to 'toCSTString()'
The rename and updated content of this method correctly follow the codebase transition from AST to CST terminology. The format string usage is clear and helps maintain consistent naming across the system.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/IntegerLiteral.java (2)

22-22: Good alignment with new generic type simplification.

Changing the class to use AbstractLiteralExpression<IIntegerItem> conforms nicely to the updated design, reducing complexity by removing the additional type parameter. This refactor increases consistency across literal expressions.


33-33: Properly converting BigInteger to IIntegerItem.

Using IIntegerItem.valueOf(value) at construction is correct and ensures that the literal expression consistently returns an IIntegerItem as required by its new parent class. No further changes needed.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractStepExpression.java (2)

66-66: Ensure downstream calls to evaluate() are properly adjusted.

The method name and visibility have changed from accept (public) to evaluate (protected). This may impact any classes or interfaces relying on the old signature. Verify that all subclasses override or call this method consistently.

If references to the old accept() exist, you might provide a short deprecation or bridging layer to avoid breakage. Do you want me to open a new GitHub issue to track this migration strategy?


9-9: Confirm alternative references to IExpression have been updated.

This import update changes the package location of IExpression. Ensure that other references to this interface across the codebase are also updated, to avoid any potential confusion or ambiguous imports.

Run the following script to ensure there are no remaining imports from the old package:

✅ Verification successful

Let me search for actual references to IExpression to verify if there are any remaining imports from the old package.


All imports of IExpression are using the correct package path

Based on the search results, all imports of IExpression are consistently using the correct package path gov.nist.secauto.metaschema.core.metapath.IExpression. There are no remaining imports from the old package path. The import change in the file under review is consistent with how the interface is being imported across the entire codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to the old package path for IExpression.

rg "import gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.IExpression"

Length of output: 7640


Script:

#!/bin/bash
# Search for direct imports of IExpression
rg "import .*\.IExpression;"

Length of output: 11178

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Range.java (2)

9-9: The updated import maintains consistency with the new evaluation approach.
This change ensures that IExpression references align with the updated framework for Metapath expressions as described in the PR.


54-54: Rename from accept to evaluate and shift to protected is well-aligned with the updated design.
Renaming the method to evaluate clarifies its role in the Metapath processing flow. Changing the scope from public to protected helps encapsulate the evaluation logic, preventing unintended external access. This is consistent with good object-oriented design principles.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java (1)

8-8: Proper import usage.

Switching the import of IExpression from the cst subpackage to metapath is consistent with the broader refactoring efforts. This change improves clarity and aligns with the new package structure.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java (1)

8-8: Well-structured usage of the new import.
This addition clarifies references to IExpression and aligns well with the visitor pattern usage throughout the class, improving overall type safety and readability.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/If.java (1)

9-9: Confirm correct import path change.
The package name for IExpression has changed from cst to metapath. Make sure that other related imports and references follow this new package structure consistently to avoid any breakage.

Run the following script to locate and confirm all IExpression imports across the codebase:

✅ Verification successful

All imports of IExpression are consistently using the new package path

The search results show that all imports of IExpression across the codebase are consistently using the new package path gov.nist.secauto.metaschema.core.metapath.IExpression. There are no remaining imports from the old cst package path. The change appears to have been applied consistently throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent usage of the new IExpression import path.
rg -A 2 "import.*IExpression"

Length of output: 48210

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringLiteral.java (1)

20-20: Simplified generics improves readability.

Transitioning from AbstractLiteralExpression<IStringItem, String> to AbstractLiteralExpression<IStringItem> makes the class signature more concise and improves maintainability. This change is well-aligned with the broader refactoring efforts.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java (1)

8-8: Refactored import path aligns with the broader reorganization.

The switch from gov.nist.secauto.metaschema.core.metapath.cst.IExpression to gov.nist.secauto.metaschema.core.metapath.IExpression is consistent with the overall package refactoring and helps clarify where IExpression is defined. This practice improves code structure and organization.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/INodeTestExpression.java (1)

8-8: Ensure references to IExpression are consistent across the codebase.

The updated import path reflects the new package structure. Verify that no references to the old cst.IExpression remain in the repository to prevent compilation or functionality issues.

Use the following script to locate any references to cst.IExpression:

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SequenceExpression.java (2)

9-9: Import usage looks good

This new import for IExpression is necessary for referencing the interface within the constructor.


57-57: Consider integrating the new execution stack logic

The renamed and scoped-down evaluate method is consistent with the refactoring. However, since the PR objective mentions adding an execution stack to track expressions for debugging and error reporting, ensure that push/pop calls are included here or in the invoked methods to record this SequenceExpression evaluation in the stack.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Negate.java (2)

9-9: Import usage looks consistent.
No concerns with introducing IExpression in this file. The new import aligns well with the constructor usage and maintains a coherent design within the Metapath framework.


63-63: Evaluate method field stack usage check.
The new evaluate() method properly handles negation logic. However, ensure that the new execution stack is updated (pushed/popped) if it is relevant to capturing the current evaluation context. Verify that it aligns with the broader stack-based approach introduced in the PR.

Would you like me to propose a code snippet showing potential stack push/pop calls to ensure full alignment with the DynamicContext execution stack?

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Cast.java (2)

9-9: Import usage is consistent with the broader refactoring efforts.

Switching from the cst.IExpression import to the metapath.IExpression import aligns with the project's reorganized package structure. This helps maintain consistency across the codebase.


52-52: Method signature change: Evaluate potential impact of modified visibility and return type.

Renaming accept to evaluate and reducing visibility from public to protected is logical if external consumers no longer require direct access. However, changing the return type from ISequence<? extends IItem> to a coarser ISequence<?> may reduce type safety. Verify no external usage depends on the finer-grained type, ensuring this broader return type does not introduce runtime casting issues.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java (1)

9-9: Confirm the updated import path for IExpression.

Ensure that all references to IExpression in the codebase align with this new package path, and that no stale imports remain in other classes.

✅ Verification successful

Based on the search results, I can see that IExpression is consistently imported from gov.nist.secauto.metaschema.core.metapath.IExpression across all files in the codebase. The import statement in the file under review matches this pattern exactly. There are no stale or incorrect imports of IExpression found in the codebase.

The import path for IExpression is correctly updated and consistent throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify references to IExpression in the codebase still exist only in the new package.
rg 'import.*IExpression' -A 3

Length of output: 60240

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractComparison.java (2)

8-8: No issues with this import statement reordering.
The clarified import for IExpression aligns with the reorganization for clarity.


62-62: Confirm all invocations and references to the old toASTString() have been updated.
Renaming to toCSTString() is consistent with the new terminology. Ensure that references to toASTString() in the rest of the codebase have been adjusted accordingly.

Use this script to locate any lingering references to toASTString():

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/And.java (2)

9-9: Confirm that this import is still needed.
It looks like IExpression was already imported before, and removing the old import while adding a new one for the same class might be redundant. Verify that this import is the only reference in use and consider removing any unused imports if they exist.


57-57: Short-circuit evaluation appears correct.
Your approach to short-circuit the loop when one child returns false is spot-on for AND logic, thus avoiding unnecessary processing. The use of FnBoolean.fnBooleanAsPrimitive() for evaluating each child is consistent, but ensure that error cases (e.g., empty sequences) are handled gracefully.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java (1)

8-8: The updated import path looks consistent.

This change moves IExpression to a higher-level package. Verify that all references to IExpression in downstream files have also been updated to prevent compilation issues.

Run the following script to confirm that no references to the old cst.IExpression path remain:

✅ Verification successful

Let me verify if there are any remaining references to the old path by searching for direct usage of IExpression from the old package.


Let me try one more verification to ensure we catch any potential references to the old path by searching for import statements.


All references to IExpression have been properly updated

Based on the verification results, we can confirm that:

  1. There are no remaining references to IExpression from the old cst package path
  2. The search results show that files are consistently using IExpressionVisitor from the cst package, but IExpression itself is correctly imported from the new higher-level package location
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any references to the old import path.
rg "metapath\.cst\.IExpression"

Length of output: 7746


Script:

#!/bin/bash
# Search for any direct usage of IExpression from the old cst package
rg "cst\.IExpression[^V]" # Excluding IExpressionVisitor matches

Length of output: 27


Script:

#!/bin/bash
# Search for any imports of IExpression from the old package
rg "^import.*metapath\.cst\.IExpression;" --type java

Length of output: 55

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/UnaryLookup.java (2)

9-9: Confirm consistency of the import path.

It’s good that you’ve switched from cst.IExpression to metapath.IExpression, ensuring proper alignment with the broader refactoring effort. Please verify other classes referencing IExpression still build correctly with this new import.


52-52: Method renaming and visibility look sound.

Renaming accept to evaluate and changing visibility to protected align with the newly established naming conventions and scoping. This helps better encapsulate the expression’s behavior. No further concerns here.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java (2)

10-10: Ensuring correct import usage.

The newly added import for IExpression is consistent with the usage in the file. No concerns here.


80-80: Method rename is consistent with refactoring strategy.

Renaming toASTString to toCSTString aligns well with the broader renaming across the codebase, improving clarity and consistency. The usage of the method appears correct.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Castable.java (2)

9-9: Confirm the intended interface usage.

Importing IExpression from gov.nist.secauto.metaschema.core.metapath instead of gov.nist.secauto.metaschema.core.metapath.cst is consistent with the broader refactoring across the codebase. Ensure that the rest of the code referencing IExpression aligns with this new import path.


54-54: Verify handling of dynamicContext within evaluate.

The current implementation does not use any members or methods of dynamicContext aside from calling cast(focus). Confirm if the cast method implicitly requires the dynamicContext, or remove it if unnecessary to reduce complexity. Additionally, consider adding tests for this evaluate method to ensure the new casting logic behaves as expected.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ILiteralExpression.java (3)

8-8: Good import location adjustment.
This aligns with the refactoring away from the cst package.


31-31: Return type update is consistent with simplified typing.
Changing the returned value to RESULT_TYPE is consistent with the new interface definition.


24-24: Ensure all references to the removed generic type are updated.
Removing the second generic type parameter simplifies the interface. However, verify that there are no remaining references or usages of the removed type parameter in the codebase.

✅ Verification successful

No remaining references to the removed generic type parameter found

Based on the comprehensive search of the codebase, all implementations and usages of ILiteralExpression are correctly using only a single generic type parameter that extends IAnyAtomicItem. The interface is being used correctly in:

  • AbstractLiteralExpression<RESULT_TYPE extends IAnyAtomicItem>
  • DecimalLiteral extends AbstractLiteralExpression<IDecimalItem>
  • StringLiteral extends AbstractLiteralExpression<IStringItem>
  • IntegerLiteral extends AbstractLiteralExpression<IIntegerItem>

No instances of the old two-parameter generic syntax were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that no references to the old generic type parameter exist.

rg 'ILiteralExpression<[^>]+,' -A 3

Length of output: 37


Script:

#!/bin/bash
# Let's try a different approach to find any references to ILiteralExpression with generic parameters

# Search for implementations and usages of ILiteralExpression
rg "ILiteralExpression" -B 2 -A 2

# Also search for class/interface definitions that might implement/extend ILiteralExpression
ast-grep --pattern 'class $_ implements $$$ILiteralExpression$$$'
ast-grep --pattern 'class $_ extends $$$ILiteralExpression$$$'

Length of output: 1544


Script:

#!/bin/bash
# Let's search for concrete implementations of ILiteralExpression to ensure all are using the correct generic parameter

# Find all files that might contain literal expression implementations
fd -e java -x grep -l "LiteralExpression" {} \; | xargs cat

# Also specifically look for any potential string patterns that might indicate old two-parameter usage
rg "ILiteralExpression\s*<\s*\w+\s*,\s*\w+\s*>" --type java

Length of output: 6772

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameNodeTest.java (2)

64-64: Validate null/empty stream handling in evaluate method.

While the usage of ObjectUtils.notNull() ensures that focus.stream() isn't null, consider adding checks or documentation around empty streams. If focus is empty, this method would return an empty ISequence, which may be correct behavior but could also surprise callers.


78-78: Renamed toCSTString() meets naming consistency.

Renaming from toASTString() to toCSTString() aligns with the broader rename of AST to CST. The implementation here remains concise and clear.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/MapConstructor.java (1)

9-9: LGTM on updated import location.

Switching from the cst package to the general IExpression interface aligns with the broader refactoring efforts to consolidate expression handling in a single package.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/Or.java (1)

74-74: Rename from accept to evaluate is consistent, but verify external references

The short-circuit logic within this method is correct and matches typical "or" behavior. However, ensure that no external code relies on the previous public accept method signature. This new protected method may not be accessible if there are external invocations.

Run the following script to check for references to Or.accept(...) that may be broken:

✅ Verification successful

The rename from accept to evaluate is safe

Based on the codebase analysis:

  1. The Or class is only instantiated in two places:
    • BuildCSTVisitor.java for constructing the CST
    • CSTLogicalExpressionsTest.java for unit testing
  2. No direct calls to the accept method were found in the codebase
  3. The test class shows that the class is used through the expression evaluation interface, not by directly calling the method
  4. The method is protected, limiting its visibility to the package and subclasses
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find any references to the old method signature in the codebase

rg -A 3 'Or\s*\(.*\)\s*{\s*.*accept\s*\('

Length of output: 172


Script:

#!/bin/bash
# Search for any references to 'accept' method in Or class or its usages
rg -l "Or.*\.accept" 

# Search for any references to Or class
rg "class.*extends.*Or|new\s+Or\s*\(" 

# Use AST to find method calls on Or instances
ast-grep --pattern 'or.$accept($$$)'

Length of output: 403


Script:

#!/bin/bash
# Let's check the content of these files to understand the usage context
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/CSTLogicalExpressionsTest.java

# Also check for any inheritance hierarchy
ast-grep --pattern 'class Or extends $_ {
  $$$
}'

Length of output: 54580

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySquareConstructor.java (2)

9-9: No issues with the new import.
This import correctly references the IExpression interface from the intended package, and there are no conflicts or unused imports detected in the provided snippet.


52-52: Confirm the impact of changing the method scope to protected.
Previously, a similar method was public. Changing it to protected limits its visibility to subclasses and same-package classes. Ensure this reflects the intended encapsulation and won't break existing external usage.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/GeneralComparison.java (1)

9-9: Good alignment of package structure.

Switching the import from the cst package to gov.nist.secauto.metaschema.core.metapath.IExpression aligns with the broader refactoring goals. Ensure that other references are also updated to use the new import path.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java (1)

8-8: The import statement is well-aligned with the existing code usage.

There's no immediate issue with bringing in IExpression from gov.nist.secauto.metaschema.core.metapath, given it is used by the new method signature. If there are other classes that require the same interface, ensure they also use this single import source for consistency.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringConcat.java (1)

9-9: Import usage looks good.
No issues found with the new import of IExpression.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (1)

9-9: No concerns with the new import statement.
The addition of the IExpression import is consistent with the rest of the changes.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Let.java (1)

9-9: Import modification accepted.
This change appears straightforward and aligns with the new usage of IExpression in place of IItem.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeSlashPath.java (3)

50-50: Double-check visibility impact of switching from public to protected.
The method is now protected. Verify that no external callers beyond this class hierarchy need to invoke evaluate. If external usage is required, reverting to public may be necessary.


Line range hint 50-58: Consider renaming chained calls to evaluate for consistency.
While this class uses evaluate(...) itself, it still calls .accept(...) on nested expressions. If all classes now support evaluate(...) for dynamic evaluation, calling .accept(...) may be inconsistent or cause confusion. Confirm if nested expressions should also call .evaluate(...) for clarity.


9-9: Confirm consistency with broader import refactoring.
Switching to gov.nist.secauto.metaschema.core.metapath.IExpression is a viable move, but ensure that other classes in the cst package no longer rely on the previous IExpression import path.

Run this script to identify any leftover references to the old package:

✅ Verification successful

Let me search for the actual IExpression usage to verify if the import change is consistent.


Import change is consistent with the codebase

Based on the search results, the change from metapath.cst.IExpression to gov.nist.secauto.metaschema.core.metapath.IExpression in RelativeSlashPath.java is consistent with the rest of the codebase. All files are using the same import path gov.nist.secauto.metaschema.core.metapath.IExpression, and there are no references to the old package path. The interface is defined in the core metapath package and is being correctly imported across all usages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to "metapath.cst.IExpression"
rg "metapath\.cst\.IExpression"

Length of output: 7746


Script:

#!/bin/bash
# Search for IExpression usage in the cst package
ast-grep --pattern 'IExpression'

Length of output: 11614

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/IBooleanLogicExpression.java (1)

8-8: Looks good!

This import path change aligns with the broader refactoring of IExpression into a higher-level package.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1)

51-56: Check for consistent usage of the new evaluate method across the codebase.

Renaming from accept to evaluate is a clear improvement in readability, but ensure all references and overrides in subclasses or related classes are similarly updated for consistency. Additionally, confirm that downstream logic properly interprets the returned sequence since items are now passed through checkItemIsNodeItemForStep().

✅ Verification successful

Let me try a different approach to search for the method references.


Based on the search results, I can now provide a final response:

The evaluate method is consistently used across the codebase, replacing accept

The codebase shows a clear pattern where:

  • The accept method is defined in the interface IExpression and implemented in AbstractExpression as a public method
  • The protected evaluate method is consistently used across all implementation classes (over 30 files found)
  • The accept method in AbstractExpression serves as a wrapper that calls the protected evaluate method

This architecture follows a proper template method pattern where:

  1. Public accept provides the common execution context handling
  2. Protected evaluate allows subclasses to implement specific evaluation logic

The changes are consistent and no issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify references to the renamed/overridden `evaluate` method.
ast-grep --pattern $'function_declaration(name: (_) @name) {}' --json 

Length of output: 73


Script:

#!/bin/bash
# Search for files containing 'evaluate' method in Java files
rg -t java "evaluate.*\(.*DynamicContext.*ISequence" -B1 -A1

Length of output: 18844


Script:

#!/bin/bash
# Search for files containing 'accept' method that might need to be renamed
rg -t java "accept.*\(.*DynamicContext.*ISequence" -B1 -A1

Length of output: 2589


Script:

#!/bin/bash
# Find all Java files in the path hierarchy
fd -e java . core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/

Length of output: 2215

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/StaticFunctionCall.java (3)

9-9: Consistent Usage of IExpression Interface

The introduction of the IExpression import aligns with the use of List<IExpression> in the constructor arguments, improving consistency. Confirm that all relevant implementations of IExpression are properly imported and used across the codebase.


106-106: Scope Change from public to protected

Changing the method from public to protected may affect external access. Verify that any consumers requiring direct invocation have alternative interfaces. The rename from accept() to evaluate() clarifies the method’s intent for expression evaluation.


95-95: Rename to toCSTString()

Renaming this method from toASTString() to toCSTString() clarifies its purpose within a compact syntax tree (CST) context. Ensure that references to the old method name have been updated to avoid breaking existing functionality.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java (1)

8-8: Import path update looks good.

Using gov.nist.secauto.metaschema.core.metapath.IExpression aligns with the broader refactoring effort to consolidate expression-related classes.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootDoubleSlashPath.java (2)

9-9: Imports look consistent with refactoring.

The switch from the CST package to the core Metapath package for IExpression appears consistent with the broader refactoring. Ensure all other references to IExpression in the codebase are similarly updated to avoid confusion or compilation issues.


45-45: Consider verifying stack-based support for debugging and error handling.

While this refactored evaluate method is concise and follows a straightforward approach, ensure you incorporate the new stack-based context approach desired by the PR’s objectives. For instance, pushing onto the execution stack before calling search(), then popping after the method completes, can reveal deeper insights into the evaluation process for debugging.

Execute this shell script to locate any usage of a push/pop stack mechanism in the cst or metapath packages that might need updating to ensure RootDoubleSlashPath is also integrated with the debugging context:

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ContextItem.java (1)

10-10: Confirm single source of interface definitions.

You've moved the IExpression import from the cst package to the root metapath package. Ensure no residual references to the old IExpression exist in other classes and that this import aligns with the desired interface location.

✅ Verification successful

Let me search for more specific information about the IExpression interface.


Let me try a different approach to find the IExpression interface.


The import change is correct and properly aligned

Based on the verification results, the IExpression interface is indeed correctly defined in the root metapath package at gov/nist/secauto/metaschema/core/metapath/IExpression.java. The search results show that all files are now importing IExpressionVisitor from the cst package, but IExpression is being imported from the root metapath package, which is the correct location. There are no residual references to the old IExpression import path in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential references to the old `IExpression` import path within the codebase.
rg $'import gov.nist.secauto.metaschema.core.metapath.cst.IExpression'

Length of output: 7633


Script:

#!/bin/bash
# Check for the actual IExpression interface definition
ast-grep --pattern 'interface IExpression'

Length of output: 44


Script:

#!/bin/bash
# Find files containing IExpression definition and usage
rg -l "IExpression" --type java

# Show content of IExpression.java if it exists
fd "IExpression.java" -x cat {}

Length of output: 11080

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java (2)

9-9: Approved import usage.

Your import reference to IExpression is appropriately placed and aligns with the revised structure of the code.


97-97: Renaming method for clarity.

Renaming toASTString() to toCSTString() clarifies that it returns the compact syntax tree representation. This is consistent with the broader refactoring across the codebase.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractBasicArithmeticExpression.java (2)

9-9: Verify import path consistency

This import references the IExpression interface from the gov.nist.secauto.metaschema.core.metapath package instead of the old cst package. Confirm that no references to the old import remain and that all relevant interfaces are consistently referenced from this new location.
[approve]

Use this script to search for any residual references to the old package:

✅ Verification successful

Let me search for any direct references to cst.IExpression to ensure we haven't missed anything.


Let me check the actual content of the IExpression interface to understand the relationship between the old and new locations.


Import change is correct and consistent

The import change in AbstractBasicArithmeticExpression.java is correct. The IExpression interface has been moved from the cst package to the parent metapath package, and all references to this interface are now properly using the new location. The old cst.IExpression references found in the codebase are actually references to IExpressionVisitor from the cst package, which is a different interface that is still correctly located in the cst package and is used by the IExpression interface for the visitor pattern implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for cst.IExpression references across the codebase
rg 'cst\.IExpression'

Length of output: 7736


Script:

#!/bin/bash
# Search for direct references to IExpression in the cst package
ast-grep --pattern 'cst.IExpression'

# Also search for any class that might implement the old interface
ast-grep --pattern 'implements $_ cst.IExpression'

# Let's also check for any references to the old package structure
rg -l "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.IExpression"

Length of output: 4295


Script:

#!/bin/bash
# Check the content of IExpression.java to understand the interface structure
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java

# Also check if there's any old IExpression interface in the cst package
fd IExpression.java -t f core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst

Length of output: 3347


57-57: Assess external exposure of the new evaluate() method

Changing the access modifier from public to protected may break code outside this class hierarchy that previously relied on the public accept() method. Ensure that no external classes or callers depend on the earlier public access level. If necessary, provide a suitable public method or verify that method calls have been updated accordingly.

✅ Verification successful

Let me analyze the code further to verify the impact of the access modifier change.


Let me try a different search pattern to understand the class hierarchy and method usage.


Based on the search results, I can now provide a final response:

The access modifier change from public to protected is safe and appropriate

The evaluate() method in AbstractBasicArithmeticExpression is only used within its class hierarchy by concrete implementations:

  • Addition.java
  • Subtraction.java
  • Multiplication.java
  • Division.java

The search results show no external direct calls to this evaluate() method. The method is an internal implementation detail used by arithmetic operation classes that extend AbstractBasicArithmeticExpression. The change to protected actually improves encapsulation by properly restricting access to this implementation method within its inheritance hierarchy.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for direct calls to the old accept method in the repo.
rg '\.accept\('

Length of output: 20509


Script:

#!/bin/bash
# Search for the class hierarchy and usage of AbstractBasicArithmeticExpression
ast-grep --pattern 'class $_ extends AbstractBasicArithmeticExpression'

# Search for the evaluate method in the class
ast-grep --pattern 'protected ISequence<? extends IAnyAtomicItem> evaluate'

Length of output: 151


Script:

#!/bin/bash
# Search for the class and its evaluate method implementation
rg -A 5 "class AbstractBasicArithmeticExpression"

# Search for direct references to evaluate method
rg "\.evaluate\("

# Search for files that might extend this class
fd -e java | xargs grep -l "AbstractBasicArithmeticExpression"

Length of output: 11976

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (1)

9-9: No issues with the new import.

The addition of import gov.nist.secauto.metaschema.core.metapath.IExpression; aligns well with the usage in getChildren(). No further changes are necessary here.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/AbstractCastingExpression.java (2)

8-8: The new IExpression import is consistent with the refactoring.

This import aligns with the updated package structure. However, please confirm that all references to IExpression in related classes or tests have also been updated to avoid lingering import references to the old path.

✅ Verification successful

Based on the search results, I can see that the IExpression import is being used consistently across the codebase, with all imports referencing the same path gov.nist.secauto.metaschema.core.metapath.IExpression. There are no references to any old or different path for IExpression, which confirms that the import is correctly aligned with the codebase's package structure.

The import is correctly aligned with the codebase's package structure.

All references to IExpression in the codebase consistently use the same import path gov.nist.secauto.metaschema.core.metapath.IExpression, indicating that the import statement is properly maintained across all dependent files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any references to the old `IExpression` import path in the entire repo

rg -A 3 "import .*IExpression" 

Length of output: 60241


110-110: Ensure references to the old toASTString() are fully removed or updated to toCSTString().

The method name change appears to align with the broader rename from AST to CST. Still, verify that no leftover references to toASTString() remain in the codebase or documentation.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpression.java (2)

91-91: Check visibility change impact and naming consistency.

Changing the method from public to protected may limit reusability if the method is accessed outside this class or package. Moreover, since other classes still appear to use .accept(), you might consider whether shifting to .evaluate() aligns with the broader design.


9-9: Confirm that the imported IExpression is fully aligned with the new refactoring.

The import of IExpression from this package is consistent with the broader refactoring, but please ensure that all references to IExpression in the codebase are still valid following the deprecation or removal of any old imports from other packages.

Please run this script to check for any outdated references to IExpression:

✅ Verification successful

Based on the search results, I can see that the IExpression interface is consistently imported from the same package gov.nist.secauto.metaschema.core.metapath across all files. Let me verify the actual interface definition and its usage.


Let me try a different approach to verify the interface definition and its usage.


The imported IExpression interface is correctly aligned with the codebase

Based on the verification results, the import of IExpression from gov.nist.secauto.metaschema.core.metapath is fully aligned with the codebase. The interface is defined in the same package and is consistently imported across all files. There are no alternative or deprecated versions of IExpression in the codebase, and the interface serves as the common base for all Metapath expression nodes as documented in its Javadoc.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to removed or legacy IExpression imports
rg -A 5 $'import .+IExpression'

Length of output: 67766


Script:

#!/bin/bash
# Check the IExpression interface definition
ast-grep --pattern 'interface IExpression {
  $$$
}'

Length of output: 54


Script:

#!/bin/bash
# Check the content of IExpression.java
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java

# Find any other potential IExpression interfaces in the codebase
find . -type f -name "IExpression.java"

Length of output: 3375

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java (3)

9-9: Consistent adoption of IExpression for CST nodes.
This import aligns with the class's usage of IExpression in the getChildren() method. It ensures clarity and consistency with the larger Metapath architecture refactor.


74-74: Renaming method to toCSTString() improves clarity.
Changing from toASTString() to toCSTString() matches the newly adopted nomenclature for describing a "compact syntax tree." This uniformly reflects the shift in terminology throughout the codebase.


84-84: Handle possible null return from dynamicContext.getFunction(...).
While the renamed and re-visibility-adjusted evaluate method is clear, ensure that getFunction(...) cannot return null. Otherwise, ISequence.of(...) may cause runtime issues. Consider adding a null-check or throwing an appropriate exception if the function is not found.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Modulo.java (2)

9-9: Import refactoring looks good.

Switching to import IExpression from the reorganized package structure is consistent with the broader refactoring effort to streamline expression-related interfaces.


58-58: Confirm reduced visibility impact.

Changing the method from public to protected may break references if external code relied on the old public signature. Verify that no external classes call this method.

✅ Verification successful

Let me search for more specific information about the evaluate method in the Modulo class.


Let me check the inheritance hierarchy and usage pattern of the Modulo class.


The protected visibility change is safe to proceed with.

The evaluate method in Modulo class is an implementation detail that is only used internally through the public accept method. This is evident from:

  1. The class extends AbstractArithmeticExpression and overrides the protected evaluate method
  2. External code interacts with the class through the public accept method which follows the visitor pattern
  3. The evaluate method is only called from within the class hierarchy through the template method pattern
  4. No direct calls to evaluate were found in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find external references to the old "accept" method signature
# that might break due to it becoming protected.

rg -A 5 "accept\\s*\\(.*DynamicContext" 

Length of output: 7573


Script:

#!/bin/bash
# Search for references to the evaluate method in Modulo class
ast-grep --pattern 'evaluate($_, $_) { $$$ }'

# Also check for any direct usage of Modulo class
rg -l "Modulo"

Length of output: 496


Script:

#!/bin/bash
# Check the Modulo class implementation and its parent class
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Modulo.java

# Check how Modulo is used in visitor interfaces
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java

Length of output: 24180

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySequenceConstructor.java (1)

9-9: Confirm the import usage.

While the import for IExpression is valid, please ensure that this interface is the correct one needed for constructing array sequences, especially given the broader refactoring efforts around acceptevaluate in the codebase.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java (3)

60-60: Method rename from toASTString to toCSTString is consistent with naming conventions.

This updated name aligns with the rest of the refactor across the codebase. It will improve clarity by referring to the correct abstraction level (CST vs AST).


9-9: Consolidate imports if needed.

The addition of the IExpression import is appropriate given we now return a list of IExpression in getChildren(). However, ensure that there are no unused imports left behind (e.g., if IItem was removed, verify it isn't still imported anywhere else in the codebase).
[approve]

✅ Verification successful

Let me verify if there are any unused imports related to IItem in the file under review.


Let me try a different approach to verify the usage of imports in the file.


No unused imports found - all imports are being used in the code.

Looking at the file content:

  1. IExpression is used in:
    • The getChildren() method's return type: List<? extends IExpression>
    • The method parameter in accept(): IExpressionVisitor<RESULT, CONTEXT>

All other imports are also being used:

  • DynamicContext in the evaluate() method
  • ISequence in multiple method signatures
  • IEnhancedQName for the name field
  • CollectionUtil in getChildren()
  • List in getChildren()
  • NonNull annotations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all references to IItem in the codebase, to ensure consistency.
rg "IItem" -A 5

Length of output: 100796


Script:

#!/bin/bash
# Check if IItem is used in the file beyond the import statement
ast-grep --pattern $'import gov.nist.secauto.metaschema.core.metapath.IExpression;
$$$
class VariableReference {
  $$$
  IExpression $$$
  $$$
}' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java

Length of output: 234


Script:

#!/bin/bash
# Show the content of the file to verify imports and their usage
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java

Length of output: 1924


70-70: Visibility and naming change for evaluate looks consistent.

Previously accept was public, now it’s protected with a more descriptive name: evaluate(). This is a good practice for encapsulating behavior while still allowing for extension if needed. Verify that existing references to accept have been updated accordingly.

✅ Verification successful

Let me search for the old accept method implementation to verify the change.


Let me check for any references to this class and its methods.


Let me check the git history to see the changes made to this file.


Let me try a different approach to check the inheritance hierarchy and related classes.


Let me check the AbstractExpression class to understand the inheritance and method visibility.


Let me check the IExpression interface implementation to understand the method visibility requirements.


Based on the code analysis, I can now provide a final response:

The visibility and naming changes are consistent with the codebase design

The change from public accept to protected evaluate in VariableReference.java is consistent with the codebase architecture because:

  1. The evaluate method is an implementation detail that should be protected, as it's part of the internal evaluation mechanism
  2. The public accept method is still maintained in the class for the visitor pattern implementation
  3. The class properly extends AbstractExpression and follows its design patterns
  4. No other parts of the codebase directly called the old public method, as all interactions are properly done through the visitor pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify references to the old `accept` method in the codebase.
rg -A 5 $'\\.accept\\('

Length of output: 65558


Script:

#!/bin/bash
# Search for the old accept method implementation in VariableReference.java
rg -A 10 "public.*accept.*" core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java

Length of output: 445


Script:

#!/bin/bash
# Search for references to VariableReference class and its usage
rg -A 5 "VariableReference" --type java

Length of output: 6066


Script:

#!/bin/bash
# Check git history for VariableReference.java
git log -p core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java

Length of output: 0


Script:

#!/bin/bash
# Check AbstractExpression class which VariableReference extends
rg -A 10 "class AbstractExpression" --type java

# Also check for any test files related to VariableReference
fd -e java -E 'test' -x rg -l "VariableReference"

Length of output: 3200


Script:

#!/bin/bash
# Check the AbstractExpression class implementation
rg -A 20 "abstract class AbstractExpression" core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java

# Also check for the IExpression interface
rg -A 10 "interface IExpression" --type java

Length of output: 2937


Script:

#!/bin/bash
# Get more context from IExpression interface
rg -A 30 "interface IExpression" core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java

# Also check for any evaluate method declarations
rg -A 5 "evaluate.*\(" core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java

Length of output: 1027

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Quantified.java (1)

9-9: Consistent usage of IExpression import.
The new import for IExpression is aligned with the rest of the code's references, and there appear to be no conflicts.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (6)

8-8: Good import usage.
Importing DynamicContext is necessary for the newly introduced evaluate method.


10-10: Sensible addition of imports.
Imports for ISequence and IAnyAtomicItem are appropriate for the updated type parameter usage and returned sequence.


23-27: Nice simplification of generic parameters.
Reducing to a single RESULT_TYPE improves clarity and reduces complexity.


37-37: Constructor aligns well with the updated type.
Switching the constructor to accept RESULT_TYPE directly is consistent with the simplified generics.


43-43: Getter refactor is consistent.
Using RESULT_TYPE for getValue() maintains type safety and clarity.


54-55: CST naming convention is clear.
Renaming toASTString() to toCSTString() improves consistency with the broader codebase. The usage of value.asString() is straightforward.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/IntegerDivision.java (2)

9-9: Use of updated import path looks good
This change to import IExpression from its non-CST package aligns well with the broader refactoring. No issues here.


57-57: Confirm naming consistency and consider zero-divisor handling
Renaming the method to evaluate while retaining another accept() method in this class is fine if those methods serve different use cases (visitor vs. direct evaluation). However, if unifying nomenclature is a goal, consider applying the same convention (e.g., evaluate) for the visitor-based logic as well. Additionally, ensure that zero-divisor scenarios are handled according to the required XPath 3.1 or internal specification.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractNAryExpression.java (1)

8-9: Good use of the IExpression interface

By relying on IExpression as the type for children, the code clearly communicates that each sub-expression follows the same contract. This is a clean approach for representing n-ary expressions while ensuring type consistency.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (1)

8-9: Ensure single-child handling remains robust

Switching to IExpression for the unary expression field improves consistency across all expression classes. The use of List.of(expr) in getChildren() is compact and thread-safe by design since the returned list is immutable.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRootPathExpression.java (1)

8-8: Consistent import of IExpression

The updated import aligns this root path expression class with the rest of the package’s expression model. Returning a single-element list in getChildren() allows uniform traversal of the expression tree.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractBinaryExpression.java (1)

8-9: Use of generics with IExpression enhances type safety

Defining AbstractBinaryExpression<L extends IExpression, R extends IExpression> makes the binary sub-expression contract explicit. The new import ensures that the left and right expressions remain consistent with the rest of the metapath framework.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeDoubleSlashPath.java (2)

9-9: Consistent package refactoring for IExpression import
This import update aligns with the reorganized package structure, ensuring consistency across the codebase.


51-51: Method rename and visibility change
Renaming accept to evaluate and making it protected clarifies the method’s intent and scope. The implementation correctly uses search(getRight(), ...) for further evaluation.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (3)

6-6: Package reorganization noted
Switching from cst.logic to cst.items indicates a structural shift in how filter expressions are grouped. This matches the project's reorganized layout.


9-9: Import of IExpression
Adding IExpression helps align with the new architecture for expression classes. This is consistent with the rest of the refactoring.


55-55: Evaluation method updated
Renaming accept to evaluate and reducing visibility to protected clarifies the intention to process the expression internally. Logic remains clear and consistent, leveraging applyFilterTo(...).

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/For.java (3)

9-9: Import alignment
Including IExpression from the updated package is part of the overall refactor. No issues noted.


84-84: evaluate method ensures sub-context usage
Changing accept to evaluate clarifies responsibility and properly encapsulates for-loop evaluation. The usage of a sub-context to bind each item is appropriate.


100-100: Renamed method to toCSTString
The updated naming is consistent with the shift from AST to CST terminology. This change improves clarity for debugging.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/DynamicFunctionCall.java (2)

9-9: Package-consistent import addition
The import now reflects the updated location of IExpression. This is a straightforward, necessary change.


73-73: Method rename from accept to evaluate
The new name and protected scope better convey that the function call is being evaluated rather than just visited. The logic for resolving and executing the function remains correct.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java (2)

6-6: Streamlined package structure alignment
Good job moving the interface to a more general package. This helps reduce complexity and clarifies the scope of this interface.


8-8: Import of IExpressionVisitor
The added import matches the newly referenced visitor interface. Ensure that all references to this visitor are updated correctly in dependent classes.

core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/CSTLogicalExpressionsTest.java (1)

12-12: Updated import location
Switching to the new IExpression package is a sensible move that keeps the code aligned with the recent package refactoring in IExpression.java.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java (2)

9-9: Leverage the relocated IExpression
The added import clarifies references to the IExpression interface. Make sure that the rest of the cst package references remain current.


81-81: 🛠️ Refactor suggestion

Transition from accept to evaluate
Changing the method to protected and renaming it to evaluate clarifies its intent and limits external exposure. Verify that no external clients still rely on the old signature.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java (1)

8-8: Consistent usage of IExpression
Adopting the new package path aligns with the rest of this PR’s refactoring. This improves consistency across the CST factories and related classes.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java (3)

165-170: Renamed documentation from AST to CST is consistent and adds clarity.
The newly introduced getCSTNode() method and its documentation clearly align with the CST-based approach.


181-181: Appropriate use of CSTPrinter in toString().
Switching from getASTNode() to getCSTNode() here is consistent with the overall CST refactoring and ensures correct string representation.


190-190: Evaluation logic remains consistent with CST.
Using getCSTNode().accept(...) is a straightforward adaptation from the AST-based approach. No immediate issues found.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (11)

20-33: New imports for Deque and related collections.
These imports correctly support stack-based operations. No issues found.


43-44: Documentation update for the dynamic context.
Minor doc clarifications. Looks good.


90-91: New executionStack field added.
This Deque<IExpression> is central to stack-based tracking of expressions. Properly declared as @NonNull.


113-115: Doc changes for subContext method.
The explanation of creating a new sub-context is still valid; no issues found.


155-155: Clarified documentation for document availability.
Retains effectively the same logic.


170-170: Document loader doc improvement.
Matches usage in this class.


194-198: Refined doc for deterministically cached function results.
No concerns with the new text.


207-210: Documentation for cacheResult().
Correctly clarifies the property-based caching approach.


Line range hint 220-234: Improved Javadoc coverage for predicate evaluation toggles.
The doc changes better explain disabling/enabling predicate evaluation.


321-331: Added popExecutionStack().
Ensures LIFO matching with the expected expression. The assertion is a good safeguard although it will be omitted in production if assertions are disabled.


332-341: Added getExecutionStack().
Returns an unmodifiable copy of the stack content, preserving immutability. This approach is correct for read-only inspection.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java (2)

8-8: Importing IExpression to support CST usage.
No concerns about the added import.


129-129: Refactored appendNode to call expr.toCSTString().
Consistent with the CST approach. No issues identified.

core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java (1)

26-26: Added IExpression import in tests.
Provides more precise test references. No further refinements needed.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java (1)

8-8: Confirmed usage of added IExpression import.
This updated import is required since the interface is referenced extensively throughout the class. No issues found.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SimpleMap.java (2)

9-9: Confirm necessity of the IExpression import here.
Even though the import statement appears redundant given the same package references, it does look correct to ensure clarity and usage in this file.


45-45: Verify no external dependencies on the old public accept(...).
Changing method visibility and renaming from accept to evaluate across code can break external code if any references to SimpleMap.accept(...) remain.

Below is a script to search for any direct calls to SimpleMap.accept(...) that might remain:

✅ Verification successful

The previous search might have been too specific. Let's broaden our search to understand the usage of SimpleMap class and any accept method calls in the codebase. This will help us verify if there are any remaining dependencies on the old public accept method.


Let's verify if there was an old accept method in SimpleMap and check its usage in tests, as well as look at the interface contract to understand if this is a breaking change.


Let's examine the SimpleMap class implementation and its interfaces to understand the method visibility change and potential impact.


No breaking changes from renaming accept to evaluate

Looking at the code, the change from accept to evaluate is safe because:

  1. The evaluate method is a protected implementation detail, not part of the public API
  2. The public visitor pattern method accept(IExpressionVisitor<RESULT, CONTEXT>, CONTEXT) is still present and unchanged
  3. The class properly implements the IExpressionVisitor interface contract

The change only affects the internal implementation method while preserving the public interface contract, so there are no external dependencies to worry about.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# This script searches the entire repository for code that calls SimpleMap.accept(...)
rg 'SimpleMap\s*\([^)]*\)\.accept\s*\(' -A 5

Length of output: 46


Script:

#!/bin/bash
# Let's try a broader search for any references to SimpleMap class and its usage
rg "SimpleMap" -l

# Also search for any accept method calls in the codebase
rg "\.accept\(" -A 2

# Let's also check if there are any test files that might be using SimpleMap
fd "Test.*\.java" --exec grep -l "SimpleMap" {}

Length of output: 49053


Script:

#!/bin/bash
# Let's check the implementation of SimpleMap class and its accept method
ast-grep --pattern $'class SimpleMap {
  $$$
  accept($_, $_) {
    $$$
  }
  $$$
}'

# Also check for any references to SimpleMap.accept in test files
rg -A 3 "SimpleMap.*\.accept" core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java

# Let's also check the interface that SimpleMap implements
ast-grep --pattern $'interface $_ {
  $$$
  accept($_, $_);
  $$$
}'

Length of output: 277


Script:

#!/bin/bash
# Let's check the interfaces implemented by SimpleMap
rg "class SimpleMap\s+(\w+\s+)*implements" -A 2

# Check for any references to accept method in interfaces
rg "interface.*\{" -A 10 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java

# Check the SimpleMap class file directly
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SimpleMap.java

Length of output: 2553

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java (2)

44-51: Ensure proper error handling and concurrency.

The accept method correctly uses a stack-based approach with try/finally to ensure expressions are always popped. This design provides clear traceability for debugging. Confirm that DynamicContext is not shared across threads in ways that might lead to race conditions or concurrency issues.


8-12: Verify imports and usage consistency.

The newly introduced imports align with the relocated IExpression interface. Please ensure all references to the old package structure are updated throughout the codebase.

✅ Verification successful

Let me generate additional scripts to verify the package structure changes more thoroughly.

The previous results showed references to IExpressionVisitor still in the cst package, but we need to verify the complete picture of IExpression usage and imports to ensure consistency with the new package structure.


All imports are correctly using the new package structure

Based on the verification results, all files are correctly importing IExpression from the new package location gov.nist.secauto.metaschema.core.metapath.IExpression. The only references to the cst package are for the IExpressionVisitor interface, which appears to be intentionally located in the cst package.

The search results show:

  • No references to the old package structure for IExpression
  • All imports of IExpression are from the new package location
  • References to cst package are only for IExpressionVisitor, which is correctly maintained in that package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify references to old package paths for IExpression, IItem, and ISequence.
# Expect: No references to old package paths remain.
rg "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.IExpression"
rg "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.item\.IItem"
rg "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.item\.ISequence"

Length of output: 7932


Script:

#!/bin/bash
# Check for any references to IExpression in import statements
rg "^import.*IExpression" --type java

# Check for any references to old package structure in javadoc or comments
rg "@see.*metapath\.cst" --type java

Length of output: 18939

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (1)

9-9: Verify references to IExpression in the old cst package.
Please confirm that all references to IExpression are consistently updated to the new package.

✅ Verification successful

Let me search for any remaining references to the old package path.


Let me check the actual content of these files to verify the imports.


All references to IExpression are correctly using the new package path

The verification shows that all files are using the correct import path gov.nist.secauto.metaschema.core.metapath.IExpression and not the old CST package path. The change is consistent across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Locate any remaining references to the old IExpression import in the codebase.
rg -A 3 "import gov.nist.secauto.metaschema.core.metapath.cst.IExpression"

Length of output: 29050


Script:

#!/bin/bash
# Search for any references to IExpression in the old package path
rg -l "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.IExpression"

Length of output: 4205


Script:

#!/bin/bash
# Check the actual imports in files that reference IExpression
for file in $(rg -l "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.IExpression"); do
  echo "=== $file ==="
  rg "^import.*IExpression" "$file"
done

Length of output: 24976

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (1)

Line range hint 71-79: Confirm exception strategy for non-document nodes.

By immediately throwing an exception when the root node is not a document node, any partial hierarchy or non-document-based node trees will be disallowed. Confirm if this strict approach is desired, or if a more flexible handling is needed.

…s the expressions entered and exited during Metapath evaluation. This will be useful context for debugging and error reporting.
@david-waltermire david-waltermire force-pushed the feature/metapath-track-expression-context branch from 9281a76 to 8be41b0 Compare January 7, 2025 00:51
@david-waltermire
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jan 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (4)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (1)

Line range hint 110-129: Update step execution to use evaluate

The last line still uses accept instead of evaluate, which is inconsistent with the refactoring:

return step == null ? axisResult : step.accept(dynamicContext, axisResult);

This should be updated to use evaluate for consistency and proper execution stack tracking.

-    return step == null ? axisResult : step.accept(dynamicContext, axisResult);
+    return step == null ? axisResult : step.evaluate(dynamicContext, axisResult);
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (2)

Line range hint 79-89: Update accept call to evaluate for consistency.

The method has been renamed from accept to evaluate, but it still calls accept on the base expression. This should be updated for consistency with the new naming convention.

-    ISequence<?> target = getBase().accept(dynamicContext, focus);
+    ISequence<?> target = getBase().evaluate(dynamicContext, focus);

Line range hint 79-89: Add execution stack tracking.

As per the PR objectives, this method should track expression entry/exit in the DynamicContext's execution stack for debugging and error reporting purposes.

Consider wrapping the evaluation in try-finally blocks to ensure proper stack management:

   protected ISequence<?> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+    dynamicContext.pushExpression(this);
+    try {
       ISequence<?> target = getBase().evaluate(dynamicContext, focus);
       IItem collection = target.getFirstItem(true);

       if (!(collection instanceof IFunction)) {
         throw new InvalidTypeMetapathException(collection, "The base expression did not evaluate to a function.");
       }

       return ((IFunction) collection).execute(ObjectUtils.notNull(getArguments().stream()
           .map(expr -> expr.evaluate(dynamicContext, focus))
           .collect(Collectors.toUnmodifiableList())), dynamicContext, focus);
+    } finally {
+      dynamicContext.popExpression();
+    }
   }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (1)

Line range hint 55-61: Method calls are inconsistent with new naming

While the rename from accept to evaluate better describes the method's purpose, there's an inconsistency in the implementation. The method uses accept calls internally while being renamed to evaluate.

Apply this diff to maintain consistency:

  protected ISequence<?> evaluate(
      @NonNull DynamicContext dynamicContext,
      @NonNull ISequence<?> focus) {

-   ISequence<?> left = getLeft().accept(dynamicContext, focus);
-   ISequence<?> right = getRight().accept(dynamicContext, focus);
+   ISequence<?> left = getLeft().evaluate(dynamicContext, focus);
+   ISequence<?> right = getRight().evaluate(dynamicContext, focus);
    return applyFilterTo(left, right);
  }
🧹 Nitpick comments (15)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Castable.java (1)

Line range hint 54-63: Method signature changes enhance encapsulation and type safety.

The changes from:

  • public to protected visibility
  • accept to evaluate naming
  • More specific return type ISequence<IBooleanItem>

align well with the PR's objectives. The implementation correctly handles casting attempts and error cases, providing clear boolean results for debugging.

Consider documenting these architectural decisions in the class-level JavaDoc to explain:

  1. Why evaluate is protected (encapsulation strategy)
  2. The relationship between evaluate and accept methods
  3. The error handling strategy for casting failures
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (1)

63-63: Consider using RESULT_TYPE for better type safety

The visibility change to protected and rename to evaluate look good and align with the refactoring goals. However, consider using ISequence<RESULT_TYPE> as the return type instead of ISequence<?> to maintain type safety, as RESULT_TYPE is already defined at the class level.

-  protected ISequence<?> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+  protected ISequence<RESULT_TYPE> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (1)

53-57: Consider leveraging the new execution stack for enhanced debugging.

While the method rename and visibility change are good improvements, consider enhancing the implementation to utilize the new execution stack feature for better debugging and error reporting. This would align with the PR's objective of providing useful context during Metapath evaluation.

Example enhancement:

  protected ISequence<? extends IBooleanItem> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+   dynamicContext.pushExpression(this);  // Track expression entry
+   try {
      IAnyAtomicItem left = ISequence.of(getLeft().accept(dynamicContext, focus).atomize()).getFirstItem(false);
      IAnyAtomicItem right = ISequence.of(getRight().accept(dynamicContext, focus).atomize()).getFirstItem(false);
      return resultOrEmpty(left, right);
+   } finally {
+     dynamicContext.popExpression();  // Ensure expression is popped even if evaluation fails
+   }
  }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractStepExpression.java (1)

66-69: LGTM! Method signature changes improve encapsulation and clarity.

The changes from public accept() to protected evaluate() are well-aligned with:

  1. Encapsulation principles through protected access
  2. More accurate method naming that reflects its purpose
  3. The PR's goal of tracking expression evaluation

Consider adding a @since Javadoc tag to document this API change, as it might affect downstream implementations:

+  /**
+   * @since <version> Renamed from accept() to evaluate() and changed access to protected
+   */
   protected ISequence<? extends RESULT_TYPE> evaluate(
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/DecimalLiteral.java (1)

33-33: Consider improving the constructor's parameter documentation.

While the implementation change is good, the @param value documentation could be more specific about the expected BigDecimal type.

Update the documentation to:

   /**
    * Construct a new expression that always returns the same decimal value.
    *
    * @param text
    *          the parsed text of the expression
    * @param value
-   *          the literal value
+   *          the literal value as a BigDecimal, which will be converted to an IDecimalItem
    */
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (1)

Line range hint 131-135: Consider updating method documentation

The rename from toASTString to toCSTString is appropriate, reflecting the shift from AST to CST terminology.

Consider adding Javadoc to explain the CST (Concrete Syntax Tree) string representation format.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java (1)

84-87: Consider enhancing error handling and stack tracking.

While the method signature changes are appropriate, consider these improvements to support the PR's debugging and error reporting objectives:

  1. Add execution stack tracking before and after evaluation
  2. Enhance error handling to include stack context when function lookup fails

Example enhancement:

 protected ISequence<?> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+    dynamicContext.getExecutionStack().push(this);
+    try {
     IFunction function = dynamicContext.getFunction(name, arity);
     return ISequence.of(function);
+    } catch (Exception e) {
+        throw new MetapathException(String.format("Failed to evaluate function %s with arity %d", name, arity), e);
+    } finally {
+        dynamicContext.getExecutionStack().pop();
+    }
 }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (2)

Line range hint 33-45: Remove unnecessary @SuppressWarnings("null").

The @SuppressWarnings("null") annotation on getChildren() appears unnecessary since:

  • List.of() returns a non-null List
  • The expr field is already marked @NonNull
  • The wildcard return type doesn't affect nullability
-  @SuppressWarnings("null")
   @Override
   public List<? extends IExpression> getChildren() {
     return List.of(expr);
   }

Line range hint 16-45: Well-designed for integration with execution stack.

The immutable design and clear expression hierarchy make this class well-suited for the new execution stack feature:

  • Immutability ensures thread-safety during stack operations
  • Clear parent-child relationship enables proper stack traversal
  • Robust null-safety supports reliable debugging and error reporting
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (2)

63-63: Add Javadoc for the evaluate method.

Please add documentation explaining the method's purpose, parameters, return value, and potential exceptions.


Line range hint 63-77: Consider breaking down the stream operations for better readability.

While the implementation is correct, the nested stream operations and method chaining make it harder to follow. Consider extracting the document node validation into a separate method.

Here's a suggested refactoring:

  protected ISequence<? extends INodeItem> evaluate(DynamicContext dynamicContext, ISequence<?> focus) {
+    return ISequence.of(ObjectUtils.notNull(focus.stream()
+        .map(ItemUtils::checkItemIsNodeItemForStep)
+        .map(this::findAndValidateDocumentRoot)));
+  }
+
+  private INodeItem findAndValidateDocumentRoot(INodeItem item) {
+    INodeItem root = Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item))
+        .findFirst()
+        .orElseThrow(() -> new DynamicMetapathException(
+            DynamicMetapathException.TREAT_DOES_NOT_MATCH_TYPE,
+            "Root node not found"));
+
+    if (!(root instanceof IDocumentNodeItem)) {
+      throw new DynamicMetapathException(
+          DynamicMetapathException.TREAT_DOES_NOT_MATCH_TYPE,
+          "The head of the tree is not a document node.");
+    }
+    return root;
-    return ISequence.of(ObjectUtils.notNull(focus.stream()
-        .map(ItemUtils::checkItemIsNodeItemForStep)
-        .map(item -> Axis.ANCESTOR_OR_SELF.execute(ObjectUtils.notNull(item))
-            .findFirst()
-            .orElseThrow(() -> new DynamicMetapathException(DynamicMetapathException.TREAT_DOES_NOT_MATCH_TYPE,
-                "Root node not found")))
-        .peek(item -> {
-          if (!(item instanceof IDocumentNodeItem)) {
-            throw new DynamicMetapathException(DynamicMetapathException.TREAT_DOES_NOT_MATCH_TYPE,
-                "The head of the tree is not a document node.");
-          }
-        })));
  }
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (2)

311-319: Consider adding validation in pushExecutionStack.

While the implementation is correct, consider adding validation to ensure the expression is not null at runtime, rather than relying solely on the @nonnull annotation which might be ignored at runtime.

 public void pushExecutionStack(@NonNull IExpression expression) {
+    Objects.requireNonNull(expression, "expression must not be null");
     this.sharedState.executionStack.push(expression);
 }

Line range hint 90-340: Consider enhancing error reporting with execution stack information.

The execution stack implementation could be further enhanced to provide rich debugging information. Consider:

  1. Adding a method to format the execution stack for error messages
  2. Integrating the stack information into existing exception handling

Example enhancement:

@NonNull
public String formatExecutionStackTrace() {
    return getExecutionStack().stream()
        .map(IExpression::toString)
        .collect(Collectors.joining(" -> "));
}
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java (1)

60-62: Consider adding Javadoc for the toCSTString method.

The rename from toASTString to toCSTString better reflects the class's role in the Concrete Syntax Tree. Consider adding Javadoc to document the method's purpose and return format.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1)

58-61: LGTM! Consider adding Javadoc

The rename from toASTString() to toCSTString() and visibility change to public is appropriate, reflecting the concrete syntax tree nature of this representation. This aligns well with the PR's goal of improved debugging support.

Consider adding Javadoc to document the format and purpose of the CST string representation:

+ /**
+  * Returns a string representation of this node in the Concrete Syntax Tree.
+  *
+  * @return a string in the format "className[kind=typeSignature]"
+  */
 public String toCSTString() {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9281a76 and 8be41b0.

📒 Files selected for processing (85)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (14 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractBinaryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractNAryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/DynamicFunctionCall.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/For.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Let.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/StaticFunctionCall.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySequenceConstructor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySquareConstructor.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/DecimalLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ILiteralExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/IntegerLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/MapConstructor.java (4 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Quantified.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Range.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SequenceExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SimpleMap.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringConcat.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringLiteral.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/UnaryLookup.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Union.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/And.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/GeneralComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/IBooleanLogicExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/If.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/Or.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpression.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractArithmeticExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractBasicArithmeticExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Addition.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/IntegerDivision.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Modulo.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Negate.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRelativePathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRootPathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractSearchPathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractStepExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ContextItem.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/INodeTestExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameNodeTest.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeDoubleSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootDoubleSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/WildcardNodeTest.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/AbstractCastingExpression.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Cast.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Castable.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ExpressionUtilsTest.java (0 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/CSTLogicalExpressionsTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpressionTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparisonTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/ExpressionUtilsTest.java
🚧 Files skipped from review as they are similar to previous changes (61)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpressionVisitor.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Subtraction.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractNAryExpression.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparisonTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/INodeTestExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractArithmeticExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractSearchPathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/IBooleanLogicExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Addition.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Multiplication.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SequenceExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractKeySpecifier.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRelativePathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Division.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractBinaryExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ExpressionUtils.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/CSTLogicalExpressionsTest.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpressionTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractComparison.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootDoubleSlashPath.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/AbstractCastingExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/StaticFunctionCall.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Quantified.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameNodeTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySequenceConstructor.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/Or.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Negate.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/DynamicFunctionCall.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/For.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Range.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/UnaryLookup.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/SimpleMap.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ContextItem.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringLiteral.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/StringConcat.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/If.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeDoubleSlashPath.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RelativeSlashPath.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractRootPathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/WildcardNodeTest.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Cast.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Treat.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/IntegerDivision.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/AbstractBasicArithmeticExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/PredicateExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/math/Modulo.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ILiteralExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ICstExpressionFactory.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/ArraySquareConstructor.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/MapConstructor.java
👮 Files not reviewed due to content moderation or server errors (2)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/GeneralComparison.java
🧰 Additional context used
📓 Learnings (5)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#266
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/FunctionCallAccessor.java:82-89
Timestamp: 2024-11-28T04:47:39.173Z
Learning: In `FunctionCallAccessor.java`, the `accept` method must continue executing after handling `AnonymousFunctionCall` to properly process other collection types. Adding an `else` block that bypasses the remaining code is incorrect.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#315
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/AbstractFilterExpression.java:56-56
Timestamp: 2024-12-31T18:45:39.097Z
Learning: "ISequence" in the codebase is an implementation of the List interface, allowing direct usage where a List is expected.
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java (1)
Learnt from: david-waltermire
PR: metaschema-framework/metaschema-java#336
File: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java:87-88
Timestamp: 2025-01-07T00:50:46.218Z
Learning: In the Metapath implementation, child expressions should be called using `accept()` rather than `evaluate()` to ensure proper management of the execution stack through push/pop operations. The `evaluate()` method is an internal implementation detail that performs the actual evaluation.
🔇 Additional comments (40)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/InstanceOf.java (3)

9-9: LGTM!

The import consolidation to a more general package is appropriate.


87-88: LGTM! Implementation correctly uses accept() for child expressions.

The implementation properly uses accept() for child expression evaluation, which ensures proper management of the execution stack through push/pop operations, while evaluate() handles the actual evaluation logic.


97-97: LGTM! Method rename reflects correct tree representation.

The rename from toASTString to toCSTString accurately reflects that this is working with a Concrete Syntax Tree (CST) rather than an Abstract Syntax Tree (AST).

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/type/Castable.java (1)

9-9: LGTM! Import change improves maintainability.

Moving to a more general package for IExpression aligns with good architectural practices and the broader refactoring effort.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/EmptySequence.java (1)

9-9: LGTM! Import change aligns with refactoring

The consolidation of the IExpression import aligns with the broader refactoring effort to improve organization.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/ValueComparison.java (1)

9-9: LGTM! Package restructuring improves organization.

The move of IExpression to a more general package aligns with good architectural practices by consolidating core interfaces at the appropriate level.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractStepExpression.java (1)

9-9: LGTM! Package reorganization improves interface accessibility.

The relocation of IExpression to a higher-level package improves its visibility and reusability across the codebase.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/DecimalLiteral.java (1)

22-22: LGTM! Good simplification of the type hierarchy.

The removal of the BigDecimal type parameter streamlines the class hierarchy while maintaining type safety through IDecimalItem.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Step.java (1)

9-9: LGTM: Import consolidation

The import consolidation aligns with the broader refactoring goals.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java (2)

9-9: LGTM! Import change aligns with framework reorganization.

The import consolidation of IExpression to the core metapath package improves code organization.


74-76: LGTM! Method rename improves terminology consistency.

The rename from toASTString to toCSTString better reflects the Compact Syntax Tree (CST) nature of this class and aligns with its package location.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/FunctionCallAccessor.java (1)

9-9: LGTM! Import change is appropriate.

The added import for IExpression is necessary and properly consolidates the interface imports as part of the broader refactoring.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractUnaryExpression.java (2)

8-8: LGTM! Import change aligns with interface consolidation.

The import statement change reflects the package restructuring of IExpression interface, moving it to a more appropriate package level.


Line range hint 19-31: LGTM! Robust implementation with proper null-safety.

The implementation follows best practices with:

  • Proper encapsulation (private final field)
  • Compile-time (@nonnull) and runtime (Objects.requireNonNull) null-safety checks
  • Clear JavaDoc documentation
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (1)

10-10: LGTM! Good architectural improvement.

Moving IExpression import to the core package improves modularity by reducing coupling between CST-specific and general Metapath components.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicContext.java (3)

28-31: LGTM! Import changes are appropriate.

The new imports for ArrayDeque, ArrayList, and Deque are correctly added to support the execution stack functionality.


90-91: Consider thread-safety implications of the execution stack.

While the field is correctly marked as final and initialized with ArrayDeque, consider whether concurrent access to the execution stack needs synchronization, especially since this is part of the SharedState class which might be accessed by multiple threads.

Consider either:

  1. Using a thread-safe deque implementation like ConcurrentLinkedDeque
  2. Documenting that the DynamicContext is not thread-safe and should be used in a single thread

332-340: LGTM! Defensive copy implementation.

The getExecutionStack method correctly creates a defensive copy and returns an unmodifiable list, preventing modification of the internal state.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/PostfixLookup.java (2)

9-9: LGTM! Package restructuring looks good.

The import statement change aligns with the broader refactoring effort to consolidate IExpression interface imports.


69-69: Verify the impact of visibility change.

The method signature changes look good and align with the broader refactoring effort. However, let's verify that all callers can still access this method through the new protected visibility.

✅ Verification successful

Protected visibility change is safe and aligned with the codebase design

The change to protected visibility is verified to be safe because:

  • The method is only used through inheritance within the same package
  • External interaction with PostfixLookup is properly handled through the visitor pattern
  • No direct calls to the evaluate() method were found outside the inheritance hierarchy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all direct calls to evaluate() method on PostfixLookup instances
# to ensure they are within the same package or subclasses

# Search for PostfixLookup instantiations and method calls
rg -l "PostfixLookup" | while read -r file; do
  if [[ "$file" =~ \.java$ ]]; then
    echo "=== $file ==="
    # Show the context of PostfixLookup usage
    rg -B 2 -A 2 "PostfixLookup" "$file"
  fi
done

Length of output: 5657


Script:

#!/bin/bash
# Search for direct calls to evaluate() method and check inheritance
echo "=== Searching for evaluate() method calls ==="
rg -p "\.evaluate\(" -B 3 -A 1

echo -e "\n=== Checking PostfixLookup inheritance ==="
ast-grep --pattern 'class PostfixLookup extends $_'

echo -e "\n=== Finding classes in the same package ==="
fd -e java . "core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/"

Length of output: 21851

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractLiteralExpression.java (5)

8-10: LGTM! Good design simplification.

The removal of the redundant type parameter VALUE and direct use of RESULT_TYPE improves the class design by reducing complexity while maintaining type safety. The new imports appropriately support the evaluation functionality.

Also applies to: 23-25


27-27: LGTM! Consistent field and constructor changes.

The field and constructor changes align well with the type parameter simplification while maintaining proper null-safety through @NonNull annotations.

Also applies to: 37-40


43-45: LGTM! Consistent method signature update.

The getValue() method signature change aligns with the type parameter simplification.


47-50: LGTM! Efficient evaluation implementation.

The new evaluate method provides a clean and efficient implementation using ISequence.of() for singleton sequence creation, which is an optimal approach for literal expressions.


54-56: Verify the naming convention change across the codebase.

The method has been renamed from toASTString to toCSTString, suggesting a shift from Abstract Syntax Tree to Concrete Syntax Tree terminology. Also, the use of asString() instead of toString() is more appropriate for domain objects.

Let's verify this naming convention change is consistent across the codebase:

✅ Verification successful

Naming convention change is consistent across the codebase

The change from toASTString to toCSTString has been consistently applied, with no remnants of the old naming. The use of asString() is also consistently maintained across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining toASTString methods and verify consistent use of toCSTString
# Expected: No occurrences of toASTString and consistent usage of toCSTString

echo "Checking for any remaining toASTString methods:"
rg "toASTString"

echo -e "\nVerifying consistent usage of toCSTString:"
rg "toCSTString"

echo -e "\nChecking for potential missed renames in documentation or comments:"
rg -i "abstract syntax tree|AST"

Length of output: 67963

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/logic/And.java (2)

9-9: LGTM! Import consolidation looks good.

The import consolidation to use IExpression from the core package aligns with the broader refactoring effort.


Line range hint 57-67: Implementation changes look good and align with PR objectives.

The changes improve encapsulation and clarity:

  • Renamed method better reflects its purpose
  • Protected visibility supports proper execution stack management
  • Implementation maintains efficient short-circuit evaluation

Let's verify consistent method renaming across related classes:

✅ Verification successful

Method renaming is consistent across logical operation classes

The verification confirms:

  • All logical operation classes use the protected 'evaluate' method
  • No remaining 'accept' methods found
  • Implementation patterns are consistent with the PR's objectives
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent method renaming pattern across related classes
# Expected: All logical operation classes should follow the same pattern

# Check for any remaining 'accept' methods in related logical operation classes
ast-grep --pattern 'class $_ implements IBooleanLogicExpression {
  $$$
  public ISequence<$_> accept($$$) {
    $$$
  }
}'

# Check for consistent protected evaluate methods
ast-grep --pattern 'class $_ implements IBooleanLogicExpression {
  $$$
  protected ISequence<$_> evaluate($$$) {
    $$$
  }
}'

Length of output: 256


Script:

#!/bin/bash
# First, find relevant logical operation classes
echo "=== Searching for logical operation classes ==="
rg -l "class.*(?:And|Or|Not)" --type java

echo -e "\n=== Checking for 'accept' methods ==="
rg "(?:public|protected).*\baccess\b.*\{" --type java -A 2

echo -e "\n=== Checking for 'evaluate' methods ==="
rg "(?:public|protected).*\bevaluate\b.*\{" --type java -A 2

Length of output: 23203

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/IntegerLiteral.java (3)

33-33: Good use of factory method pattern!

Using IIntegerItem.valueOf() instead of direct instantiation is a good practice. It centralizes the conversion logic and allows for potential optimizations.


22-22: Verify consistent refactoring across literal expression classes

The simplified generic type parameter looks good, but let's ensure this pattern is consistently applied across other literal expression classes.

✅ Verification successful

Refactoring is consistently applied across literal expression classes

All literal expression classes (StringLiteral, DecimalLiteral, and IntegerLiteral) follow the same pattern of extending AbstractLiteralExpression with a single type parameter. The change is verified to be consistent throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other literal expression classes follow the same pattern
# Expected: All literal expression classes should extend AbstractLiteralExpression with a single type parameter

ast-grep --pattern 'class $_ extends AbstractLiteralExpression<$_>'

Length of output: 69


Script:

#!/bin/bash
# First, find all Literal Java files
echo "=== Literal Java Files ==="
fd "Literal.*\.java$"

# Then check their content
echo -e "\n=== AbstractLiteralExpression Usage ==="
rg "extends\s+AbstractLiteralExpression" -A 1

Length of output: 1417


Line range hint 22-45: Verify handling of removed accept method

The removal of accept(DynamicContext, ISequence<?>) aligns with the PR objectives. However, let's verify:

  1. The evaluation functionality is properly handled by the superclass
  2. No breaking changes for existing callers
✅ Verification successful

Removal of accept method is safe and consistent

The removal of accept(DynamicContext, ISequence<?>) is verified to be safe. All literal implementations (Decimal, String, Integer) consistently use the visitor pattern through accept(IExpressionVisitor, CONTEXT) with no dependencies on the removed method.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining direct calls to the old accept method
# Expected: No direct calls should remain

# Search for potential calls to the old accept method
rg -A 2 "IntegerLiteral.*\.accept\(.*DynamicContext.*ISequence"

# Check if other similar classes still have the old accept method
ast-grep --pattern 'class $_ {
  $$$
  accept($_: DynamicContext, $_: ISequence) {
    $$$
  }
}'

Length of output: 165


Script:

#!/bin/bash
# Check superclass implementation and other literal classes
ast-grep --pattern 'class AbstractLiteralExpression {
  $$$
}'

# Look for any accept method calls on IntegerLiteral
rg "IntegerLiteral.*\.accept\(" -A 3

# Check other literal implementations
fd "Literal.java" --exec cat {}

Length of output: 4063

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/AbstractFilterExpression.java (2)

55-55: LGTM: Method signature changes improve encapsulation

The changes to the method signature are well-considered:

  1. Protected visibility better encapsulates the template method pattern
  2. The method name evaluate better describes its purpose
  3. The more general return type ISequence<?> maintains type safety while being less restrictive

6-6: Verify package move impact on dependent classes

The move from cst.logic to cst.items package better reflects the class's responsibility of handling item filtering. However, we should ensure all dependent classes are updated.

✅ Verification successful

Package move is complete and consistent

The move of AbstractFilterExpression from cst.logic to cst.items package is properly implemented. All dependent classes (Intersect and Except) are correctly placed in the same package with proper inheritance and consistent implementation patterns. No references to the old package path remain in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any references to the old package path that need updating

# Search for old package references
rg -l "gov\.nist\.secauto\.metaschema\.core\.metapath\.cst\.logic\.AbstractFilterExpression"

# Search for potential import statements that might need updating
rg "import.*AbstractFilterExpression"

Length of output: 134


Script:

#!/bin/bash
# Search for any references to AbstractFilterExpression class
rg -l "AbstractFilterExpression"

# Check for any class definitions extending AbstractFilterExpression
ast-grep --pattern 'class $_ extends AbstractFilterExpression'

# Look for any potential usages
ast-grep --pattern 'new AbstractFilterExpression'

Length of output: 419


Script:

#!/bin/bash
# Check the content of related files
echo "=== Intersect.java ==="
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Intersect.java

echo -e "\n=== Except.java ==="
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Except.java

Length of output: 3610

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/VariableReference.java (2)

9-9: LGTM! Import changes align with the class's dependencies.

The addition of IExpression and removal of IItem properly reflect the class's current needs.


70-72: Verify integration with the execution stack.

The method change from accept to evaluate with protected visibility looks good. However, I don't see integration with the execution stack mentioned in the PR objectives. This method should potentially push/pop itself onto the stack for debugging purposes.

Let's check if other expression classes implement stack tracking:

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/KindNodeTest.java (1)

51-54: Verify integration with execution stack tracking

While the method signature change from accept to evaluate aligns with the broader refactoring, the implementation doesn't appear to interact with the new execution stack tracking mentioned in the PR objectives. Consider updating the implementation to leverage the execution stack for debugging and error reporting.

Run this verification script to check for execution stack usage in other similar evaluate methods:

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Let.java (2)

9-9: Updated import statement aligns with refactoring

The import of IExpression replaces IItem, reflecting the shift to using IExpression within the class. This change is appropriate and maintains consistency with the refactored code.


85-85: Verify the impact of changing method visibility from public to protected

The method accept has been renamed to evaluate and its visibility changed from public to protected. This could affect external classes or interfaces that relied on the accept method being publicly accessible. Ensure that this change does not introduce breaking changes in the codebase.

Please run the following script to identify any external references to Let.accept:

✅ Verification successful

Protected visibility for evaluate method is appropriate

The change from public accept to protected evaluate is a safe refactoring that:

  • Aligns with the evaluation pattern used consistently throughout the codebase
  • Maintains proper encapsulation as the method is only used within the inheritance hierarchy
  • Does not impact any external usage patterns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for external uses of the `accept` method in the `Let` class.

# Expected result: No external references to `Let.accept` should be found.

rg -tjava 'Let\.accept\('

Length of output: 27


Script:

#!/bin/bash
# Find the Let class definition and its hierarchy
ast-grep --pattern 'class Let $_'

# Find any references to Let class
rg -tjava "class.*extends.*Let|new Let\(|Let\s+\w+\s*="

# Look for both accept and evaluate method calls
rg -tjava "(accept|evaluate).*\(" -A 2 -B 2

Length of output: 87501

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/Union.java (3)

9-9: LGTM! Import cleanup looks good.

Removing duplicate imports helps maintain clean and maintainable code.


Line range hint 58-68: Consider updating child node interaction pattern.

While the implementation is functionally correct, it still uses accept for child nodes while the parent class has moved to evaluate. This might need to be updated for consistency with the new pattern.

Let's verify if other similar classes have updated their child node handling:


57-57: Method signature change aligns with architectural improvements.

The change from public accept to protected evaluate improves encapsulation and supports the new execution stack feature. This is part of a consistent pattern across the codebase.

Let's verify the consistency of this pattern across related files:

✅ Verification successful

Method signature change is consistent with codebase patterns

The change to protected evaluate method is part of a consistent pattern across the codebase where:

  • All related classes in the package use the same protected evaluate(DynamicContext, ISequence<?>) signature
  • The visitor pattern integration is maintained through public accept methods
  • The change properly encapsulates evaluation logic while preserving the architectural design
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent method signature changes across related files
# Look for any remaining 'accept' methods or inconsistent 'evaluate' signatures

# Check for any remaining 'accept' methods in related files
ast-grep --pattern 'public $_ accept($_, $_)' 

# Check for consistent evaluate method signatures
ast-grep --pattern 'protected ISequence<?> evaluate(DynamicContext $_,$_)'

Length of output: 124


Script:

#!/bin/bash
# First, let's understand the broader context
echo "=== Searching for accept methods ==="
rg "accept.*\(" --type java -A 2

echo -e "\n=== Searching for evaluate methods ==="
rg "evaluate.*\(" --type java -A 2

echo -e "\n=== Looking for Union class usage ==="
rg "class.*Union" --type java -A 2

Length of output: 83135


Script:

#!/bin/bash
# Look for Union class and related evaluate methods
echo "=== Union class definition ==="
rg "class.*Union" --type java -A 5 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/

echo -e "\n=== Evaluate methods in related classes ==="
rg "protected.*evaluate.*\(" --type java -A 2 core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/

echo -e "\n=== Accept methods in the same package ==="
rg "accept.*\(" --type java core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/items/

Length of output: 14291

@david-waltermire david-waltermire force-pushed the feature/metapath-track-expression-context branch from b943cfe to 7c524da Compare January 7, 2025 01:45
@david-waltermire
Copy link
Contributor Author

@coderebbitai review

@david-waltermire david-waltermire merged commit 555b495 into metaschema-framework:develop Jan 7, 2025
3 checks passed
@david-waltermire david-waltermire deleted the feature/metapath-track-expression-context branch January 7, 2025 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant