Skip to content

Commit

Permalink
Reworked definition and instance model classes to reduce extra interf…
Browse files Browse the repository at this point in the history
…aces and to simplify and align implementations.
  • Loading branch information
david-waltermire committed May 9, 2024
1 parent 5ed7314 commit f282d5c
Show file tree
Hide file tree
Showing 304 changed files with 4,169 additions and 6,155 deletions.
5 changes: 3 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
gov/nist/secauto/metaschema/core/model/xml/xmlbeans/**/*</exclude>
<!-- filter generated code -->
<exclude>gov/nist/secauto/metaschema/core/model/xml/xmlbeans/**/*</exclude>
<exclude>org/apache/xmlbeans/**/*</exclude>
<exclude>gov/nist/secauto/metaschema/core/metapath/antlr/*</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<? extends IDataTypeAdapter<?>> getJavaTypeAdapters() {
* if another type adapter has no name
*/
protected void registerDatatype(@NonNull IDataTypeAdapter<?> adapter) {
if (adapter.getNames().size() == 0) {
if (adapter.getNames().isEmpty()) {
throw new IllegalArgumentException("The adapter has no name: " + adapter.getClass().getName());
}
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public HtmlNodeRenderer apply(DataHolder options) {
public static class DoubleQuoteNode
extends TypographicQuotes {

@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
public DoubleQuoteNode(TypographicQuotes node) {
super(node.getOpeningMarker(), node.getText(), node.getClosingMarker());
setTypographicOpening(node.getTypographicOpening());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Supplier<List<ITEM_TYPE>> supplier() {

@Override
public BiConsumer<List<ITEM_TYPE>, ITEM_TYPE> accumulator() {
return (list, value) -> list.add(value);
return List::add;
}

@Override
Expand Down Expand Up @@ -280,7 +280,7 @@ static <T extends R, R extends IItem> ISequence<R> map(
@NonNull Function<T, R> mapFunction,
@NonNull ISequence<T> seq) {
return seq.safeStream()
.map(item -> mapFunction.apply(item))
.map(mapFunction::apply)
.collect(toSequence());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public BuildCSTVisitor(@NonNull StaticContext context) {
this.context = context;
}

/* ============================================================
* Expressions - https://www.w3.org/TR/xpath-31/#id-expressions
/*
* ============================================================ Expressions -
* https://www.w3.org/TR/xpath-31/#id-expressions
* ============================================================
*/
@NonNull
Expand All @@ -155,8 +156,9 @@ protected IExpression handleExpr(ExprContext ctx) {
});
}

/* =================================================================
* Literal Expressions - https://www.w3.org/TR/xpath-31/#id-literals
/*
* ================================================================= Literal
* Expressions - https://www.w3.org/TR/xpath-31/#id-literals
* =================================================================
*/

Expand Down Expand Up @@ -185,8 +187,9 @@ protected IExpression handleNumericLiteral(NumericliteralContext ctx) {
return retval;
}

/* ==================================================================
* Variable References - https://www.w3.org/TR/xpath-31/#id-variables
/*
* ================================================================== Variable
* References - https://www.w3.org/TR/xpath-31/#id-variables
* ==================================================================
*/

Expand All @@ -198,8 +201,9 @@ protected IExpression handleVarref(VarrefContext ctx) {
getContext().getVariablePrefixResolver()));
}

/* ====================================================================
* For Expressions - https://www.w3.org/TR/xpath-31/#id-for-expressions
/*
* ==================================================================== For
* Expressions - https://www.w3.org/TR/xpath-31/#id-for-expressions
* ====================================================================
*/

Expand Down Expand Up @@ -234,8 +238,9 @@ protected IExpression handleForexpr(ForexprContext ctx) {
return retval;
}

/* ====================================================================
* Let Expressions - https://www.w3.org/TR/xpath-31/#id-let-expressions
/*
* ==================================================================== Let
* Expressions - https://www.w3.org/TR/xpath-31/#id-let-expressions
* ====================================================================
*/

Expand All @@ -262,9 +267,12 @@ protected IExpression handleLet(LetexprContext context) {
return retval;
}

/* ==================================================================================
* Quantified Expressions - https://www.w3.org/TR/xpath-31/#id-quantified-expressions
* ==================================================================================
/*
* =============================================================================
* ===== Quantified Expressions -
* https://www.w3.org/TR/xpath-31/#id-quantified-expressions
* =============================================================================
* =====
*/

@Override
Expand Down Expand Up @@ -302,8 +310,9 @@ protected IExpression handleQuantifiedexpr(QuantifiedexprContext ctx) {
return new Quantified(quantifier, vars, satisfies);
}

/* =======================================================================
* Arrow operator (=>) - https://www.w3.org/TR/xpath-31/#id-arrow-operator
/*
* ======================================================================= Arrow
* operator (=>) - https://www.w3.org/TR/xpath-31/#id-arrow-operator
* =======================================================================
*/

Expand Down Expand Up @@ -333,27 +342,34 @@ protected IExpression handleArrowexpr(ArrowexprContext context) {
});
}

/* =================================================================================
* Parenthesized Expressions - https://www.w3.org/TR/xpath-31/#id-paren-expressions
* =================================================================================
/*
* =============================================================================
* ==== Parenthesized Expressions -
* https://www.w3.org/TR/xpath-31/#id-paren-expressions
* =============================================================================
* ====
*/

@Override
protected IExpression handleEmptyParenthesizedexpr(ParenthesizedexprContext ctx) {
return EmptySequence.instance();
}

/* =====================================================================================
* Context Item Expression - https://www.w3.org/TR/xpath-31/#id-context-item-expression
* =====================================================================================
/*
* =============================================================================
* ======== Context Item Expression -
* https://www.w3.org/TR/xpath-31/#id-context-item-expression
* =============================================================================
* ========
*/

@Override
protected IExpression handleContextitemexpr(ContextitemexprContext ctx) {
return ContextItem.instance();
}

/* =========================================================================
/*
* =========================================================================
* Static Function Calls - https://www.w3.org/TR/xpath-31/#id-function-calls
* =========================================================================
*/
Expand Down Expand Up @@ -396,7 +412,8 @@ protected IExpression handleFunctioncall(FunctioncallContext ctx) {
.collect(Collectors.toUnmodifiableList())));
}

/* =========================================================================
/*
* =========================================================================
* Filter Expressions - https://www.w3.org/TR/xpath-31/#id-filter-expression
* =========================================================================
*/
Expand Down Expand Up @@ -461,8 +478,9 @@ protected IExpression handlePostfixexpr(PostfixexprContext ctx) {
}
return retval;
}
/* ======================================================================
* Path Expressions - https://www.w3.org/TR/xpath-31/#id-path-expressions
/*
* ====================================================================== Path
* Expressions - https://www.w3.org/TR/xpath-31/#id-path-expressions
* ======================================================================
*/

Expand Down Expand Up @@ -498,9 +516,12 @@ protected IExpression handlePathexpr(PathexprContext ctx) {
return retval;
}

/* =======================================================================================
* RelativePath Expressions - https://www.w3.org/TR/xpath-31/#id-relative-path-expressions
* =======================================================================================
/*
* =============================================================================
* ========== RelativePath Expressions -
* https://www.w3.org/TR/xpath-31/#id-relative-path-expressions
* =============================================================================
* ==========
*/

@Override
Expand Down Expand Up @@ -528,8 +549,9 @@ protected IExpression handleRelativepathexpr(RelativepathexprContext context) {
});
}

/* ================================================
* Steps - https://www.w3.org/TR/xpath-31/#id-steps
/*
* ================================================ Steps -
* https://www.w3.org/TR/xpath-31/#id-steps
* ================================================
*/

Expand Down Expand Up @@ -594,13 +616,15 @@ protected IExpression handleReversestep(ReversestepContext ctx) {
return new Step(axis, parseNodeTest(ctx.nodetest(), false));
}

/* =======================================================
* Node Tests - https://www.w3.org/TR/xpath-31/#node-tests
/*
* ======================================================= Node Tests -
* https://www.w3.org/TR/xpath-31/#node-tests
* =======================================================
*/

/* =======================================================
* Node Tests - https://www.w3.org/TR/xpath-31/#node-tests
/*
* ======================================================= Node Tests -
* https://www.w3.org/TR/xpath-31/#node-tests
* =======================================================
*/

Expand All @@ -627,17 +651,16 @@ protected INameTestExpression parseNameTest(NametestContext ctx, boolean flag) {
@Override
protected Wildcard handleWildcard(WildcardContext ctx) {
Predicate<IDefinitionNodeItem<?, ?>> matcher = null;
TerminalNode node;
if ((node = ctx.STAR()) == null) {
if ((node = ctx.CS()) != null) {
if (ctx.STAR() == null) {
if (ctx.CS() != null) {
// specified prefix, any local-name
String prefix = ctx.NCName().getText();
String namespace = getContext().lookupNamespaceForPrefix(prefix);
if (namespace == null) {
throw new IllegalStateException(String.format("Prefix '%s' did not map to a namespace.", prefix));
}
matcher = new Wildcard.MatchAnyLocalName(namespace);
} else if ((node = ctx.SC()) != null) {
} else if (ctx.SC() != null) {
// any prefix, specified local-name
matcher = new Wildcard.MatchAnyNamespace(ctx.NCName().getText());
} else {
Expand All @@ -651,7 +674,8 @@ protected Wildcard handleWildcard(WildcardContext ctx) {
return new Wildcard(matcher);
}

/* ======================================================================
/*
* ======================================================================
* Predicates within Steps - https://www.w3.org/TR/xpath-31/#id-predicate
* ======================================================================
*/
Expand All @@ -667,8 +691,9 @@ protected IExpression handleAxisstep(AxisstepContext ctx) {
return predicates.isEmpty() ? step : new PredicateExpression(step, predicates);
}

/* ===========================================================
* Abbreviated Syntax - https://www.w3.org/TR/xpath-31/#abbrev
/*
* =========================================================== Abbreviated
* Syntax - https://www.w3.org/TR/xpath-31/#abbrev
* ===========================================================
*/

Expand All @@ -691,7 +716,8 @@ protected IExpression handleAbbrevreversestep(AbbrevreversestepContext ctx) {
return Axis.PARENT;
}

/* ======================================================================
/*
* ======================================================================
* Constructing Sequences - https://www.w3.org/TR/xpath-31/#construct_seq
* ======================================================================
*/
Expand All @@ -706,7 +732,8 @@ protected IExpression handleRangeexpr(RangeexprContext ctx) {
return new Range(left, right);
}

/* ========================================================================
/*
* ========================================================================
* Combining Node Sequences - https://www.w3.org/TR/xpath-31/#combining_seq
* ========================================================================
*/
Expand Down Expand Up @@ -744,7 +771,8 @@ protected IExpression handleIntersectexceptexpr(IntersectexceptexprContext conte
});
}

/* ======================================================================
/*
* ======================================================================
* Arithmetic Expressions - https://www.w3.org/TR/xpath-31/#id-arithmetic
* ======================================================================
*/
Expand Down Expand Up @@ -835,9 +863,12 @@ protected IExpression handleUnaryexpr(UnaryexprContext ctx) {
return retval;
}

/* ========================================================================================
* String Concatenation Expressions - https://www.w3.org/TR/xpath-31/#id-string-concat-expr
* ========================================================================================
/*
* =============================================================================
* =========== String Concatenation Expressions -
* https://www.w3.org/TR/xpath-31/#id-string-concat-expr
* =============================================================================
* ===========
*/

@Override
Expand All @@ -848,7 +879,8 @@ protected IExpression handleStringconcatexpr(StringconcatexprContext ctx) {
});
}

/* =======================================================================
/*
* =======================================================================
* Comparison Expressions - https://www.w3.org/TR/xpath-31/#id-comparisons
* =======================================================================
*/
Expand Down Expand Up @@ -924,7 +956,8 @@ protected IExpression handleComparisonexpr(ComparisonexprContext ctx) { // NOPMD
return retval;
}

/* ============================================================================
/*
* ============================================================================
* Logical Expressions - https://www.w3.org/TR/xpath-31/#id-logical-expressions
* ============================================================================
*/
Expand All @@ -945,7 +978,8 @@ protected IExpression handleAndexpr(AndexprContext ctx) {
});
}

/* =========================================================================
/*
* =========================================================================
* Conditional Expressions - https://www.w3.org/TR/xpath-31/#id-conditionals
* =========================================================================
*/
Expand All @@ -959,7 +993,8 @@ protected IExpression handleIfexpr(IfexprContext ctx) {
return new If(testExpr, thenExpr, elseExpr);
}

/* =========================================================================
/*
* =========================================================================
* Simple map operator (!) - https://www.w3.org/TR/xpath-31/#id-map-operator
* =========================================================================
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static <RESULT_TYPE> Class<? extends RESULT_TYPE> analyzeStaticResultType
retval = baseType;
} else {
List<Class<?>> expressionClasses = ObjectUtils.notNull(expressions.stream()
.map(expr -> expr.getStaticResultType()).collect(Collectors.toList()));
.map(IExpression::getStaticResultType).collect(Collectors.toList()));

// check if the expression classes, are derived from the base type
if (checkDerivedFrom(baseType, expressionClasses)) {
Expand Down
Loading

0 comments on commit f282d5c

Please sign in to comment.