From 5b14eb08401a4878367627e9762190a9bbbb4a43 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 25 Dec 2024 12:26:32 +0100 Subject: [PATCH] refactor: Enum values should be compared with "==" (#4811) Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../openrewrite/SourceFileWithReferences.java | 2 +- .../config/YamlResourceLoader.java | 2 +- .../RemoveRedundantDependencyVersions.java | 8 ++--- .../groovy/GroovyParserVisitor.java | 2 +- .../java/org/openrewrite/hcl/HclTemplate.java | 10 +++--- .../hcl/format/AttributeSpaceVisitor.java | 4 +-- .../hcl/format/BracketsVisitor.java | 4 +-- .../hcl/format/TabsAndIndentsVisitor.java | 8 ++--- .../openrewrite/hcl/internal/HclPrinter.java | 2 +- .../openrewrite/hcl/tree/HclCoordinates.java | 2 +- .../java/org/openrewrite/hcl/tree/Space.java | 4 +-- ...ReloadableJava11ParserInputFileObject.java | 2 +- .../ReloadableJava11ParserVisitor.java | 2 +- ...ReloadableJava17ParserInputFileObject.java | 2 +- .../ReloadableJava17ParserVisitor.java | 2 +- ...ReloadableJava21ParserInputFileObject.java | 2 +- .../ReloadableJava21ParserVisitor.java | 2 +- .../java/Java8ParserInputFileObject.java | 2 +- .../java/ReloadableJava8Parser.java | 2 +- .../java/ReloadableJava8ParserVisitor.java | 2 +- .../org/openrewrite/java/JavaPrinter.java | 2 +- .../org/openrewrite/java/JavaVisitor.java | 2 +- .../org/openrewrite/java/PackageMatcher.java | 2 +- .../org/openrewrite/java/TypeMatcher.java | 2 +- .../openrewrite/java/VariableNameUtils.java | 2 +- .../java/format/TabsAndIndentsVisitor.java | 16 ++++----- .../BlockStatementTemplateGenerator.java | 2 +- .../template/JavaTemplateJavaExtension.java | 34 +++++++++---------- .../java/internal/template/Substitutions.java | 2 +- .../openrewrite/java/style/Autodetect.java | 2 +- .../java/tree/JavaCoordinates.java | 2 +- .../openrewrite/maven/RemoveDependency.java | 2 +- .../maven/RemoveManagedDependency.java | 2 +- .../RemoveRedundantDependencyVersions.java | 10 +++--- .../internal/InsertDependencyComparator.java | 2 +- .../org/openrewrite/xml/XmlParserTest.java | 4 +-- 36 files changed, 77 insertions(+), 77 deletions(-) diff --git a/rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java b/rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java index d53fa550e7a..0a8bb5faad8 100644 --- a/rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java +++ b/rewrite-core/src/main/java/org/openrewrite/SourceFileWithReferences.java @@ -45,7 +45,7 @@ public Collection findMatches(Reference.Matcher matcher, Reference.Ki private List findMatchesInternal(Reference.Matcher matcher, Reference.@Nullable Kind kind) { List list = new ArrayList<>(); for (Reference ref : references) { - if ((kind == null || ref.getKind().equals(kind)) && ref.matches(matcher) ) { + if ((kind == null || ref.getKind() == kind) && ref.matches(matcher) ) { list.add(ref); } } diff --git a/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java b/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java index 7d1f24d8ad1..1984d383600 100644 --- a/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java +++ b/rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java @@ -200,7 +200,7 @@ private Collection> loadResources(ResourceType resourceType) for (Object resource : yaml.loadAll(yamlSource)) { if (resource instanceof Map) { @SuppressWarnings("unchecked") Map resourceMap = (Map) resource; - if (resourceType.equals(ResourceType.fromSpec((String) resourceMap.get("type")))) { + if (resourceType == ResourceType.fromSpec((String) resourceMap.get("type"))) { resources.add(resourceMap); } } diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantDependencyVersions.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantDependencyVersions.java index 3aaa09f6a4e..a2cd1dab3b3 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantDependencyVersions.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveRedundantDependencyVersions.java @@ -292,7 +292,7 @@ private boolean matchesComparator(@Nullable String managedVersion, String reques if (managedVersion == null) { return false; } - if (comparator.equals(Comparator.ANY)) { + if (comparator == Comparator.ANY) { return true; } if (!isExact(managedVersion)) { @@ -301,11 +301,11 @@ private boolean matchesComparator(@Nullable String managedVersion, String reques int comparison = new LatestIntegration(null) .compare(null, managedVersion, requestedVersion); if (comparison < 0) { - return comparator.equals(Comparator.LT) || comparator.equals(Comparator.LTE); + return comparator == Comparator.LT || comparator == Comparator.LTE; } else if (comparison > 0) { - return comparator.equals(Comparator.GT) || comparator.equals(Comparator.GTE); + return comparator == Comparator.GT || comparator == Comparator.GTE; } else { - return comparator.equals(Comparator.EQ) || comparator.equals(Comparator.LTE) || comparator.equals(Comparator.GTE); + return comparator == Comparator.EQ || comparator == Comparator.LTE || comparator == Comparator.GTE; } } diff --git a/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java b/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java index 5ce8d628352..af660485f32 100644 --- a/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java +++ b/rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java @@ -1100,7 +1100,7 @@ public void visitBlockStatement(BlockStatement block) { J expr = visit(statement); if (i == blockStatements.size() - 1 && (expr instanceof Expression)) { if (parent instanceof ClosureExpression || (parent instanceof MethodNode && - !JavaType.Primitive.Void.equals(typeMapping.type(((MethodNode) parent).getReturnType())))) { + JavaType.Primitive.Void != typeMapping.type(((MethodNode) parent).getReturnType()))) { expr = new J.Return(randomId(), expr.getPrefix(), Markers.EMPTY, expr.withPrefix(EMPTY)); expr = expr.withMarkers(expr.getMarkers().add(new ImplicitReturn(randomId()))); diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/HclTemplate.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/HclTemplate.java index 5fb3297f4c3..e7b2dd0933e 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/HclTemplate.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/HclTemplate.java @@ -69,7 +69,7 @@ public H apply(Cursor scope, HclCoordinates coordinates, Object. @Override public Hcl visitConfigFile(Hcl.ConfigFile configFile, Integer p) { Hcl.ConfigFile c = (Hcl.ConfigFile) super.visitConfigFile(configFile, p); - if (loc.equals(Space.Location.CONFIG_FILE_EOF)) { + if (loc == Space.Location.CONFIG_FILE_EOF) { List gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate)); if (coordinates.getComparator() != null) { @@ -100,7 +100,7 @@ public Hcl visitConfigFile(Hcl.ConfigFile configFile, Integer p) { ) ); } - } else if (loc.equals(Space.Location.CONFIG_FILE)) { + } else if (loc == Space.Location.CONFIG_FILE) { List gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate)); c = c.withBody( ListUtils.concatAll( @@ -116,7 +116,7 @@ public Hcl visitConfigFile(Hcl.ConfigFile configFile, Integer p) { @Override public Hcl visitBlock(Hcl.Block block, Integer p) { Hcl.Block b = (Hcl.Block) super.visitBlock(block, p); - if (loc.equals(Space.Location.BLOCK_CLOSE)) { + if (loc == Space.Location.BLOCK_CLOSE) { if (b.isScope(insertionPoint)) { List gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate)); @@ -145,7 +145,7 @@ public Hcl visitBlock(Hcl.Block block, Integer p) { .orElse(SpacesStyle.DEFAULT)).visit(b, p, getCursor().getParentOrThrow()); assert b != null; } - } else if (loc.equals(Space.Location.BLOCK)) { + } else if (loc == Space.Location.BLOCK) { if (b.isScope(insertionPoint)) { b = (Hcl.Block) autoFormat(templateParser.parseBodyContent(substitutedTemplate).get(0), p, getCursor().getParentOrThrow()); @@ -158,7 +158,7 @@ public Hcl visitBlock(Hcl.Block block, Integer p) { public Hcl visitExpression(Expression expression, Integer p) { Hcl e = super.visitExpression(expression, p); - if (loc.equals(Space.Location.EXPRESSION_PREFIX)) { + if (loc == Space.Location.EXPRESSION_PREFIX) { if (e.isScope(insertionPoint)) { e = templateParser.parseExpression(substitutedTemplate).withPrefix(expression.getPrefix()); } diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/AttributeSpaceVisitor.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/AttributeSpaceVisitor.java index dc497dd9af1..a384b1d7d4b 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/AttributeSpaceVisitor.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/AttributeSpaceVisitor.java @@ -52,7 +52,7 @@ public Hcl.Attribute visitAttribute(Hcl.Attribute attribute, P p) { if (parent instanceof Hcl.Block || parent instanceof Hcl.ObjectValue) { List siblingAttributes = getSiblingAttributes(parent); - if (attribute.getType().equals(Hcl.Attribute.Type.Assignment)) { + if (attribute.getType() == Hcl.Attribute.Type.Assignment) { HclLeftPadded type = a.getPadding().getType(); if (Boolean.TRUE.equals(style.getBodyContent().getColumnarAlignment())) { @@ -106,7 +106,7 @@ private List attributesInGroup(List siblings, Hcl. boolean groupFound = false; Hcl.Attribute perviousSibling = null; for (Hcl.Attribute sibling : siblings) { - if (sibling.getType().equals(Hcl.Attribute.Type.Assignment)) { + if (sibling.getType() == Hcl.Attribute.Type.Assignment) { boolean siblingPrefixHasNewLines = sibling.getPrefix().getWhitespace().split("\r\n|\r|\n").length > 2; boolean siblingIsMultiline = sibling.getValue().print(getCursor()).split("\r\n|\r|\n").length > 2; boolean previousSiblingIsMultiline = perviousSibling != null && perviousSibling.getValue().print(getCursor()).split("\r\n|\r|\n").length > 2; diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/BracketsVisitor.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/BracketsVisitor.java index 6bbd596c11e..cb885fa0818 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/BracketsVisitor.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/BracketsVisitor.java @@ -42,11 +42,11 @@ public BracketsVisitor(BracketsStyle style, @Nullable Tree stopAfter) { @Override public Space visitSpace(Space space, Space.Location loc, P p) { - if (loc.equals(Space.Location.BLOCK_CLOSE) && !space.getLastWhitespace().contains("\n")) { + if (loc == Space.Location.BLOCK_CLOSE && !space.getLastWhitespace().contains("\n")) { return space.withLastWhitespace("\n"); } - if (loc.equals(Space.Location.BLOCK_OPEN) && !space.getWhitespace().equals(" ")) { + if (loc == Space.Location.BLOCK_OPEN && !space.getWhitespace().equals(" ")) { return space.withWhitespace(" "); } diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java index 8c2be10c242..1b561786f24 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java @@ -103,7 +103,7 @@ public Space visitSpace(Space space, Space.Location loc, P p) { IndentType indentType = getCursor().getParentOrThrow().getNearestMessage("indentType", IndentType.ALIGN); // block spaces are always aligned to their parent - boolean alignBlockToParent = loc.equals(Space.Location.BLOCK_CLOSE) || loc.equals(Space.Location.OBJECT_VALUE_ATTRIBUTE_SUFFIX); + boolean alignBlockToParent = loc == Space.Location.BLOCK_CLOSE || loc == Space.Location.OBJECT_VALUE_ATTRIBUTE_SUFFIX; if (alignBlockToParent) { indentType = IndentType.ALIGN; @@ -266,7 +266,7 @@ private Space indentTo(Space space, int column, Space.Location spaceLocation) { space = space.withComments(ListUtils.map(space.getComments(), c -> { // The suffix of the last element in the comment list sets the whitespace for the end of the block. // The column for comments that come before the last element are incremented. - int incrementBy = spaceLocation.equals(Space.Location.BLOCK_CLOSE) && !c.equals(lastElement) ? style.getIndentSize() : 0; + int incrementBy = spaceLocation == Space.Location.BLOCK_CLOSE && !c.equals(lastElement) ? style.getIndentSize() : 0; return c.getStyle() == Comment.Style.INLINE ? indentMultilineComment(c, column + incrementBy) : indentSingleLineComment(c, column + incrementBy); @@ -274,8 +274,8 @@ private Space indentTo(Space space, int column, Space.Location spaceLocation) { // Prevent formatting trailing comments, the whitespace in a trailing comment won't have a new line character. // Compilation unit prefixes are an exception, since they do not exist in a block. - if (space.getWhitespace().contains("\n") || spaceLocation.equals(Space.Location.CONFIG_FILE)) { - int incrementBy = spaceLocation.equals(Space.Location.BLOCK_CLOSE) ? style.getIndentSize() : 0; + if (space.getWhitespace().contains("\n") || spaceLocation == Space.Location.CONFIG_FILE) { + int incrementBy = spaceLocation == Space.Location.BLOCK_CLOSE ? style.getIndentSize() : 0; int indent = getLengthOfWhitespace(space.getWhitespace()); if (indent != (column + incrementBy)) { int shift = column + incrementBy - indent; diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java index 76bb09325a4..125040cbc4f 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java @@ -90,7 +90,7 @@ public Hcl visitAttribute(Hcl.Attribute attribute, PrintOutputCapture

p) { beforeSyntax(attribute, Space.Location.ATTRIBUTE, p); visit(attribute.getName(), p); visitSpace(attribute.getPadding().getType().getBefore(), Space.Location.ATTRIBUTE_ASSIGNMENT, p); - p.append(attribute.getType().equals(Hcl.Attribute.Type.Assignment) ? "=" : ":"); + p.append(attribute.getType() == Hcl.Attribute.Type.Assignment ? "=" : ":"); visit(attribute.getValue(), p); if (attribute.getComma() != null) { visitSpace(attribute.getComma().getPrefix(), Space.Location.OBJECT_VALUE_ATTRIBUTE_COMMA, p); diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/HclCoordinates.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/HclCoordinates.java index 5616b533f28..39327ffbddb 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/HclCoordinates.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/HclCoordinates.java @@ -34,7 +34,7 @@ public class HclCoordinates implements Coordinates { Comparator comparator; public boolean isReplacement() { - return Mode.REPLACEMENT.equals(mode); + return Mode.REPLACEMENT == mode; } public enum Mode { diff --git a/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Space.java b/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Space.java index 48d5282eb67..1b4c56e5bdc 100644 --- a/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Space.java +++ b/rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Space.java @@ -156,7 +156,7 @@ public static Space format(String formatting) { for (char c : charArray) { switch (c) { case '#': - if (Comment.Style.LINE_SLASH.equals(inLineSlashOrHashComment)) { + if (Comment.Style.LINE_SLASH == inLineSlashOrHashComment) { comment.append(c); } else { if (inSingleLineComment) { @@ -169,7 +169,7 @@ public static Space format(String formatting) { } break; case '/': - if (Comment.Style.LINE_HASH.equals(inLineSlashOrHashComment)) { + if (Comment.Style.LINE_HASH == inLineSlashOrHashComment) { comment.append(c); } else { if (inSingleLineComment) { diff --git a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java index 6ff41fecbd5..e117030dc6f 100644 --- a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java +++ b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserInputFileObject.java @@ -111,7 +111,7 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) && + return kind == getKind() && path.getFileName().toString().equals(baseName); } diff --git a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserVisitor.java b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserVisitor.java index 22086c5db31..ac0714e55af 100644 --- a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserVisitor.java +++ b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11ParserVisitor.java @@ -761,7 +761,7 @@ public J visitLiteral(LiteralTree node, Space fmt) { singletonList(new J.Literal.UnicodeEscape(1, valueSource.substring(3, valueSource.length() - 1))), type); } - } else if (JavaType.Primitive.String.equals(type)) { + } else if (JavaType.Primitive.String == type) { StringBuilder valueSourceWithoutSurrogates = new StringBuilder(); List unicodeEscapes = null; diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java index 49e01f39290..f4e6faf4c6d 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserInputFileObject.java @@ -111,7 +111,7 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) && + return kind == getKind() && path.getFileName().toString().equals(baseName); } diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java index 6dea46ebda4..673d84fff4e 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java @@ -826,7 +826,7 @@ public J visitLiteral(LiteralTree node, Space fmt) { singletonList(new J.Literal.UnicodeEscape(1, valueSource.substring(3, valueSource.length() - 1))), type); } - } else if (JavaType.Primitive.String.equals(type)) { + } else if (JavaType.Primitive.String == type) { StringBuilder valueSourceWithoutSurrogates = new StringBuilder(); List unicodeEscapes = null; diff --git a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java index fbb8065f806..8e05405ad90 100644 --- a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java +++ b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserInputFileObject.java @@ -111,7 +111,7 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) && + return kind == getKind() && path.getFileName().toString().equals(baseName); } diff --git a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserVisitor.java b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserVisitor.java index 8fd8d2809d9..0eeba8521e6 100644 --- a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserVisitor.java +++ b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserVisitor.java @@ -823,7 +823,7 @@ public J visitLiteral(LiteralTree node, Space fmt) { singletonList(new J.Literal.UnicodeEscape(1, valueSource.substring(3, valueSource.length() - 1))), type); } - } else if (JavaType.Primitive.String.equals(type)) { + } else if (JavaType.Primitive.String == type) { StringBuilder valueSourceWithoutSurrogates = new StringBuilder(); List unicodeEscapes = null; diff --git a/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java b/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java index 122bdce7957..37e1eb655ae 100644 --- a/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java +++ b/rewrite-java-8/src/main/java/org/openrewrite/java/Java8ParserInputFileObject.java @@ -110,7 +110,7 @@ public Kind getKind() { @Override public boolean isNameCompatible(String simpleName, Kind kind) { String baseName = simpleName + kind.extension; - return kind.equals(getKind()) && + return kind == getKind() && path.getFileName().toString().equals(baseName); } diff --git a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8Parser.java b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8Parser.java index 227b6f3609c..de46c937d0a 100644 --- a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8Parser.java +++ b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8Parser.java @@ -318,7 +318,7 @@ public String inferBinaryName(Location location, JavaFileObject file) { @Override public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException { - if (StandardLocation.CLASS_PATH.equals(location)) { + if (StandardLocation.CLASS_PATH == location) { Iterable listed = super.list(location, packageName, kinds, recurse); return Stream.concat( classByteClasspath.stream() diff --git a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8ParserVisitor.java b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8ParserVisitor.java index e9123f68062..8a502fd31b8 100644 --- a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8ParserVisitor.java +++ b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8ParserVisitor.java @@ -761,7 +761,7 @@ public J visitLiteral(LiteralTree node, Space fmt) { singletonList(new J.Literal.UnicodeEscape(1, valueSource.substring(3, valueSource.length() - 1))), type); } - } else if (JavaType.Primitive.String.equals(type)) { + } else if (JavaType.Primitive.String == type) { StringBuilder valueSourceWithoutSurrogates = new StringBuilder(); List unicodeEscapes = null; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaPrinter.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaPrinter.java index b75e24d02c3..71a1d56ccac 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaPrinter.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaPrinter.java @@ -537,7 +537,7 @@ public J visitClassDeclaration(ClassDeclaration classDecl, PrintOutputCapture

visitContainer("<", classDecl.getPadding().getTypeParameters(), JContainer.Location.TYPE_PARAMETERS, ",", ">", p); visitContainer("(", classDecl.getPadding().getPrimaryConstructor(), JContainer.Location.RECORD_STATE_VECTOR, ",", ")", p); visitLeftPadded("extends", classDecl.getPadding().getExtends(), JLeftPadded.Location.EXTENDS, p); - visitContainer(classDecl.getKind().equals(ClassDeclaration.Kind.Type.Interface) ? "extends" : "implements", + visitContainer(classDecl.getKind() == ClassDeclaration.Kind.Type.Interface ? "extends" : "implements", classDecl.getPadding().getImplements(), JContainer.Location.IMPLEMENTS, ",", null, p); visitContainer("permits", classDecl.getPadding().getPermits(), JContainer.Location.PERMITS, ",", null, p); visit(classDecl.getBody(), p); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaVisitor.java index eec6aeb187d..be5ca459848 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaVisitor.java @@ -1463,7 +1463,7 @@ protected boolean isInSameNameScope(Cursor base, Cursor child) { Object childScope = it.next(); if (childScope instanceof J.ClassDeclaration) { J.ClassDeclaration childClass = (J.ClassDeclaration) childScope; - if (!(childClass.getKind().equals(J.ClassDeclaration.Kind.Type.Class)) || + if (childClass.getKind() != J.ClassDeclaration.Kind.Type.Class || childClass.hasModifier(J.Modifier.Type.Static)) { //Short circuit the search if a terminating element is encountered. return false; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java index 9c5f91105dc..55a93b768ab 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/PackageMatcher.java @@ -38,7 +38,7 @@ public PackageMatcher(@Nullable String targetPackage, boolean recursive) { @Override public boolean matchesReference(Reference reference) { - if (reference.getKind().equals(Reference.Kind.TYPE) || reference.getKind().equals(Reference.Kind.PACKAGE)) { + if (reference.getKind() == Reference.Kind.TYPE || reference.getKind() == Reference.Kind.PACKAGE) { String recursivePackageNamePrefix = targetPackage + "."; if (reference.getValue().equals(targetPackage) || recursive && reference.getValue().startsWith(recursivePackageNamePrefix)) { return true; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java index 1a1b5aa6f40..4d4f0e4133b 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/TypeMatcher.java @@ -112,7 +112,7 @@ private static boolean isPlainIdentifier(MethodSignatureParser.TargetTypePattern @Override public boolean matchesReference(Reference reference) { - return reference.getKind().equals(Reference.Kind.TYPE) && matchesTargetTypeName(reference.getValue()); + return reference.getKind() == Reference.Kind.TYPE && matchesTargetTypeName(reference.getValue()); } @Override diff --git a/rewrite-java/src/main/java/org/openrewrite/java/VariableNameUtils.java b/rewrite-java/src/main/java/org/openrewrite/java/VariableNameUtils.java index e9a880d0600..fc4f1ddc048 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/VariableNameUtils.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/VariableNameUtils.java @@ -50,7 +50,7 @@ public static String generateVariableName(String baseName, Cursor scope, Generat Set namesInScope = findNamesInScope(scope); // Generate a new name to prevent namespace shadowing. String newName = baseName; - if (GenerationStrategy.INCREMENT_NUMBER.equals(strategy)) { + if (GenerationStrategy.INCREMENT_NUMBER == strategy) { StringBuilder postFix = new StringBuilder(); char[] charArray = baseName.toCharArray(); for (int i = charArray.length - 1; i >= 0; i--) { diff --git a/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java index d333c9c04d9..a69183dd763 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java @@ -143,18 +143,18 @@ public Space visitSpace(Space space, Space.Location loc, P p) { // block spaces are always aligned to their parent Object value = getCursor().getValue(); - boolean alignBlockPrefixToParent = loc.equals(Space.Location.BLOCK_PREFIX) && space.getWhitespace().contains("\n") && + boolean alignBlockPrefixToParent = loc == Space.Location.BLOCK_PREFIX && space.getWhitespace().contains("\n") && // ignore init blocks. (value instanceof J.Block && !(getCursor().getParentTreeCursor().getValue() instanceof J.Block)); - boolean alignBlockToParent = loc.equals(Space.Location.BLOCK_END) || - loc.equals(Space.Location.NEW_ARRAY_INITIALIZER_SUFFIX) || - loc.equals(Space.Location.CATCH_PREFIX) || - loc.equals(Space.Location.TRY_FINALLY) || - loc.equals(Space.Location.ELSE_PREFIX); + boolean alignBlockToParent = loc == Space.Location.BLOCK_END || + loc == Space.Location.NEW_ARRAY_INITIALIZER_SUFFIX || + loc == Space.Location.CATCH_PREFIX || + loc == Space.Location.TRY_FINALLY || + loc == Space.Location.ELSE_PREFIX; - if ((loc.equals(Space.Location.EXTENDS) && space.getWhitespace().contains("\n")) || - Space.Location.EXTENDS.equals(getCursor().getParent().getMessage("lastLocation"))) { + if ((loc == Space.Location.EXTENDS && space.getWhitespace().contains("\n")) || + Space.Location.EXTENDS == getCursor().getParent().getMessage("lastLocation")) { indentType = IndentType.CONTINUATION_INDENT; } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java index f586b011fcb..f0f22eceff2 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java @@ -60,7 +60,7 @@ public String template(Cursor cursor, String template, Space.Location location, // for CoordinateBuilder.MethodDeclaration#replaceBody() if (cursor.getValue() instanceof J.MethodDeclaration && - location.equals(Space.Location.BLOCK_PREFIX)) { + location == Space.Location.BLOCK_PREFIX) { J.MethodDeclaration method = cursor.getValue(); J.MethodDeclaration m = method.withBody(null).withLeadingAnnotations(emptyList()).withPrefix(Space.EMPTY); before.insert(0, m.printTrimmed(cursor.getParentOrThrow()).trim() + '{'); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/JavaTemplateJavaExtension.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/JavaTemplateJavaExtension.java index 476aeaa2e03..a3c8e1fd7ac 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/JavaTemplateJavaExtension.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/JavaTemplateJavaExtension.java @@ -55,7 +55,7 @@ public TreeVisitor getMixin() { return new JavaVisitor() { @Override public J visitAnnotation(J.Annotation annotation, Integer integer) { - if (loc.equals(ANNOTATION_PREFIX) && mode.equals(JavaCoordinates.Mode.REPLACEMENT) && + if (loc == ANNOTATION_PREFIX && mode == JavaCoordinates.Mode.REPLACEMENT && annotation.isScope(insertionPoint)) { List gen = substitutions.unsubstitute(templateParser.parseAnnotations(getCursor(), substitutedTemplate)); if (gen.isEmpty()) { @@ -64,7 +64,7 @@ public J visitAnnotation(J.Annotation annotation, Integer integer) { "\nUse JavaTemplate.Builder.doBeforeParseTemplate() to see what stub is being generated and include it in any bug report."); } return gen.get(0).withPrefix(annotation.getPrefix()); - } else if (loc.equals(ANNOTATION_ARGUMENTS) && mode.equals(JavaCoordinates.Mode.REPLACEMENT) && + } else if (loc == ANNOTATION_ARGUMENTS && mode == JavaCoordinates.Mode.REPLACEMENT && annotation.isScope(insertionPoint)) { List gen = substitutions.unsubstitute(templateParser.parseAnnotations(getCursor(), "@Example(" + substitutedTemplate + ")")); return annotation.withArguments(gen.get(0).getArguments()); @@ -144,7 +144,7 @@ public J visitClassDeclaration(J.ClassDeclaration classDecl, Integer p) { case ANNOTATIONS: { List gen = substitutions.unsubstitute(templateParser.parseAnnotations(getCursor(), substitutedTemplate)); J.ClassDeclaration c = classDecl; - if (mode.equals(JavaCoordinates.Mode.REPLACEMENT)) { + if (mode == JavaCoordinates.Mode.REPLACEMENT) { c = c.withLeadingAnnotations(gen); if (c.getTypeParameters() != null) { c = c.withTypeParameters(ListUtils.map(c.getTypeParameters(), tp -> tp.withAnnotations(emptyList()))); @@ -176,7 +176,7 @@ public J visitClassDeclaration(J.ClassDeclaration classDecl, Integer p) { .collect(toList()); J.ClassDeclaration c = classDecl; - if (mode.equals(JavaCoordinates.Mode.REPLACEMENT)) { + if (mode == JavaCoordinates.Mode.REPLACEMENT) { c = c.withImplements(implementings); //noinspection ConstantConditions c = c.getPadding().withImplements(c.getPadding().getImplements().withBefore(Space.EMPTY)); @@ -202,8 +202,8 @@ public J visitClassDeclaration(J.ClassDeclaration classDecl, Integer p) { @Override public J visitExpression(Expression expression, Integer p) { - if ((loc.equals(EXPRESSION_PREFIX) || - loc.equals(STATEMENT_PREFIX) && expression instanceof Statement) && + if ((loc == EXPRESSION_PREFIX || + loc == STATEMENT_PREFIX && expression instanceof Statement) && expression.isScope(insertionPoint)) { return autoFormat(substitutions.unsubstitute(templateParser.parseExpression( getCursor(), @@ -216,13 +216,13 @@ public J visitExpression(Expression expression, Integer p) { @Override public J visitFieldAccess(J.FieldAccess fa, Integer p) { - if (loc.equals(FIELD_ACCESS_PREFIX) && fa.isScope(insertionPoint)) { + if (loc == FIELD_ACCESS_PREFIX && fa.isScope(insertionPoint)) { return autoFormat(substitutions.unsubstitute(templateParser.parseExpression( getCursor(), substitutedTemplate, loc)) .withPrefix(fa.getPrefix()), p); - } else if (loc.equals(STATEMENT_PREFIX) && fa.isScope(insertionPoint)) { + } else if (loc == STATEMENT_PREFIX && fa.isScope(insertionPoint)) { // NOTE: while `J.FieldAccess` inherits from `Statement` they can only ever be used as expressions return autoFormat(substitutions.unsubstitute(templateParser.parseExpression( getCursor(), @@ -236,7 +236,7 @@ public J visitFieldAccess(J.FieldAccess fa, Integer p) { @Override public J visitIdentifier(J.Identifier ident, Integer p) { // ONLY for backwards compatibility, otherwise the same as expression replacement - if (loc.equals(IDENTIFIER_PREFIX) && ident.isScope(insertionPoint)) { + if (loc == IDENTIFIER_PREFIX && ident.isScope(insertionPoint)) { return autoFormat(substitutions.unsubstitute(templateParser.parseExpression( getCursor(), substitutedTemplate, @@ -248,7 +248,7 @@ public J visitIdentifier(J.Identifier ident, Integer p) { @Override public J visitLambda(J.Lambda lambda, Integer p) { - if (loc.equals(LAMBDA_PARAMETERS_PREFIX) && lambda.getParameters().isScope(insertionPoint)) { + if (loc == LAMBDA_PARAMETERS_PREFIX && lambda.getParameters().isScope(insertionPoint)) { return lambda.withParameters(substitutions.unsubstitute(templateParser.parseLambdaParameters(getCursor(), substitutedTemplate))); } return maybeReplaceStatement(lambda, J.class, 0); @@ -261,7 +261,7 @@ public J visitMethodDeclaration(J.MethodDeclaration method, Integer p) { case ANNOTATIONS: { List gen = substitutions.unsubstitute(templateParser.parseAnnotations(getCursor(), substitutedTemplate)); J.MethodDeclaration m = method; - if (mode.equals(JavaCoordinates.Mode.REPLACEMENT)) { + if (mode == JavaCoordinates.Mode.REPLACEMENT) { m = method.withLeadingAnnotations(gen); if (m.getTypeParameters() != null) { m = m.withTypeParameters(ListUtils.map(m.getTypeParameters(), tp -> tp.withAnnotations(emptyList()))); @@ -384,9 +384,9 @@ public J visitMethodDeclaration(J.MethodDeclaration method, Integer p) { @Override public J visitMethodInvocation(J.MethodInvocation method, Integer integer) { - if ((loc.equals(METHOD_INVOCATION_ARGUMENTS) || loc.equals(METHOD_INVOCATION_NAME)) && method.isScope(insertionPoint)) { + if ((loc == METHOD_INVOCATION_ARGUMENTS || loc == METHOD_INVOCATION_NAME) && method.isScope(insertionPoint)) { J.MethodInvocation m; - if (loc.equals(METHOD_INVOCATION_ARGUMENTS)) { + if (loc == METHOD_INVOCATION_ARGUMENTS) { m = substitutions.unsubstitute(templateParser.parseMethodArguments(getCursor(), substitutedTemplate, loc)); m = autoFormat(m, 0); m = method.withArguments(m.getArguments()).withMethodType(m.getMethodType()); @@ -433,7 +433,7 @@ public J visitNewClass(J.NewClass newClass, Integer p) { @Override public J visitPackage(J.Package pkg, Integer integer) { - if (loc.equals(PACKAGE_PREFIX) && pkg.isScope(insertionPoint)) { + if (loc == PACKAGE_PREFIX && pkg.isScope(insertionPoint)) { return pkg.withExpression(substitutions.unsubstitute(templateParser.parsePackage(getCursor(), substitutedTemplate))); } return super.visitPackage(pkg, integer); @@ -445,8 +445,8 @@ public J visitStatement(Statement statement, Integer p) { } private J3 maybeReplaceStatement(Statement statement, Class expected, Integer p) { - if (loc.equals(STATEMENT_PREFIX) && statement.isScope(insertionPoint)) { - if (mode.equals(JavaCoordinates.Mode.REPLACEMENT)) { + if (loc == STATEMENT_PREFIX && statement.isScope(insertionPoint)) { + if (mode == JavaCoordinates.Mode.REPLACEMENT) { List gen = substitutions.unsubstitute(templateParser.parseBlockStatements(getCursor(), expected, substitutedTemplate, loc, mode)); if (gen.size() != 1) { @@ -481,7 +481,7 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, Integer if (loc == ANNOTATIONS) { J.VariableDeclarations v = multiVariable; final List gen = substitutions.unsubstitute(templateParser.parseAnnotations(getCursor(), substitutedTemplate)); - if (mode.equals(JavaCoordinates.Mode.REPLACEMENT)) { + if (mode == JavaCoordinates.Mode.REPLACEMENT) { v = v.withLeadingAnnotations(gen); if (v.getTypeExpression() instanceof J.AnnotatedType) { v = v.withTypeExpression(((J.AnnotatedType) v.getTypeExpression()).getTypeExpression()); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java index 16a9a68438c..6331cc78d69 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java @@ -146,7 +146,7 @@ private String substituteTypedPattern(String key, int index, TemplateParameterPa String fqn = getTypeName(type); JavaType.Primitive primitive = JavaType.Primitive.fromKeyword(fqn); - s = primitive == null || primitive.equals(JavaType.Primitive.String) ? + s = primitive == null || primitive == JavaType.Primitive.String ? newObjectParameter(fqn, index) : newPrimitiveParameter(fqn, index); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java b/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java index 34a3a10abf5..d545053d8b8 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/style/Autodetect.java @@ -577,7 +577,7 @@ public ImportLayoutStyle getImportLayoutStyle() { List countOfBlocksInStaticGroups = new ArrayList<>(); for (Block block : longestBlocks) { - if (BlockType.ImportStatic.equals(block.type)) { + if (BlockType.ImportStatic == block.type) { staticBlocks.add(block); countOfBlocksInStaticGroups.add(0); countOfBlocksInStaticGroups.set(staticCountPos, countOfBlocksInStaticGroups.get(staticCountPos) + 1); diff --git a/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaCoordinates.java b/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaCoordinates.java index 04bf5e5e1f5..482bf3cfe43 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaCoordinates.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/tree/JavaCoordinates.java @@ -34,7 +34,7 @@ public class JavaCoordinates implements Coordinates { Comparator comparator; public boolean isReplacement() { - return Mode.REPLACEMENT.equals(mode); + return Mode.REPLACEMENT == mode; } /** diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveDependency.java index 0d015f4417d..d60df379b3c 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveDependency.java @@ -70,7 +70,7 @@ public TreeVisitor getVisitor() { @Override public Validated validate() { return super.validate().and(Validated.test("scope", "Scope must be one of compile, runtime, test, or provided", - scope, s -> !Scope.Invalid.equals(Scope.fromName(s)))); + scope, s -> Scope.Invalid != Scope.fromName(s))); } private class RemoveDependencyVisitor extends MavenIsoVisitor { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveManagedDependency.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveManagedDependency.java index f65fbf99269..2f1de67fc90 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveManagedDependency.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveManagedDependency.java @@ -69,7 +69,7 @@ public TreeVisitor getVisitor() { @Override public Validated validate() { return super.validate().and(Validated.test("scope", "Scope must be one of compile, runtime, test, or provided", - scope, s -> !Scope.Invalid.equals(Scope.fromName(s)))); + scope, s -> Scope.Invalid != Scope.fromName(s))); } private class RemoveManagedDependencyVisitor extends MavenIsoVisitor { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java index d4e94d99975..dbe5719624e 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/RemoveRedundantDependencyVersions.java @@ -167,7 +167,7 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { if (d != document) { d = (Xml.Document) new RemoveEmptyDependenciesTags().visitNonNull(d, ctx); d = (Xml.Document) new RemoveEmptyPluginsTags().visitNonNull(d, ctx); - if (!comparator.equals(Comparator.EQ)) { + if (comparator != Comparator.EQ) { maybeUpdateModel(); } } @@ -323,7 +323,7 @@ private boolean matchesComparator(@Nullable String managedVersion, String reques if (managedVersion == null) { return false; } - if (comparator.equals(Comparator.ANY)) { + if (comparator == Comparator.ANY) { return true; } if (!isExact(managedVersion)) { @@ -333,11 +333,11 @@ private boolean matchesComparator(@Nullable String managedVersion, String reques .compare(null, managedVersion, Objects.requireNonNull(getResolutionResult().getPom().getValue(requestedVersion))); if (comparison < 0) { - return comparator.equals(Comparator.LT) || comparator.equals(Comparator.LTE); + return comparator == Comparator.LT || comparator == Comparator.LTE; } else if (comparison > 0) { - return comparator.equals(Comparator.GT) || comparator.equals(Comparator.GTE); + return comparator == Comparator.GT || comparator == Comparator.GTE; } else { - return comparator.equals(Comparator.EQ) || comparator.equals(Comparator.LTE) || comparator.equals(Comparator.GTE); + return comparator == Comparator.EQ || comparator == Comparator.LTE || comparator == Comparator.GTE; } } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/internal/InsertDependencyComparator.java b/rewrite-maven/src/main/java/org/openrewrite/maven/internal/InsertDependencyComparator.java index 6669c1321af..d439dcb0154 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/internal/InsertDependencyComparator.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/internal/InsertDependencyComparator.java @@ -71,7 +71,7 @@ public int compare(Content o1, Content o2) { private static final Comparator dependencyComparator = (d1, d2) -> { Scope scope1 = Scope.fromName(d1.getChildValue("scope").orElse(null)); Scope scope2 = Scope.fromName(d2.getChildValue("scope").orElse(null)); - if (!scope1.equals(scope2)) { + if (scope1 != scope2) { return scope1.compareTo(scope2); } diff --git a/rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java b/rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java index cff46087276..57ae47a0905 100755 --- a/rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java +++ b/rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java @@ -146,8 +146,8 @@ void javaReferenceDocument() { """, spec -> spec.afterRecipe(doc -> { assertThat(doc.getReferences().getReferences().stream().anyMatch(typeRef -> typeRef.getValue().equals("java.lang.String"))).isTrue(); - assertThat(doc.getReferences().getReferences().stream().anyMatch(typeRef -> typeRef.getKind().equals(Reference.Kind.TYPE))).isTrue(); - assertThat(doc.getReferences().getReferences().stream().anyMatch(typeRef -> typeRef.getKind().equals(Reference.Kind.PACKAGE))).isTrue(); + assertThat(doc.getReferences().getReferences().stream().anyMatch(typeRef -> typeRef.getKind() == Reference.Kind.TYPE)).isTrue(); + assertThat(doc.getReferences().getReferences().stream().anyMatch(typeRef -> typeRef.getKind() == Reference.Kind.PACKAGE)).isTrue(); }) ) );