Skip to content

Commit

Permalink
Meta-annotation indirection enforces the constraint without literring…
Browse files Browse the repository at this point in the history
… generated overrides with annotations (openrewrite#4253)
  • Loading branch information
jkschneider authored Jun 13, 2024
1 parent 3e06d4f commit 1a7b14f
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class DataTable<Row> {
private final Class<Row> type;

@Language("markdown")
private final String displayName;
private final @NlsRewrite.DisplayName String displayName;

@Language("markdown")
private final String description;
private final @NlsRewrite.Description String description;

@Setter
private boolean enabled = true;
Expand Down
29 changes: 29 additions & 0 deletions rewrite-core/src/main/java/org/openrewrite/MyRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite;

public class MyRecipe extends Recipe {

@Override
public String getDisplayName() {
return "My Title";
}

@Override
public String getDescription() {
return "";
}
}
31 changes: 31 additions & 0 deletions rewrite-core/src/main/java/org/openrewrite/NlsRewrite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite;

import org.jetbrains.annotations.Nls;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class NlsRewrite {
@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface DisplayName {
}

@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface Description {
}
}
8 changes: 6 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {
@Language("markdown") String displayName() default "";
@Language("markdown") String description() default "";
@Language("markdown") @NlsRewrite.DisplayName String displayName() default "";

@Language("markdown") @NlsRewrite.Description String description() default "";

String example() default "";

String[] valid() default "";

boolean required() default true;
}
5 changes: 3 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Setter;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.Nls;
import org.openrewrite.config.DataTableDescriptor;
import org.openrewrite.config.OptionDescriptor;
import org.openrewrite.config.RecipeDescriptor;
Expand Down Expand Up @@ -103,7 +104,7 @@ public int maxCycles() {
* @return The display name.
*/
@Language("markdown")
public abstract String getDisplayName();
public abstract @NlsRewrite.DisplayName String getDisplayName();

/**
* A human-readable display name for this recipe instance, including some descriptive
Expand Down Expand Up @@ -179,7 +180,7 @@ public String getInstanceNameSuffix() {
* @return The display name.
*/
@Language("markdown")
public abstract String getDescription();
public abstract @NlsRewrite.Description String getDescription();

/**
* A set of strings used for categorizing related recipes. For example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.Value;
import lombok.With;
import org.intellij.lang.annotations.Language;
import org.openrewrite.NlsRewrite;

import java.util.Set;

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

@Language("markdown")
@NlsRewrite.DisplayName
String displayName;

String packageName;

@Language("markdown")
@NlsRewrite.Description
String description;

Set<String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;
import org.openrewrite.internal.lang.Nullable;

@Value
Expand All @@ -30,8 +31,10 @@ public class ColumnDescriptor {
String type;

@Nullable
@NlsRewrite.DisplayName
String displayName;

@Nullable
@NlsRewrite.Description
String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;

import java.util.List;

Expand All @@ -27,8 +28,10 @@ public class DataTableDescriptor {
@EqualsAndHashCode.Include
String name;

@NlsRewrite.DisplayName
String displayName;

@NlsRewrite.Description
String description;

@EqualsAndHashCode.Include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;
import org.openrewrite.internal.lang.Nullable;

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

@Nullable
@NlsRewrite.DisplayName
String displayName;

@Nullable
@NlsRewrite.Description
String description;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.With;
import org.openrewrite.NlsRewrite;
import org.openrewrite.Tree;
import org.openrewrite.Validated;
import org.openrewrite.internal.lang.Nullable;
Expand All @@ -42,9 +43,11 @@ public class NamedStyles implements Marker {
@EqualsAndHashCode.Include
String name;

@NlsRewrite.DisplayName
String displayName;

@Nullable
@NlsRewrite.Description
String description;

Set<String> tags;
Expand Down

0 comments on commit 1a7b14f

Please sign in to comment.