Skip to content

Commit 2215018

Browse files
committed
refactor: start to use problem2
1 parent ab4a0c3 commit 2215018

File tree

4 files changed

+130
-41
lines changed

4 files changed

+130
-41
lines changed

Diff for: project/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ object Dependencies {
2828
"com.vladsch.flexmark" % "flexmark-ext-yaml-front-matter" % flexmarkVersion,
2929
)
3030

31-
val compilerInterface = "org.scala-sbt" % "compiler-interface" % "1.9.0"
31+
val compilerInterface = "org.scala-sbt" % "compiler-interface" % "1.9.3"
3232
}

Diff for: sbt-bridge/src/dotty/tools/xsbt/CompilerBridgeDriver.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,24 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
136136
doCompile(compiler, sourcesBuffer.toList(), context);
137137

138138
for (xsbti.Problem problem: delegate.problems()) {
139-
callback.problem(problem.category(), problem.position(), problem.message(), problem.severity(),
140-
true);
139+
try {
140+
log.info(() -> "should be sending problem 2");
141+
AnalysisCallback2 callback2 = (AnalysisCallback2)callback;
142+
callback2.problem2(
143+
problem.category(),
144+
problem.position(),
145+
problem.message(),
146+
problem.severity(),
147+
true, // reported
148+
problem.rendered(),
149+
problem.diagnosticCode(),
150+
problem.diagnosticRelatedInformation(),
151+
problem.actions()
152+
);
153+
} catch (NoClassDefFoundError e) {
154+
callback.problem(problem.category(), problem.position(), problem.message(), problem.severity(),
155+
true);
156+
}
141157
}
142158
} else {
143159
delegate.printSummary();

Diff for: sbt-bridge/test/xsbt/DependencySpecification.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ class DependencySpecification {
209209
compilerForTesting.extractDependenciesFromSrcs(srcA, srcB, srcC, srcD)
210210
classDependencies
211211
}
212-
}
212+
}

Diff for: sbt-bridge/test/xsbti/TestCallback.scala

+110-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22
package xsbti
33

44
import java.io.File
@@ -8,49 +8,95 @@ import xsbti.VirtualFileRef
88
import xsbti.api.ClassLike
99
import xsbti.api.DependencyContext
1010
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])
1216

13-
class TestCallback extends AnalysisCallback
14-
{
15-
case class TestUsedName(name: String, scopes: EnumSet[UseScope])
1617
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
2230

2331
def usedNames = usedNamesAndScopes.view.mapValues(_.map(_.name)).toMap
2432

2533
override def startSource(source: File): Unit = ???
2634
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+
)
2839
apis(source) = Seq.empty
2940
}
3041

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 = {
3356
binaryDependencies += ((binary, name, fromClassName, source, context))
3457
}
3558

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))
4074
()
4175
}
4276

4377
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))
4683
()
4784
}
4885

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))
5193
}
5294

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 = {
54100
usedNamesAndScopes(className) += TestUsedName(name, scopes)
55101
}
56102

@@ -59,7 +105,24 @@ class TestCallback extends AnalysisCallback
59105
apis(source) = classApi +: apis(source)
60106
}
61107

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 = ()
63126
override def dependencyPhaseCompleted(): Unit = ()
64127
override def apiPhaseCompleted(): Unit = ()
65128
override def enabled(): Boolean = true
@@ -68,29 +131,39 @@ class TestCallback extends AnalysisCallback
68131
override def mainClass(source: VirtualFileRef, className: String): Unit = ???
69132

70133
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+
???
72136
override def isPickleJava(): Boolean = ???
73137
}
74138

75139
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+
)
79145
object ExtractedClassDependencies {
80146
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),
86153
pairsToMultiMap(inheritancePairs),
87-
pairsToMultiMap(localInheritancePairs))
154+
pairsToMultiMap(localInheritancePairs)
155+
)
88156
}
89157

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)
93167
}
94168
}
95169
}
96-

0 commit comments

Comments
 (0)