@@ -13,6 +13,7 @@ import dotty.tools.dotc.fromtasty._
13
13
import dotty .tools .dotc .util .ClasspathFromClassloader
14
14
import dotty .tools .dotc .CompilationUnit
15
15
import dotty .tools .unsupported
16
+ import dotty .tools .dotc .report
16
17
17
18
import java .io .File .pathSeparator
18
19
@@ -57,13 +58,39 @@ trait TastyInspector:
57
58
val files = tastyFiles ::: jars
58
59
files.nonEmpty && inspectFiles(dependenciesClasspath, files)
59
60
60
- private def inspectFiles (classpath : List [String ], classes : List [String ]): Boolean =
61
- if (classes.isEmpty)
62
- throw new IllegalArgumentException (" Parameter classes should no be empty" )
61
+ /** Load and process TASTy files using TASTy reflect and provided context
62
+ *
63
+ * Used in doctool to reuse reporter and setup provided by sbt
64
+ *
65
+ * @param classes List of paths of `.tasty` and `.jar` files (no validation is performed)
66
+ * @param classpath Classpath with extra dependencies needed to load class in the `.tasty` files
67
+ */
68
+ protected def inspectFilesInContext (classpath : List [String ], classes : List [String ])(using Context ): Unit =
69
+ if (classes.isEmpty) report.error(" Parameter classes should no be empty" )
70
+ inspectorDriver().process(inspectorArgs(classpath, classes), summon[Context ])
71
+
63
72
73
+ private def inspectorDriver () =
64
74
class InspectorDriver extends Driver :
65
75
override protected def newCompiler (implicit ctx : Context ): Compiler = new TastyFromClass
66
76
77
+ class TastyInspectorPhase extends Phase :
78
+ override def phaseName : String = " tastyInspector"
79
+
80
+ override def run (implicit ctx : Context ): Unit =
81
+ val qctx = QuotesImpl ()
82
+ self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf [qctx.reflect.Tree ])
83
+
84
+ class TastyInspectorFinishPhase extends Phase :
85
+ override def phaseName : String = " tastyInspectorFinish"
86
+
87
+ override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
88
+ val qctx = QuotesImpl ()
89
+ self.postProcess(using qctx)
90
+ units
91
+
92
+ override def run (implicit ctx : Context ): Unit = unsupported(" run" )
93
+
67
94
class TastyFromClass extends TASTYCompiler :
68
95
69
96
override protected def frontendPhases : List [List [Phase ]] =
@@ -83,35 +110,19 @@ trait TastyInspector:
83
110
reset()
84
111
new TASTYRun (this , ctx.fresh.addMode(Mode .ReadPositions ).addMode(Mode .ReadComments ))
85
112
86
- end TastyFromClass
113
+ new InspectorDriver
87
114
88
- class TastyInspectorPhase extends Phase :
89
-
90
- override def phaseName : String = " tastyInspector"
91
-
92
- override def run (implicit ctx : Context ): Unit =
93
- val qctx = QuotesImpl ()
94
- self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf [qctx.reflect.Tree ])
95
-
96
- end TastyInspectorPhase
97
-
98
- class TastyInspectorFinishPhase extends Phase :
99
-
100
- override def phaseName : String = " tastyInspectorFinish"
101
-
102
- override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
103
- val qctx = QuotesImpl ()
104
- self.postProcess(using qctx)
105
- units
115
+ private def inspectorArgs (classpath : List [String ], classes : List [String ]): Array [String ] =
116
+ val currentClasspath = ClasspathFromClassloader (getClass.getClassLoader)
117
+ val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
118
+ (" -from-tasty" :: " -Yretain-trees" :: " -classpath" :: fullClasspath :: classes).toArray
106
119
107
- override def run (implicit ctx : Context ): Unit = unsupported(" run" )
108
120
109
- end TastyInspectorFinishPhase
121
+ private def inspectFiles (classpath : List [String ], classes : List [String ]): Boolean =
122
+ if (classes.isEmpty)
123
+ throw new IllegalArgumentException (" Parameter classes should no be empty" )
110
124
111
- val currentClasspath = ClasspathFromClassloader (getClass.getClassLoader)
112
- val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
113
- val args = " -from-tasty" :: " -Yretain-trees" :: " -classpath" :: fullClasspath :: classes
114
- val reporter = (new InspectorDriver ).process(args.toArray)
125
+ val reporter = inspectorDriver().process(inspectorArgs(classpath, classes))
115
126
reporter.hasErrors
116
127
117
128
end inspectFiles
0 commit comments