mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Fixed @Data and @SuperBuilder doubled constructor issue
#513 GitOrigin-RevId: ef333491d7447ae19b60f362cef3f07eba7af296
This commit is contained in:
committed by
intellij-monorepo-bot
parent
45bd4808b2
commit
96808db81a
@@ -24,6 +24,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -97,7 +98,7 @@ public class DataProcessor extends AbstractClassProcessor {
|
||||
final String staticName = PsiAnnotationUtil.getStringAnnotationValue(psiAnnotation, "staticConstructor");
|
||||
if (shouldGenerateRequiredArgsConstructor(psiClass, staticName)) {
|
||||
target.addAll(requiredArgsConstructorProcessor.createRequiredArgsConstructor(psiClass, PsiModifier.PUBLIC, psiAnnotation, staticName));
|
||||
// if there are no required field, it will alredy have a default constructor without parameters
|
||||
// if there are no required field, it will already have a default constructor without parameters
|
||||
hasConstructorWithoutParamaters = requiredArgsConstructorProcessor.getRequiredFields(psiClass).isEmpty();
|
||||
} else {
|
||||
hasConstructorWithoutParamaters = false;
|
||||
@@ -112,7 +113,7 @@ public class DataProcessor extends AbstractClassProcessor {
|
||||
boolean result = false;
|
||||
// create required constructor only if there are no other constructor annotations
|
||||
@SuppressWarnings("unchecked") final boolean notAnnotatedWith = PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, NoArgsConstructor.class,
|
||||
RequiredArgsConstructor.class, AllArgsConstructor.class, Builder.class);
|
||||
RequiredArgsConstructor.class, AllArgsConstructor.class, Builder.class, SuperBuilder.class);
|
||||
if (notAnnotatedWith) {
|
||||
final Collection<PsiMethod> definedConstructors = PsiClassUtil.collectClassConstructorIntern(psiClass);
|
||||
filterToleratedElements(definedConstructors);
|
||||
|
||||
@@ -51,4 +51,12 @@ public class DataTest extends AbstractLombokParsingTestCase {
|
||||
public void testData$Klasse663() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testData$DataAndBuilder() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testData$DataAndSuperBuilder() {
|
||||
doTest(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.plushnikov.data;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class DataAndBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// FooDataAndBuilder instance = new FooDataAndBuilder();
|
||||
// System.out.println(instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.plushnikov.data;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
public class DataAndSuperBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// FooDataAndSuperBuilder instance = new FooDataAndSuperBuilder();
|
||||
// System.out.println(instance);
|
||||
}
|
||||
}
|
||||
81
plugins/lombok/testData/after/data/DataAndBuilder.java
Normal file
81
plugins/lombok/testData/after/data/DataAndBuilder.java
Normal file
@@ -0,0 +1,81 @@
|
||||
public class DataAndBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
DataAndBuilder(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public static DataAndBuilderBuilder builder() {
|
||||
return new DataAndBuilderBuilder();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof DataAndBuilder)) return false;
|
||||
final DataAndBuilder other = (DataAndBuilder) o;
|
||||
if (!other.canEqual((Object) this)) return false;
|
||||
if (this.getX() != other.getX()) return false;
|
||||
if (this.getY() != other.getY()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof DataAndBuilder;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getX();
|
||||
result = result * PRIME + this.getY();
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DataAndBuilder(x=" + this.getX() + ", y=" + this.getY() + ")";
|
||||
}
|
||||
|
||||
public static class DataAndBuilderBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
DataAndBuilderBuilder() {
|
||||
}
|
||||
|
||||
public DataAndBuilder.DataAndBuilderBuilder x(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataAndBuilder.DataAndBuilderBuilder y(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataAndBuilder build() {
|
||||
return new DataAndBuilder(x, y);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DataAndBuilder.DataAndBuilderBuilder(x=" + this.x + ", y=" + this.y + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
91
plugins/lombok/testData/after/data/DataAndSuperBuilder.java
Normal file
91
plugins/lombok/testData/after/data/DataAndSuperBuilder.java
Normal file
@@ -0,0 +1,91 @@
|
||||
public class DataAndSuperBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
protected DataAndSuperBuilder(DataAndSuperBuilderBuilder<?, ?> b) {
|
||||
this.x = b.x;
|
||||
this.y = b.y;
|
||||
}
|
||||
|
||||
public static DataAndSuperBuilderBuilder<?, ?> builder() {
|
||||
return new DataAndSuperBuilderBuilderImpl();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof DataAndSuperBuilder)) return false;
|
||||
final DataAndSuperBuilder other = (DataAndSuperBuilder) o;
|
||||
if (!other.canEqual((Object) this)) return false;
|
||||
if (this.getX() != other.getX()) return false;
|
||||
if (this.getY() != other.getY()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof DataAndSuperBuilder;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getX();
|
||||
result = result * PRIME + this.getY();
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DataAndSuperBuilder(x=" + this.getX() + ", y=" + this.getY() + ")";
|
||||
}
|
||||
|
||||
public static abstract class DataAndSuperBuilderBuilder<C extends DataAndSuperBuilder, B extends DataAndSuperBuilderBuilder<C, B>> {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public B x(int x) {
|
||||
this.x = x;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B y(int y) {
|
||||
this.y = y;
|
||||
return self();
|
||||
}
|
||||
|
||||
protected abstract B self();
|
||||
|
||||
public abstract C build();
|
||||
|
||||
public String toString() {
|
||||
return "DataAndSuperBuilder.DataAndSuperBuilderBuilder(x=" + this.x + ", y=" + this.y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
private static final class DataAndSuperBuilderBuilderImpl extends DataAndSuperBuilderBuilder<DataAndSuperBuilder, DataAndSuperBuilderBuilderImpl> {
|
||||
private DataAndSuperBuilderBuilderImpl() {
|
||||
}
|
||||
|
||||
protected DataAndSuperBuilder.DataAndSuperBuilderBuilderImpl self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataAndSuperBuilder build() {
|
||||
return new DataAndSuperBuilder(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
plugins/lombok/testData/before/data/DataAndBuilder.java
Normal file
9
plugins/lombok/testData/before/data/DataAndBuilder.java
Normal file
@@ -0,0 +1,9 @@
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class DataAndBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import lombok.Data;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
public class DataAndSuperBuilder {
|
||||
private int x;
|
||||
private int y;
|
||||
}
|
||||
Reference in New Issue
Block a user