1
- /** Copied from https://github.com/sbt/sbt /blob/0.13/interface/ src/test /scala/xsbti/TestCallback.scala */
1
+ // Taken from https://github.com/sbt/zinc /blob/aa1c04f445092e87f76aaceee4da61ea0724419e/internal/zinc-testing/ src/main /scala/xsbti/TestCallback.scala
2
2
package xsbti
3
3
4
4
import java .io .File
@@ -8,49 +8,95 @@ import xsbti.VirtualFileRef
8
8
import xsbti .api .ClassLike
9
9
import xsbti .api .DependencyContext
10
10
import DependencyContext ._
11
- import java .util .EnumSet
11
+ import java .{util => ju }
12
+ import ju .Optional
13
+
14
+ class TestCallback extends AnalysisCallback2 {
15
+ case class TestUsedName (name : String , scopes : ju.EnumSet [UseScope ])
12
16
13
- class TestCallback extends AnalysisCallback
14
- {
15
- case class TestUsedName (name : String , scopes : EnumSet [UseScope ])
16
17
val classDependencies = new ArrayBuffer [(String , String , DependencyContext )]
17
- val binaryDependencies = new ArrayBuffer [(Path , String , String , VirtualFileRef , DependencyContext )]
18
- val products = new ArrayBuffer [(VirtualFileRef , Path )]
19
- val usedNamesAndScopes = scala.collection.mutable.Map .empty[String , Set [TestUsedName ]].withDefaultValue(Set .empty)
20
- val classNames = scala.collection.mutable.Map .empty[VirtualFileRef , Set [(String , String )]].withDefaultValue(Set .empty)
21
- val apis : scala.collection.mutable.Map [VirtualFileRef , Seq [ClassLike ]] = scala.collection.mutable.Map .empty
18
+ val binaryDependencies =
19
+ new ArrayBuffer [(Path , String , String , VirtualFileRef , DependencyContext )]
20
+ val productClassesToSources =
21
+ scala.collection.mutable.Map .empty[Path , VirtualFileRef ]
22
+ val usedNamesAndScopes = scala.collection.mutable.Map
23
+ .empty[String , Set [TestUsedName ]]
24
+ .withDefaultValue(Set .empty)
25
+ val classNames = scala.collection.mutable.Map
26
+ .empty[VirtualFileRef , Set [(String , String )]]
27
+ .withDefaultValue(Set .empty)
28
+ val apis : scala.collection.mutable.Map [VirtualFileRef , Seq [ClassLike ]] =
29
+ scala.collection.mutable.Map .empty
22
30
23
31
def usedNames = usedNamesAndScopes.view.mapValues(_.map(_.name)).toMap
24
32
25
33
override def startSource (source : File ): Unit = ???
26
34
override def startSource (source : VirtualFile ): Unit = {
27
- assert(! apis.contains(source), s " startSource can be called only once per source file: $source" )
35
+ assert(
36
+ ! apis.contains(source),
37
+ s " startSource can be called only once per source file: $source"
38
+ )
28
39
apis(source) = Seq .empty
29
40
}
30
41
31
- override def binaryDependency (binary : File , name : String , fromClassName : String , source : File , context : DependencyContext ): Unit = ???
32
- override def binaryDependency (binary : Path , name : String , fromClassName : String , source : VirtualFileRef , context : DependencyContext ): Unit = {
42
+ override def binaryDependency (
43
+ binary : File ,
44
+ name : String ,
45
+ fromClassName : String ,
46
+ source : File ,
47
+ context : DependencyContext
48
+ ): Unit = ???
49
+ override def binaryDependency (
50
+ binary : Path ,
51
+ name : String ,
52
+ fromClassName : String ,
53
+ source : VirtualFileRef ,
54
+ context : DependencyContext
55
+ ): Unit = {
33
56
binaryDependencies += ((binary, name, fromClassName, source, context))
34
57
}
35
58
36
- override def generatedNonLocalClass (source : File , module : File , binaryClassName : String , srcClassName : String ): Unit = ???
37
- override def generatedNonLocalClass (source : VirtualFileRef , module : Path , binaryClassName : String , srcClassName : String ): Unit = {
38
- products += ((source, module))
39
- classNames(source) += ((srcClassName, binaryClassName))
59
+ override def generatedNonLocalClass (
60
+ source : File ,
61
+ module : File ,
62
+ binaryClassName : String ,
63
+ srcClassName : String
64
+ ): Unit = ???
65
+
66
+ override def generatedNonLocalClass (
67
+ sourceFile : VirtualFileRef ,
68
+ classFile : Path ,
69
+ binaryClassName : String ,
70
+ srcClassName : String
71
+ ): Unit = {
72
+ productClassesToSources += ((classFile, sourceFile))
73
+ classNames(sourceFile) += ((srcClassName, binaryClassName))
40
74
()
41
75
}
42
76
43
77
override def generatedLocalClass (source : File , module : File ): Unit = ???
44
- override def generatedLocalClass (source : VirtualFileRef , module : Path ): Unit = {
45
- products += ((source, module))
78
+ override def generatedLocalClass (
79
+ sourceFile : VirtualFileRef ,
80
+ classFile : Path
81
+ ): Unit = {
82
+ productClassesToSources += ((classFile, sourceFile))
46
83
()
47
84
}
48
85
49
- override def classDependency (onClassName : String , sourceClassName : String , context : DependencyContext ): Unit = {
50
- if (onClassName != sourceClassName) classDependencies += ((onClassName, sourceClassName, context))
86
+ override def classDependency (
87
+ onClassName : String ,
88
+ sourceClassName : String ,
89
+ context : DependencyContext
90
+ ): Unit = {
91
+ if (onClassName != sourceClassName)
92
+ classDependencies += ((onClassName, sourceClassName, context))
51
93
}
52
94
53
- override def usedName (className : String , name : String , scopes : EnumSet [UseScope ]): Unit = {
95
+ override def usedName (
96
+ className : String ,
97
+ name : String ,
98
+ scopes : ju.EnumSet [UseScope ]
99
+ ): Unit = {
54
100
usedNamesAndScopes(className) += TestUsedName (name, scopes)
55
101
}
56
102
@@ -59,7 +105,24 @@ class TestCallback extends AnalysisCallback
59
105
apis(source) = classApi +: apis(source)
60
106
}
61
107
62
- override def problem (category : String , pos : xsbti.Position , message : String , severity : xsbti.Severity , reported : Boolean ): Unit = ()
108
+ override def problem (
109
+ category : String ,
110
+ pos : xsbti.Position ,
111
+ message : String ,
112
+ severity : xsbti.Severity ,
113
+ reported : Boolean
114
+ ): Unit = ()
115
+ override def problem2 (
116
+ category : String ,
117
+ pos : Position ,
118
+ msg : String ,
119
+ severity : Severity ,
120
+ reported : Boolean ,
121
+ rendered : Optional [String ],
122
+ diagnosticCode : Optional [xsbti.DiagnosticCode ],
123
+ diagnosticRelatedInformation : ju.List [xsbti.DiagnosticRelatedInformation ],
124
+ actions : ju.List [xsbti.Action ]
125
+ ): Unit = ()
63
126
override def dependencyPhaseCompleted (): Unit = ()
64
127
override def apiPhaseCompleted (): Unit = ()
65
128
override def enabled (): Boolean = true
@@ -68,29 +131,39 @@ class TestCallback extends AnalysisCallback
68
131
override def mainClass (source : VirtualFileRef , className : String ): Unit = ???
69
132
70
133
override def classesInOutputJar (): java.util.Set [String ] = ???
71
- override def getPickleJarPair (): java.util.Optional [xsbti.T2 [Path , Path ]] = ???
134
+ override def getPickleJarPair (): java.util.Optional [xsbti.T2 [Path , Path ]] =
135
+ ???
72
136
override def isPickleJava (): Boolean = ???
73
137
}
74
138
75
139
object TestCallback {
76
- case class ExtractedClassDependencies (memberRef : Map [String , Set [String ]],
77
- inheritance : Map [String , Set [String ]],
78
- localInheritance : Map [String , Set [String ]])
140
+ case class ExtractedClassDependencies (
141
+ memberRef : Map [String , Set [String ]],
142
+ inheritance : Map [String , Set [String ]],
143
+ localInheritance : Map [String , Set [String ]]
144
+ )
79
145
object ExtractedClassDependencies {
80
146
def fromPairs (
81
- memberRefPairs : collection.Seq [(String , String )],
82
- inheritancePairs : collection.Seq [(String , String )],
83
- localInheritancePairs : collection.Seq [(String , String )]
84
- ): ExtractedClassDependencies = {
85
- ExtractedClassDependencies (pairsToMultiMap(memberRefPairs),
147
+ memberRefPairs : collection.Seq [(String , String )],
148
+ inheritancePairs : collection.Seq [(String , String )],
149
+ localInheritancePairs : collection.Seq [(String , String )]
150
+ ): ExtractedClassDependencies = {
151
+ ExtractedClassDependencies (
152
+ pairsToMultiMap(memberRefPairs),
86
153
pairsToMultiMap(inheritancePairs),
87
- pairsToMultiMap(localInheritancePairs))
154
+ pairsToMultiMap(localInheritancePairs)
155
+ )
88
156
}
89
157
90
- private def pairsToMultiMap [A , B ](pairs : collection.Seq [(A , B )]): Map [A , Set [B ]] = {
91
- pairs.groupBy(_._1).view.mapValues(values => values.map(_._2).toSet)
92
- .toMap.withDefaultValue(Set .empty)
158
+ private def pairsToMultiMap [A , B ](
159
+ pairs : collection.Seq [(A , B )]
160
+ ): Map [A , Set [B ]] = {
161
+ pairs
162
+ .groupBy(_._1)
163
+ .view
164
+ .mapValues(values => values.map(_._2).toSet)
165
+ .toMap
166
+ .withDefaultValue(Set .empty)
93
167
}
94
168
}
95
169
}
96
-
0 commit comments