Skip to content

Commit 1a7b14f

Browse files
authored
Meta-annotation indirection enforces the constraint without literring generated overrides with annotations (#4253)
1 parent 3e06d4f commit 1a7b14f

10 files changed

+86
-6
lines changed

rewrite-core/src/main/java/org/openrewrite/DataTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public class DataTable<Row> {
3737
private final Class<Row> type;
3838

3939
@Language("markdown")
40-
private final String displayName;
40+
private final @NlsRewrite.DisplayName String displayName;
4141

4242
@Language("markdown")
43-
private final String description;
43+
private final @NlsRewrite.Description String description;
4444

4545
@Setter
4646
private boolean enabled = true;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite;
17+
18+
public class MyRecipe extends Recipe {
19+
20+
@Override
21+
public String getDisplayName() {
22+
return "My Title";
23+
}
24+
25+
@Override
26+
public String getDescription() {
27+
return "";
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite;
17+
18+
import org.jetbrains.annotations.Nls;
19+
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Target;
22+
23+
public class NlsRewrite {
24+
@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
25+
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface DisplayName {
26+
}
27+
28+
@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
29+
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface Description {
30+
}
31+
}

rewrite-core/src/main/java/org/openrewrite/Option.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
@Target({ElementType.FIELD, ElementType.METHOD})
2626
@Retention(RetentionPolicy.RUNTIME)
2727
public @interface Option {
28-
@Language("markdown") String displayName() default "";
29-
@Language("markdown") String description() default "";
28+
@Language("markdown") @NlsRewrite.DisplayName String displayName() default "";
29+
30+
@Language("markdown") @NlsRewrite.Description String description() default "";
31+
3032
String example() default "";
33+
3134
String[] valid() default "";
35+
3236
boolean required() default true;
3337
}

rewrite-core/src/main/java/org/openrewrite/Recipe.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.annotation.JsonTypeInfo;
2121
import lombok.Setter;
2222
import org.intellij.lang.annotations.Language;
23+
import org.jetbrains.annotations.Nls;
2324
import org.openrewrite.config.DataTableDescriptor;
2425
import org.openrewrite.config.OptionDescriptor;
2526
import org.openrewrite.config.RecipeDescriptor;
@@ -103,7 +104,7 @@ public int maxCycles() {
103104
* @return The display name.
104105
*/
105106
@Language("markdown")
106-
public abstract String getDisplayName();
107+
public abstract @NlsRewrite.DisplayName String getDisplayName();
107108

108109
/**
109110
* A human-readable display name for this recipe instance, including some descriptive
@@ -179,7 +180,7 @@ public String getInstanceNameSuffix() {
179180
* @return The display name.
180181
*/
181182
@Language("markdown")
182-
public abstract String getDescription();
183+
public abstract @NlsRewrite.Description String getDescription();
183184

184185
/**
185186
* A set of strings used for categorizing related recipes. For example

rewrite-core/src/main/java/org/openrewrite/config/CategoryDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import lombok.Value;
1919
import lombok.With;
2020
import org.intellij.lang.annotations.Language;
21+
import org.openrewrite.NlsRewrite;
2122

2223
import java.util.Set;
2324

@@ -29,11 +30,13 @@ public class CategoryDescriptor {
2930
public static final int HIGHEST_PRECEDENCE = Integer.MAX_VALUE;
3031

3132
@Language("markdown")
33+
@NlsRewrite.DisplayName
3234
String displayName;
3335

3436
String packageName;
3537

3638
@Language("markdown")
39+
@NlsRewrite.Description
3740
String description;
3841

3942
Set<String> tags;

rewrite-core/src/main/java/org/openrewrite/config/ColumnDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.EqualsAndHashCode;
1919
import lombok.Value;
20+
import org.openrewrite.NlsRewrite;
2021
import org.openrewrite.internal.lang.Nullable;
2122

2223
@Value
@@ -30,8 +31,10 @@ public class ColumnDescriptor {
3031
String type;
3132

3233
@Nullable
34+
@NlsRewrite.DisplayName
3335
String displayName;
3436

3537
@Nullable
38+
@NlsRewrite.Description
3639
String description;
3740
}

rewrite-core/src/main/java/org/openrewrite/config/DataTableDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.EqualsAndHashCode;
1919
import lombok.Value;
20+
import org.openrewrite.NlsRewrite;
2021

2122
import java.util.List;
2223

@@ -27,8 +28,10 @@ public class DataTableDescriptor {
2728
@EqualsAndHashCode.Include
2829
String name;
2930

31+
@NlsRewrite.DisplayName
3032
String displayName;
3133

34+
@NlsRewrite.Description
3235
String description;
3336

3437
@EqualsAndHashCode.Include

rewrite-core/src/main/java/org/openrewrite/config/OptionDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.EqualsAndHashCode;
1919
import lombok.Value;
20+
import org.openrewrite.NlsRewrite;
2021
import org.openrewrite.internal.lang.Nullable;
2122

2223
import java.util.List;
@@ -32,9 +33,11 @@ public class OptionDescriptor {
3233
String type;
3334

3435
@Nullable
36+
@NlsRewrite.DisplayName
3537
String displayName;
3638

3739
@Nullable
40+
@NlsRewrite.Description
3841
String description;
3942

4043
@Nullable

rewrite-core/src/main/java/org/openrewrite/style/NamedStyles.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import lombok.Data;
2020
import lombok.EqualsAndHashCode;
2121
import lombok.With;
22+
import org.openrewrite.NlsRewrite;
2223
import org.openrewrite.Tree;
2324
import org.openrewrite.Validated;
2425
import org.openrewrite.internal.lang.Nullable;
@@ -42,9 +43,11 @@ public class NamedStyles implements Marker {
4243
@EqualsAndHashCode.Include
4344
String name;
4445

46+
@NlsRewrite.DisplayName
4547
String displayName;
4648

4749
@Nullable
50+
@NlsRewrite.Description
4851
String description;
4952

5053
Set<String> tags;

0 commit comments

Comments
 (0)