Skip to content

Add Support of Parsing Runtime Invisible Annotations to Classfile Parser #6731

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 1 commit into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,24 @@ object StdNames {
final val bridgeAnnot: N = "bridge"

// Classfile Attributes
final val AnnotationDefaultATTR: N = "AnnotationDefault"
final val BridgeATTR: N = "Bridge"
final val ClassfileAnnotationATTR: N = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS. Currently not used (Apr 2009).
final val CodeATTR: N = "Code"
final val ConstantValueATTR: N = "ConstantValue"
final val DeprecatedATTR: N = "Deprecated"
final val ExceptionsATTR: N = "Exceptions"
final val InnerClassesATTR: N = "InnerClasses"
final val LineNumberTableATTR: N = "LineNumberTable"
final val LocalVariableTableATTR: N = "LocalVariableTable"
final val RuntimeAnnotationATTR: N = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME
final val RuntimeParamAnnotationATTR: N = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
final val ScalaATTR: N = "Scala"
final val ScalaSignatureATTR: N = "ScalaSig"
final val TASTYATTR: N = "TASTY"
final val SignatureATTR: N = "Signature"
final val SourceFileATTR: N = "SourceFile"
final val SyntheticATTR: N = "Synthetic"
final val AnnotationDefaultATTR: N = "AnnotationDefault"
final val BridgeATTR: N = "Bridge"
final val CodeATTR: N = "Code"
final val ConstantValueATTR: N = "ConstantValue"
final val DeprecatedATTR: N = "Deprecated"
final val ExceptionsATTR: N = "Exceptions"
final val InnerClassesATTR: N = "InnerClasses"
final val LineNumberTableATTR: N = "LineNumberTable"
final val LocalVariableTableATTR: N = "LocalVariableTable"
final val RuntimeVisibleAnnotationATTR: N = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME
final val RuntimeInvisibleAnnotationATTR: N = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS
final val RuntimeParamAnnotationATTR: N = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
final val ScalaATTR: N = "Scala"
final val ScalaSignatureATTR: N = "ScalaSig"
final val TASTYATTR: N = "TASTY"
final val SignatureATTR: N = "Signature"
final val SourceFileATTR: N = "SourceFile"
final val SyntheticATTR: N = "Synthetic"


// ----- Term names -----------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,14 @@ class ClassfileParser(
case tpnme.AnnotationDefaultATTR =>
sym.addAnnotation(Annotation(defn.AnnotationDefaultAnnot, Nil))
// Java annotations on classes / methods / fields with RetentionPolicy.RUNTIME
case tpnme.RuntimeAnnotationATTR =>
case tpnme.RuntimeVisibleAnnotationATTR
| tpnme.RuntimeInvisibleAnnotationATTR =>
parseAnnotations(attrLen)

// TODO 1: parse runtime visible annotations on parameters
// case tpnme.RuntimeParamAnnotationATTR

// TODO 2: also parse RuntimeInvisibleAnnotation / RuntimeInvisibleParamAnnotation,
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

No good reason that I'm aware of. I agree we should parse these and give then StaticAnnotation parent.

// TODO 2: also parse RuntimeInvisibleParamAnnotation
// i.e. java annotations with RetentionPolicy.CLASS?

case tpnme.ExceptionsATTR =>
Expand Down Expand Up @@ -852,7 +853,7 @@ class ClassfileParser(
return Some(NoEmbedded)
}

if (scan(tpnme.RuntimeAnnotationATTR)) {
if (scan(tpnme.RuntimeVisibleAnnotationATTR) || scan(tpnme.RuntimeInvisibleAnnotationATTR)) {
val attrLen = in.nextInt
val nAnnots = in.nextChar
var i = 0
Expand Down