diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 522138468b..8d9c5f7be8 100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2021 The Project Lombok Authors. + * Copyright (C) 2010-2024 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -101,6 +101,9 @@ public static class HandleNoArgsConstructor extends EclipseAnnotationHandler onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@NoArgsConstructor(onConstructor=...)"); + } handleConstructor.generateConstructor(typeNode, level, Collections.emptyList(), force, staticName, SkipIfConstructorExists.NO, onConstructor, annotationNode); } @@ -125,6 +128,9 @@ public static class HandleRequiredArgsConstructor extends EclipseAnnotationHandl } List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@RequiredArgsConstructor(onConstructor=...)"); + } handleConstructor.generateConstructor( typeNode, level, findRequiredFields(typeNode), false, staticName, SkipIfConstructorExists.NO, @@ -132,6 +138,36 @@ typeNode, level, findRequiredFields(typeNode), false, staticName, SkipIfConstruc } } + @Provides + public static class HandleAllArgsConstructor extends EclipseAnnotationHandler { + private static final String NAME = AllArgsConstructor.class.getSimpleName(); + + private HandleConstructor handleConstructor = new HandleConstructor(); + + @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { + handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor"); + + EclipseNode typeNode = annotationNode.up(); + if (!checkLegality(typeNode, annotationNode, NAME)) return; + AllArgsConstructor ann = annotation.getInstance(); + AccessLevel level = ann.access(); + if (level == AccessLevel.NONE) return; + String staticName = ann.staticName(); + if (annotation.isExplicit("suppressConstructorProperties")) { + annotationNode.addError("This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'."); + } + + List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@AllArgsConstructor(onConstructor=...)"); + } + + handleConstructor.generateConstructor( + typeNode, level, findAllFields(typeNode), false, staticName, SkipIfConstructorExists.NO, + onConstructor, annotationNode); + } + } + private static List findRequiredFields(EclipseNode typeNode) { return findFields(typeNode, true); } @@ -167,33 +203,6 @@ static List findAllFields(EclipseNode typeNode, boolean evenFinalIn return fields; } - @Provides - public static class HandleAllArgsConstructor extends EclipseAnnotationHandler { - private static final String NAME = AllArgsConstructor.class.getSimpleName(); - - private HandleConstructor handleConstructor = new HandleConstructor(); - - @Override public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { - handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor"); - - EclipseNode typeNode = annotationNode.up(); - if (!checkLegality(typeNode, annotationNode, NAME)) return; - AllArgsConstructor ann = annotation.getInstance(); - AccessLevel level = ann.access(); - if (level == AccessLevel.NONE) return; - String staticName = ann.staticName(); - if (annotation.isExplicit("suppressConstructorProperties")) { - annotationNode.addError("This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'."); - } - - List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor", annotationNode); - - handleConstructor.generateConstructor( - typeNode, level, findAllFields(typeNode), false, staticName, SkipIfConstructorExists.NO, - onConstructor, annotationNode); - } - } - static boolean checkLegality(EclipseNode typeNode, EclipseNode errorNode, String name) { if (!isClassOrEnum(typeNode)) { errorNode.addError(name + " is only supported on a class or an enum."); diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 5ed2c2d94f..dbe8cc92c3 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -147,6 +147,9 @@ public void handle(AnnotationValues annotation, Annotation ast, EclipseN if (node == null) return; List onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod", annotationNode); + if (!onMethod.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Getter(onMethod=...)"); + } switch (node.getKind()) { case FIELD: diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index f09f148579..99552efcf1 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2022 The Project Lombok Authors. + * Copyright (C) 2009-2024 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -120,7 +120,13 @@ public void generateSetterForField(EclipseNode fieldNode, EclipseNode sourceNode if (level == AccessLevel.NONE || node == null) return; List onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod", annotationNode); + if (!onMethod.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Setter(onMethod=...)"); + } List onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam", annotationNode); + if (!onParam.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Setter(onParam=...)"); + } switch (node.getKind()) { case FIELD: diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 6a5dad1b0a..372bc57d21 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2021 The Project Lombok Authors. + * Copyright (C) 2010-2024 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -73,6 +73,9 @@ public static class HandleNoArgsConstructor extends JavacAnnotationHandler onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@NoArgsConstructor(onConstructor=...)"); + } NoArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); if (level == AccessLevel.NONE) return; @@ -95,6 +98,9 @@ public static class HandleRequiredArgsConstructor extends JavacAnnotationHandler JavacNode typeNode = annotationNode.up(); if (!checkLegality(typeNode, annotationNode, NAME)) return; List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@RequiredArgsConstructor(onConstructor=...)"); + } RequiredArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); if (level == AccessLevel.NONE) return; @@ -107,6 +113,33 @@ public static class HandleRequiredArgsConstructor extends JavacAnnotationHandler } } + @Provides + public static class HandleAllArgsConstructor extends JavacAnnotationHandler { + private static final String NAME = AllArgsConstructor.class.getSimpleName(); + private HandleConstructor handleConstructor = new HandleConstructor(); + + @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { + handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor"); + + deleteAnnotationIfNeccessary(annotationNode, AllArgsConstructor.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); + JavacNode typeNode = annotationNode.up(); + if (!checkLegality(typeNode, annotationNode, NAME)) return; + List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor", annotationNode); + if (!onConstructor.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@AllArgsConstructor(onConstructor=...)"); + } + AllArgsConstructor ann = annotation.getInstance(); + AccessLevel level = ann.access(); + if (level == AccessLevel.NONE) return; + String staticName = ann.staticName(); + if (annotation.isExplicit("suppressConstructorProperties")) { + annotationNode.addError("This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'."); + } + handleConstructor.generateConstructor(typeNode, level, onConstructor, findAllFields(typeNode), false, staticName, SkipIfConstructorExists.NO, annotationNode); + } + } + public static List findRequiredFields(JavacNode typeNode) { return findFields(typeNode, true); } @@ -132,30 +165,6 @@ public static List findFields(JavacNode typeNode, boolean nullMarked) return fields.toList(); } - @Provides - public static class HandleAllArgsConstructor extends JavacAnnotationHandler { - private static final String NAME = AllArgsConstructor.class.getSimpleName(); - private HandleConstructor handleConstructor = new HandleConstructor(); - - @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor"); - - deleteAnnotationIfNeccessary(annotationNode, AllArgsConstructor.class); - deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); - JavacNode typeNode = annotationNode.up(); - if (!checkLegality(typeNode, annotationNode, NAME)) return; - List onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor", annotationNode); - AllArgsConstructor ann = annotation.getInstance(); - AccessLevel level = ann.access(); - if (level == AccessLevel.NONE) return; - String staticName = ann.staticName(); - if (annotation.isExplicit("suppressConstructorProperties")) { - annotationNode.addError("This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'."); - } - handleConstructor.generateConstructor(typeNode, level, onConstructor, findAllFields(typeNode), false, staticName, SkipIfConstructorExists.NO, annotationNode); - } - } - public static List findAllFields(JavacNode typeNode) { return findAllFields(typeNode, false); } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index dac524dd3b..cdd3153172 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -144,6 +144,9 @@ public void generateGetterForField(JavacNode fieldNode, DiagnosticPosition pos, if (node == null) return; List onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod", annotationNode); + if (!onMethod.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Getter(onMethod=...)"); + } switch (node.getKind()) { case FIELD: diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 04fa8b771a..380f71ca21 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2022 The Project Lombok Authors. + * Copyright (C) 2009-2024 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -123,7 +123,13 @@ public void generateSetterForField(JavacNode fieldNode, JavacNode sourceNode, Ac if (level == AccessLevel.NONE || node == null) return; List onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod", annotationNode); + if (!onMethod.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Setter(onMethod=...)"); + } List onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam", annotationNode); + if (!onParam.isEmpty()) { + handleFlagUsage(annotationNode, ConfigurationKeys.ON_X_FLAG_USAGE, "@Setter(onParam=...)"); + } switch (node.getKind()) { case FIELD: diff --git a/test/transform/resource/before/OnXFlagUsage.java b/test/transform/resource/before/OnXFlagUsage.java new file mode 100644 index 0000000000..7e7a48bf71 --- /dev/null +++ b/test/transform/resource/before/OnXFlagUsage.java @@ -0,0 +1,22 @@ +//version 8: +//conf: lombok.onX.flagUsage = warning +//skip compare content: We're just checking if the flagUsage key works. +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter(onMethod_ = @Deprecated) +@Setter(onMethod_ = @Deprecated, onParam_ = @Deprecated) +@NoArgsConstructor(onConstructor_ = @Deprecated) +@AllArgsConstructor(onConstructor_ = @Deprecated) +public class OnXFlagUsage { + private final String a = ""; + private String b; +} + +@RequiredArgsConstructor(onConstructor_ = @Deprecated) +class OnXFlagUsage2 { + private final String a = ""; +} \ No newline at end of file diff --git a/test/transform/resource/messages-delombok/OnXFlagUsage.java.messages b/test/transform/resource/messages-delombok/OnXFlagUsage.java.messages new file mode 100644 index 0000000000..c4187b9fd0 --- /dev/null +++ b/test/transform/resource/messages-delombok/OnXFlagUsage.java.messages @@ -0,0 +1,6 @@ +9 Use of @Getter(onMethod=...) is flagged according to lombok configuration. +10 Use of @Setter(onMethod=...) is flagged according to lombok configuration. +10 Use of @Setter(onParam=...) is flagged according to lombok configuration. +11 Use of @NoArgsConstructor(onConstructor=...) is flagged according to lombok configuration. +12 Use of @AllArgsConstructor(onConstructor=...) is flagged according to lombok configuration. +18 Use of @RequiredArgsConstructor(onConstructor=...) is flagged according to lombok configuration. \ No newline at end of file diff --git a/test/transform/resource/messages-ecj/OnXFlagUsage.java.messages b/test/transform/resource/messages-ecj/OnXFlagUsage.java.messages new file mode 100644 index 0000000000..c4187b9fd0 --- /dev/null +++ b/test/transform/resource/messages-ecj/OnXFlagUsage.java.messages @@ -0,0 +1,6 @@ +9 Use of @Getter(onMethod=...) is flagged according to lombok configuration. +10 Use of @Setter(onMethod=...) is flagged according to lombok configuration. +10 Use of @Setter(onParam=...) is flagged according to lombok configuration. +11 Use of @NoArgsConstructor(onConstructor=...) is flagged according to lombok configuration. +12 Use of @AllArgsConstructor(onConstructor=...) is flagged according to lombok configuration. +18 Use of @RequiredArgsConstructor(onConstructor=...) is flagged according to lombok configuration. \ No newline at end of file