mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
[lombok] IDEA-354173 java: Improve @Getter/@Setter 'supported on' validation (is invalid on records)
GitOrigin-RevId: fa6a65ad6c3c5ea0befa1a55cdf9987fd009fa68
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9dcd3e8ec5
commit
eaf8c3f891
@@ -106,7 +106,7 @@ public abstract class AbstractClassProcessor extends AbstractProcessor implement
|
|||||||
public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
|
public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
|
||||||
Collection<LombokProblem> result = Collections.emptyList();
|
Collection<LombokProblem> result = Collections.emptyList();
|
||||||
// check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
|
// check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
|
||||||
PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
|
PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiRecordComponent.class, PsiMethod.class, PsiClass.class);
|
||||||
if (psiElement instanceof PsiClass) {
|
if (psiElement instanceof PsiClass) {
|
||||||
ProblemValidationSink problemNewBuilder = new ProblemValidationSink();
|
ProblemValidationSink problemNewBuilder = new ProblemValidationSink();
|
||||||
validate(psiAnnotation, (PsiClass) psiElement, problemNewBuilder);
|
validate(psiAnnotation, (PsiClass) psiElement, problemNewBuilder);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public final class GetterProcessor extends AbstractClassProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void validateAnnotationOnRightType(@NotNull PsiClass psiClass, @NotNull ProblemSink builder) {
|
private static void validateAnnotationOnRightType(@NotNull PsiClass psiClass, @NotNull ProblemSink builder) {
|
||||||
if (psiClass.isAnnotationType() || psiClass.isInterface()) {
|
if (psiClass.isAnnotationType() || psiClass.isInterface() || psiClass.isRecord()) {
|
||||||
builder.addErrorMessage("inspection.message.getter.only.supported.on.class.enum.or.field.type");
|
builder.addErrorMessage("inspection.message.getter.only.supported.on.class.enum.or.field.type");
|
||||||
builder.markFailed();
|
builder.markFailed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public final class SetterProcessor extends AbstractClassProcessor {
|
|||||||
private static void validateAnnotationOnRightType(@NotNull PsiAnnotation psiAnnotation,
|
private static void validateAnnotationOnRightType(@NotNull PsiAnnotation psiAnnotation,
|
||||||
@NotNull PsiClass psiClass,
|
@NotNull PsiClass psiClass,
|
||||||
@NotNull ProblemSink builder) {
|
@NotNull ProblemSink builder) {
|
||||||
if (psiClass.isAnnotationType() || psiClass.isInterface() || psiClass.isEnum()) {
|
if (psiClass.isAnnotationType() || psiClass.isInterface() || psiClass.isEnum() || psiClass.isRecord()) {
|
||||||
builder.addErrorMessage("inspection.message.s.only.supported.on.class.or.field.type", psiAnnotation.getQualifiedName());
|
builder.addErrorMessage("inspection.message.setter.only.supported.on.class.or.field.type");
|
||||||
builder.markFailed();
|
builder.markFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ inspection.message.generating.equals.hashcode.with.super.call=Generating equals/
|
|||||||
inspection.message.generating.equals.hashcode.implementation=Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '(callSuper=false)' to your type.
|
inspection.message.generating.equals.hashcode.implementation=Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '(callSuper=false)' to your type.
|
||||||
inspection.message.lazy.not.supported.for.getter.on.type='lazy' is not supported for @Getter on a type
|
inspection.message.lazy.not.supported.for.getter.on.type='lazy' is not supported for @Getter on a type
|
||||||
inspection.message.getter.only.supported.on.class.enum.or.field.type=@Getter is only supported on a class, enum or field type
|
inspection.message.getter.only.supported.on.class.enum.or.field.type=@Getter is only supported on a class, enum or field type
|
||||||
inspection.message.s.only.supported.on.class.or.field.type=''@{0}'' is only supported on a class or field type
|
inspection.message.setter.only.supported.on.class.or.field.type=@Setter is only supported on a class or field type
|
||||||
inspection.message.to.string.only.supported.on.class.or.enum.type=@ToString is only supported on a class or enum type
|
inspection.message.to.string.only.supported.on.class.or.enum.type=@ToString is only supported on a class or enum type
|
||||||
inspection.message.not.generated.s.method.with.same.name.already.exists=Not generated ''{0}()'': A method with same name already exists
|
inspection.message.not.generated.s.method.with.same.name.already.exists=Not generated ''{0}()'': A method with same name already exists
|
||||||
inspection.message.utility.classes.cannot.have.declared.constructors=@UtilityClasses cannot have declared constructors.
|
inspection.message.utility.classes.cannot.have.declared.constructors=@UtilityClasses cannot have declared constructors.
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@@ -11,6 +13,8 @@ import lombok.experimental.FieldNameConstants;
|
|||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
<error descr="@Getter is only supported on a class, enum or field type">@Getter</error>
|
||||||
|
<error descr="@Setter is only supported on a class or field type">@Setter</error>
|
||||||
<error descr="@Data is only supported on a class type">@Data</error>
|
<error descr="@Data is only supported on a class type">@Data</error>
|
||||||
<error descr="@Value is only supported on a class type">@Value</error>
|
<error descr="@Value is only supported on a class type">@Value</error>
|
||||||
<error descr="@ToString is only supported on a class or enum type">@ToString</error>
|
<error descr="@ToString is only supported on a class or enum type">@ToString</error>
|
||||||
@@ -23,5 +27,5 @@ import lombok.experimental.UtilityClass;
|
|||||||
@With//OK on records
|
@With//OK on records
|
||||||
@Builder//OK on records
|
@Builder//OK on records
|
||||||
@FieldNameConstants//OK on records
|
@FieldNameConstants//OK on records
|
||||||
public record InvalidLombokAnnotationsOnRecord(int a, int b) {
|
public record InvalidLombokAnnotationsOnRecord(@Getter /*OK on record param*/int a, int b) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user