Skip to content

Commit d9648b3

Browse files
committed
Also parse transient/volatile & test
1 parent a5c49c6 commit d9648b3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ class ClassfileParser(
276276
val sym = denot.symbol
277277
val isEnum = (jflags & JAVA_ACC_ENUM) != 0
278278
val isNative = (jflags & JAVA_ACC_NATIVE) != 0
279+
val isTransient = (jflags & JAVA_ACC_TRANSIENT) != 0
280+
val isVolatile = (jflags & JAVA_ACC_VOLATILE) != 0
279281
val isConstructor = name eq nme.CONSTRUCTOR
280282

281283
/** Strip leading outer param from constructor and trailing access tag for
@@ -315,9 +317,11 @@ class ClassfileParser(
315317
denot.info = sigToType(sig, isVarargs = isVarargs)
316318
if (isConstructor) normalizeConstructorParams()
317319
if isNative then
318-
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.NativeAnnot) {
319-
New(defn.NativeAnnot.typeRef, Nil)
320-
}
320+
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.NativeAnnot)(New(defn.NativeAnnot.typeRef, Nil))
321+
if isTransient then
322+
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.TransientAnnot)(New(defn.TransientAnnot.typeRef, Nil))
323+
if isVolatile then
324+
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.VolatileAnnot)(New(defn.VolatileAnnot.typeRef, Nil))
321325
denot.info = translateTempPoly(attrCompleter.complete(denot.info, isVarargs))
322326
if (isConstructor) normalizeConstructorInfo()
323327

compiler/test/dotty/tools/AnnotationsTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ class AnnotationsTest:
8989
s"A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}")
9090
}
9191
}
92+
93+
@Test def hasNativeAnnot: Unit =
94+
inCompilerContext(TestConfiguration.basicClasspath) {
95+
val term: TermSymbol = requiredClass("java.lang.invoke.MethodHandle").requiredMethod("invokeExact")
96+
assert(term.hasAnnotation(defn.NativeAnnot), i"${term.annotations}")
97+
}

0 commit comments

Comments
 (0)