-
Notifications
You must be signed in to change notification settings - Fork 534
Add support for annotations to TypeTable
#5485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
56d2767
Add support for annotations to `TypeTable`
knutwannheden 26a6812
Some cleanups
knutwannheden c6925d8
Some more cleanups
knutwannheden 89cf5d3
More cleanups
knutwannheden c364f57
Merge remote-tracking branch 'origin/main' into type-table-annotations
knutwannheden 016e38d
Support annotation member default values
knutwannheden e713052
Corrections
knutwannheden 2931517
More corrections
knutwannheden 0624e0e
Escape more characters in strings
knutwannheden f90567b
Merge remote-tracking branch 'origin/main' into type-table-annotations
knutwannheden 10d1001
Refactor
knutwannheden 4fb3d8b
More elaborate tests
knutwannheden 0711b2d
Remove test
knutwannheden 7faddc4
Fix failing tests
knutwannheden 1c31f37
Unify serialization format
knutwannheden ac22996
Polish
knutwannheden ad89c31
Another test
knutwannheden 2f6cf04
Merge remote-tracking branch 'origin/main' into type-table-annotations
knutwannheden b0b3da2
Cleanups
knutwannheden f8d1fc7
Fixes
knutwannheden 670e939
Also write field constants to TSV
knutwannheden 553c48c
Add some missing newlines
knutwannheden 4d0a3e4
Polish tests
knutwannheden aba4962
Revert some accidental changes
knutwannheden 1f951fa
Remove stdout print from test
knutwannheden a9bb50c
Some more corrections
knutwannheden 1c96eb1
Replace rewrite-gradle type table
knutwannheden 709729d
Fix problem with enum constants in TSV
knutwannheden 21609c1
Polish tests
knutwannheden 119936c
Apply suggestions from code review
timtebeek 662af14
Polish tests
knutwannheden 5970ade
Add one more test case
knutwannheden 490d079
More proper parsing
knutwannheden 4840e71
Some more polishing
knutwannheden f89af6c
Some more polishing
knutwannheden 1bcaa8c
Merge branch 'main' into type-table-annotations
knutwannheden a81d32a
Revert "Some more polishing"
knutwannheden ec0a835
Some more polishing
knutwannheden 573f00e
Merge remote-tracking branch 'origin/main' into type-table-annotations
knutwannheden 7dd84fb
Fix merge errors
knutwannheden f336a2c
Align annotation format with `javap` output
knutwannheden 1bf84a5
Include runtime invisible annotations
knutwannheden 918c748
Parameter and type annotations
knutwannheden 3af256b
Fixes
knutwannheden 9fe5d81
More fixes
knutwannheden 6fbd93f
Formatting fixes
knutwannheden 20030b9
Only escape pipes where required
knutwannheden b2c3cde
Polish
knutwannheden 2df06d7
Fix bug after format change
knutwannheden 40dde54
Update type table
knutwannheden 1bbf3bc
Add TypeTable.Reader#read() overload
knutwannheden f9b1fab
Add TypeTable.Reader.Options
knutwannheden b5c3471
Simplify processing of type annotations
knutwannheden 5d798a9
Merge remote-tracking branch 'origin/main' into type-table-annotations
knutwannheden 5f5f3de
Update Gradle type table
knutwannheden 69c3892
Polish
knutwannheden a3237a4
Revert `JavaParser` changes
knutwannheden da724f5
Restore original type table for rewrite-gradle
knutwannheden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
279 changes: 226 additions & 53 deletions
279
rewrite-java/src/main/java/org/openrewrite/java/internal/parser/TypeTable.java
Large diffs are not rendered by default.
Oops, something went wrong.
1,059 changes: 1,059 additions & 0 deletions
1,059
...e-java/src/main/java/org/openrewrite/java/internal/parser/TypeTableAnnotationSupport.java
Large diffs are not rendered by default.
Oops, something went wrong.
468 changes: 468 additions & 0 deletions
468
...-java/src/test/java/org/openrewrite/java/internal/parser/AnnotationSerializationTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
rewrite-java/src/test/java/org/openrewrite/java/internal/parser/data/AnnotatedClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright 2025 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.java.internal.parser.data; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
|
|
||
| @BasicAnnotation( | ||
| intValue = 100, | ||
| longValue = 200L, | ||
| floatValue = 1.5f, | ||
| doubleValue = 2.5, | ||
| boolValue = false, | ||
| charValue = 'Y', | ||
| byteValue = 10, | ||
| shortValue = 20 | ||
| ) | ||
| @StringAnnotation( | ||
| value = "Custom value", | ||
| // escaped = "Testing \"quotes\" and \\ backslashes", | ||
| unicode = "More unicode: \u2764\uFE0F" | ||
| // multiLine = "Line 1\nLine 2\nLine 3" | ||
| ) | ||
| @NestedAnnotation( | ||
| basic = @BasicAnnotation(intValue = 999), | ||
| string = @StringAnnotation(value = "Nested string"), | ||
| nested = @NestedLevel2( | ||
| value = "Custom nested", | ||
| deepNested = @NestedLevel3(value = "Deep nested custom") | ||
| ) | ||
| ) | ||
| @ArrayAnnotation( | ||
| strings = {"A", "B", "C"}, | ||
| ints = {10, 20, 30}, | ||
| classes = {String.class, Integer.class, Object.class}, | ||
| annotations = { | ||
| @BasicAnnotation(intValue = 1), | ||
| @BasicAnnotation(intValue = 2) | ||
| } | ||
| ) | ||
| @ClassRefAnnotation( | ||
| value = Integer.class, | ||
| primitive = boolean.class, | ||
| array = String[].class, | ||
| innerClass = AnnotatedClass.InnerClass.class | ||
| ) | ||
| @EnumAnnotation( | ||
| value = TestEnum.THREE, | ||
| values = {TestEnum.TWO, TestEnum.THREE}, | ||
| elementType = ElementType.FIELD | ||
| ) | ||
| @ConstantAnnotation( | ||
| value = Constants.STRING_CONSTANT, | ||
| number = Constants.INT_CONSTANT, | ||
| decimal = Constants.DOUBLE_CONSTANT | ||
| ) | ||
| public class AnnotatedClass { | ||
|
|
||
| @BasicAnnotation | ||
| private String field; | ||
|
|
||
| @StringAnnotation | ||
| public void method() { | ||
| // Method body | ||
| } | ||
|
|
||
| public static class InnerClass { | ||
| // Inner class for testing class references | ||
| } | ||
| } | ||
|
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
|
||
32 changes: 32 additions & 0 deletions
32
rewrite-java/src/test/java/org/openrewrite/java/internal/parser/data/ArrayAnnotation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2025 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.java.internal.parser.data; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) | ||
| public @interface ArrayAnnotation { | ||
| String[] emptyArray() default {}; | ||
| String[] singleElement() default {"single"}; | ||
| String[] strings() default {"one", "two", "three"}; | ||
| int[] ints() default {1, 2, 3}; | ||
| Class<?>[] classes() default {String.class, Integer.class}; | ||
| BasicAnnotation[] annotations() default {@BasicAnnotation, @BasicAnnotation(intValue = 100)}; | ||
| } | ||
|
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
|
||
34 changes: 34 additions & 0 deletions
34
rewrite-java/src/test/java/org/openrewrite/java/internal/parser/data/BasicAnnotation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2025 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.java.internal.parser.data; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) | ||
| public @interface BasicAnnotation { | ||
| int intValue() default 42; | ||
| long longValue() default Long.MAX_VALUE; | ||
| float floatValue() default 3.14f; | ||
| double doubleValue() default Math.PI; | ||
| boolean boolValue() default true; | ||
| char charValue() default 'X'; | ||
| byte byteValue() default 8; | ||
| short shortValue() default 16; | ||
| } | ||
|
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
|
||
30 changes: 30 additions & 0 deletions
30
rewrite-java/src/test/java/org/openrewrite/java/internal/parser/data/ClassRefAnnotation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2025 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.java.internal.parser.data; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) | ||
| public @interface ClassRefAnnotation { | ||
| Class<?> value() default String.class; | ||
| Class<?> primitive() default int.class; | ||
| Class<?> array() default byte[].class; | ||
| Class<?> innerClass() default Thread.State.class; | ||
| } | ||
|
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
knutwannheden marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.