Skip to content

Conversation

knutwannheden
Copy link
Contributor

@knutwannheden knutwannheden commented May 22, 2025

This PR enhances the TypeTable infrastructure to support all three types of Java annotations (element, parameter, and
type annotations) as well as annotation attribute default values and compile-time constant values for static final fields. The TypeTable now provides complete type information including annotations, enabling more sophisticated type analysis and transformation capabilities.

Key Changes

  1. Complete Annotation Support 📝
  • Added support for (runtime-invisible and -visible) annotations (CLASS and RUNTIME retention)
  • Added support for parameter annotations on method parameters
  • Added support for type annotations (TYPE_USE) on type references
  • Added support for annotation default values in annotation types
  • Added support for field compile-time constant values (e.g., 10 + 20 * 2 stored as 50)
  1. Updated TypeTable.Reader API 🔧
  • Introduced TypeTable.Reader.Options with builder pattern for extensible configuration
  • Added read() method that accepts Options for flexible reading
  1. Format Migration 🔄
  • Changed default resource from .tsv.zip to .tsv.gz for better compression
  • Maintained backward compatibility for reading existing type tables
  • Automatic handling of both compressed formats

Why This Change?

For parser use cases, having access to both annotation default values and static final field constants is essential for proper type attribution. This change ensures complete information about types is preserved in the TypeTable without requiring access to source files or full classpath resolution.

Technical Details

The implementation cleanly separates:

  • TSV Storage: Preserves all compile-time constant and annotation default information
  • Bytecode Generation: Follows JVM specifications for both annotation defaults and field ConstantValue attributes
  • Serialization: Handles complex nested structures with proper escaping

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-java/src/main/java/org/openrewrite/java/internal/parser/TypeTable.java
    • lines 402-402
  • rewrite-java/src/test/java/org/openrewrite/java/internal/parser/TypeTableTest.java
    • lines 805-805
    • lines 813-815
  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-java/src/main/java/org/openrewrite/java/internal/parser/TypeTable.java
    • lines 402-402
  • rewrite-java/src/test/java/org/openrewrite/java/internal/parser/TypeTableTest.java
    • lines 805-805
    • lines 813-815
  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleDependencyConfiguration.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleDependencyConfiguration.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleDependencyConfiguration.java
    • lines 26-26

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • rewrite-gradle/src/main/java/org/openrewrite/gradle/marker/GradleDependencyConfiguration.java
    • lines 26-26

@knutwannheden knutwannheden merged commit ebf8f8e into main Aug 14, 2025
2 checks passed
@knutwannheden knutwannheden deleted the type-table-annotations branch August 14, 2025 12:37
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Aug 14, 2025
dcsekar pushed a commit to dcsekar/rewrite that referenced this pull request Aug 18, 2025
* Add support for annotations to `TypeTable`

* Some cleanups

* Some more cleanups

* More cleanups

* Support annotation member default values

* Corrections

* More corrections

* Escape more characters in strings

* Refactor

* More elaborate tests

* Remove test

* Fix failing tests

* Unify serialization format

* Polish

* Another test

* Cleanups

* Fixes

* Also write field constants to TSV

* Add some missing newlines

* Polish tests

* Revert some accidental changes

* Remove stdout print from test

* Some more corrections

* Replace rewrite-gradle type table

* Fix problem with enum constants in TSV

* Polish tests

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Polish tests

* Add one more test case

* More proper parsing

* Some more polishing

* Some more polishing

* Revert "Some more polishing"

This reverts commit f89af6c.

* Some more polishing

* Fix merge errors

* Align annotation format with `javap` output

* Include runtime invisible annotations

* Parameter and type annotations

* Fixes

* More fixes

* Formatting fixes

* Only escape pipes where required

* Polish

* Fix bug after format change

* Update type table

* Add TypeTable.Reader#read() overload

* Add TypeTable.Reader.Options

* Simplify processing of type annotations

* Update Gradle type table

* Polish

* Revert `JavaParser` changes

* Restore original type table for rewrite-gradle

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Include annotation type element default value in type tables
2 participants