@@ -67,7 +67,7 @@ abstract class AccessProxies {
67
67
import ast .tpd ._
68
68
69
69
/** The name of the accessor for definition with given `name` in given `site` */
70
- def accessorNameOf (name : TermName , site : Symbol )(using Context ): TermName
70
+ def accessorNameOf (name : TermName , site : Symbol , isStatic : Boolean )(using Context ): TermName
71
71
def needsAccessor (sym : Symbol )(using Context ): Boolean
72
72
73
73
def ifNoHost (reference : RefTree )(using Context ): Tree = {
@@ -76,20 +76,21 @@ abstract class AccessProxies {
76
76
}
77
77
78
78
/** A fresh accessor symbol */
79
- private def newAccessorSymbol (owner : Symbol , name : TermName , info : Type , accessed : Symbol )(using Context ): TermSymbol = {
79
+ private def newAccessorSymbol (owner : Symbol , name : TermName , info : Type , accessed : Symbol , isStatic : Boolean )(using Context ): TermSymbol = {
80
80
val sym = newSymbol(owner, name, Synthetic | Method , info, coord = accessed.span).entered
81
81
if accessed.is(Private ) then sym.setFlag(Final )
82
+ if isStatic then sym.setFlag(JavaStaticTerm )
82
83
else if sym.allOverriddenSymbols.exists(! _.is(Deferred )) then sym.setFlag(Override )
83
84
if accessed.hasAnnotation(defn.ExperimentalAnnot ) then
84
85
sym.addAnnotation(defn.ExperimentalAnnot )
85
86
sym
86
87
}
87
88
88
89
/** An accessor symbol, create a fresh one unless one exists already */
89
- protected def accessorSymbol (owner : Symbol , accessorName : TermName , accessorInfo : Type , accessed : Symbol )(using Context ): Symbol = {
90
+ protected def accessorSymbol (owner : Symbol , accessorName : TermName , accessorInfo : Type , accessed : Symbol , isStatic : Boolean = false )(using Context ): Symbol = {
90
91
def refersToAccessed (sym : Symbol ) = accessedBy.get(sym).contains(accessed)
91
92
owner.info.decl(accessorName).suchThat(refersToAccessed).symbol.orElse {
92
- val acc = newAccessorSymbol(owner, accessorName, accessorInfo, accessed)
93
+ val acc = newAccessorSymbol(owner, accessorName, accessorInfo, accessed, isStatic )
93
94
accessedBy(acc) = accessed
94
95
acc
95
96
}
@@ -127,16 +128,17 @@ abstract class AccessProxies {
127
128
/** Create an accessor unless one exists already, and replace the original
128
129
* access with a reference to the accessor.
129
130
*
130
- * @param reference The original reference to the non-public symbol
131
- * @param onLHS The reference is on the left-hand side of an assignment
131
+ * @param reference The original reference to the non-public symbol
132
+ * @param accessorClass Class where the accessor will be generated
133
+ * @param isStatic If this accessor will become a java static method
132
134
*/
133
- def useAccessor (reference : RefTree , accessorClass : Symbol )(using Context ): Tree = {
135
+ def useAccessor (reference : RefTree , accessorClass : Symbol , isStatic : Boolean = false )(using Context ): Tree = {
134
136
val accessed = reference.symbol.asTerm
135
137
if (accessorClass.exists) {
136
- val accessorName = accessorNameOf(accessed.name, accessorClass)
138
+ val accessorName = accessorNameOf(accessed.name, accessorClass, isStatic )
137
139
val accessorInfo =
138
140
accessed.info.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner)
139
- val accessor = accessorSymbol(accessorClass, accessorName, accessorInfo, accessed)
141
+ val accessor = accessorSymbol(accessorClass, accessorName, accessorInfo, accessed, isStatic )
140
142
rewire(reference, accessor)
141
143
}
142
144
else ifNoHost(reference)
0 commit comments