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

Add support for Metapath arrays #32

Conversation

david-waltermire
Copy link
Contributor

@david-waltermire david-waltermire commented May 10, 2024

Committer Notes

This PR adds support for Metapath arrays.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you squashed any non-relevant commits and commit messages? [instructions]
  • Do all automated CI/CD checks pass?

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](https://pages.nist.gov/metaschema) and readme documentation affected by the changes you made? Changes to the website can be made in the website/content directory of your branch.

Summary by CodeRabbit

  • New Features

    • Enhanced parsing capabilities with updated grammar rules for more accurate and efficient expression evaluations.
    • Introduced new classes and methods to better handle array and sequence operations within expressions, improving the handling of complex data structures.
  • Improvements

    • Updated method signatures and renamed methods for clearer understanding and consistency across the codebase.
    • Streamlined sequence creation and manipulation through new static factory methods, enhancing usability and flexibility.
  • Bug Fixes

    • Adjusted data retrieval methods to ensure correct handling and processing of sequences, preventing potential data inconsistencies.

Copy link

coderabbitai bot commented May 10, 2024

Important

Review Skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

92 files out of 149 files are above the max files limit of 50. Please upgrade to Pro plan to get higher limits.

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

Walkthrough

The recent updates focus on enhancing the handling and parsing of array constructions and expressions within the Metapath grammar and associated Java classes. Significant changes include the addition of new classes and methods to manage array sequences and members, updates to parsing rules in the ANTLR grammar, and refinements in sequence interfaces and visitor patterns to streamline array processing and querying functionalities within the metaschema framework.

Changes

File Path Change Summary
.../antlr4/Metapath10.g4 Updated grammar rules for expressions and array constructors.
.../java/.../ISequence.java Modified sequence interface, added new methods for sequence creation.
.../java/.../AbstractAstVisitor.java Added context handling for new array constructors.
.../java/.../cst/AbstractCSTVisitorBase.java Added @Nullable annotation, new collection conversion method.
.../java/.../cst/AbstractExpressionVisitor.java Introduced methods to handle array sequences and members.
.../java/.../cst/AbstractFilterExpression.java Changed data retrieval method from asList() to getValue().
.../java/.../cst/ArrayMembers.java New class to handle array members, added multiple handling methods.
.../java/.../cst/ArraySequence.java New class for array sequence handling, methods for item processing added.
.../java/.../cst/BuildCSTVisitor.java Updated handling for array constructors and enhanced comment documentation.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

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: 11

Out of diff range and nitpick comments (2)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ComparisonFunctions.java (2)

Line range hint 106-106: Correct the typo in the method name from generalCompairison to generalComparison.

- public static IBooleanItem generalCompairison(
+ public static IBooleanItem generalComparison(

Line range hint 150-150: Fix the logical error in casting conditions. Replace the duplicate IDayTimeDurationItem check with IYearMonthDurationItem.

- } else if (item instanceof IDayTimeDurationItem) {
+ } else if (item instanceof IYearMonthDurationItem) {
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between a8e366a and e75c797.
Files selected for processing (55)
  • core/src/main/antlr4/Metapath10.g4 (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java (5 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/antlr/AbstractAstVisitor.java (29 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AbstractCSTVisitorBase.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/AbstractFilterExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ArrayMembers.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ArraySequence.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java (25 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/CSTPrinter.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Except.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/IExpressionVisitor.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Intersect.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Metapath.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/SimpleMap.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/StringConcat.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/Union.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Axis.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Flag.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/ModelInstance.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/NameTest.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashOnlyPath.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/RootSlashPath.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/Wildcard.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/AbstractFunction.java (1 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/function/DefaultFunction.java (4 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/FunctionUtils.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ISequenceType.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/SequenceTypeImpl.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpRecurseDepth.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractArrayItem.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/AbstractSequence.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/ArrayItemN.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/ImmutableCollections.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/SequenceN.java (2 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/SingletonSequence.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/StreamSequence.java (3 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayMember.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java (1 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/DefaultConstraintValidator.java (6 hunks)
  • core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FindingCollectingConstraintValidationHandler.java (2 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/MetapathExpressionTest.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/TestUtils.java (1 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCstVisitorTest.java (4 hunks)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpressionTest.java (2 hunks)
Files not processed due to max files limit (4)
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/function/library/FunctionTestBase.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItemTest.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/model/xml/MetaConstraintLoaderTest.java
  • databind/src/main/java/gov/nist/secauto/metaschema/databind/codegen/impl/AnnotationGenerator.java
Files not reviewed due to errors (2)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/antlr/AbstractAstVisitor.java (no review received)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java (no review received)
Files skipped from review due to trivial changes (3)
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/path/AbstractPathExpression.java
  • core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayMember.java
  • core/src/test/java/gov/nist/secauto/metaschema/core/metapath/cst/PredicateExpressionTest.java
Additional comments not posted (75)
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/AbstractFunction.java (3)

31-32: Import of javax.xml.namespace.QName is correctly placed and necessary for the QName handling in the class.


37-52: The constructors are well-defined and use the @NonNull annotation to ensure that null values are not passed to them, which is crucial for avoiding null pointer exceptions in the application.


56-57: The method getQName correctly returns the QName of the function. This is a straightforward getter with no side effects, ensuring encapsulation is maintained.

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

42-45: The constructor uses varargs to accept an array of ITEM objects and converts them into an unmodifiable list. This is a good use of CollectionUtil and ObjectUtils to ensure the list is safely constructed without null values.


47-49: The constructor that accepts a list of ITEM objects directly assigns it to the items field. This is straightforward and correctly uses the @NonNull annotation to prevent null values.


51-54: The getValue method provides access to the internal list of items. This method is essential for classes that encapsulate collections to allow controlled access to their data.

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

48-48: The accept method correctly implements the mapping logic using a flatMap operation on the sequence. This is a key part of the functionality, allowing for each item in the left sequence to be transformed by the right expression. The use of ObjectUtils.notNull ensures that null values do not cause issues during the stream operations.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/SequenceN.java (4)

44-44: The constructor that accepts a collection of ITEM objects and converts it into a list is correctly implemented. It ensures that the items are stored in a new list, providing encapsulation.


48-48: The constructor that allows for a choice between copying the list or using it directly is flexible and useful for different scenarios where immutability or performance is a concern.


52-54: The varargs constructor simplifies the creation of a SequenceN from an array of items, using utility classes to ensure the list is non-null and unmodifiable.


57-63: The getValue method provides a safe way to access the internal list of items, which is crucial for encapsulation in data structure classes.

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

32-32: The extension of IItem to include IArrayMember is a significant change, indicating that items can now be considered as part of array structures. This aligns with the PR's focus on enhancing array support.

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

42-44: The static method empty correctly provides a type-safe way to obtain an empty sequence, utilizing a generic singleton pattern to avoid unnecessary object creation.


48-48: The collect method, which simply returns this, is an appropriate implementation for a method that is supposed to return a sequence containing all the items of the current sequence.


57-62: The implementations of equals and hashCode are crucial for correct behavior in collections and other data structures that rely on these methods. The use of getValue().equals and getValue().hashCode ensures that the sequence's identity is effectively tied to its contents.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/impl/SingletonSequence.java (4)

43-44: The constructor correctly initializes the item field with a non-null value, ensuring that the SingletonSequence always contains a valid item.


47-55: The getValue method effectively wraps the single item in a list, using CollectionUtil.singletonList, which is an efficient way to handle immutable single-item collections.


59-65: The isEmpty and size methods provide correct and expected behaviors for a singleton sequence, with isEmpty always returning false and size always returning one.


70-76: The stream and forEach methods are well-implemented, providing streamlined ways to process the single item in the sequence. These methods are essential for integrating with Java's functional programming features.

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

58-58: The applyFilterTo method correctly implements the 'except' logic by filtering out items from the result that are contained in the items list. This is a straightforward and efficient implementation of the set difference operation in the context of sequences.

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

59-59: The implementation of the intersection operation using streams is correct and efficient.

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

63-63: Ensure robust error handling for cases where findFirst() returns an empty Optional.

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

57-60: The factory method for creating sequence types is correctly implemented and follows good design principles.

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

71-71: The implementation for sequentially processing expressions in a Metapath context is correct and efficient.

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

39-39: The constructor for SequenceTypeImpl correctly initializes the type and occurrence with non-null checks.

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

77-77: The implementation for processing the union of expressions in a Metapath context is correct and efficiently ensures distinct results.

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

74-74: TODO: Replace with concat function when implemented.

This is noted as a future task. Ensure to address this as part of upcoming updates.

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

80-80: Implementation of name test filtering looks correct.

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

66-75: Proper handling of array sequences with null checks and conversion to array items.

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

53-72: Effective handling of array members with appropriate handling of different result sizes.

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

74-74: Implementation of filtering logic using items from the right expression appears correct.

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

93-93: Correct implementation of test for Metapath expression with appropriate assertions.

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

72-72: Effective handling of flag node items with appropriate stream operations for matching.

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

74-74: Effective handling of model node items with appropriate stream operations for matching.

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

63-63: The implementation of the accept method correctly applies the filtering logic based on the provided predicate. Good use of stream operations and predicate testing.

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

101-101: The implementation of the accept method in the Axis enum correctly applies the axis operations to the sequence of node items. Efficient use of stream operations.

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

55-64: The implementation of the sequence() and sequence(T... items) methods correctly creates sequences of items using ISequence.of(). Proper use of generics and non-null annotations.

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

75-102: The implementation of the execute method in AbstractArrayItem correctly performs array operations based on the position argument. The methods hashCode and equals are also correctly implemented.

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

102-102: The implementation of the accept method in PredicateExpression correctly applies predicates to filter items based on conditions. Efficient use of streams and lambda expressions.

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

46-168: The implementation of the abstract classes AbstractImmutableCollection and AbstractImmutableList in ImmutableCollections correctly enforces immutability by throwing UnsupportedOperationException for all modification operations. The design allows subclasses to provide the underlying data structure through the getValue method.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnData.java (1)

130-130: The implementation of the fnData method in FnData correctly atomizes a sequence of items. The method efficiently uses a flatMap operation to handle each item.

core/src/main/java/gov/nist/secauto/metaschema/core/model/IGroupable.java (1)

169-169: The implementation of the getItemValues method in IGroupable correctly returns an empty list by default, using CollectionUtil.emptyList() to ensure immutability.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnMinMax.java (2)

104-104: Implementation of min function looks correct and efficient.


117-117: Implementation of max function looks correct and efficient.

core/src/main/java/gov/nist/secauto/metaschema/core/model/constraint/FindingCollectingConstraintValidationHandler.java (2)

83-83: Handling of cardinality minimum violation is correctly implemented.


94-94: Handling of cardinality maximum violation is correctly implemented.

core/src/main/antlr4/Metapath10.g4 (5)

16-16: Modification to enclosedexpr supports new syntax correctly.


73-73: Addition of postfixexpr supports new syntax correctly.


78-79: Addition of lookup and keyspecifier supports new syntax correctly.


84-84: Modification to primaryexpr to include arrayconstructor and unarylookup is correctly implemented.


105-109: Addition of arrayconstructor, squarearrayconstructor, and curlyarrayconstructor supports new array syntax correctly.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnSum.java (2)

108-108: Implementation of sum function with default zero value is correct.


126-126: Implementation of sum function with specified zero value is correct.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnAvg.java (1)

96-96: Implementation of average function is correct and handles different item types effectively.

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

356-359: Method visitArray(ArraySequence expr, CONTEXT context) correctly implements the visitor pattern for ArraySequence.


361-364: Method visitArray(ArrayMembers expr, CONTEXT context) correctly implements the visitor pattern for ArrayMembers.

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

134-154: Method nAiryToCollection effectively handles collections of expressions. Ensure it integrates well with other visitor components.

Verification successful

The method nAiryToCollection is correctly integrated within the BuildCSTVisitor.java, specifically in the handleArrayConstructor method. This usage aligns well with the visitor pattern and is tailored for handling array constructors in XPath expressions.

  • File: BuildCSTVisitor.java
  • Method: handleArrayConstructor
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of `nAiryToCollection` with other visitor components.

# Test: Search for usage of `nAiryToCollection`. Expect: Proper integration with visitor pattern.
rg --type java $'nAiryToCollection'

Length of output: 282



Script:

#!/bin/bash
# Description: Extract the usage context of `nAiryToCollection` in `BuildCSTVisitor.java`.

# Test: Display the surrounding code where `nAiryToCollection` is used in `BuildCSTVisitor.java`.
rg --type java --context 10 'nAiryToCollection' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/BuildCSTVisitor.java

Length of output: 778

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

339-341: The implementation of visitArray for ArraySequence is consistent with other visitor methods and correctly uses appendNode to build the string representation.

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

141-141: The update to use sequence.getValue() in requireFirstItem aligns with the new sequence interface changes.


172-172: The modifications in getFirstItem to use sequence.getValue() are correctly implemented and handle the singleton condition effectively.

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

248-248: The implementation of convertArguments correctly handles type checks and conversions based on the function's signature, adhering to XPath 3.1 rules.

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

95-97: Ensure proper null handling in getName() method.


105-107: Ensure proper null handling in getNamespace() method.

Verification successful

The implementation of getQName() in AbstractFunction.java ensures that the QName object is never null, as it is initialized with non-null parameters and the field is annotated with @NonNull. Additionally, the QName class in Java ensures that the namespace URI is never null, defaulting to an empty string if not provided. Therefore, the use of ObjectUtils.notNull(getQName().getNamespaceURI()) in the getNamespace() method of IFunction.java is safe and correctly handles potential null values.

  • The getQName() method in AbstractFunction.java ensures non-null return through its implementation and annotations.
  • The QName constructor used in AbstractFunction ensures that the namespace URI is never null.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `getQName().getNamespaceURI()` never returns null which could cause `ObjectUtils.notNull` to throw an exception.

# Test: Search for the implementation of `getQName()` and check for null handling.
ast-grep --lang java --pattern $'class $_ { $$$ QName getQName() { $$$ } $$$ }'

Length of output: 80



Script:

#!/bin/bash
# Description: Search for any occurrence of `getQName()` in Java files to locate its definition or usage, which might give clues about its implementation and null handling.
rg "getQName()" -t java

Length of output: 3515



Script:

#!/bin/bash
# Description: Extract the implementation of `getQName()` from `AbstractFunction.java` to verify null handling.
ast-grep --lang java --pattern $'class AbstractFunction { $$$ QName getQName() { $$$ } $$$ }'

Length of output: 94



Script:

#!/bin/bash
# Description: Directly pull the content of `AbstractFunction.java` to inspect the implementation of `getQName()`.
rg --files-with-matches --glob '*AbstractFunction.java' | xargs cat

Length of output: 466



Script:

#!/bin/bash
# Description: Correctly list and display the content of `AbstractFunction.java` to inspect the implementation of `getQName()`.
rg --files --glob '*AbstractFunction.java' | xargs cat

Length of output: 2655

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

150-150: Ensure that the test testAbbreviatedParentAxis correctly asserts the expected results.


224-224: Ensure that the test testAbbreviatedForwardAxisModelName correctly asserts the expected results.


245-245: Ensure that the test testAbbreviatedForwardAxisFlagName correctly asserts the expected results.

Verification successful

The test method testAbbreviatedForwardAxisFlagName in the BuildCstVisitorTest.java file has been located. The method involves compiling a Metapath expression and evaluating it against a document node. The assertion checks if the result contains an instance of IRootAssemblyNodeItem with a specific property. This setup appears to be correctly implemented for testing the functionality described by the method's name, which suggests that the test is likely asserting the expected results correctly.

Given this information, the original review comment concern seems to be addressed properly in the code.

Final response:

  • The test method testAbbreviatedForwardAxisFlagName is implemented correctly and includes appropriate assertions for its scope.
  • The method compiles and evaluates a Metapath expression and checks the results accurately.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the test setup and assertions are correctly implemented for the `testAbbreviatedForwardAxisFlagName` method.

# Test: Search for the implementation of `IFlagNodeItem` and its properties.
ast-grep --lang java --pattern $'class $_ { $$$ class IFlagNodeItem { $$$ } $$$ }'

Length of output: 83



Script:

#!/bin/bash
# Broad search for any class or interface that might be related to IFlagNodeItem
ast-grep --lang java --pattern $'class $_ { $$$ }'
ast-grep --lang java --pattern $'interface $_ { $$$ }'

Length of output: 276278



Script:

#!/bin/bash
# Search for the test method `testAbbreviatedForwardAxisFlagName` and display its content.
rg --multiline "void testAbbreviatedForwardAxisFlagName" --context 10

Length of output: 2654


266-266: Ensure that the test testForwardstepChild correctly asserts the expected results.

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

523-534: Add new visit methods for ArraySequence and ArrayMembers.

These methods are essential for supporting the new array features in Metapath expressions as per the PR's objectives.

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java (4)

29-35: Ensure that the newly imported classes are utilized within the file to avoid unnecessary imports.

Verification successful

The review comment raised a concern about the utilization of newly imported classes in the ISequence.java file, specifically AbstractSequence, SequenceN, SingletonSequence, and StreamSequence. The objective was to ensure these imports are not unnecessary by verifying their usage within the file.

From the script output, it is evident that:

  • AbstractSequence is used in the method empty().
  • SingletonSequence is utilized in methods that handle single item sequences.
  • SequenceN is extensively used in various methods that create sequences from multiple elements.
  • StreamSequence is used in a method that handles stream inputs.

Each of the imported classes is indeed used in the file, which confirms that the imports are necessary and correctly utilized.

Given this information, the appropriate response is to confirm that the imports are used as intended and are not unnecessary.

The verification confirms that all newly imported classes (`AbstractSequence`, `SequenceN`, `SingletonSequence`, `StreamSequence`) are utilized within `ISequence.java`. Each class is appropriately used in methods relevant to their functionality, ensuring that there are no unnecessary imports.

- `AbstractSequence` is used for creating empty sequences.
- `SingletonSequence` is used for sequences with a single item.
- `SequenceN` is used for sequences with multiple items.
- `StreamSequence` is used for sequences created from streams.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the newly imported classes are used in the file.

# Test: Search for the usage of the newly imported classes. Expect: At least one occurrence of each class.
rg --type java 'AbstractSequence|SequenceN|SingletonSequence|StreamSequence' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java

Length of output: 1323


64-64: The interface declaration has been modified to extend IArrayMember. Confirm that this change aligns with the intended design and does not introduce any unintended side effects.

Verification successful

The interface ISequence extending IArrayMember appears to be consistent with the design patterns observed in other parts of the system. Several classes and interfaces within the same package also extend IArrayMember, indicating that this is a standard practice for collection-like structures in this context. Therefore, the modification aligns with the intended design and does not introduce any unintended side effects.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the impact of `ISequence` extending `IArrayMember` on other parts of the system.

# Test: Search for other interfaces or classes that extend `IArrayMember` and check for consistency. Expect: Consistent usage across the system.
rg --type java 'extends IArrayMember' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/

Length of output: 3971


89-89: The method getValue() replaces asList(). Verify that all occurrences of asList() are replaced with getValue() to maintain functionality.


503-523: The method copyOf(Collection<? extends T> collection) is introduced to create sequences from collections. Ensure that this method is used appropriately and does not duplicate functionality provided by other methods.

Verification successful

The search results indicate that while there are multiple methods in the codebase that interact with collections, none of them seem to directly duplicate the functionality of the copyOf method in the ISequence interface. The copyOf method specifically creates an unmodifiable sequence from a given collection, ensuring that the collection is non-null and does not contain any null items. This functionality appears to be unique to this method within the context of the ISequence interface and related classes.

Given this, it seems that the copyOf method does not duplicate existing functionality but rather provides a specific utility for creating sequences from collections in a safe and controlled manner.

Conclusion:

  • The copyOf method in the ISequence interface provides unique functionality for creating unmodifiable sequences from collections, ensuring input validity.
  • No other methods with identical functionality were found in the related classes or the ISequence interface itself.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `copyOf` and ensure it does not duplicate existing functionality.

# Test: Search for other methods that create sequences from collections and compare their functionality with `copyOf`. Expect: Distinct functionality.
rg --type java 'of\(.*Collection' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/

Length of output: 97



Script:

#!/bin/bash
# Description: Broaden the search to find any methods that might create sequences from collections in the ISequence interface or related classes.

# Search for any method in the ISequence interface that takes a Collection as a parameter
ast-grep --lang java --pattern $'interface ISequence {
  $$$
  $_($_ Collection $$$) {
    $$$
  }
  $$$
}' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/ISequence.java

# Additionally, search for any method in related classes that might create sequences from collections
rg --type java 'Collection' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/

Length of output: 19829

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItem.java (3)

55-56: The interface IArrayItem now extends multiple interfaces (IFunction, IItem, List<ITEM>). Confirm that this multi-inheritance does not introduce method conflicts or unexpected behaviors.

Verification successful

Based on the detailed examination of the methods defined in the IFunction and IItem interfaces, and considering the typical methods of the List interface, there do not appear to be any direct method conflicts. The methods in IFunction are specific to function properties and execution, which are distinct from list operations. Similarly, IItem focuses on value retrieval, which does not overlap with List methods.

Therefore, it seems unlikely that the multi-inheritance in IArrayItem introduces method conflicts or unexpected behaviors, given the distinct responsibilities and method signatures of the interfaces it extends.

  • IFunction primarily includes methods for handling function properties, arguments, and execution.
  • IItem provides methods related to the value of items, which are distinct from list operations.

This analysis suggests that Java's interface resolution mechanisms are sufficient to handle this multi-inheritance without issues.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the multi-inheritance in `IArrayItem` does not introduce method conflicts.

# Test: Check for method conflicts or unexpected behaviors due to multi-inheritance. Expect: No conflicts or unexpected behaviors.
rg --type java 'IArrayItem' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/

Length of output: 7586



Script:

#!/bin/bash
# Extract method signatures from IFunction and IItem interfaces
ast-grep --lang java --pattern $'interface IFunction { $$$ }' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/
ast-grep --lang java --pattern $'interface IItem { $$$ }' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/

Length of output: 273



Script:

#!/bin/bash
# Search for IFunction and IItem interfaces to confirm their existence and file paths
fd 'IFunction.java' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/
fd 'IItem.java' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/

Length of output: 187



Script:

#!/bin/bash
# Broaden the search for IFunction and IItem interfaces across the entire repository
fd 'IFunction.java'
fd 'IItem.java'

Length of output: 197



Script:

#!/bin/bash
# Extract method signatures from IFunction and IItem interfaces using the correct file paths
ast-grep --lang java --pattern $'interface IFunction { $$$ }' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/
ast-grep --lang java --pattern $'interface IItem { $$$ }' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/

Length of output: 259



Script:

#!/bin/bash
# Manually inspect the content of IFunction and IItem interfaces
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/IFunction.java
cat core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/IItem.java

Length of output: 19396


239-241: The method of(List<? extends T> items) creates an IArrayItem from a list. Ensure that this method handles empty lists and null values correctly as per the implementation.


502-504: The method of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8, T e9, T e10) introduces a way to create an IArrayItem with ten elements. Verify that this method is used appropriately and does not introduce performance issues with large arrays.

Verification successful

The method IArrayItem.of designed to create an IArrayItem with ten elements is primarily used within test cases, as evidenced by its multiple occurrences in IArrayItemTest.java. This suggests that its primary application is for unit testing rather than in performance-critical production environments. There is one occurrence in the production code within ArraySequence.java, which might warrant a closer look to ensure it does not introduce performance issues when handling large arrays.

  • Test Usage: core/src/test/java/gov/nist/secauto/metaschema/core/metapath/item/function/IArrayItemTest.java
  • Production Usage: core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/ArraySequence.java

Given the limited use in production code, performance issues related to this method may not be as critical as initially feared, but monitoring its impact in ArraySequence.java could be beneficial.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage and performance of the method `of` with ten elements.

# Test: Check for usage patterns and performance implications of `of` with ten elements. Expect: Efficient usage without performance issues.
rg --type java 'IArrayItem.of' core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/function/

Length of output: 106



Script:

#!/bin/bash
# Broaden the search for the usage of the `of` method across the entire project.
rg --type java 'IArrayItem.of'

# Verify the definition of the method `of` in the IArrayItem interface to confirm its existence and parameters.
ast-grep --lang java --pattern $'interface IArrayItem {
  $$$
  static <T extends IArrayMember> IArrayItem<T> of($_, $_, $_, $_, $_, $_, $_, $_, $_, $_) {
    $$$
  }
  $$$
}'

Length of output: 1024

@david-waltermire david-waltermire force-pushed the feature-metapath-arrays branch from befb71a to cffe487 Compare May 21, 2024 04:29
@david-waltermire david-waltermire force-pushed the feature-metapath-arrays branch from 51eccd0 to 7af34c0 Compare May 25, 2024 13:33
@david-waltermire david-waltermire force-pushed the feature-metapath-arrays branch from 3818ef9 to 5b5e434 Compare May 25, 2024 15:13
@david-waltermire david-waltermire marked this pull request as ready for review May 26, 2024 18:34
@david-waltermire david-waltermire merged commit 82b9b76 into metaschema-framework:develop May 26, 2024
1 check passed
david-waltermire added a commit that referenced this pull request May 26, 2024
* Completed code to support Metapath array construction.
* Implemented array postfix and unary lookups.
* Cleaned up ISequence implementations, moving getFirstItem to be a method member. Added a utility function to convert a sequence into an array member.
* Added support for the following Metapath functions:
  - array:get 
  - array:put
  - array:append
  - array:subarray
  - array:remove
  - array:insert-before
  - array:join
  - array:head
  - array:tail
  - array:reverse
  - array:flatten
* Fixed spotbugs null check warnings
* Cleaned up some Javadocs.
* Incorporated changes based on CodeRabbit review.
* normalized line endings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant