Skip to content

Commit

Permalink
Run upgraded prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmith-hs committed Sep 3, 2024
1 parent 9e54bae commit f59d5eb
Show file tree
Hide file tree
Showing 31 changed files with 111 additions and 194 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> c = (
(JinjavaInterpreter) context
.getELResolver()
.getValue(context, null, ExtendedParser.INTERPRETER)
).getContext()
.withPartialMacroEvaluation(false)
TemporaryValueClosable<Boolean> c =
((JinjavaInterpreter) context
.getELResolver()
.getValue(context, null, ExtendedParser.INTERPRETER)).getContext()
.withPartialMacroEvaluation(false)
) {
params = new Object[types.length];
int varargIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ private EagerAstParameters(List<AstNode> nodes, boolean convertedToEvalResultHol
@Override
public Object[] eval(Bindings bindings, ELContext context) {
try (
TemporaryValueClosable<Boolean> c = (
(JinjavaInterpreter) context
.getELResolver()
.getValue(context, null, ExtendedParser.INTERPRETER)
).getContext()
.withPartialMacroEvaluation(false)
TemporaryValueClosable<Boolean> c =
((JinjavaInterpreter) context
.getELResolver()
.getValue(context, null, ExtendedParser.INTERPRETER)).getContext()
.withPartialMacroEvaluation(false)
) {
try {
setEvalResult(super.eval(bindings, context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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() &&
Expand All @@ -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();
Expand All @@ -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)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ private Object getValue(
List<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 "";
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/hubspot/jinjava/lib/tag/ForTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -207,9 +205,7 @@ private static Map<String, Object> getMapForCurrentContextAlias(
return (Map<String, Object>) parentValueForChild;
} else if (parentValueForChild instanceof DeferredValue) {
if (((DeferredValue) parentValueForChild).getOriginalValue() instanceof Map) {
return (Map<String, Object>) (
(DeferredValue) parentValueForChild
).getOriginalValue();
return (Map<String, Object>) ((DeferredValue) parentValueForChild).getOriginalValue();
}
Map<String, Object> newMap = new PyMap(new HashMap<>());
child
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/hubspot/jinjava/tree/TreeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit f59d5eb

Please sign in to comment.