Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-4788 Respect RetentionPolicy of Java annotations
Also closes SI-5420 and SI-5948.
- Loading branch information
Showing
13 changed files
with
155 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,48 @@ | ||
/* NSC -- new Scala compiler | ||
* Copyright 2005-2013 LAMP/EPFL | ||
* @author Jason Zaugg | ||
*/ | ||
|
||
package scala.tools.nsc | ||
package backend.jvm | ||
import scala.tools.nsc.symtab._ | ||
|
||
trait GenCommon extends BytecodeWriters { | ||
import global._ | ||
import definitions.{ AnnotationRetentionAttr, AnnotationRetentionPolicyAttr, ClassfileAnnotationClass } | ||
|
||
// ----------------------------------------------------------------------------------------- | ||
// Static forwarders (related to mirror classes but also present in | ||
// a plain class lacking companion module, for details see `isCandidateForForwarders`). | ||
// ----------------------------------------------------------------------------------------- | ||
val ExcludedForwarderFlags = { | ||
import Flags._ | ||
// Should include DEFERRED but this breaks findMember. | ||
(SPECIALIZED | LIFTED | PROTECTED | STATIC | EXPANDEDNAME | BridgeAndPrivateFlags | MACRO) | ||
} | ||
|
||
lazy val AnnotationRetentionPolicyModule = AnnotationRetentionPolicyAttr.companionModule | ||
lazy val AnnotationRetentionPolicySourceValue = AnnotationRetentionPolicyModule.tpe.member(TermName("SOURCE")) | ||
lazy val AnnotationRetentionPolicyClassValue = AnnotationRetentionPolicyModule.tpe.member(TermName("CLASS")) | ||
lazy val AnnotationRetentionPolicyRuntimeValue = AnnotationRetentionPolicyModule.tpe.member(TermName("RUNTIME")) | ||
|
||
/** | ||
* Whether an annotation should be emitted as a Java annotation | ||
* .initialize: if 'annot' is read from pickle, atp might be un-initialized | ||
*/ | ||
def shouldEmitAnnotation(annot: AnnotationInfo) = | ||
annot.symbol.initialize.isJavaDefined && | ||
annot.matches(ClassfileAnnotationClass) && | ||
retentionPolicyOf(annot) != AnnotationRetentionPolicySourceValue && | ||
annot.args.isEmpty | ||
|
||
def isRuntimeVisible(annot: AnnotationInfo): Boolean = | ||
annot.atp.getAnnotation(AnnotationRetentionAttr) | ||
.exists(_.assocs.contains((nme.value -> LiteralAnnotArg(Constant(AnnotationRetentionPolicyRuntimeValue))))) | ||
|
||
def retentionPolicyOf(annot: AnnotationInfo): Symbol = | ||
annot.atp.getAnnotation(AnnotationRetentionAttr).map(_.assocs).map(assoc => | ||
assoc.collectFirst { | ||
case (`nme`.value, LiteralAnnotArg(Constant(value: Symbol))) => value | ||
}.getOrElse(AnnotationRetentionPolicyClassValue)).getOrElse(AnnotationRetentionPolicyClassValue) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,4 @@ | ||
warning: there were 1 deprecation warning(s); re-run with -deprecation for details | ||
None | ||
Some(@Ljavax/jws/soap/InitParam;(name="", value="") // invisible) | ||
Some(@Ljavax/xml/ws/Action;()) |
This file contains 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,2 @@ | ||
@javax.jws.soap.InitParam(name="", value="") // RetentionPolicy.CLASS | ||
class C |
This file contains 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,2 @@ | ||
@javax.xml.ws.Action // RetentionPolicy.RUNTIME | ||
class R |
This file contains 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,2 @@ | ||
@javax.annotation.Generated(Array("")) // RetentionPolicy.SOURCE | ||
class S |
Oops, something went wrong.
165da8d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job pr-scala failed for 165da8d Took 24 min. (ping @soc) (results):
To retry exactly this commit, comment "PLS REBUILD/pr-scala@165da8da557ae77bf8d6a30fb57d49868109d1aa" on PR 3459.
NOTE: New commits are rebuilt automatically as they appear. A forced rebuild is only necessary for transient failures.