Skip to content

SemanticDB generator #5761

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

Merged
merged 42 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3e7af5c
Add local symbol handling
poechsel Nov 25, 2018
c944b5e
Refactore symbol creation for type, add tests
poechsel Nov 26, 2018
77c141e
Port logic from semanticdb
poechsel Nov 26, 2018
863544f
fix wildcard issue
poechsel Nov 27, 2018
eb580a3
fix package path printing
poechsel Nov 28, 2018
71b9e3a
Add examples & add missing case for typetrees
poechsel Nov 28, 2018
35cfbd7
improvements on parametric class definition. Bugfix in TreeUtils
poechsel Nov 30, 2018
a63dde5
adjustement for init symbol in class definition
poechsel Dec 4, 2018
9943ade
avoid generating init symbol for objects
poechsel Dec 9, 2018
a3ceec2
self symbols
poechsel Dec 9, 2018
44d4cce
Add support for pattern bind
poechsel Dec 9, 2018
7757bf6
improve class def & deal with default arguments
poechsel Dec 10, 2018
4a68508
improve position for self symbols
poechsel Dec 10, 2018
0d460cb
Implement case class and case object
poechsel Dec 10, 2018
70fc3b6
fix several bugs
poechsel Dec 10, 2018
88871af
Add missing test file
poechsel Dec 10, 2018
7ae6c6e
Fix issue with non jvm compatible characters
poechsel Dec 11, 2018
5160763
improve 'isUserCreated' for typetrees
poechsel Dec 11, 2018
051c726
clean up
poechsel Dec 11, 2018
db2e922
Support locally, implicitly. Assert are experimental
poechsel Dec 11, 2018
f11c8ff
do not register compiler generated definitions
poechsel Dec 26, 2018
863cf1d
fix case class definitions
poechsel Dec 27, 2018
6a5d6f0
Compile semanticdb tests using -Yno-inline
poechsel Jan 10, 2019
c81c79c
Add basic cli for semanticdb
poechsel Jan 12, 2019
6361419
Make semanticdb cli able to generate a semanticdb file for a given sc…
poechsel Jan 13, 2019
5617e3e
bump scala version in semanticdb tests
poechsel Jan 13, 2019
4f2a5ff
semanticdb tests use new utils class functions
poechsel Jan 14, 2019
98ff433
Bug fixes on types, this overloading and super statement
poechsel Jan 15, 2019
8a83849
Handle correct positions of reversed binary operators (eg #::)
poechsel Jan 16, 2019
30257de
Improvement on class constructor handling
poechsel Jan 18, 2019
1b58468
Infer var setter usage when assigning value to a var
poechsel Jan 19, 2019
25a0fd1
fix bug with var definition and protected[this] var and vals
poechsel Jan 19, 2019
9071531
improve testing infrastructure and fix small bugs
poechsel Jan 20, 2019
44c055c
Improve test infrastructure and fix build errors:
poechsel Jan 20, 2019
fe9df6f
Refactor onfly source code parsing and clean up ranges creation
poechsel Jan 21, 2019
83b0246
Add documentation
poechsel Jan 21, 2019
df71b4a
Implement nested multiline comments for pseudo parsing
poechsel Jan 22, 2019
d9e5270
Add documentation about new flags
poechsel Jan 23, 2019
055e732
add new flags to showFlags
poechsel Jan 23, 2019
2029173
Fix bug with java class not recorded as types
poechsel Jan 24, 2019
9f708d8
Add comment to distinguish between scala(s semanticdb imported method…
poechsel Jan 30, 2019
4abf222
Replace Flags.Stable by Flags.StableRealizable in semanticdbconsumer
poechsel Jan 30, 2019
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
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
def StableRealizable: Flags = core.Flags.StableRealizable
def Param: Flags = core.Flags.Param
def ParamAccessor: Flags = core.Flags.ParamAccessor
def Enum: Flags = core.Flags.Enum
def ModuleClass: Flags = core.Flags.ModuleClass
def PrivateLocal: Flags = core.Flags.PrivateLocal
def Package: Flags = core.Flags.Package
def ImplClass: Flags = core.Flags.ImplClass
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dotty.tools.dotc.tastyreflect

import dotty.tools.dotc.ast.{Trees, untpd}
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Decorators._

trait ImportSelectorOpsImpl extends scala.tasty.reflect.ImportSelectorOps with CoreImpl {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with CoreImpl {
def PatternDeco(pattern: Pattern): PatternAPI = new PatternAPI {
def pos(implicit ctx: Context): Position = pattern.sourcePos
def tpe(implicit ctx: Context): Type = pattern.tpe.stripTypeVar
def symbol(implicit ctx: Context): Symbol = pattern.symbol
}

object Pattern extends PatternModule {
Expand Down
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {

def owner(implicit ctx: Context): Symbol = symbol.owner

def isLocalDummy(implicit ctx: Context): Boolean = symbol.isLocalDummy
def isRefinementClass(implicit ctx: Context): Boolean = symbol.isRefinementClass
def isAliasType(implicit ctx: Context): Boolean = symbol.isAliasType
def isAnonymousClass(implicit ctx: Context): Boolean = symbol.isAnonymousClass
def isAnonymousFunction(implicit ctx: Context): Boolean = symbol.isAnonymousFunction
def isAbstractType(implicit ctx: Context): Boolean = symbol.isAbstractType
def isClassConstructor(implicit ctx: Context): Boolean = symbol.isClassConstructor

def localContext(implicit ctx: Context): Context = {
if (symbol.exists) ctx.withOwner(symbol)
else ctx
Expand Down Expand Up @@ -167,6 +175,11 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
if (sym.exists) Some(sym.asTerm) else None
}

def moduleClass(implicit ctx: Context): Option[Symbol] = {
val sym = symbol.moduleClass
if (sym.exists) Some(sym.asTerm) else None
}

private def isField(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && !sym.is(Flags.Method)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI

def classSymbol(implicit ctx: Context): Option[ClassSymbol] =
if (tpe.classSymbol.exists) Some(tpe.classSymbol.asClass) else None

def typeSymbol(implicit ctx: Context): Symbol = tpe.typeSymbol
}

def ConstantTypeDeco(x: ConstantType): Type.ConstantTypeAPI = new Type.ConstantTypeAPI {
Expand Down
15 changes: 15 additions & 0 deletions library/src/scala/tasty/reflect/FlagsOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ trait FlagsOps extends Core {

/** Is this symbol a parameter accessor */
def ParamAccessor: Flags

/** Is this symbol an enum */
def Enum: Flags

/** Is this symbol a module class */
def ModuleClass: Flags

/** Is this symbol labeled private[this] */
def PrivateLocal: Flags

/** Is this symbol a package */
def Package: Flags

/** Is this symbol an implementation class of a Scala2 trait */
def ImplClass: Flags
}

}
2 changes: 2 additions & 0 deletions library/src/scala/tasty/reflect/PatternOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ trait PatternOps extends Core {
def pos(implicit ctx: Context): Position

def tpe(implicit ctx: Context): Type

def symbol(implicit ctx: Context): Symbol
}
implicit def PatternDeco(pattern: Pattern): PatternAPI

Expand Down
10 changes: 10 additions & 0 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ trait Printers
if (flags.is(Flags.StableRealizable)) flagList += "Flags.StableRealizable"
if (flags.is(Flags.Param)) flagList += "Flags.Param"
if (flags.is(Flags.ParamAccessor)) flagList += "Flags.ParamAccessor"
if (flags.is(Flags.Enum)) flagList += "Flags.Enum"
if (flags.is(Flags.ModuleClass)) flagList += "Flags.ModuleClass"
if (flags.is(Flags.PrivateLocal)) flagList += "Flags.PrivateLocal"
if (flags.is(Flags.Package)) flagList += "Flags.Package"
if (flags.is(Flags.ImplClass)) flagList += "Flags.ImplClass"
flagList.result().mkString(" | ")
}

Expand Down Expand Up @@ -504,6 +509,11 @@ trait Printers
if (flags.is(Flags.StableRealizable)) flagList += "stableRealizable"
if (flags.is(Flags.Param)) flagList += "param"
if (flags.is(Flags.ParamAccessor)) flagList += "paramAccessor"
if (flags.is(Flags.Enum)) flagList += "enum"
if (flags.is(Flags.ModuleClass)) flagList += "moduleClass"
if (flags.is(Flags.PrivateLocal)) flagList += "private[this]"
if (flags.is(Flags.Package)) flagList += "package"
if (flags.is(Flags.ImplClass)) flagList += "implClass"
flagList.result().mkString("/*", " ", "*/")
}

Expand Down
12 changes: 11 additions & 1 deletion library/src/scala/tasty/reflect/SymbolOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ trait SymbolOps extends Core {
/** Flags of this symbol */
def flags(implicit ctx: Context): Flags

def isLocalDummy(implicit ctx: Context): Boolean
def isRefinementClass(implicit ctx: Context): Boolean
def isAliasType(implicit ctx: Context): Boolean
def isAnonymousClass(implicit ctx: Context): Boolean
def isAnonymousFunction(implicit ctx: Context): Boolean
def isAbstractType(implicit ctx: Context): Boolean
def isClassConstructor(implicit ctx: Context): Boolean

/** This symbol is private within the resulting type. */
def privateWithin(implicit ctx: Context): Option[Type]

Expand All @@ -26,6 +34,7 @@ trait SymbolOps extends Core {
/** The full name of this symbol up to the root package. */
def fullName(implicit ctx: Context): String

/** The position of this symbol */
def pos(implicit ctx: Context): Position

def localContext(implicit ctx: Context): Context
Expand Down Expand Up @@ -111,6 +120,7 @@ trait SymbolOps extends Core {
/** The symbol of the companion module */
def companionModule(implicit ctx: Context): Option[ValSymbol]

def moduleClass(implicit ctx: Context): Option[Symbol]
}
implicit def ClassSymbolDeco(symbol: ClassSymbol): ClassSymbolAPI

Expand Down Expand Up @@ -170,7 +180,7 @@ trait SymbolOps extends Core {
}

trait BindSymbolAPI {
/** Bind pattern of this defintion. */
/** Bind pattern of this definition. */
def tree(implicit ctx: Context): Bind
}
implicit def BindSymbolDeco(symbol: BindSymbol): BindSymbolAPI
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/TypeOrBoundsOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ trait TypeOrBoundsOps extends Core {
def <:<(other: Type)(implicit ctx: Context): Boolean
def widen(implicit ctx: Context): Type
def classSymbol(implicit ctx: Context): Option[ClassSymbol]
def typeSymbol(implicit ctx: Context): Symbol
}

val IsType: IsTypeModule
Expand Down
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ object Build {
baseDirectory in (Compile, run) := baseDirectory.value / "..",
baseDirectory in Test := baseDirectory.value / "..",
unmanagedSourceDirectories in Test += baseDirectory.value / "input" / "src" / "main" / "scala",
scalacOptions in Test ++= Seq("-Yno-inline"),
libraryDependencies ++= List(
("org.scalameta" %% "semanticdb" % "4.0.0").withDottyCompat(scalaVersion.value),
"com.novocode" % "junit-interface" % "0.11",
Expand Down
16 changes: 16 additions & 0 deletions semanticdb/input/src/main/scala/example/Access.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ class Access {
protected[this] def m5 = ???
protected[example] def m6 = ???
def m7 = ???

private val mv1 = ???
private[this] val mv2 = ???
private[Access] val mv3 = ???
protected val mv4 = ???
protected[this] val mv5 = ???
protected[example] val mv6 = ???
val mv7 = ???

private var mr1 = ???
private[this] var mr2 = ???
private[Access] var mr3 = ???
protected var mr4 = ???
protected[this] var mr5 = ???
protected[example] var mr6 = ???
var mr7 = ???
}
3 changes: 1 addition & 2 deletions semanticdb/input/src/main/scala/example/Advanced.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package example

import scala.language.existentials
import scala.language.higherKinds
import scala.language.{existentials, higherKinds=>h}
import scala.language.reflectiveCalls

class AdvC[T] {
Expand Down
2 changes: 1 addition & 1 deletion semanticdb/input/src/main/scala/example/Anonymous.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class Anonymous {

trait Foo
var x = new Foo {}
}
}
9 changes: 9 additions & 0 deletions semanticdb/input/src/main/scala/example/Apply.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

class TestApply {
object Foo {
def apply(x: Int) : Int = x
}
val z = Foo(1)
val y = Foo.apply(1)
}
7 changes: 7 additions & 0 deletions semanticdb/input/src/main/scala/example/BinaryOp.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package example

class BinaryOp {
val y = 1 #:: 2 #:: Stream.empty[Int]
val x = 1 :: 2 :: 3 :: Nil
val z = 1 + 2
}
12 changes: 12 additions & 0 deletions semanticdb/input/src/main/scala/example/Case.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package example

class CaseTest {
def foo (x: Option[Int]) : Int =
x match {
case y @ Some(x) => x
case None => 0
}
}

case class CaseClass(x: Int)
case object CaseObject
29 changes: 26 additions & 3 deletions semanticdb/input/src/main/scala/example/Classes.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package example

class CDep[X]
class CDependenat[X /* This is a comment /* and a nested comment
*/*/](var x1: CDep[X])
class CVarArg(var x1 : Int)


class CDefaultWrapper {
val glob = 3
class Cdefault(val x1: Int = glob)
}
class C1(val x1: Int) extends AnyVal

class C2(val x2: Int) extends AnyVal
object C2

case class C3(x: Int)
case class C3[Y ](x: Int)

case class C4(x: Int)
object C4
object C4 {
val foo: Int = 4
}

object M {
implicit class C5(x: Int)
Expand All @@ -30,4 +42,15 @@ object N {
val local = 2
local + 2
}
}

val otheranon = {
var a = 1
a
}

val lastanon = {
val a = new CVarArg(4)
a.x1 = 8
a.x1
}
}
9 changes: 9 additions & 0 deletions semanticdb/input/src/main/scala/example/DependantModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

class DepTemp {

}

abstract class DepAdvD[CC[X[C] <: B], X[Z], C] extends DepTemp {
val foo: List[Option[Option[X[C]]]]
}
9 changes: 9 additions & 0 deletions semanticdb/input/src/main/scala/example/DottyPredef.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

class PredefsDotty {
locally {
val x: Int => Int = _ => ???
}
assert(true)
assert(false, "bonjour")
}
3 changes: 2 additions & 1 deletion semanticdb/input/src/main/scala/example/Example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class Example {
x +
y
)
var b = 4
}

class ExampleInit() {
class ExampleInit {

}
9 changes: 4 additions & 5 deletions semanticdb/input/src/main/scala/example/Flags.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package example

package object p {
package object example {
private lazy val x = 1
protected implicit var y: Int = 2
/*protected implicit var y: Int = 2
def z(pp: Int) = 3
def m[TT] = ???
abstract class C[+T, -U, V](x: T, y: U, z: V) {
abstract class Cex[+T, -U, V](x: T, y: U, z: V) {
def this() = this(???, ???, ???)
def w: Int
}
Expand All @@ -20,5 +19,5 @@ package object p {
class S[@specialized T]
val List(xs1) = ???
??? match { case List(xs2) => ??? }
??? match { case _: List[t] => ??? }
??? match { case _: List[t] => ??? }*/
}
8 changes: 8 additions & 0 deletions semanticdb/input/src/main/scala/example/IgnoredSymbol.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example

class IgnoredTest {
val _ = 2
def foo(x: Int): Unit = {
val _ = x
}
}
1 change: 0 additions & 1 deletion semanticdb/input/src/main/scala/example/Imports.scala

This file was deleted.

17 changes: 16 additions & 1 deletion semanticdb/input/src/main/scala/example/MacroAnnotations.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/*
// This text is deactivated for now as macro annotations require to enable
// macro paradise

package example

//@MacroAnnotation

import scala.annotation.StaticAnnotation
import scala.annotation.compileTimeOnly
import scala.language.experimental.macros

@compileTimeOnly("enable macro paradise to expand macro annotations")
class MacroAnnotation extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = ???
}

@MacroAnnotation
class MacroAnnotations
object MacroAnnotations
*/
5 changes: 5 additions & 0 deletions semanticdb/input/src/main/scala/example/MultiArguments.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example

class Multiple {
def m19(x: Int)(z: Int = 3) = ???
}
Loading