Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from openrewrite:main #12

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Collection<Reference> findMatches(Reference.Matcher matcher, Reference.Ki
private List<Reference> findMatchesInternal(Reference.Matcher matcher, Reference.@Nullable Kind kind) {
List<Reference> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private Collection<Map<String, Object>> loadResources(ResourceType resourceType)
for (Object resource : yaml.loadAll(yamlSource)) {
if (resource instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Object> resourceMap = (Map<String, Object>) resource;
if (resourceType.equals(ResourceType.fromSpec((String) resourceMap.get("type")))) {
if (resourceType == ResourceType.fromSpec((String) resourceMap.get("type"))) {
resources.add(resourceMap);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private JavaType genericType(GenericsType g, String signature) {
}
}

List<JavaType.FullyQualified> thrownExceptions = null;
List<JavaType> thrownExceptions = null;
if(node.getExceptions() != null) {
for (ClassNode e : node.getExceptions()) {
thrownExceptions = new ArrayList<>(node.getExceptions().length);
Expand Down
10 changes: 5 additions & 5 deletions rewrite-hcl/src/main/java/org/openrewrite/hcl/HclTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public <H extends Hcl> 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<BodyContent> gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate));

if (coordinates.getComparator() != null) {
Expand Down Expand Up @@ -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<BodyContent> gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate));
c = c.withBody(
ListUtils.concatAll(
Expand All @@ -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<BodyContent> gen = substitutions.unsubstitute(templateParser.parseBodyContent(substitutedTemplate));

Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Hcl.Attribute visitAttribute(Hcl.Attribute attribute, P p) {
if (parent instanceof Hcl.Block || parent instanceof Hcl.ObjectValue) {
List<Hcl.Attribute> siblingAttributes = getSiblingAttributes(parent);

if (attribute.getType().equals(Hcl.Attribute.Type.Assignment)) {
if (attribute.getType() == Hcl.Attribute.Type.Assignment) {
HclLeftPadded<Hcl.Attribute.Type> type = a.getPadding().getType();

if (Boolean.TRUE.equals(style.getBodyContent().getColumnarAlignment())) {
Expand Down Expand Up @@ -106,7 +106,7 @@ private List<Hcl.Attribute> attributesInGroup(List<Hcl.Attribute> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,16 +266,16 @@ 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);
}));

// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Hcl visitAttribute(Hcl.Attribute attribute, PrintOutputCapture<P> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HclCoordinates implements Coordinates {
Comparator<? extends Hcl> comparator;

public boolean isReplacement() {
return Mode.REPLACEMENT.equals(mode);
return Mode.REPLACEMENT == mode;
}

public enum Mode {
Expand Down
4 changes: 2 additions & 2 deletions rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Space.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<J.Literal.UnicodeEscape> unicodeEscapes = null;

Expand Down
Loading
Loading