[java-stubs] Hide synthetic equals/hashCode/toString in records (stubs+decompiler)

Makes IDEA-247576 obsolete
Review ID: IJ-CR-2597

GitOrigin-RevId: 4dbb09153b683f2c191d8ba89a3c4ad8c3da038d
master
Tagir Valeev 4 years ago committed by intellij-monorepo-bot
parent 1651445c90
commit f61e659e58
  1. 18
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. BIN
      testData/classes/records/TestRecordEmpty.class
  3. 37
      testData/results/TestRecordAnno.dec
  4. 28
      testData/results/TestRecordEmpty.dec
  5. 37
      testData/results/TestRecordGenericVararg.dec
  6. 37
      testData/results/TestRecordSimple.dec
  7. 37
      testData/results/TestRecordVararg.dec
  8. 6
      testData/src/records/TestRecordEmpty.java

@ -262,6 +262,21 @@ public class ClassWriter {
DecompilerContext.getLogger().endWriteClass();
}
private static boolean isSyntheticRecordMethod(StructMethod mt, TextBuffer code) {
if (mt.getClassStruct().getRecordComponents() == null) return false;
String name = mt.getName();
String descriptor = mt.getDescriptor();
if (name.equals("equals") && descriptor.equals("(Ljava/lang/Object;)Z") ||
name.equals("hashCode") && descriptor.equals("()I") ||
name.equals("toString") && descriptor.equals("()Ljava/lang/String;")) {
if (code.countLines() == 1) {
String str = code.toString().trim();
return str.startsWith("return this." + name + "<invokedynamic>(this");
}
}
return false;
}
private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) {
StructLineNumberTableAttribute table = method.getAttribute(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(table);
@ -880,7 +895,8 @@ public class ClassWriter {
BytecodeMappingTracer codeTracer = new BytecodeMappingTracer(tracer.getCurrentSourceLine());
TextBuffer code = root.toJava(indent + 1, codeTracer);
hideMethod = (code.length() == 0) && (clinit || dinit || hideConstructor(node, init, throwsExceptions, paramCount, flags));
hideMethod = (code.length() == 0) && (clinit || dinit || hideConstructor(node, init, throwsExceptions, paramCount, flags))
|| isSyntheticRecordMethod(mt, code);
buffer.append(code);

@ -6,18 +6,6 @@ public record TestRecordAnno(@RC @TA int x, int y) {
this.y = y;
}
public final String toString() {
return this.toString<invokedynamic>(this);
}
public final int hashCode() {
return this.hashCode<invokedynamic>(this);
}
public final boolean equals(Object o) {
return this.equals<invokedynamic>(this, o);
}
@TA
public int x() {
return this.x;
@ -36,31 +24,16 @@ class 'records/TestRecordAnno' {
e 6
}
method 'toString ()Ljava/lang/String;' {
1 9
6 9
}
method 'hashCode ()I' {
1 13
6 13
}
method 'equals (Ljava/lang/Object;)Z' {
2 17
7 17
}
method 'x ()I' {
1 22
4 22
1 10
4 10
}
method 'y ()I' {
1 27
4 27
1 15
4 15
}
}
Lines mapping:
5 <-> 28
5 <-> 16

@ -1,35 +1,17 @@
package records;
public record TestRecordEmpty() {
public final String toString() {
return this.toString<invokedynamic>(this);
}
public final int hashCode() {
return this.hashCode<invokedynamic>(this);
}
public final boolean equals(Object o) {
return this.equals<invokedynamic>(this, o);// 3
public int hashCode() {
return 0;// 5
}
}
class 'records/TestRecordEmpty' {
method 'toString ()Ljava/lang/String;' {
1 4
6 4
}
method 'hashCode ()I' {
1 8
6 8
}
method 'equals (Ljava/lang/Object;)Z' {
2 12
7 12
0 4
1 4
}
}
Lines mapping:
3 <-> 13
5 <-> 5

@ -7,18 +7,6 @@ public record TestRecordGenericVararg<T>(T first, T... other) {
this.other = other;
}
public final String toString() {
return this.toString<invokedynamic>(this);
}
public final int hashCode() {
return this.hashCode<invokedynamic>(this);
}
public final boolean equals(Object o) {
return this.equals<invokedynamic>(this, o);
}
public T first() {
return this.first;
}
@ -35,32 +23,17 @@ class 'records/TestRecordGenericVararg' {
e 7
}
method 'toString ()Ljava/lang/String;' {
1 10
6 10
}
method 'hashCode ()I' {
1 14
6 14
}
method 'equals (Ljava/lang/Object;)Z' {
2 18
7 18
}
method 'first ()Ljava/lang/Object;' {
1 22
4 22
1 10
4 10
}
method 'other ()[Ljava/lang/Object;' {
1 26
4 26
1 14
4 14
}
}
Lines mapping:
3 <-> 27
3 <-> 15
5 <-> 6

@ -6,18 +6,6 @@ public record TestRecordSimple(int x, int y) {
this.y = y;
}
public final String toString() {
return this.toString<invokedynamic>(this);
}
public final int hashCode() {
return this.hashCode<invokedynamic>(this);
}
public final boolean equals(Object o) {
return this.equals<invokedynamic>(this, o);
}
public int x() {
return this.x;
}
@ -34,31 +22,16 @@ class 'records/TestRecordSimple' {
e 6
}
method 'toString ()Ljava/lang/String;' {
1 9
6 9
}
method 'hashCode ()I' {
1 13
6 13
}
method 'equals (Ljava/lang/Object;)Z' {
2 17
7 17
}
method 'x ()I' {
1 21
4 21
1 9
4 9
}
method 'y ()I' {
1 25
4 25
1 13
4 13
}
}
Lines mapping:
3 <-> 26
3 <-> 14

@ -6,18 +6,6 @@ public record TestRecordVararg(int x, int[]... y) {
this.y = y;
}
public final String toString() {
return this.toString<invokedynamic>(this);
}
public final int hashCode() {
return this.hashCode<invokedynamic>(this);
}
public final boolean equals(Object o) {
return this.equals<invokedynamic>(this, o);
}
public int x() {
return this.x;
}
@ -34,31 +22,16 @@ class 'records/TestRecordVararg' {
e 6
}
method 'toString ()Ljava/lang/String;' {
1 9
6 9
}
method 'hashCode ()I' {
1 13
6 13
}
method 'equals (Ljava/lang/Object;)Z' {
2 17
7 17
}
method 'x ()I' {
1 21
4 21
1 9
4 9
}
method 'y ()[[I' {
1 25
4 25
1 13
4 13
}
}
Lines mapping:
3 <-> 26
3 <-> 14

@ -1,3 +1,7 @@
package records;
public record TestRecordEmpty() {}
public record TestRecordEmpty() {
public int hashCode() {
return 0;
}
}
Loading…
Cancel
Save