@@ -482,11 +482,25 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
482
482
483
483
// ----- Tree -----------------------------------------------------
484
484
485
- extension TreeOps on (self : Tree ) {
485
+ /** Members of Tree */
486
+ extension TreeOps on (tree : Tree ) {
486
487
/** Position in the source code */
487
- def pos (given ctx : Context ): Position = internal.Tree_pos (self )
488
+ def pos (given ctx : Context ): Position = internal.Tree_pos (tree )
488
489
489
- def symbol (given ctx : Context ): Symbol = internal.Tree_symbol (self)
490
+ /** Symbol of defined or refered by this tree */
491
+ def symbol (given ctx : Context ): Symbol = internal.Tree_symbol (tree)
492
+
493
+ /** Shows the tree as extractors */
494
+ def showExtractors (given ctx : Context ): String =
495
+ new ExtractorsPrinter [self.type ](self).showTree(tree)
496
+
497
+ /** Shows the tree as fully typed source code */
498
+ def show (given ctx : Context ): String =
499
+ tree.showWith(SyntaxHighlight .plain)
500
+
501
+ /** Shows the tree as fully typed source code */
502
+ def showWith (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
503
+ new SourceCodePrinter [self.type ](self)(syntaxHighlight).showTree(tree)
490
504
}
491
505
492
506
given (given Context ): IsInstanceOf [PackageClause ] = internal.isInstanceOfPackageClause
@@ -1581,6 +1595,21 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
1581
1595
/** Returns the type (Type) of T */
1582
1596
def typeOf [T ](given qtype : scala.quoted.Type [T ]): Type = qtype.unseal.tpe
1583
1597
1598
+ /** Members of `TypeOrBounds` */
1599
+ extension TypeOrBoundsOps on (tpe : TypeOrBounds ) {
1600
+ /** Shows the tree as extractors */
1601
+ def showExtractors (given ctx : Context ): String =
1602
+ new ExtractorsPrinter [self.type ](self).showTypeOrBounds(tpe)
1603
+
1604
+ /** Shows the tree as fully typed source code */
1605
+ def show (given ctx : Context ): String =
1606
+ tpe.showWith(SyntaxHighlight .plain)
1607
+
1608
+ /** Shows the tree as fully typed source code */
1609
+ def showWith (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
1610
+ new SourceCodePrinter [self.type ](self)(syntaxHighlight).showTypeOrBounds(tpe)
1611
+ }
1612
+
1584
1613
// ----- Types ----------------------------------------------------
1585
1614
1586
1615
extension TypeOps on (self : Type ) {
@@ -1941,8 +1970,23 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
1941
1970
// CONSTANTS //
1942
1971
// /////////////
1943
1972
1973
+ /** Members of `Constant` */
1944
1974
extension ConstantOps on (const : Constant ) {
1975
+
1976
+ /** Returns the value of the constant */
1945
1977
def value : Any = internal.Constant_value (const)
1978
+
1979
+ /** Shows the tree as extractors */
1980
+ def showExtractors (given ctx : Context ): String =
1981
+ new ExtractorsPrinter [self.type ](self).showConstant(const)
1982
+
1983
+ /** Shows the tree as fully typed source code */
1984
+ def show (given ctx : Context ): String =
1985
+ const.showWith(SyntaxHighlight .plain)
1986
+
1987
+ /** Shows the tree as fully typed source code */
1988
+ def showWith (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
1989
+ new SourceCodePrinter [self.type ](self)(syntaxHighlight).showConstant(const)
1946
1990
}
1947
1991
1948
1992
/** Module of Constant literals */
@@ -2046,36 +2090,37 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2046
2090
internal.Symbol_noSymbol
2047
2091
}
2048
2092
2049
- extension symbolOps on (self : Symbol ) {
2093
+ /** Members of `Symbol` */
2094
+ extension SymbolOps on (sym : Symbol ) {
2050
2095
2051
2096
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */
2052
- def owner (given ctx : Context ): Symbol = internal.Symbol_owner (self )
2097
+ def owner (given ctx : Context ): Symbol = internal.Symbol_owner (sym )
2053
2098
2054
2099
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns `NoSymbol` if this symbol does not have an owner. */
2055
- def maybeOwner (given ctx : Context ): Symbol = internal.Symbol_maybeOwner (self )
2100
+ def maybeOwner (given ctx : Context ): Symbol = internal.Symbol_maybeOwner (sym )
2056
2101
2057
2102
/** Flags of this symbol */
2058
- def flags (given ctx : Context ): Flags = internal.Symbol_flags (self )
2103
+ def flags (given ctx : Context ): Flags = internal.Symbol_flags (sym )
2059
2104
2060
2105
/** This symbol is private within the resulting type */
2061
- def privateWithin (given ctx : Context ): Option [Type ] = internal.Symbol_privateWithin (self )
2106
+ def privateWithin (given ctx : Context ): Option [Type ] = internal.Symbol_privateWithin (sym )
2062
2107
2063
2108
/** This symbol is protected within the resulting type */
2064
- def protectedWithin (given ctx : Context ): Option [Type ] = internal.Symbol_protectedWithin (self )
2109
+ def protectedWithin (given ctx : Context ): Option [Type ] = internal.Symbol_protectedWithin (sym )
2065
2110
2066
2111
/** The name of this symbol */
2067
- def name (given ctx : Context ): String = internal.Symbol_name (self )
2112
+ def name (given ctx : Context ): String = internal.Symbol_name (sym )
2068
2113
2069
2114
/** The full name of this symbol up to the root package */
2070
- def fullName (given ctx : Context ): String = internal.Symbol_fullName (self )
2115
+ def fullName (given ctx : Context ): String = internal.Symbol_fullName (sym )
2071
2116
2072
2117
/** The position of this symbol */
2073
- def pos (given ctx : Context ): Position = internal.Symbol_pos (self )
2118
+ def pos (given ctx : Context ): Position = internal.Symbol_pos (sym )
2074
2119
2075
- def localContext (given ctx : Context ): Context = internal.Symbol_localContext (self )
2120
+ def localContext (given ctx : Context ): Context = internal.Symbol_localContext (sym )
2076
2121
2077
2122
/** The comment for this symbol, if any */
2078
- def comment (given ctx : Context ): Option [Comment ] = internal.Symbol_comment (self )
2123
+ def comment (given ctx : Context ): Option [Comment ] = internal.Symbol_comment (sym )
2079
2124
2080
2125
/** Tree of this definition
2081
2126
*
@@ -2087,97 +2132,109 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2087
2132
* if this symbol `isBind` it will return a `Bind`
2088
2133
*/
2089
2134
def tree (given ctx : Context ): Tree =
2090
- internal.Symbol_tree (self )
2135
+ internal.Symbol_tree (sym )
2091
2136
2092
2137
/** Annotations attached to this symbol */
2093
- def annots (given ctx : Context ): List [Term ] = internal.Symbol_annots (self )
2138
+ def annots (given ctx : Context ): List [Term ] = internal.Symbol_annots (sym )
2094
2139
2095
- def isDefinedInCurrentRun (given ctx : Context ): Boolean = internal.Symbol_isDefinedInCurrentRun (self )
2140
+ def isDefinedInCurrentRun (given ctx : Context ): Boolean = internal.Symbol_isDefinedInCurrentRun (sym )
2096
2141
2097
- def isLocalDummy (given ctx : Context ): Boolean = internal.Symbol_isLocalDummy (self )
2098
- def isRefinementClass (given ctx : Context ): Boolean = internal.Symbol_isRefinementClass (self )
2099
- def isAliasType (given ctx : Context ): Boolean = internal.Symbol_isAliasType (self )
2100
- def isAnonymousClass (given ctx : Context ): Boolean = internal.Symbol_isAnonymousClass (self )
2101
- def isAnonymousFunction (given ctx : Context ): Boolean = internal.Symbol_isAnonymousFunction (self )
2102
- def isAbstractType (given ctx : Context ): Boolean = internal.Symbol_isAbstractType (self )
2103
- def isClassConstructor (given ctx : Context ): Boolean = internal.Symbol_isClassConstructor (self )
2142
+ def isLocalDummy (given ctx : Context ): Boolean = internal.Symbol_isLocalDummy (sym )
2143
+ def isRefinementClass (given ctx : Context ): Boolean = internal.Symbol_isRefinementClass (sym )
2144
+ def isAliasType (given ctx : Context ): Boolean = internal.Symbol_isAliasType (sym )
2145
+ def isAnonymousClass (given ctx : Context ): Boolean = internal.Symbol_isAnonymousClass (sym )
2146
+ def isAnonymousFunction (given ctx : Context ): Boolean = internal.Symbol_isAnonymousFunction (sym )
2147
+ def isAbstractType (given ctx : Context ): Boolean = internal.Symbol_isAbstractType (sym )
2148
+ def isClassConstructor (given ctx : Context ): Boolean = internal.Symbol_isClassConstructor (sym )
2104
2149
2105
2150
/** Is this the definition of a type? */
2106
- def isType (given ctx : Context ): Boolean = internal.Symbol_isType (self )
2151
+ def isType (given ctx : Context ): Boolean = internal.Symbol_isType (sym )
2107
2152
2108
2153
/** Is this the definition of a term? */
2109
- def isTerm (given ctx : Context ): Boolean = internal.Symbol_isTerm (self )
2154
+ def isTerm (given ctx : Context ): Boolean = internal.Symbol_isTerm (sym )
2110
2155
2111
2156
/** Is this the definition of a PackageDef tree? */
2112
- def isPackageDef (given ctx : Context ): Boolean = internal.Symbol_isPackageDef (self )
2157
+ def isPackageDef (given ctx : Context ): Boolean = internal.Symbol_isPackageDef (sym )
2113
2158
2114
2159
/** Is this the definition of a ClassDef tree? */
2115
- def isClassDef (given ctx : Context ): Boolean = internal.Symbol_isClassDef (self )
2160
+ def isClassDef (given ctx : Context ): Boolean = internal.Symbol_isClassDef (sym )
2116
2161
2117
2162
/** Is this the definition of a TypeDef tree */
2118
- def isTypeDef (given ctx : Context ): Boolean = internal.Symbol_isTypeDef (self )
2163
+ def isTypeDef (given ctx : Context ): Boolean = internal.Symbol_isTypeDef (sym )
2119
2164
2120
2165
/** Is this the definition of a ValDef tree? */
2121
- def isValDef (given ctx : Context ): Boolean = internal.Symbol_isValDef (self )
2166
+ def isValDef (given ctx : Context ): Boolean = internal.Symbol_isValDef (sym )
2122
2167
2123
2168
/** Is this the definition of a DefDef tree? */
2124
- def isDefDef (given ctx : Context ): Boolean = internal.Symbol_isDefDef (self )
2169
+ def isDefDef (given ctx : Context ): Boolean = internal.Symbol_isDefDef (sym )
2125
2170
2126
2171
/** Is this the definition of a Bind pattern? */
2127
- def isBind (given ctx : Context ): Boolean = internal.Symbol_isBind (self )
2172
+ def isBind (given ctx : Context ): Boolean = internal.Symbol_isBind (sym )
2128
2173
2129
2174
/** Does this symbol represent a no definition? */
2130
- def isNoSymbol (given ctx : Context ): Boolean = self == Symbol .noSymbol
2175
+ def isNoSymbol (given ctx : Context ): Boolean = sym == Symbol .noSymbol
2131
2176
2132
2177
/** Does this symbol represent a definition? */
2133
- def exists (given ctx : Context ): Boolean = self != Symbol .noSymbol
2178
+ def exists (given ctx : Context ): Boolean = sym != Symbol .noSymbol
2134
2179
2135
2180
/** Fields directly declared in the class */
2136
2181
def fields (given ctx : Context ): List [Symbol ] =
2137
- internal.Symbol_fields (self )
2182
+ internal.Symbol_fields (sym )
2138
2183
2139
2184
/** Field with the given name directly declared in the class */
2140
2185
def field (name : String )(given ctx : Context ): Symbol =
2141
- internal.Symbol_field (self )(name)
2186
+ internal.Symbol_field (sym )(name)
2142
2187
2143
2188
/** Get non-private named methods defined directly inside the class */
2144
2189
def classMethod (name : String )(given ctx : Context ): List [Symbol ] =
2145
- internal.Symbol_classMethod (self )(name)
2190
+ internal.Symbol_classMethod (sym )(name)
2146
2191
2147
2192
/** Get all non-private methods defined directly inside the class, exluding constructors */
2148
2193
def classMethods (given ctx : Context ): List [Symbol ] =
2149
- internal.Symbol_classMethods (self )
2194
+ internal.Symbol_classMethods (sym )
2150
2195
2151
2196
/** Get named non-private methods declared or inherited */
2152
2197
def method (name : String )(given ctx : Context ): List [Symbol ] =
2153
- internal.Symbol_method (self )(name)
2198
+ internal.Symbol_method (sym )(name)
2154
2199
2155
2200
/** Get all non-private methods declared or inherited */
2156
2201
def methods (given ctx : Context ): List [Symbol ] =
2157
- internal.Symbol_methods (self )
2202
+ internal.Symbol_methods (sym )
2158
2203
2159
2204
/** Fields of a case class type -- only the ones declared in primary constructor */
2160
2205
def caseFields (given ctx : Context ): List [Symbol ] =
2161
- internal.Symbol_caseFields (self )
2206
+ internal.Symbol_caseFields (sym )
2162
2207
2163
2208
def isTypeParam (given ctx : Context ): Boolean =
2164
- internal.Symbol_isTypeParam (self )
2209
+ internal.Symbol_isTypeParam (sym )
2165
2210
2166
2211
/** Signature of this definition */
2167
2212
def signature (given ctx : Context ): Signature =
2168
- internal.Symbol_signature (self )
2213
+ internal.Symbol_signature (sym )
2169
2214
2170
2215
/** The class symbol of the companion module class */
2171
2216
def moduleClass (given ctx : Context ): Symbol =
2172
- internal.Symbol_moduleClass (self )
2217
+ internal.Symbol_moduleClass (sym )
2173
2218
2174
2219
/** The symbol of the companion class */
2175
2220
def companionClass (given ctx : Context ): Symbol =
2176
- internal.Symbol_companionClass (self )
2221
+ internal.Symbol_companionClass (sym )
2177
2222
2178
2223
/** The symbol of the companion module */
2179
2224
def companionModule (given ctx : Context ): Symbol =
2180
- internal.Symbol_companionModule (self)
2225
+ internal.Symbol_companionModule (sym)
2226
+
2227
+ /** Shows the tree as extractors */
2228
+ def showExtractors (given ctx : Context ): String =
2229
+ new ExtractorsPrinter [self.type ](self).showSymbol(sym)
2230
+
2231
+ /** Shows the tree as fully typed source code */
2232
+ def show (given ctx : Context ): String =
2233
+ sym.showWith(SyntaxHighlight .plain)
2234
+
2235
+ /** Shows the tree as fully typed source code */
2236
+ def showWith (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2237
+ new SourceCodePrinter [self.type ](self)(syntaxHighlight).showSymbol(sym)
2181
2238
}
2182
2239
2183
2240
@@ -2443,16 +2500,29 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2443
2500
// FLAGS //
2444
2501
// /////////////
2445
2502
2446
- extension FlagsOps on (self : Flags ) {
2503
+ /** Members of `Flag` */
2504
+ extension FlagsOps on (flags : Flags ) {
2447
2505
2448
2506
/** Is the given flag set a subset of this flag sets */
2449
- def is (that : Flags ): Boolean = internal.Flags_is (self )(that)
2507
+ def is (that : Flags ): Boolean = internal.Flags_is (flags )(that)
2450
2508
2451
2509
/** Union of the two flag sets */
2452
- def | (that : Flags ): Flags = internal.Flags_or (self )(that)
2510
+ def | (that : Flags ): Flags = internal.Flags_or (flags )(that)
2453
2511
2454
2512
/** Intersection of the two flag sets */
2455
- def & (that : Flags ): Flags = internal.Flags_and (self)(that)
2513
+ def & (that : Flags ): Flags = internal.Flags_and (flags)(that)
2514
+
2515
+ /** Shows the tree as extractors */
2516
+ def showExtractors (given ctx : Context ): String =
2517
+ new ExtractorsPrinter [self.type ](self).showFlags(flags)
2518
+
2519
+ /** Shows the tree as fully typed source code */
2520
+ def show (given ctx : Context ): String =
2521
+ flags.showWith(SyntaxHighlight .plain)
2522
+
2523
+ /** Shows the tree as fully typed source code */
2524
+ def showWith (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2525
+ new SourceCodePrinter [self.type ](self)(syntaxHighlight).showFlags(flags)
2456
2526
2457
2527
}
2458
2528
@@ -2636,83 +2706,6 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2636
2706
def warning (msg : => String , source : SourceFile , start : Int , end : Int )(given ctx : Context ): Unit =
2637
2707
internal.warning(msg, source, start, end)
2638
2708
2639
- // ////////////
2640
- // PRINTERS //
2641
- // ////////////
2642
-
2643
- /** Adds `show` as an extension method of a `Tree` */
2644
- implicit class TreeShowDeco (tree : Tree ) {
2645
- /** Shows the tree as extractors */
2646
- def showExtractors (given ctx : Context ): String =
2647
- new ExtractorsPrinter [self.type ](self).showTree(tree)
2648
-
2649
- /** Shows the tree as fully typed source code */
2650
- def show (given ctx : Context ): String =
2651
- show(SyntaxHighlight .plain)
2652
-
2653
- /** Shows the tree as fully typed source code */
2654
- def show (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2655
- new SourceCodePrinter [self.type ](self)(syntaxHighlight).showTree(tree)
2656
-
2657
- }
2658
-
2659
- /** Adds `show` as an extension method of a `TypeOrBounds` */
2660
- implicit class TypeOrBoundsShowDeco (tpe : TypeOrBounds ) {
2661
- /** Shows the tree as extractors */
2662
- def showExtractors (given ctx : Context ): String =
2663
- new ExtractorsPrinter [self.type ](self).showTypeOrBounds(tpe)
2664
-
2665
- /** Shows the tree as fully typed source code */
2666
- def show (given ctx : Context ): String =
2667
- show(SyntaxHighlight .plain)
2668
-
2669
- /** Shows the tree as fully typed source code */
2670
- def show (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2671
- new SourceCodePrinter [self.type ](self)(syntaxHighlight).showTypeOrBounds(tpe)
2672
- }
2673
-
2674
- /** Adds `show` as an extension method of a `Constant` */
2675
- implicit class ConstantShowDeco (const : Constant ) {
2676
- /** Shows the tree as extractors */
2677
- def showExtractors (given ctx : Context ): String =
2678
- new ExtractorsPrinter [self.type ](self).showConstant(const)
2679
-
2680
- /** Shows the tree as fully typed source code */
2681
- def show (given ctx : Context ): String = show(SyntaxHighlight .plain)
2682
-
2683
- /** Shows the tree as fully typed source code */
2684
- def show (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2685
- new SourceCodePrinter [self.type ](self)(syntaxHighlight).showConstant(const)
2686
- }
2687
-
2688
- /** Adds `show` as an extension method of a `Symbol` */
2689
- implicit class SymbolShowDeco (symbol : Symbol ) {
2690
- /** Shows the tree as extractors */
2691
- def showExtractors (given ctx : Context ): String =
2692
- new ExtractorsPrinter [self.type ](self).showSymbol(symbol)
2693
-
2694
- /** Shows the tree as fully typed source code */
2695
- def show (given ctx : Context ): String = show(SyntaxHighlight .plain)
2696
-
2697
- /** Shows the tree as fully typed source code */
2698
- def show (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2699
- new SourceCodePrinter [self.type ](self)(syntaxHighlight).showSymbol(symbol)
2700
- }
2701
-
2702
- /** Adds `show` as an extension method of a `Flags` */
2703
- implicit class FlagsShowDeco (flags : Flags ) {
2704
- /** Shows the tree as extractors */
2705
- def showExtractors (given ctx : Context ): String =
2706
- new ExtractorsPrinter [self.type ](self).showFlags(flags)
2707
-
2708
- /** Shows the tree as fully typed source code */
2709
- def show (given ctx : Context ): String = show(SyntaxHighlight .plain)
2710
-
2711
- /** Shows the tree as fully typed source code */
2712
- def show (syntaxHighlight : SyntaxHighlight )(given ctx : Context ): String =
2713
- new SourceCodePrinter [self.type ](self)(syntaxHighlight).showFlags(flags)
2714
- }
2715
-
2716
2709
2717
2710
// ////////////
2718
2711
// COMMENTS //
0 commit comments