Skip to content

Commit 755d607

Browse files
Merge pull request #5437 from dotty-staging/add-tasty-reflect-documentation
Add documentation to TASTy reflect
2 parents bf5ba46 + e3b9aa2 commit 755d607

10 files changed

+200
-23
lines changed

library/src/scala/tasty/reflect/Core.scala

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,42 @@ trait Core {
124124
/** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */
125125
type TermOrTypeTree /* Term | TypeTree */
126126

127-
/** Tree representing executable code written in the source */
127+
/** Tree representing code written in the source */
128128
type Tree
129+
130+
/** Tree representing a pacakage clause in the source code */
129131
type PackageClause <: Tree
132+
133+
/** Tree representing a statement in the source code */
130134
type Statement <: Tree
135+
136+
/** Tree representing an import in the source code */
131137
type Import <: Statement
138+
139+
/** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef`*/
132140
type Definition <: Statement
141+
142+
/** Tree representing a package definition. This includes definitions in all source files. */
133143
type PackageDef <: Definition
144+
145+
/** Tree representing a class definition. This includes annonymus class definitions and the class of a module object. */
134146
type ClassDef <: Definition
147+
148+
/** Tree representing a type (paramter or member) definition in the source code. */
135149
type TypeDef <: Definition
150+
151+
/** Tree representing a method definition in the source code. */
136152
type DefDef <: Definition
153+
154+
/** Tree representing a value definition in the source code. This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
137155
type ValDef <: Definition
156+
157+
/** Tree representing an expression in the source code. */
138158
type Term <: Statement
139159

160+
// TODO Add subtype types of Term for documentation? Or support refined bindings and add the types.
161+
162+
140163
/** Branch of a pattern match or catch clause */
141164
type CaseDef
142165

@@ -145,30 +168,69 @@ trait Core {
145168

146169
/** Pattern tree of the pattern part of a CaseDef */
147170
type Pattern
171+
172+
/** Pattern representing a value. This includes `1`, ```x``` and `_` */
148173
type Value <: Pattern
174+
175+
/** Pattern representing a `_ @ _` binding. */
149176
type Bind <: Pattern
177+
178+
/** Pattern representing a `Xyz(...)` unapply. */
150179
type Unapply <: Pattern
180+
181+
/** Pattern representing `X | Y | ...` alternatives. */
151182
type Alternative <: Pattern
183+
184+
/** Pattern representing a `x: Y` type test. */
152185
type TypeTest <: Pattern
153186

154-
/** Tree representing a type written in the source */
187+
/** Type tree representing a type or a bounds written in the source */
155188
type TypeOrBoundsTree
189+
190+
/** Type tree representing a type written in the source */
156191
type TypeTree <: TypeOrBoundsTree
192+
193+
// TODO Add subtype types of TypeTree for documentation? Or support refined bindings and add the types.
194+
195+
196+
/** Type tree representing a type bound written in the source */
157197
type TypeBoundsTree <: TypeOrBoundsTree
158198

199+
/** Type or bounds */
159200
type TypeOrBounds
201+
202+
/** NoPrefix for a type selection */
160203
type NoPrefix <: TypeOrBounds
204+
205+
/** Type bounds */
161206
type TypeBounds <: TypeOrBounds
207+
208+
/** A type */
162209
type Type <: TypeOrBounds
210+
211+
/** A type that is recursively defined */
163212
type RecursiveType <: Type
213+
164214
// TODO can we add the bound back without an cake?
165215
// TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors
216+
/** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */
166217
type LambdaType[ParamInfo /*<: TypeOrBounds*/] <: Type
218+
219+
/** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */
167220
type MethodType <: LambdaType[Type]
221+
222+
/** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */
168223
type PolyType <: LambdaType[TypeBounds]
224+
225+
/** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */
169226
type TypeLambda <: LambdaType[TypeBounds]
170227

171228

229+
/** Import selectors:
230+
* * SimpleSelector: `.bar` in `import foo.bar`
231+
* * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}`
232+
* * OmitSelector: `.{bar => _}` in `import foo.{bar => _}`
233+
*/
172234
type ImportSelector
173235

174236
/** Untyped identifier */
@@ -187,12 +249,26 @@ trait Core {
187249
* Then can be compared with == to know if the definition is the same.
188250
*/
189251
type Symbol
252+
253+
/** Symbol of a package defnition */
190254
type PackageSymbol <: Symbol
255+
256+
/** Symbol of a class defnition. This includes annonymus class definitions and the class of a module object. */
191257
type ClassSymbol <: Symbol
258+
259+
/** Symbol of a type (paramter or member) definition. */
192260
type TypeSymbol <: Symbol
261+
262+
/** Symbol representing a method definition. */
193263
type DefSymbol <: Symbol
264+
265+
/** Symbol representing a value definition. This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
194266
type ValSymbol <: Symbol
267+
268+
/** Symbol representing a bind definition. */
195269
type BindSymbol <: Symbol
270+
271+
/** No symbol availabe. */
196272
type NoSymbol <: Symbol
197273

198274
}
Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,85 @@
11
package scala.tasty.reflect
22

33
trait FlagSet {
4+
5+
/** Is this symbol `protected` */
46
def isProtected: Boolean
7+
8+
/** Is this symbol `abstract` */
59
def isAbstract: Boolean
10+
11+
/** Is this symbol `final` */
612
def isFinal: Boolean
13+
14+
/** Is this symbol `sealed` */
715
def isSealed: Boolean
16+
17+
/** Is this symbol `case` */
818
def isCase: Boolean
19+
20+
/** Is this symbol `implicit` */
921
def isImplicit: Boolean
22+
23+
/** Is this symbol `erased` */
1024
def isErased: Boolean
25+
26+
/** Is this symbol `lazy` */
1127
def isLazy: Boolean
28+
29+
/** Is this symbol `override` */
1230
def isOverride: Boolean
31+
32+
/** Is this symbol `inline` */
1333
def isInline: Boolean
14-
def isMacro: Boolean // inline method containing toplevel splices
15-
def isStatic: Boolean // mapped to static Java member
16-
def isObject: Boolean // an object or its class (used for a ValDef or a ClassDef extends Modifier respectively)
17-
def isTrait: Boolean // a trait (used for a ClassDef)
18-
def isLocal: Boolean // used in conjunction with Private/private[Type] to mean private[this] extends Modifier proctected[this]
19-
def isSynthetic: Boolean // generated by Scala compiler
20-
def isArtifact: Boolean // to be tagged Java Synthetic
21-
def isMutable: Boolean // when used on a ValDef: a var
22-
def isFieldAccessor: Boolean // a getter or setter
23-
def isCaseAcessor: Boolean // getter for class parameter
24-
def isCovariant: Boolean // type parameter marked “+”
25-
def isContravariant: Boolean // type parameter marked “-”
26-
def isScala2X: Boolean // Imported from Scala2.x
27-
def isDefaultParameterized: Boolean // Method with default parameters
28-
def isStable: Boolean // Method that is assumed to be stable
34+
35+
/** Is this symbol markes as a macro. An inline method containing toplevel splices */
36+
def isMacro: Boolean
37+
38+
/** Is this symbol marked as static. Mapped to static Java member */
39+
def isStatic: Boolean
40+
41+
/** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */
42+
def isObject: Boolean
43+
44+
/** Is this symbol a trait */
45+
def isTrait: Boolean
46+
47+
/** Is this symbol local? Used in conjunction with Private/private[Type] to mean private[this] extends Modifier proctected[this] */
48+
def isLocal: Boolean
49+
50+
/** Was this symbol generated by Scala compiler */
51+
def isSynthetic: Boolean
52+
53+
/** Is this symbol to be tagged Java Synthetic */
54+
def isArtifact: Boolean
55+
56+
/** Is this symbol a `var` (when used on a ValDef) */
57+
def isMutable: Boolean
58+
59+
/** Is this symbol a getter or a setter */
60+
def isFieldAccessor: Boolean
61+
62+
/** Is this symbol a getter for case class parameter */
63+
def isCaseAcessor: Boolean
64+
65+
/** Is this symbol a type parameter marked as covariant `+` */
66+
def isCovariant: Boolean
67+
68+
/** Is this symbol a type parameter marked as contravariant `-` */
69+
def isContravariant: Boolean
70+
71+
/** Was this symbol imported from Scala2.x */
72+
def isScala2X: Boolean
73+
74+
/** Is this symbol a method with default parameters */
75+
def isDefaultParameterized: Boolean
76+
77+
/** Is this symbol member that is assumed to be stable */
78+
def isStable: Boolean
79+
80+
/** Is this symbol a parameter */
2981
def isParam: Boolean
82+
83+
/** Is this symbol a parameter accessor */
3084
def isParamAccessor: Boolean
3185
}

library/src/scala/tasty/reflect/IdOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package reflect
44
trait IdOps extends Core {
55

66
trait IdAPI {
7+
/** Position in the source code */
78
def pos(implicit ctx: Context): Position
89
def name(implicit ctx: Context): String
910
}

library/src/scala/tasty/reflect/PatternOps.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package reflect
44
trait PatternOps extends Core {
55

66
trait PatternAPI {
7-
def tpe(implicit ctx: Context): Type
7+
/** Position in the source code */
88
def pos(implicit ctx: Context): Position
9+
10+
def tpe(implicit ctx: Context): Type
911
}
1012
implicit def PatternDeco(pattern: Pattern): PatternAPI
1113

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ package scala.tasty.reflect
33
trait PositionOps extends Core {
44

55
trait PositionAPI {
6-
def start: Int
7-
def end: Int
86

7+
/** The path of source file */
98
def sourceFile: java.nio.file.Path
109

10+
/** The start index in the source file */
11+
def start: Int
12+
13+
/** The end index in the source file */
14+
def end: Int
15+
16+
/** The start line in the source file */
1117
def startLine: Int
18+
19+
/** The start column in the source file */
1220
def startColumn: Int
21+
22+
/** The end line in the source file */
1323
def endLine: Int
24+
25+
/** The end column in the source file */
1426
def endColumn: Int
27+
1528
}
1629
implicit def PositionDeco(pos: Position): PositionAPI
1730

library/src/scala/tasty/reflect/SettingsOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trait SettingsOps extends Core {
66
def settings: Settings
77

88
trait SettingsAPI {
9+
/** Can print output using colors? */
910
def color: Boolean
1011
}
1112
implicit def SettingsDeco(settings: Settings): SettingsAPI

library/src/scala/tasty/reflect/SignatureOps.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package scala.tasty.reflect
22

33
trait SignatureOps extends Core {
44

5+
/** Erased (JVM) signatures. */
56
val Signature: SignatureExtractor
67
abstract class SignatureExtractor {
8+
/** Matches the erased (JVM) signature and returns its parameters and result type. */
79
def unapply(sig: Signature)(implicit ctx: Context): Option[(List[String], String)]
810
}
911

1012
trait SignatureAPI {
13+
/** The (JVM) erased signatures of the parameters. */
1114
def paramSigs: List[String]
15+
/** The (JVM) erased result type. */
1216
def resultSig: String
1317
}
1418
implicit def SignatureDeco(sig: Signature): SignatureAPI

0 commit comments

Comments
 (0)