Skip to content

Commit

Permalink
First batch of review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W committed Jan 21, 2025
1 parent f7de8fd commit 7a5dafc
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public J visitDeconstructionPattern(DeconstructionPatternTree node, Space fmt) {
return new J.DeconstructionPattern(randomId(),
fmt,
Markers.EMPTY,
convert(node.getDeconstructor(), t -> sourceBefore("(")),
convert(node.getDeconstructor()),
JContainer.build(convertAll(node.getNestedPatterns(), commaDelim, t -> sourceBefore(")"))),
type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ private JavaType.FullyQualified classType(Type.ClassType classType, String signa
if (sym.members_field != null) {
for (Symbol elem : sym.members_field.getSymbols()) {
if (elem instanceof Symbol.VarSymbol &&
(elem.flags_field & (Flags.SYNTHETIC | Flags.BRIDGE | Flags.HYPOTHETICAL |
Flags.GENERATEDCONSTR | Flags.ANONCONSTR)) == 0) {
(elem.flags_field & (Flags.SYNTHETIC | Flags.BRIDGE | Flags.HYPOTHETICAL |
Flags.GENERATEDCONSTR | Flags.ANONCONSTR)) == 0) {
if (fqn.equals("java.lang.String") && elem.name.toString().equals("serialPersistentFields")) {
// there is a "serialPersistentFields" member within the String class which is used in normal Java
// serialization to customize how the String field is serialized. This field is tripping up Jackson
Expand All @@ -305,7 +305,7 @@ private JavaType.FullyQualified classType(Type.ClassType classType, String signa
}
fields.add(variableType(elem, clazz));
} else if (elem instanceof Symbol.MethodSymbol &&
(elem.flags_field & (Flags.SYNTHETIC | Flags.BRIDGE | Flags.HYPOTHETICAL | Flags.ANONCONSTR)) == 0) {
(elem.flags_field & (Flags.SYNTHETIC | Flags.BRIDGE | Flags.HYPOTHETICAL | Flags.ANONCONSTR)) == 0) {
if (methods == null) {
methods = new ArrayList<>();
}
Expand Down Expand Up @@ -426,7 +426,7 @@ public JavaType.Primitive primitive(TypeTag tag) {
}

private JavaType.@Nullable Variable variableType(@Nullable Symbol symbol,
JavaType.@Nullable FullyQualified owner) {
JavaType.@Nullable FullyQualified owner) {
if (!(symbol instanceof Symbol.VarSymbol)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.java.MinimumJava21;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import static org.openrewrite.java.Assertions.java;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ public J visitInstanceOf(InstanceOf instanceOf, PrintOutputCapture<P> p) {
@Override
public J visitDeconstructionPattern(DeconstructionPattern deconstructionPattern, PrintOutputCapture<P> p) {
beforeSyntax(deconstructionPattern, Space.Location.DECONSTRUCTOR_PREFIX, p);
visitRightPadded(deconstructionPattern.getDeconstructor(), JRightPadded.Location.DECONSTRUCTOR, p);
visitContainer("(", deconstructionPattern.getNested(), JContainer.Location.DECONSTRUCTOR, ",", ")", p);
visitAndCast(deconstructionPattern.getDeconstructor(), p);
visitContainer("(", deconstructionPattern.getPadding().getNested(), JContainer.Location.DECONSTRUCTOR, ",", ")", p);
afterSyntax(deconstructionPattern, p);
return deconstructionPattern;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ public J visitDeconstructionPattern(J.DeconstructionPattern deconstructionPatter
J.DeconstructionPattern d = deconstructionPattern;
d = d.withPrefix(visitSpace(d.getPrefix(), Space.Location.DECONSTRUCTOR_PREFIX, p));
d = d.withMarkers(visitMarkers(d.getMarkers(), p));
d = d.withDeconstructor(visitRightPadded(d.getDeconstructor(), JRightPadded.Location.DECONSTRUCTOR, p));
d = d.withNested(visitContainer(d.getNested(), JContainer.Location.DECONSTRUCTOR, p));
d = d.withDeconstructor(visitAndCast(d.getDeconstructor(), p));
d = d.getPadding().withNested(visitContainer(d.getPadding().getNested(), JContainer.Location.DECONSTRUCTOR, p));
d = d.withType(visitType(d.getType(), p));
return d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,25 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, J j) {
return instanceOf;
}

@Override
public J.DeconstructionPattern visitDeconstructionPattern(J.DeconstructionPattern deconstructionPattern, J j) {
if (isEqual.get()) {
if (!(j instanceof J.DeconstructionPattern)) {
isEqual.set(false);
return deconstructionPattern;
}

J.DeconstructionPattern compareTo = (J.DeconstructionPattern) j;
if (!TypeUtils.isOfType(deconstructionPattern.getType(), compareTo.getType())) {
isEqual.set(false);
return deconstructionPattern;
}
visit(deconstructionPattern.getDeconstructor(), compareTo.getDeconstructor());
this.visitList(deconstructionPattern.getNested(), compareTo.getNested());
}
return deconstructionPattern;
}

@Override
public J.Label visitLabel(J.Label label, J j) {
if (isEqual.get()) {
Expand Down
35 changes: 24 additions & 11 deletions rewrite-java/src/main/java/org/openrewrite/java/tree/J.java
Original file line number Diff line number Diff line change
Expand Up @@ -3073,12 +3073,18 @@ final class DeconstructionPattern implements J, Pattern, TypedTree {

@With
@Getter
JRightPadded<Expression> deconstructor;
Expression deconstructor;

@With
@Getter
JContainer<Pattern> nested;

public List<Pattern> getNested() {
return nested.getElements();
}

public DeconstructionPattern withNested(List<Pattern> nested) {
return getPadding().withNested(JContainer.withElements(this.nested, nested));
}

@Getter
@With
JavaType type;
Expand All @@ -3098,18 +3104,25 @@ public CoordinateBuilder.DeconstructionPattern getCoordinates() {
return new CoordinateBuilder.DeconstructionPattern(this);
}

public Padding getPadding() {
Padding p;
if (this.padding == null) {
p = new Padding(this);
this.padding = new WeakReference<>(p);
} else {
p = this.padding.get();
if (p == null || p.t != this) {
p = new Padding(this);
this.padding = new WeakReference<>(p);
}
}
return p;
}

@RequiredArgsConstructor
public static class Padding {
private final DeconstructionPattern t;

public JRightPadded<Expression> getDeconstructor() {
return t.deconstructor;
}

public DeconstructionPattern withDeconstructor(JRightPadded<Expression> deconstructor) {
return t.deconstructor == deconstructor ? t : new DeconstructionPattern(t.id, t.prefix, t.markers, deconstructor, t.nested, t.type);
}

public JContainer<Pattern> getNested() {
return t.nested;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static Space format(String formatting, int beginIndex, int toIndex) {

@SuppressWarnings("ConstantConditions")
public static <J2 extends J> @Nullable List<JRightPadded<J2>> formatLastSuffix(@Nullable List<JRightPadded<J2>> trees,
Space suffix) {
Space suffix) {
if (trees == null) {
return null;
}
Expand Down

0 comments on commit 7a5dafc

Please sign in to comment.