From 9e54baed8acb7876e26981b40c272ad47b963eea Mon Sep 17 00:00:00 2001 From: Jack Smith Date: Tue, 3 Sep 2024 18:53:30 -0400 Subject: [PATCH 1/2] Upgrade basepom to 59.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 24c1fa0fb..9518a2a85 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.hubspot basepom - 59.7 + 59.11 com.hubspot.jinjava From f59d5ebf041cf6584251cd49cda511f45157b3ea Mon Sep 17 00:00:00 2001 From: Jack Smith Date: Tue, 3 Sep 2024 18:54:57 -0400 Subject: [PATCH 2/2] Run upgraded prettier --- .../jinjava/el/ExpressionResolver.java | 6 +- .../jinjava/el/ext/ExtendedParser.java | 6 +- .../jinjava/el/ext/JinjavaBeanELResolver.java | 18 ++--- .../el/ext/eager/EagerAstMacroFunction.java | 11 ++-- .../el/ext/eager/EagerAstParameters.java | 11 ++-- .../el/ext/eager/EvalResultHolder.java | 26 +++----- .../jinjava/interpret/JinjavaInterpreter.java | 6 +- .../expression/DefaultExpressionStrategy.java | 6 +- .../expression/EagerExpressionStrategy.java | 6 +- .../lib/filter/FileSizeFormatFilter.java | 4 +- .../jinjava/lib/filter/IpAddrFilter.java | 6 +- .../lib/fn/eager/EagerMacroFunction.java | 12 ++-- .../com/hubspot/jinjava/lib/tag/ForTag.java | 7 +- .../jinjava/lib/tag/eager/DeferredToken.java | 6 +- .../tag/eager/EagerBlockSetTagStrategy.java | 4 +- .../jinjava/lib/tag/eager/EagerCallTag.java | 6 +- .../jinjava/lib/tag/eager/EagerIfTag.java | 4 +- .../jinjava/lib/tag/eager/EagerImportTag.java | 6 +- .../jinjava/lib/tag/eager/EagerPrintTag.java | 6 +- .../lib/tag/eager/EagerStateChangingTag.java | 6 +- .../AliasedEagerImportingStrategy.java | 10 +-- .../com/hubspot/jinjava/tree/TreeParser.java | 6 +- .../jinjava/util/EagerContextWatcher.java | 6 +- .../util/EagerReconstructionUtils.java | 6 +- .../java/com/hubspot/jinjava/EagerTest.java | 2 +- .../jinjava/interpret/DeferredTest.java | 2 +- .../jinjava/lib/filter/XmlAttrFilterTest.java | 7 +- .../lib/tag/eager/EagerImportTagTest.java | 66 +++++++------------ .../lib/tag/eager/EagerTagDecoratorTest.java | 19 +++--- .../util/EagerExpressionResolverTest.java | 6 +- .../util/EagerReconstructionUtilsTest.java | 12 ++-- 31 files changed, 111 insertions(+), 194 deletions(-) diff --git a/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java b/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java index da810555c..d96ea0ea2 100644 --- a/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java +++ b/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java @@ -292,10 +292,8 @@ private void handleELException(String expression, ELException e) { TemplateError.fromException( new TemplateSyntaxException( expression, - ( - e.getCause() == null || - StringUtils.endsWith(originatingException, e.getCause().getMessage()) - ) + (e.getCause() == null || + StringUtils.endsWith(originatingException, e.getCause().getMessage())) ? e.getMessage() : combinedMessage, interpreter.getLineNumber(), diff --git a/src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java b/src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java index c8d619f14..4f7f741a0 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java @@ -585,9 +585,9 @@ private boolean isPossibleExpTestOrFilter(String namespace) throws ParseException, ScanException { if ( FILTER_PREFIX.substring(0, FILTER_PREFIX.length() - 1).equals(namespace) || - EXPTEST_PREFIX.substring(0, EXPTEST_PREFIX.length() - 1).equals(namespace) && - lookahead(1).getSymbol() == DOT && - lookahead(2).getSymbol() == IDENTIFIER + (EXPTEST_PREFIX.substring(0, EXPTEST_PREFIX.length() - 1).equals(namespace) && + lookahead(1).getSymbol() == DOT && + lookahead(2).getSymbol() == IDENTIFIER) ) { Token property = lookahead(2); if ( diff --git a/src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java b/src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java index af5f25cc9..435d8525b 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java @@ -106,10 +106,8 @@ public Object invoke( if ( method == null || DEFAULT_RESTRICTED_METHODS.contains(method.toString()) || - ( - interpreter != null && - interpreter.getConfig().getRestrictedMethods().contains(method.toString()) - ) + (interpreter != null && + interpreter.getConfig().getRestrictedMethods().contains(method.toString())) ) { throw new MethodNotFoundException( "Cannot find method '" + method + "' in " + base.getClass() @@ -221,10 +219,8 @@ private String validatePropertyName(Object property) { if ( DEFAULT_RESTRICTED_PROPERTIES.contains(propertyName) || - ( - interpreter != null && - interpreter.getConfig().getRestrictedProperties().contains(propertyName) - ) + (interpreter != null && + interpreter.getConfig().getRestrictedProperties().contains(propertyName)) ) { return null; } @@ -253,10 +249,8 @@ protected boolean isRestrictedClass(Object o) { } return ( - ( - o.getClass().getPackage() != null && - o.getClass().getPackage().getName().startsWith("java.lang.reflect") - ) || + (o.getClass().getPackage() != null && + o.getClass().getPackage().getName().startsWith("java.lang.reflect")) || o instanceof Class || o instanceof ClassLoader || o instanceof Thread || diff --git a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstMacroFunction.java b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstMacroFunction.java index 082828cbf..4e3ff190b 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstMacroFunction.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstMacroFunction.java @@ -78,12 +78,11 @@ protected Object invoke( if (types.length > 0) { // This is just the AstFunction.invoke, but surrounded with this try-with-resources try ( - TemporaryValueClosable c = ( - (JinjavaInterpreter) context - .getELResolver() - .getValue(context, null, ExtendedParser.INTERPRETER) - ).getContext() - .withPartialMacroEvaluation(false) + TemporaryValueClosable c = + ((JinjavaInterpreter) context + .getELResolver() + .getValue(context, null, ExtendedParser.INTERPRETER)).getContext() + .withPartialMacroEvaluation(false) ) { params = new Object[types.length]; int varargIndex; diff --git a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstParameters.java b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstParameters.java index 2c1cca48e..afc49dac6 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstParameters.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/eager/EagerAstParameters.java @@ -40,12 +40,11 @@ private EagerAstParameters(List nodes, boolean convertedToEvalResultHol @Override public Object[] eval(Bindings bindings, ELContext context) { try ( - TemporaryValueClosable c = ( - (JinjavaInterpreter) context - .getELResolver() - .getValue(context, null, ExtendedParser.INTERPRETER) - ).getContext() - .withPartialMacroEvaluation(false) + TemporaryValueClosable c = + ((JinjavaInterpreter) context + .getELResolver() + .getValue(context, null, ExtendedParser.INTERPRETER)).getContext() + .withPartialMacroEvaluation(false) ) { try { setEvalResult(super.eval(bindings, context)); diff --git a/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java b/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java index d9b0df0ea..b34edad65 100644 --- a/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java +++ b/src/main/java/com/hubspot/jinjava/el/ext/eager/EvalResultHolder.java @@ -51,11 +51,9 @@ default Object checkEvalResultSize(ELContext context) { if ( evalResult instanceof Collection && ((Collection) evalResult).size() > 100 && // TODO make size configurable - ( - (JinjavaInterpreter) context + ((JinjavaInterpreter) context .getELResolver() - .getValue(context, null, ExtendedParser.INTERPRETER) - ).getContext() + .getValue(context, null, ExtendedParser.INTERPRETER)).getContext() .isDeferLargeObjects() ) { throw new DeferredValueException("Collection too big"); @@ -83,8 +81,8 @@ static String reconstructNode( preserveIdentifier = IdentifierPreservationStrategy.preserving( preserveIdentifier.isPreserving() || - astNode instanceof AstIdentifier && - ExtendedParser.INTERPRETER.equals(((AstIdentifier) astNode).getName()) + (astNode instanceof AstIdentifier && + ExtendedParser.INTERPRETER.equals(((AstIdentifier) astNode).getName())) ); if ( preserveIdentifier.isPreserving() && @@ -107,13 +105,9 @@ static String reconstructNode( } if ( !preserveIdentifier.isPreserving() || - ( - astNode.hasEvalResult() && - ( - EagerExpressionResolver.isPrimitive(evalResult) || - evalResult instanceof PartiallyDeferredValue - ) - ) + (astNode.hasEvalResult() && + (EagerExpressionResolver.isPrimitive(evalResult) || + evalResult instanceof PartiallyDeferredValue)) ) { if (exceptionMatchesNode(exception, astNode)) { return exception.getDeferredEvalResult(); @@ -131,11 +125,9 @@ static String reconstructNode( if (astNode instanceof AstIdentifier) { String name = ((AstIdentifier) astNode).getName(); if ( - ( - (JinjavaInterpreter) context + ((JinjavaInterpreter) context .getELResolver() - .getValue(context, null, ExtendedParser.INTERPRETER) - ).getContext() + .getValue(context, null, ExtendedParser.INTERPRETER)).getContext() .getComputedMetaContextVariables() .contains(name) ) { diff --git a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java index f14ccfa00..9f5a99ce9 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java +++ b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java @@ -492,10 +492,8 @@ private void resolveBlockStubs(OutputList output) { private boolean isExtendsTag(Node node) { return ( node instanceof TagNode && - ( - ((TagNode) node).getTag() instanceof ExtendsTag || - isEagerExtendsTag((TagNode) node) - ) + (((TagNode) node).getTag() instanceof ExtendsTag || + isEagerExtendsTag((TagNode) node)) ); } diff --git a/src/main/java/com/hubspot/jinjava/lib/expression/DefaultExpressionStrategy.java b/src/main/java/com/hubspot/jinjava/lib/expression/DefaultExpressionStrategy.java index d49a39291..1754f455f 100644 --- a/src/main/java/com/hubspot/jinjava/lib/expression/DefaultExpressionStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/expression/DefaultExpressionStrategy.java @@ -37,10 +37,8 @@ public RenderedOutputNode interpretOutput( if (interpreter.getConfig().isNestedInterpretationEnabled()) { if ( !StringUtils.equals(result, master.getImage()) && - ( - StringUtils.contains(result, master.getSymbols().getExpressionStart()) || - StringUtils.contains(result, master.getSymbols().getExpressionStartWithTag()) - ) + (StringUtils.contains(result, master.getSymbols().getExpressionStart()) || + StringUtils.contains(result, master.getSymbols().getExpressionStartWithTag())) ) { try { result = interpreter.renderFlat(result); diff --git a/src/main/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategy.java b/src/main/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategy.java index 66f1f43a1..4ba01ac6d 100644 --- a/src/main/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/expression/EagerExpressionStrategy.java @@ -99,10 +99,8 @@ public static String postProcessResult( ) { if ( !StringUtils.equals(result, master.getImage()) && - ( - StringUtils.contains(result, master.getSymbols().getExpressionStart()) || - StringUtils.contains(result, master.getSymbols().getExpressionStartWithTag()) - ) + (StringUtils.contains(result, master.getSymbols().getExpressionStart()) || + StringUtils.contains(result, master.getSymbols().getExpressionStartWithTag())) ) { if (interpreter.getConfig().isNestedInterpretationEnabled()) { long errorSizeStart = getParsingErrorsCount(interpreter); diff --git a/src/main/java/com/hubspot/jinjava/lib/filter/FileSizeFormatFilter.java b/src/main/java/com/hubspot/jinjava/lib/filter/FileSizeFormatFilter.java index 3d3f5b348..0653c0891 100644 --- a/src/main/java/com/hubspot/jinjava/lib/filter/FileSizeFormatFilter.java +++ b/src/main/java/com/hubspot/jinjava/lib/filter/FileSizeFormatFilter.java @@ -61,11 +61,11 @@ public Object filter(Object var, JinjavaInterpreter interpreter, String... args) prefix = sizes[i]; if (bytes < unit) { - return String.format("%.1f %s", (double) (base * bytes / unit), prefix); + return String.format("%.1f %s", (double) ((base * bytes) / unit), prefix); } } - return String.format("%.1f %s", (double) (base * bytes / unit), prefix); + return String.format("%.1f %s", (double) ((base * bytes) / unit), prefix); } private static final String[] BINARY_SIZES = { diff --git a/src/main/java/com/hubspot/jinjava/lib/filter/IpAddrFilter.java b/src/main/java/com/hubspot/jinjava/lib/filter/IpAddrFilter.java index 5a550ace3..9fa3bb257 100644 --- a/src/main/java/com/hubspot/jinjava/lib/filter/IpAddrFilter.java +++ b/src/main/java/com/hubspot/jinjava/lib/filter/IpAddrFilter.java @@ -194,10 +194,8 @@ private Object getValue( List parts = PREFIX_SPLITTER.splitToList(fullAddress); if ( parts.size() == 1 && - ( - parameter.equalsIgnoreCase(PUBLIC_STRING) || - parameter.equalsIgnoreCase(PRIVATE_STRING) - ) + (parameter.equalsIgnoreCase(PUBLIC_STRING) || + parameter.equalsIgnoreCase(PRIVATE_STRING)) ) { parts = new ArrayList<>(parts); parts.add("0"); diff --git a/src/main/java/com/hubspot/jinjava/lib/fn/eager/EagerMacroFunction.java b/src/main/java/com/hubspot/jinjava/lib/fn/eager/EagerMacroFunction.java index ed9f051a8..9e805daa3 100644 --- a/src/main/java/com/hubspot/jinjava/lib/fn/eager/EagerMacroFunction.java +++ b/src/main/java/com/hubspot/jinjava/lib/fn/eager/EagerMacroFunction.java @@ -100,11 +100,9 @@ public Object doEvaluate( ); if ( !eagerExecutionResult.getResult().isFullyResolved() && - ( - !interpreter.getContext().isPartialMacroEvaluation() || + (!interpreter.getContext().isPartialMacroEvaluation() || !eagerExecutionResult.getSpeculativeBindings().isEmpty() || - interpreter.getContext().isDeferredExecutionMode() - ) + interpreter.getContext().isDeferredExecutionMode()) ) { PrefixToPreserveState prefixToPreserveState = EagerReconstructionUtils.resetAndDeferSpeculativeBindings( @@ -251,10 +249,8 @@ public String reconstructImage(String fullName) { } if ( - ( - interpreter.getContext().getMacroStack().contains(getName()) && - !differentMacroWithSameNameExists(interpreter) - ) || + (interpreter.getContext().getMacroStack().contains(getName()) && + !differentMacroWithSameNameExists(interpreter)) || (!isCaller() && AstMacroFunction.checkAndPushMacroStack(interpreter, fullName)) ) { return ""; diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/ForTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/ForTag.java index 8bc2c888b..622c014f0 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/ForTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/ForTag.java @@ -281,11 +281,8 @@ public String renderForCollection( } if ( interpreter.getConfig().getMaxNumDeferredTokens() < - ( - loop.getLength() * - interpreter.getContext().getDeferredTokens().size() / - loop.getIndex() - ) + ((loop.getLength() * interpreter.getContext().getDeferredTokens().size()) / + loop.getIndex()) ) { throw new DeferredValueException(TOO_LARGE_EXCEPTION_MESSAGE); } diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/DeferredToken.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/DeferredToken.java index 306eeaf1f..6ee5c8e61 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/DeferredToken.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/DeferredToken.java @@ -317,10 +317,8 @@ private static void deferDuplicatePointers(Context context, String word) { .stream() .filter(entry -> entry.getValue() == wordValue || - ( - entry.getValue() instanceof DeferredValue && - ((DeferredValue) entry.getValue()).getOriginalValue() == wordValue - ) + (entry.getValue() instanceof DeferredValue && + ((DeferredValue) entry.getValue()).getOriginalValue() == wordValue) ) .forEach(entry -> { matchingEntries.add(entry); diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java index 6c48a97ef..e6ea02fd6 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerBlockSetTagStrategy.java @@ -49,8 +49,8 @@ protected EagerExecutionResult getEagerExecutionResult( .build() ); if ( - !eagerExecutionResult.getResult().isFullyResolved() && - !eagerExecutionResult.getSpeculativeBindings().isEmpty() || + (!eagerExecutionResult.getResult().isFullyResolved() && + !eagerExecutionResult.getSpeculativeBindings().isEmpty()) || interpreter.getContext().isDeferredExecutionMode() ) { EagerReconstructionUtils.resetAndDeferSpeculativeBindings( diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerCallTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerCallTag.java index e00d2de6c..7e912d30c 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerCallTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerCallTag.java @@ -153,10 +153,8 @@ public String eagerInterpret( } if ( StringUtils.isNotBlank(tagNode.getEndName()) && - ( - !(getTag() instanceof FlexibleTag) || - ((FlexibleTag) getTag()).hasEndTag((TagToken) tagNode.getMaster()) - ) + (!(getTag() instanceof FlexibleTag) || + ((FlexibleTag) getTag()).hasEndTag((TagToken) tagNode.getMaster())) ) { result.append(EagerReconstructionUtils.reconstructEnd(tagNode)); } // Possible set tag in front of this one. diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java index 202789bc0..dddc449c4 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerIfTag.java @@ -181,8 +181,8 @@ private int findNextElseToken(TagNode tagNode, int startIdx) { for (i = startIdx; i < tagNode.getChildren().size(); i++) { Node childNode = tagNode.getChildren().get(i); if ( - (TagNode.class.isAssignableFrom(childNode.getClass())) && - childNode.getName().equals(ElseIfTag.TAG_NAME) || + ((TagNode.class.isAssignableFrom(childNode.getClass())) && + childNode.getName().equals(ElseIfTag.TAG_NAME)) || childNode.getName().equals(ElseTag.TAG_NAME) ) { return i; diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTag.java index 5a7b1cb86..ea46cae3b 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTag.java @@ -75,10 +75,8 @@ public String getEagerTagImage(TagToken tagToken, JinjavaInterpreter interpreter // and all defined variables and macros should be deferred too. if ( !child.getContext().getDeferredNodes().isEmpty() || - ( - interpreter.getContext().isDeferredExecutionMode() && - !child.getContext().getGlobalMacros().isEmpty() - ) + (interpreter.getContext().isDeferredExecutionMode() && + !child.getContext().getGlobalMacros().isEmpty()) ) { ImportTag.handleDeferredNodesDuringImport( node, diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerPrintTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerPrintTag.java index fe48831e5..e0697dc0a 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerPrintTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerPrintTag.java @@ -78,14 +78,12 @@ public static String interpretExpression( // Possible macro/set tag in front of this one. return ( prefixToPreserveState.toString() + - ( - includeExpressionResult + (includeExpressionResult ? EagerReconstructionUtils.wrapInRawIfNeeded( eagerExecutionResult.getResult().toString(true), interpreter ) - : "" - ) + : "") ); } EagerReconstructionUtils.hydrateReconstructionFromContextBeforeDeferring( diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerStateChangingTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerStateChangingTag.java index dd17401cb..5f0b19e81 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerStateChangingTag.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/EagerStateChangingTag.java @@ -51,10 +51,8 @@ public String eagerInterpret( } if ( StringUtils.isNotBlank(tagNode.getEndName()) && - ( - !(getTag() instanceof FlexibleTag) || - ((FlexibleTag) getTag()).hasEndTag((TagToken) tagNode.getMaster()) - ) + (!(getTag() instanceof FlexibleTag) || + ((FlexibleTag) getTag()).hasEndTag((TagToken) tagNode.getMaster())) ) { result.append(EagerReconstructionUtils.reconstructEnd(tagNode)); } diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/eager/importing/AliasedEagerImportingStrategy.java b/src/main/java/com/hubspot/jinjava/lib/tag/eager/importing/AliasedEagerImportingStrategy.java index c96454701..74932f7fb 100644 --- a/src/main/java/com/hubspot/jinjava/lib/tag/eager/importing/AliasedEagerImportingStrategy.java +++ b/src/main/java/com/hubspot/jinjava/lib/tag/eager/importing/AliasedEagerImportingStrategy.java @@ -120,10 +120,8 @@ public void integrateChild(JinjavaInterpreter child) { .entrySet() .stream() .filter(entry -> - !( - entry.getKey().equals(Context.GLOBAL_MACROS_SCOPE_KEY) || - entry.getKey().equals(Context.IMPORT_RESOURCE_ALIAS_KEY) - ) + !(entry.getKey().equals(Context.GLOBAL_MACROS_SCOPE_KEY) || + entry.getKey().equals(Context.IMPORT_RESOURCE_ALIAS_KEY)) ) .forEach(entry -> mapForCurrentContextAlias.put(entry.getKey(), entry.getValue())); } @@ -207,9 +205,7 @@ private static Map getMapForCurrentContextAlias( return (Map) parentValueForChild; } else if (parentValueForChild instanceof DeferredValue) { if (((DeferredValue) parentValueForChild).getOriginalValue() instanceof Map) { - return (Map) ( - (DeferredValue) parentValueForChild - ).getOriginalValue(); + return (Map) ((DeferredValue) parentValueForChild).getOriginalValue(); } Map newMap = new PyMap(new HashMap<>()); child diff --git a/src/main/java/com/hubspot/jinjava/tree/TreeParser.java b/src/main/java/com/hubspot/jinjava/tree/TreeParser.java index 9c3198188..8bdc29653 100644 --- a/src/main/java/com/hubspot/jinjava/tree/TreeParser.java +++ b/src/main/java/com/hubspot/jinjava/tree/TreeParser.java @@ -208,12 +208,10 @@ private boolean isRightTrim(Node lastSibling) { if (lastSibling instanceof TagNode) { return ( ((TagNode) lastSibling).getEndName() == null || - ( - ((TagNode) lastSibling).getTag() instanceof FlexibleTag && + (((TagNode) lastSibling).getTag() instanceof FlexibleTag && !((FlexibleTag) ((TagNode) lastSibling).getTag()).hasEndTag( (TagToken) lastSibling.getMaster() - ) - ) + )) ) ? lastSibling.getMaster().isRightTrim() : lastSibling.getMaster().isRightTrimAfterEnd(); diff --git a/src/main/java/com/hubspot/jinjava/util/EagerContextWatcher.java b/src/main/java/com/hubspot/jinjava/util/EagerContextWatcher.java index c848fe454..6dcb266b3 100644 --- a/src/main/java/com/hubspot/jinjava/util/EagerContextWatcher.java +++ b/src/main/java/com/hubspot/jinjava/util/EagerContextWatcher.java @@ -120,11 +120,9 @@ private static Map getInitiallyResolvedAsStrings( // This creates a stringified snapshot of the context // so it can be disabled via the config because it may cause performance issues. Stream> entryStream = - ( - interpreter.getConfig().getExecutionMode().useEagerContextReverting() + (interpreter.getConfig().getExecutionMode().useEagerContextReverting() ? entrySet - : interpreter.getContext().getCombinedScope().entrySet() - ).stream() + : interpreter.getContext().getCombinedScope().entrySet()).stream() .filter(entry -> initiallyResolvedHashes.containsKey(entry.getKey())) .filter(entry -> EagerExpressionResolver.isResolvableObject(entry.getValue(), 4, 400) // TODO make this configurable diff --git a/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java b/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java index 9467c2bb0..eb12536f5 100644 --- a/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java +++ b/src/main/java/com/hubspot/jinjava/util/EagerReconstructionUtils.java @@ -639,10 +639,8 @@ public static String wrapInAutoEscapeIfNeeded( ) { if ( interpreter.getContext().isAutoEscape() && - ( - interpreter.getContext().getParent() == null || - !interpreter.getContext().getParent().isAutoEscape() - ) + (interpreter.getContext().getParent() == null || + !interpreter.getContext().getParent().isAutoEscape()) ) { output = wrapInTag(output, AutoEscapeTag.TAG_NAME, interpreter, false); } diff --git a/src/test/java/com/hubspot/jinjava/EagerTest.java b/src/test/java/com/hubspot/jinjava/EagerTest.java index 0bfdc6fa1..76d5f170f 100644 --- a/src/test/java/com/hubspot/jinjava/EagerTest.java +++ b/src/test/java/com/hubspot/jinjava/EagerTest.java @@ -379,7 +379,7 @@ public void itDefersAllVariablesUsedInDeferredNode() { public void itDefersDependantVariables() { String template = ""; template += - "{% set resolved_variable = 'resolved' %} {% set deferred_variable = deferred + '-' + resolved_variable %}"; + "{% set resolved_variable = 'resolved' %} {% set deferred_variable = deferred + '-' + resolved_variable %}"; template += "{{ deferred_variable }}"; interpreter.render(template); localContext.get("resolved_variable"); diff --git a/src/test/java/com/hubspot/jinjava/interpret/DeferredTest.java b/src/test/java/com/hubspot/jinjava/interpret/DeferredTest.java index cdf3ea825..b7974b6fa 100644 --- a/src/test/java/com/hubspot/jinjava/interpret/DeferredTest.java +++ b/src/test/java/com/hubspot/jinjava/interpret/DeferredTest.java @@ -266,7 +266,7 @@ public void itDefersAllVariablesUsedInDeferredNode() { public void itDefersDependantVariables() { String template = ""; template += - "{% set resolved_variable = 'resolved' %} {% set deferred_variable = deferred + '-' + resolved_variable %}"; + "{% set resolved_variable = 'resolved' %} {% set deferred_variable = deferred + '-' + resolved_variable %}"; template += "{{ deferred_variable }}"; interpreter.render(template); localContext.get("resolved_variable"); diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/XmlAttrFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/XmlAttrFilterTest.java index fb916766f..13f9a6bc7 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/XmlAttrFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/XmlAttrFilterTest.java @@ -45,11 +45,8 @@ public void itDoesNotAllowInvalidKeys() { ) .matches(templateErrors -> templateErrors.size() == 1 && - templateErrors - .get(0) - .getException() - .getCause() - .getCause() instanceof IllegalArgumentException + templateErrors.get(0).getException().getCause().getCause() instanceof + IllegalArgumentException ) ); } diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java index 1ce65ee32..632de43a6 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerImportTagTest.java @@ -150,11 +150,9 @@ public void itHandlesMultiLayerAliased() { ) .isInstanceOf(Map.class); assertThat( - ( - (Map) ( - (Map) interpreter.getContext().get(CONTEXT_VAR) - ).get(child2Alias) - ).get("foo") + ((Map) ((Map) interpreter + .getContext() + .get(CONTEXT_VAR)).get(child2Alias)).get("foo") ) .isEqualTo("foo val"); @@ -176,36 +174,24 @@ public void itHandlesMultiLayerAliasedAndDeferred() { assertThat(result.getContext().get(CONTEXT_VAR)).isInstanceOf(DeferredValue.class); assertThat( - ( - (Map) ( - (DeferredValue) result.getContext().get(CONTEXT_VAR) - ).getOriginalValue() - ).get(child2Alias) + ((Map) ((DeferredValue) result + .getContext() + .get(CONTEXT_VAR)).getOriginalValue()).get(child2Alias) ) .isInstanceOf(DeferredValue.class); assertThat( - ( - ( - (Map) ( - (DeferredValue) ( - ( - (Map) ( - (DeferredValue) result.getContext().get(CONTEXT_VAR) - ).getOriginalValue() - ) - ).get(child2Alias) - ).getOriginalValue() - ).get("foo") - ) + (((Map) ((DeferredValue) (((Map) ((DeferredValue) result + .getContext() + .get(CONTEXT_VAR)).getOriginalValue())).get( + child2Alias + )).getOriginalValue()).get("foo")) ) .isEqualTo("foo val"); assertThat( - ( - (Map) ( - (DeferredValue) result.getContext().get(CONTEXT_VAR) - ).getOriginalValue() - ).get("bar") + ((Map) ((DeferredValue) result + .getContext() + .get(CONTEXT_VAR)).getOriginalValue()).get("bar") ) .isEqualTo("bar val"); } @@ -255,11 +241,9 @@ public void itHandlesMultiLayerSomeAliased() { ) .isInstanceOf(Map.class); assertThat( - ( - (Map) ( - (Map) interpreter.getContext().get(CONTEXT_VAR) - ).get(child3Alias) - ).get("foobar") + ((Map) ((Map) interpreter + .getContext() + .get(CONTEXT_VAR)).get(child3Alias)).get("foobar") ) .isEqualTo("foobar val"); @@ -301,19 +285,15 @@ public void itHandlesMultiLayerAliasedAndParallel() { ) .isInstanceOf(Map.class); assertThat( - ( - (Map) ( - (Map) interpreter.getContext().get(CONTEXT_VAR) - ).get(child2Alias) - ).get("foo") + ((Map) ((Map) interpreter + .getContext() + .get(CONTEXT_VAR)).get(child2Alias)).get("foo") ) .isEqualTo("foo val"); assertThat( - ( - (Map) ( - (Map) interpreter.getContext().get(CONTEXT_VAR) - ).get(child2BAlias) - ).get("foo_b") + ((Map) ((Map) interpreter + .getContext() + .get(CONTEXT_VAR)).get(child2BAlias)).get("foo_b") ) .isEqualTo("foo_b val"); diff --git a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java index f50f929c9..4554108d0 100644 --- a/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/tag/eager/EagerTagDecoratorTest.java @@ -91,12 +91,10 @@ public void itLimitsEagerInterpretLength() { for (int i = 0; i < MAX_OUTPUT_SIZE; i++) { tooLong.append(i); } - TagNode tagNode = (TagNode) ( - interpreter + TagNode tagNode = (TagNode) (interpreter .parse(String.format("{%% raw %%}%s{%% endraw %%}", tooLong.toString())) .getChildren() - .get(0) - ); + .get(0)); assertThatThrownBy(() -> eagerTagDecorator.eagerInterpret(tagNode, interpreter, null)) .isInstanceOf(OutputTooBigException.class); } @@ -108,21 +106,20 @@ public void itLimitsInterpretLength() { for (int i = 0; i < MAX_OUTPUT_SIZE; i++) { tooLong.append(i); } - TagNode tagNode = (TagNode) ( - interpreter + TagNode tagNode = (TagNode) (interpreter .parse(String.format("{%% raw %%}%s{%% endraw %%}", tooLong.toString())) .getChildren() - .get(0) - ); + .get(0)); assertThatThrownBy(() -> eagerTagDecorator.interpret(tagNode, interpreter)) .isInstanceOf(DeferredValueException.class); } @Test public void itLimitsTagLength() { - TagNode tagNode = (TagNode) ( - interpreter.parse("{% print range(0, 50) %}").getChildren().get(0) - ); + TagNode tagNode = (TagNode) (interpreter + .parse("{% print range(0, 50) %}") + .getChildren() + .get(0)); assertThatThrownBy(() -> eagerTagDecorator.getEagerTagImage((TagToken) tagNode.getMaster(), interpreter) ) diff --git a/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java b/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java index fca09dd45..21b9d2592 100644 --- a/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java +++ b/src/test/java/com/hubspot/jinjava/util/EagerExpressionResolverTest.java @@ -339,9 +339,9 @@ public void itSerializesDateProperly() throws IOException { " %}" ); assertThat( - ( - (PyishDate) ((Map) interpreter.getContext().get("foo")).get("a") - ).toDateTime() + ((PyishDate) ((Map) interpreter.getContext().get("foo")).get( + "a" + )).toDateTime() ) .isEqualTo(date.toDateTime()); } diff --git a/src/test/java/com/hubspot/jinjava/util/EagerReconstructionUtilsTest.java b/src/test/java/com/hubspot/jinjava/util/EagerReconstructionUtilsTest.java index 5bc68dad3..2db59282d 100644 --- a/src/test/java/com/hubspot/jinjava/util/EagerReconstructionUtilsTest.java +++ b/src/test/java/com/hubspot/jinjava/util/EagerReconstructionUtilsTest.java @@ -69,12 +69,10 @@ public void teardown() { public void itExecutesInChildContextAndTakesNewValue() { context.put("foo", new PyList(new ArrayList<>())); EagerExecutionResult result = EagerContextWatcher.executeInChildContext( - ( - interpreter1 -> { + (interpreter1 -> { ((List) interpreter1.getContext().get("foo")).add(1); return EagerExpressionResult.fromString("function return"); - } - ), + }), interpreter, EagerContextWatcher.EagerChildContextConfig .newBuilder() @@ -97,15 +95,13 @@ public void itExecutesInChildContextAndTakesNewValue() { public void itExecutesInChildContextAndDefersNewValue() { context.put("foo", new ArrayList()); EagerExecutionResult result = EagerContextWatcher.executeInChildContext( - ( - interpreter1 -> { + (interpreter1 -> { context.put( "foo", DeferredValue.instance(interpreter1.getContext().get("foo")) ); return EagerExpressionResult.fromString("function return"); - } - ), + }), interpreter, EagerContextWatcher.EagerChildContextConfig .newBuilder()