Skip to content
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

Parse native in Java bytecode as @native #16232

Merged
merged 2 commits into from
Oct 24, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ class ClassfileParser(
def complete(denot: SymDenotation)(using Context): Unit = {
val sym = denot.symbol
val isEnum = (jflags & JAVA_ACC_ENUM) != 0
val isNative = (jflags & JAVA_ACC_NATIVE) != 0
val isTransient = (jflags & JAVA_ACC_TRANSIENT) != 0
val isVolatile = (jflags & JAVA_ACC_VOLATILE) != 0
val isConstructor = name eq nme.CONSTRUCTOR

/** Strip leading outer param from constructor and trailing access tag for
Expand Down Expand Up @@ -313,6 +316,12 @@ class ClassfileParser(
val isVarargs = denot.is(Flags.Method) && (jflags & JAVA_ACC_VARARGS) != 0
denot.info = sigToType(sig, isVarargs = isVarargs)
if (isConstructor) normalizeConstructorParams()
if isNative then
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.NativeAnnot)(New(defn.NativeAnnot.typeRef, Nil))
if isTransient then
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.TransientAnnot)(New(defn.TransientAnnot.typeRef, Nil))
if isVolatile then
attrCompleter.annotations ::= Annotation.deferredSymAndTree(defn.VolatileAnnot)(New(defn.VolatileAnnot.typeRef, Nil))
denot.info = translateTempPoly(attrCompleter.complete(denot.info, isVarargs))
if (isConstructor) normalizeConstructorInfo()

Expand Down
6 changes: 6 additions & 0 deletions compiler/test/dotty/tools/AnnotationsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ class AnnotationsTest:
s"A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}")
}
}

@Test def hasNativeAnnot: Unit =
inCompilerContext(TestConfiguration.basicClasspath) {
val term: TermSymbol = requiredClass("java.lang.invoke.MethodHandle").requiredMethod("invokeExact")
assert(term.hasAnnotation(defn.NativeAnnot), i"${term.annotations}")
}