Skip to content

Commit 7652a2f

Browse files
Merge pull request #5435 from poechsel/tasty-to-semanticdb
Addition to TASTy reflect to semantic DB
2 parents 052c3b1 + 4373c10 commit 7652a2f

38 files changed

+1259
-24
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ val `dotty-language-server` = Build.`dotty-language-server`
1313
val `dotty-bench` = Build.`dotty-bench`
1414
val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped`
1515
val `dotty-semanticdb` = Build.`dotty-semanticdb`
16+
val `dotty-semanticdb-input` = Build.`dotty-semanticdb-input`
1617
val `scala-library` = Build.`scala-library`
1718
val `scala-compiler` = Build.`scala-compiler`
1819
val `scala-reflect` = Build.`scala-reflect`

compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
66
def start: Int = pos.start
77
def end: Int = pos.end
88

9+
def exists: Boolean = pos.exists
10+
911
def sourceFile: java.nio.file.Path = pos.source.file.jpath
1012

1113
def startLine: Int = pos.startLine
@@ -14,5 +16,4 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
1416
def startColumn: Int = pos.startColumn
1517
def endColumn: Int = pos.endColumn
1618
}
17-
1819
}

compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
2626
def name(implicit ctx: Context): String = symbol.name.toString
2727
def fullName(implicit ctx: Context): String = symbol.fullName.toString
2828

29+
def pos(implicit ctx: Context): Position = symbol.pos
30+
2931
def owner(implicit ctx: Context): Symbol = symbol.owner
3032

3133
def localContext(implicit ctx: Context): Context = {

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
1818

1919
def TypeTreeDeco(tpt: TypeTree): TypeTreeAPI = new TypeTreeAPI {
2020
def pos(implicit ctx: Context): Position = tpt.pos
21-
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
2221
def symbol(implicit ctx: Context): Symbol = tpt.symbol
22+
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
2323
}
2424

2525
object IsTypeTree extends IsTypeTreeExtractor {

library/src/scala/tasty/reflect/PositionOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ trait PositionOps extends Core {
44

55
trait PositionAPI {
66

7-
/** The path of source file */
7+
def exists: Boolean
8+
89
def sourceFile: java.nio.file.Path
910

1011
/** The start index in the source file */

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ trait SymbolOps extends Core {
2626
/** The full name of this symbol up to the root package. */
2727
def fullName(implicit ctx: Context): String
2828

29-
/** Returns the context within this symbol. */
29+
def pos(implicit ctx: Context): Position
30+
3031
def localContext(implicit ctx: Context): Context
3132

3233
/** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safly check and cast to PackageSymbol */

library/src/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ trait TreeUtils
104104
case TypeTree.Block(typedefs, tpt) => foldTypeTree(foldTrees(x, typedefs), tpt)
105105
case TypeTree.MatchType(boundopt, selector, cases) =>
106106
foldTypeCaseDefs(foldTypeTree(boundopt.fold(x)(foldTypeTree(x, _)), selector), cases)
107+
case SyntheticBounds() => x
107108
case TypeBoundsTree(lo, hi) => foldTypeTree(foldTypeTree(x, lo), hi)
108109
}
109110

library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ trait TypeOrBoundsTreeOps extends Core {
2828
val TypeTree: TypeTreeModule
2929
abstract class TypeTreeModule extends TypeTreeCoreModule {
3030

31+
3132
/** TypeTree containing an inferred type */
3233
val Synthetic: SyntheticExtractor
3334
abstract class SyntheticExtractor {

project/Build.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ object Build {
393393
baseDirectory in Test := baseDirectory.value / "..",
394394
unmanagedSourceDirectories in Test += baseDirectory.value / "input" / "src" / "main" / "scala",
395395
libraryDependencies ++= List(
396-
("org.scalameta" %% "semanticdb" % "4.0.0" % Test).withDottyCompat(scalaVersion.value),
397-
"com.novocode" % "junit-interface" % "0.11" % Test,
398-
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % Test
396+
("org.scalameta" %% "semanticdb" % "4.0.0").withDottyCompat(scalaVersion.value),
397+
"com.novocode" % "junit-interface" % "0.11",
398+
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0"
399399
)
400400
)
401401

@@ -919,6 +919,11 @@ object Build {
919919
lazy val `dotty-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)
920920

921921
lazy val `dotty-semanticdb` = project.in(file("semanticdb")).asDottySemanticdb(Bootstrapped)
922+
lazy val `dotty-semanticdb-input` = project.in(file("semanticdb/input")).settings(
923+
scalaVersion := "2.12.7",
924+
scalacOptions += "-Yrangepos",
925+
addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "4.0.0" cross CrossVersion.full)
926+
)
922927

923928
// Depend on dotty-library so that sbt projects using dotty automatically
924929
// depend on the dotty-library
@@ -1317,6 +1322,7 @@ object Build {
13171322
enablePlugins(JmhPlugin)
13181323

13191324
def asDottySemanticdb(implicit mode: Mode): Project = project.withCommonSettings.
1325+
aggregate(`dotty-semanticdb-input`).
13201326
dependsOn(dottyCompiler).
13211327
settings(semanticdbSettings)
13221328

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example
2+
3+
class Access {
4+
private def m1 = ???
5+
private[this] def m2 = ???
6+
private[Access] def m3 = ???
7+
protected def m4 = ???
8+
protected[this] def m5 = ???
9+
protected[example] def m6 = ???
10+
def m7 = ???
11+
}

0 commit comments

Comments
 (0)