diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 89d8659dd4bc..80f0d98fd435 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -16,6 +16,7 @@ import NameOps._ import util.Spans.Span import util.{SourceFile, SourcePosition} import transform.SymUtils._ +import SymbolInformation.{Kind => k} import scala.jdk.CollectionConverters._ import scala.collection.mutable @@ -450,13 +451,31 @@ class ExtractSemanticDB extends Phase: props |= SymbolInformation.Property.ENUM.value props + private def symbolAccess(sym: Symbol, kind: SymbolInformation.Kind)(using Context): Access = + kind match + case k.LOCAL | k.PARAMETER | k.SELF_PARAMETER | k.TYPE_PARAMETER | k.PACKAGE | k.PACKAGE_OBJECT => + Access.Empty + case _ => + if (sym.privateWithin == NoSymbol) + if (sym.isAllOf(PrivateLocal)) PrivateThisAccess() + else if (sym.is(Private)) PrivateAccess() + else if (sym.isAllOf(ProtectedLocal)) ProtectedThisAccess() + else if (sym.is(Protected)) ProtectedAccess() + else PublicAccess() + else + val ssym = symbolName(sym.privateWithin) + if (sym.is(Protected)) ProtectedWithinAccess(ssym) + else PrivateWithinAccess(ssym) + private def symbolInfo(sym: Symbol, symbolName: String, symkinds: Set[SymbolKind])(using Context): SymbolInformation = + val kind = symbolKind(sym, symkinds) SymbolInformation( symbol = symbolName, language = Language.SCALA, - kind = symbolKind(sym, symkinds), + kind = kind, properties = symbolProps(sym, symkinds), - displayName = Symbols.displaySymbol(sym) + displayName = Symbols.displaySymbol(sym), + access = symbolAccess(sym, kind), ) private def registerSymbol(sym: Symbol, symbolName: String, symkinds: Set[SymbolKind])(using Context): Unit = diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala index ce2e943ed7a1..426b4e4cd9d0 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala @@ -85,9 +85,24 @@ object Tools: case UNKNOWN_LANGUAGE | Unrecognized(_) => "unknown" end languageString + private def accessString(access: Access): String = + access match + case Access.Empty => "" + case _: PublicAccess => "" + case _: PrivateAccess => "private " + case _: ProtectedAccess => "protected " + case _: PrivateThisAccess => "private[this] " + case _: ProtectedThisAccess => "protected[this] " + case PrivateWithinAccess(ssym) => + s"private[${ssym}] " + case ProtectedWithinAccess(ssym) => + s"protected[${ssym}] " + + private def processSymbol(info: SymbolInformation)(using sb: StringBuilder): Unit = import SymbolInformation.Kind._ sb.append(info.symbol).append(" => ") + sb.append(accessString(info.access)) if info.isAbstract then sb.append("abstract ") if info.isFinal then sb.append("final ") if info.isSealed then sb.append("sealed ") diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 00ed8c849766..6149cb9895a2 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -12,12 +12,12 @@ Occurrences => 19 entries Symbols: example/Access# => class Access example/Access#``(). => primary ctor -example/Access#m1(). => method m1 -example/Access#m2(). => method m2 -example/Access#m3(). => method m3 -example/Access#m4(). => method m4 -example/Access#m5(). => method m5 -example/Access#m6(). => method m6 +example/Access#m1(). => private[this] method m1 +example/Access#m2(). => private[this] method m2 +example/Access#m3(). => private[example/Access#] method m3 +example/Access#m4(). => protected method m4 +example/Access#m5(). => protected[this] method m5 +example/Access#m6(). => protected[example/] method m6 example/Access#m7(). => method m7 Occurrences: @@ -201,12 +201,12 @@ annot/Annotations#``(). => primary ctor annot/Annotations#``().(x) => param x annot/Annotations#field. => val method field annot/Annotations#method(). => method method -annot/Annotations#x. => val method x +annot/Annotations#x. => private[this] val method x annot/B# => class B annot/B#``(). => primary ctor annot/B#``().(x) => param x annot/B#``(+1). => ctor -annot/B#x. => val method x +annot/B#x. => private[this] val method x annot/M. => final object M annot/M.m(). => macro m annot/M.m().[TT] => typeparam TT @@ -411,7 +411,7 @@ classes/C6#``().(x) => param x classes/C6#copy$default$1(). => method copy$default$1 classes/C6#copy(). => method copy classes/C6#copy().(x) => param x -classes/C6#x. => val method x +classes/C6#x. => private val method x classes/C6. => final object C6 classes/C6.apply(). => method apply classes/C6.apply().(x) => param x @@ -421,19 +421,19 @@ classes/C6.unapply().(x$1) => param x$1 classes/C7# => class C7 classes/C7#``(). => primary ctor classes/C7#``().(x) => param x -classes/C7#x. => val method x +classes/C7#x. => private[this] val method x classes/C8# => class C8 classes/C8#``(). => primary ctor classes/C8#``().(x) => param x -classes/C8#x. => val method x +classes/C8#x. => private[this] val method x classes/C9# => class C9 classes/C9#``(). => primary ctor classes/C9#``().(x) => param x -classes/C9#x(). => var method x +classes/C9#x(). => private[this] var method x classes/C10# => class C10 classes/C10#``(). => primary ctor classes/C10#``().(s) => param s -classes/C10#s. => val method s +classes/C10#s. => private[this] val method s classes/C11# => class C11 classes/C11#``(). => primary ctor classes/C11#foo(). => macro foo @@ -465,7 +465,7 @@ classes/M. => final object M classes/M.C5# => class C5 classes/M.C5#``(). => primary ctor classes/M.C5#``().(x) => param x -classes/M.C5#x. => val method x +classes/M.C5#x. => private[this] val method x classes/M.C5(). => final implicit method C5 classes/M.C5().(x) => param x classes/N. => final object N @@ -779,7 +779,7 @@ enumVal/Color#``(). => primary ctor enumVal/Color#``().(rgb) => val param rgb enumVal/Color#rgb. => val method rgb enumVal/Color. => final object Color -enumVal/Color.$values. => val method $values +enumVal/Color.$values. => private[this] val method $values enumVal/Color.Blue. => case val static enum method Blue enumVal/Color.Green. => case val static enum method Green enumVal/Color.Red. => case val static enum method Red @@ -828,9 +828,9 @@ _empty_/Enums. => final object Enums _empty_/Enums.Coin# => abstract sealed enum class Coin _empty_/Enums.Coin#``(). => primary ctor _empty_/Enums.Coin#``().(value) => param value -_empty_/Enums.Coin#value. => val method value +_empty_/Enums.Coin#value. => private[this] val method value _empty_/Enums.Coin. => final object Coin -_empty_/Enums.Coin.$values. => val method $values +_empty_/Enums.Coin.$values. => private[this] val method $values _empty_/Enums.Coin.Dime. => case val static enum method Dime _empty_/Enums.Coin.Dollar. => case val static enum method Dollar _empty_/Enums.Coin.Nickel. => case val static enum method Nickel @@ -844,10 +844,10 @@ _empty_/Enums.Coin.values(). => method values _empty_/Enums.Colour# => abstract sealed enum class Colour _empty_/Enums.Colour#``(). => primary ctor _empty_/Enums.Colour. => final object Colour -_empty_/Enums.Colour.$new(). => method $new +_empty_/Enums.Colour.$new(). => private[this] method $new _empty_/Enums.Colour.$new().($name) => param $name _empty_/Enums.Colour.$new().(_$ordinal) => param _$ordinal -_empty_/Enums.Colour.$values. => val method $values +_empty_/Enums.Colour.$values. => private[this] val method $values _empty_/Enums.Colour.Blue. => case val static enum method Blue _empty_/Enums.Colour.Green. => case val static enum method Green _empty_/Enums.Colour.Red. => case val static enum method Red @@ -859,10 +859,10 @@ _empty_/Enums.Colour.values(). => method values _empty_/Enums.Directions# => abstract sealed enum class Directions _empty_/Enums.Directions#``(). => primary ctor _empty_/Enums.Directions. => final object Directions -_empty_/Enums.Directions.$new(). => method $new +_empty_/Enums.Directions.$new(). => private[this] method $new _empty_/Enums.Directions.$new().($name) => param $name _empty_/Enums.Directions.$new().(_$ordinal) => param _$ordinal -_empty_/Enums.Directions.$values. => val method $values +_empty_/Enums.Directions.$values. => private[this] val method $values _empty_/Enums.Directions.East. => case val static enum method East _empty_/Enums.Directions.North. => case val static enum method North _empty_/Enums.Directions.South. => case val static enum method South @@ -900,17 +900,17 @@ _empty_/Enums.Maybe.None. => case val static enum method None _empty_/Enums.Maybe.fromOrdinal(). => method fromOrdinal _empty_/Enums.Maybe.fromOrdinal().(ordinal) => param ordinal _empty_/Enums.Planet# => abstract sealed enum class Planet -_empty_/Enums.Planet#G. => final val method G +_empty_/Enums.Planet#G. => private[this] final val method G _empty_/Enums.Planet#``(). => primary ctor _empty_/Enums.Planet#``().(mass) => param mass _empty_/Enums.Planet#``().(radius) => param radius -_empty_/Enums.Planet#mass. => val method mass -_empty_/Enums.Planet#radius. => val method radius +_empty_/Enums.Planet#mass. => private[this] val method mass +_empty_/Enums.Planet#radius. => private[this] val method radius _empty_/Enums.Planet#surfaceGravity(). => method surfaceGravity _empty_/Enums.Planet#surfaceWeight(). => method surfaceWeight _empty_/Enums.Planet#surfaceWeight().(otherMass) => param otherMass _empty_/Enums.Planet. => final object Planet -_empty_/Enums.Planet.$values. => val method $values +_empty_/Enums.Planet.$values. => private[this] val method $values _empty_/Enums.Planet.Earth. => case val static enum method Earth _empty_/Enums.Planet.Jupiter. => case val static enum method Jupiter _empty_/Enums.Planet.Mars. => case val static enum method Mars @@ -927,10 +927,10 @@ _empty_/Enums.Planet.values(). => method values _empty_/Enums.Suits# => abstract sealed enum class Suits _empty_/Enums.Suits#``(). => primary ctor _empty_/Enums.Suits. => final object Suits -_empty_/Enums.Suits.$new(). => method $new +_empty_/Enums.Suits.$new(). => private[this] method $new _empty_/Enums.Suits.$new().($name) => param $name _empty_/Enums.Suits.$new().(_$ordinal) => param _$ordinal -_empty_/Enums.Suits.$values. => val method $values +_empty_/Enums.Suits.$values. => private[this] val method $values _empty_/Enums.Suits.Clubs. => case val static enum method Clubs _empty_/Enums.Suits.Diamonds. => case val static enum method Diamonds _empty_/Enums.Suits.Hearts. => case val static enum method Hearts @@ -949,7 +949,7 @@ _empty_/Enums.Tag# => abstract sealed enum class Tag _empty_/Enums.Tag#[A] => typeparam A _empty_/Enums.Tag#``(). => primary ctor _empty_/Enums.Tag. => final object Tag -_empty_/Enums.Tag.$values. => val method $values +_empty_/Enums.Tag.$values. => private[this] val method $values _empty_/Enums.Tag.BooleanTag. => case val static enum method BooleanTag _empty_/Enums.Tag.IntTag. => case val static enum method IntTag _empty_/Enums.Tag.fromOrdinal(). => method fromOrdinal @@ -960,10 +960,10 @@ _empty_/Enums.Tag.values(). => method values _empty_/Enums.WeekDays# => abstract sealed enum class WeekDays _empty_/Enums.WeekDays#``(). => primary ctor _empty_/Enums.WeekDays. => final object WeekDays -_empty_/Enums.WeekDays.$new(). => method $new +_empty_/Enums.WeekDays.$new(). => private[this] method $new _empty_/Enums.WeekDays.$new().($name) => param $name _empty_/Enums.WeekDays.$new().(_$ordinal) => param _$ordinal -_empty_/Enums.WeekDays.$values. => val method $values +_empty_/Enums.WeekDays.$values. => private[this] val method $values _empty_/Enums.WeekDays.Friday. => case val static enum method Friday _empty_/Enums.WeekDays.Monday. => case val static enum method Monday _empty_/Enums.WeekDays.Saturday. => case val static enum method Saturday @@ -1568,7 +1568,7 @@ example/ImplicitConversion.newAny2stringadd#`+`(). => method + example/ImplicitConversion.newAny2stringadd#`+`().(other) => param other example/ImplicitConversion.newAny2stringadd#``(). => primary ctor example/ImplicitConversion.newAny2stringadd#``().(self) => param self -example/ImplicitConversion.newAny2stringadd#self. => val method self +example/ImplicitConversion.newAny2stringadd#self. => private val method self example/ImplicitConversion.newAny2stringadd(). => final implicit method newAny2stringadd example/ImplicitConversion.newAny2stringadd().(self) => param self example/ImplicitConversion.newAny2stringadd().[A] => typeparam A @@ -1769,7 +1769,7 @@ givens/InventedNames$package.given_Y# => class given_Y givens/InventedNames$package.given_Y#``(). => primary ctor givens/InventedNames$package.given_Y#``().(x$1) => implicit val param x$1 givens/InventedNames$package.given_Y#doY(). => method doY -givens/InventedNames$package.given_Y#x$1. => implicit val method x$1 +givens/InventedNames$package.given_Y#x$1. => protected implicit val method x$1 givens/InventedNames$package.given_Y(). => final implicit method given_Y givens/InventedNames$package.given_Y().(x$1) => implicit param x$1 givens/InventedNames$package.given_Z_T# => class given_Z_T @@ -3179,7 +3179,7 @@ Symbols: example/ValUsages. => final object ValUsages example/ValUsages.v. => val method v example/Vals# => abstract class Vals -example/Vals#_explicitSetter(). => var method _explicitSetter +example/Vals#_explicitSetter(). => private[this] var method _explicitSetter example/Vals#``(). => primary ctor example/Vals#``().(p) => param p example/Vals#``().(xp) => val param xp @@ -3198,19 +3198,19 @@ example/Vals#`yp_=`(). => var method yp_= example/Vals#`yp_=`().(x$1) => param x$1 example/Vals#explicitSetter(). => method explicitSetter example/Vals#m(). => method m -example/Vals#p. => val method p +example/Vals#p. => private[this] val method p example/Vals#xam. => abstract val method xam example/Vals#xfm. => final val method xfm example/Vals#xim. => implicit val method xim -example/Vals#xlm. => val method xlm +example/Vals#xlm. => private[this] val method xlm example/Vals#xm. => val method xm example/Vals#xp. => val method xp -example/Vals#xzlm. => lazy val method xzlm +example/Vals#xzlm. => private[this] lazy val method xzlm example/Vals#xzm. => lazy val method xzm example/Vals#yam(). => abstract var method yam example/Vals#yfm(). => final var method yfm example/Vals#yim(). => implicit var method yim -example/Vals#ylm(). => var method ylm +example/Vals#ylm(). => private[this] var method ylm example/Vals#ym(). => var method ym example/Vals#yp(). => var method yp local0 => val local xl @@ -3401,10 +3401,10 @@ exports/example/Codec#``().(decode) => param decode exports/example/Codec#``().(encode) => param encode exports/example/Codec#decode(). => final method decode exports/example/Codec#decode().(a) => param a -exports/example/Codec#decode. => val method decode +exports/example/Codec#decode. => private[this] val method decode exports/example/Codec#encode(). => final method encode exports/example/Codec#encode().(t) => param t -exports/example/Codec#encode. => val method encode +exports/example/Codec#encode. => private[this] val method encode exports/example/Decoder# => trait Decoder exports/example/Decoder#[T] => covariant typeparam T exports/example/Decoder#``(). => primary ctor @@ -3516,7 +3516,7 @@ Symbols: i9727/Test# => class Test i9727/Test#``(). => primary ctor i9727/Test#``().(a) => param a -i9727/Test#a. => val method a +i9727/Test#a. => private[this] val method a i9727/i9727$package. => final package object i9727 i9727/i9727$package.a. => val method a i9727/i9727$package.b. => val method b @@ -3777,7 +3777,7 @@ flags/p/package.AA#``().(y) => val param y flags/p/package.AA#``().(z) => var param z flags/p/package.AA#`z_=`(). => var method z_= flags/p/package.AA#`z_=`().(x$1) => param x$1 -flags/p/package.AA#x. => val method x +flags/p/package.AA#x. => private[this] val method x flags/p/package.AA#y. => val method y flags/p/package.AA#z(). => var method z flags/p/package.C# => abstract class C @@ -3792,9 +3792,9 @@ flags/p/package.C#``(+1). => ctor flags/p/package.C#``(+2). => ctor flags/p/package.C#``(+2).(t) => param t flags/p/package.C#w(). => abstract method w -flags/p/package.C#x. => val method x -flags/p/package.C#y. => val method y -flags/p/package.C#z. => val method z +flags/p/package.C#x. => private[this] val method x +flags/p/package.C#y. => private[this] val method y +flags/p/package.C#z. => private[this] val method z flags/p/package.S# => class S flags/p/package.S#[T] => typeparam T flags/p/package.S#``(). => primary ctor @@ -3808,13 +3808,13 @@ flags/p/package.Y# => final class Y flags/p/package.Y#``(). => primary ctor flags/p/package.Z# => sealed trait Z flags/p/package.Z#``(). => primary ctor -flags/p/package.`y_=`(). => var method y_= +flags/p/package.`y_=`(). => protected var method y_= flags/p/package.`y_=`().(x$1) => param x$1 flags/p/package.m(). => macro m flags/p/package.m().[TT] => typeparam TT -flags/p/package.x. => lazy val method x +flags/p/package.x. => private[flags/p/] lazy val method x flags/p/package.xs1. => val method xs1 -flags/p/package.y(). => implicit var method y +flags/p/package.y(). => protected implicit var method y flags/p/package.z(). => method z flags/p/package.z().(pp) => param pp local0 => val local xs2 @@ -4053,7 +4053,7 @@ types/ann# => class ann types/ann#[T] => typeparam T types/ann#``(). => primary ctor types/ann#``().(x) => param x -types/ann#x. => val method x +types/ann#x. => private[this] val method x types/ann1# => class ann1 types/ann1#``(). => primary ctor types/ann2# => class ann2