Skip to content

Commit

Permalink
Cleaned up Java compile and PMD warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Jan 4, 2025
1 parent b2e2409 commit 98f3d59
Show file tree
Hide file tree
Showing 46 changed files with 646 additions and 869 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,113 +6,98 @@
package gov.nist.secauto.metaschema.core.metapath;

/**
* MPST: Exceptions related to the Metapath static context and static
* evaluation.
* MPST: Exceptions related to the Metapath static context and static evaluation.
*/
@SuppressWarnings("PMD.DataClass")
public class StaticMetapathException
extends AbstractCodedMetapathException {
/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0003">err:MPST0003</a>: It
* is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
* error</a> if an expression is not a valid instance of the Metapath grammar.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0003">err:MPST0003</a>: It is a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if an expression is
* not a valid instance of the Metapath grammar.
*/
// TODO: need a Metapath grammar link
public static final int INVALID_PATH_GRAMMAR = 3;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0008">err:MPST0008</a>: It
* is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
* error</a> if an expression refers to an element name, attribute name, schema
* type name, namespace prefix, or variable name that is not defined in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static
* context</a>, except for an ElementName in an <a href=
* "https://www.w3.org/TR/xpath-31/#doc-xpath31-ElementTest">ElementTest</a> or
* an AttributeName in an <a href=
* "https://www.w3.org/TR/xpath-31/#doc-xpath31-AttributeTest">AttributeTest</a>.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0008">err:MPST0008</a>: It is a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if an expression
* refers to an element name, attribute name, schema type name, namespace prefix, or variable name
* that is not defined in the <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static
* context</a>, except for an ElementName in an
* <a href= "https://www.w3.org/TR/xpath-31/#doc-xpath31-ElementTest">ElementTest</a> or an
* AttributeName in an
* <a href= "https://www.w3.org/TR/xpath-31/#doc-xpath31-AttributeTest">AttributeTest</a>.
*/
public static final int NOT_DEFINED = 8;
/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0010">err:MPST0010</a>: An
* implementation that does not support the namespace axis must raise a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if
* it encounters a reference to the namespace axis and XPath 1.0 compatibility
* mode is false.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0010">err:MPST0010</a>: An implementation that
* does not support the namespace axis must raise a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if it encounters a
* reference to the namespace axis and XPath 1.0 compatibility mode is false.
*/
public static final int AXIS_NAMESPACE_UNSUPPORTED = 10;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0017">err:MPST0017</a>: It
* is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
* error</a> if the
* <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
* QName</a> and number of arguments in a static function call do not match the
* name and arity of a
* <a href="https://www.w3.org/TR/xpath-31/#dt-known-func-signatures">function
* signature</a> in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static
* context</a>.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0017">err:MPST0017</a>: It is a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if the
* <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded QName</a> and number of
* arguments in a static function call do not match the name and arity of a
* <a href="https://www.w3.org/TR/xpath-31/#dt-known-func-signatures">function signature</a> in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-context">static context</a>.
*/
public static final int NO_FUNCTION_MATCH = 17;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0051">err:MPST0051</a>: It
* is a static error if the
* <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
* QName</a> for an AtomicOrUnionType in a SequenceType is not defined in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope schema
* types</a> as a <a href=
* "https://www.w3.org/TR/xpath-31/#dt-generalized-atomic-type">generalized
* atomic type</a>.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0051">err:MPST0051</a>: It is a static error if
* the <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded QName</a> for an
* AtomicOrUnionType in a SequenceType is not defined in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope schema types</a> as a
* <a href= "https://www.w3.org/TR/xpath-31/#dt-generalized-atomic-type">generalized atomic
* type</a>.
*/
public static final int UNKNOWN_TYPE = 51;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0052">err:MQST0052</a>: The
* type named in a cast or castable expression must be the name of a type
* defined in the <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope
* schema types</a>, and the type must be simple.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0052">err:MQST0052</a>: The type named in a cast
* or castable expression must be the name of a type defined in the
* <a href="https://www.w3.org/TR/xpath-31/#dt-is-types">in-scope schema types</a>, and the type
* must be simple.
*/
public static final int CAST_UNKNOWN_TYPE = 52;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MQST0070</a>: A
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> is
* raised if any of the following conditions is statically detected in any
* expression.
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> is raised if any of
* the following conditions is statically detected in any expression.
* <ul>
* <li>The prefix xml is bound to some namespace URI other than
* http://www.w3.org/XML/1998/namespace.</li>
* <li>A prefix other than xml is bound to the namespace URI
* http://www.w3.org/XML/1998/namespace.</li>
* <li>The prefix xmlns is bound to any namespace URI.</li>
* <li>A prefix other than xmlns is bound to the namespace URI
* http://www.w3.org/2000/xmlns/.</li>
* http://www.w3.org/XML/1998/namespace.
* <li>A prefix other than xml is bound to the namespace URI http://www.w3.org/XML/1998/namespace.
* <li>The prefix xmlns is bound to any namespace URI.
* <li>A prefix other than xmlns is bound to the namespace URI http://www.w3.org/2000/xmlns/.
* </ul>
*/
public static final int NAMESPACE_MISUSE = 70;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0080">err:MPST0080</a>: It
* is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
* error</a> if the target type of a cast or castable expression is
* meta:anyAtomicType.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXPST0080">err:MPST0080</a>: It is a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if the target type of
* a cast or castable expression is meta:anyAtomicType.
*/
public static final int CAST_ANY_ATOMIC = 80;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MPST0070</a>: It
* is a <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static
* error</a> if a QName used in an expression contains a namespace prefix that
* cannot be expanded into a namespace URI by using the
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-namespaces">statically
* known namespaces</a>.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0070">err:MPST0070</a>: It is a
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-error">static error</a> if a QName used in an
* expression contains a namespace prefix that cannot be expanded into a namespace URI by using the
* <a href="https://www.w3.org/TR/xpath-31/#dt-static-namespaces">statically known namespaces</a>.
*/
public static final int PREFIX_NOT_EXPANDABLE = 81;

/**
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0134">err:MPST0134</a>: The
* namespace axis is not supported.
* <a href= "https://www.w3.org/TR/xpath-31/#ERRXQST0134">err:MPST0134</a>: The namespace axis is
* not supported.
*/
public static final int AXIS_NAMESPACE_UNSUPPORTED_IN_TEST = 134;

Expand All @@ -122,8 +107,7 @@ public class StaticMetapathException
private static final long serialVersionUID = 2L;

/**
* Constructs a new exception with the provided {@code code}, {@code message},
* and {@code cause}.
* Constructs a new exception with the provided {@code code}, {@code message}, and {@code cause}.
*
* @param code
* the error code value
Expand All @@ -137,8 +121,7 @@ public StaticMetapathException(int code, String message, Throwable cause) {
}

/**
* Constructs a new exception with the provided {@code code}, {@code message},
* and no cause.
* Constructs a new exception with the provided {@code code}, {@code message}, and no cause.
*
* @param code
* the error code value
Expand All @@ -150,8 +133,7 @@ public StaticMetapathException(int code, String message) {
}

/**
* Constructs a new exception with the provided {@code code}, no message, and
* the {@code cause}.
* Constructs a new exception with the provided {@code code}, no message, and the {@code cause}.
*
* @param code
* the error code value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@
import edu.umd.cs.findbugs.annotations.Nullable;

/**
* Provides utility methods for processing Metapath abstract syntax tree (AST)
* nodes to produce a compact syntax tree (CST).
* Provides utility methods for processing Metapath abstract syntax tree (AST) nodes to produce a
* compact syntax tree (CST).
* <p>
* This base class implements common visitor patterns for transforming AST nodes
* into a more compact representation. The CST is optimized for efficient
* evaluation of Metapath expressions.
* This base class implements common visitor patterns for transforming AST nodes into a more compact
* representation. The CST is optimized for efficient evaluation of Metapath expressions.
* <p>
* Key utility methods include:
* <ul>
* <li>{@link #nairyToList} - Processes n-airy expressions into a list</li>
* <li>{@link #nairyToCollection} - Processes n-airy expressions into a
* collection</li>
* <li>{@link #handleNAiryCollection} - Handles n-airy expressions with
* operators</li>
* <li>{@link #handleGroupedNAiry} - Processes grouped n-airy expressions</li>
* <li>{@link #nairyToList} - Processes n-airy expressions into a list
* <li>{@link #nairyToCollection} - Processes n-airy expressions into a collection
* <li>{@link #handleNAiryCollection} - Handles n-airy expressions with operators
* <li>{@link #handleGroupedNAiry} - Processes grouped n-airy expressions
* </ul>
*/
@SuppressWarnings({
Expand All @@ -55,21 +52,19 @@ public abstract class AbstractCSTVisitorBase
private static final Pattern QUALIFIED_NAME_PATTERN = Pattern.compile("^Q\\{([^}]*)\\}(.+)$");

/**
* Get the QName for an
* <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
* Get the QName for an <a href="https://www.w3.org/TR/xpath-31/#dt-expanded-qname">expanded
* QName</a>.
*
* @param eqname
* the expanded QName
* @param context
* the Metapath evaluation static context
* @param requireNamespace
* if {@code true} require the resulting QName to have a namespace, or
* {@code false} otherwise
* if {@code true} require the resulting QName to have a namespace, or {@code false}
* otherwise
* @return the QName
* @throws StaticMetapathException
* if the expanded QName prefix is not bound or if the resulting
* namespace is invalid
* if the expanded QName prefix is not bound or if the resulting namespace is invalid
*/
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.CognitiveComplexity" })
@NonNull
Expand Down Expand Up @@ -214,22 +209,19 @@ R nairyToCollection(
}

/**
* Parse the provided context as an n-airy phrase, which will be one of the
* following.
* Parse the provided context as an n-airy phrase, which will be one of the following.
* <ol>
* <li>A single <code>expr</code> for which that expr will be returned</li>
* <li><code>left (operator right)*</code> for which a collection of the left
* and right members will be returned based on what is provided by the
* supplier.</li>
* <li>A single <code>expr</code> for which that expr will be returned
* <li><code>left (operator right)*</code> for which a collection of the left and right members will
* be returned based on what is provided by the supplier.
* </ol>
*
* @param <CONTEXT>
* the context type to parse
* @param context
* the context instance
* @param supplier
* a supplier that will instantiate an expression based on the provided
* parsed collection
* a supplier that will instantiate an expression based on the provided parsed collection
* @return the left expression or the supplied expression for a collection
*/
@NonNull
Expand All @@ -245,16 +237,15 @@ R nairyToCollection(
}

/**
* Parse the provided context as an n-airy phrase, which will be one of the
* following.
* Parse the provided context as an n-airy phrase, which will be one of the following.
* <ol>
* <li><code>expr</code> for which the expr will be returned.</li>
* <li><code>left</code> plus a number of additional recurring tokens as defined
* by the <em>step</em>.</li>
* <li><code>expr</code> for which the expr will be returned.
* <li><code>left</code> plus a number of additional recurring tokens as defined by the
* <em>step</em>.
* </ol>
* <p>
* In the second case, the supplier will be used to generate an expression from
* the collection of tuples.
* In the second case, the supplier will be used to generate an expression from the collection of
* tuples.
*
* @param <CONTEXT>
* the context type to parse
Expand All @@ -267,8 +258,7 @@ R nairyToCollection(
* @param parser
* a binary function used to parse the context children
* @param supplier
* a supplier that will instantiate an expression based on the provided
* collection
* a supplier that will instantiate an expression based on the provided collection
* @return the left expression or the supplied expression for a collection
*/
@NonNull
Expand Down Expand Up @@ -310,29 +300,27 @@ R nairyToCollection(
}

/**
* Parse the provided context as a simple n-airy phrase, which will be one of
* the following.
* Parse the provided context as a simple n-airy phrase, which will be one of the following.
* <ol>
* <li><code>expr</code> for which the expr will be returned</li>
* <li><code>left (operator right)*</code> for which a collection of the left
* and right members will be returned based on what is provided by the supplier.
* <li><code>expr</code> for which the expr will be returned
* <li><code>left (operator right)*</code> for which a collection of the left and right members will
* be returned based on what is provided by the supplier.
* </ol>
* <p>
* In the second case, the supplier will be used to generate an expression from
* the collection of tuples.
* In the second case, the supplier will be used to generate an expression from the collection of
* tuples.
*
* @param <CONTEXT>
* the context type to parse
* @param context
* the context instance
* @param startingIndex
* the index of the first child expression, which must be a
* non-negative value that is less than the number of children
* the index of the first child expression, which must be a non-negative value that is less
* than the number of children
* @param step
* the amount to advance the loop over the context children
* @param parser
* a trinary function used to parse the context children and supply a
* result
* a trinary function used to parse the context children and supply a result
* @return the left expression or the supplied expression
*/
protected <CONTEXT extends ParserRuleContext> IExpression handleGroupedNAiry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
/**
* Implements the '+' operator for Metapath addition operations.
* <p>
* An XPath 3.1
* <a href="https://www.w3.org/TR/xpath-31/#id-arithmetic">arithmetic
* expression</a> supporting addition.
* An XPath 3.1 <a href="https://www.w3.org/TR/xpath-31/#id-arithmetic">arithmetic expression</a>
* supporting addition.
* <p>
* Supports addition operations between:
* <ul>
* <li>Numeric values
* <li>Date/DateTime + {@link IYearMonthDurationItem}
* <li>Date/DateTime/Time + {@link IDayTimeDurationItem}
* <li>Date/Time arithmetic (adding durations to dates/times)</li>
* <li>Date/Time arithmetic (adding durations to dates/times)
* <li>{@link IYearMonthDurationItem} + {@link IYearMonthDurationItem}
* <li>{@link IDayTimeDurationItem} + {@link IDayTimeDurationItem}
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* An XPath 3.1
* <a href="https://www.w3.org/TR/xpath-31/#id-arithmetic">arithmetic
* expression</a> supporting multiplication.
* An XPath 3.1 <a href="https://www.w3.org/TR/xpath-31/#id-arithmetic">arithmetic expression</a>
* supporting multiplication.
* <p>
* Supports multiplication between:
* <ul>
* <li>Numeric values</li>
* <li>YearMonthDuration × Numeric</li>
* <li>DayTimeDuration × Numeric</li>
* <li>Numeric values
* <li>YearMonthDuration × Numeric
* <li>DayTimeDuration × Numeric
* </ul>
*
* <p>
* Numeric operands are automatically converted using
* {@link FunctionUtils#toNumeric}.
* Numeric operands are automatically converted using {@link FunctionUtils#toNumeric}.
*/
public class Multiplication
extends AbstractBasicArithmeticExpression {
Expand Down
Loading

0 comments on commit 98f3d59

Please sign in to comment.