Skip to content

Commit f1a16f4

Browse files
committed
refactor: use scala types
1 parent a991149 commit f1a16f4

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

compiler/src/dotty/tools/dotc/reporting/CodeAction.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import dotty.tools.dotc.rewrites.Rewrites.ActionPatch
1111
*/
1212
case class CodeAction(
1313
title: String,
14-
description: java.util.Optional[String],
15-
patches: java.util.List[ActionPatch]
14+
description: Option[String],
15+
patches: List[ActionPatch]
1616
)

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,10 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
414414
*/
415415
def showAlways = false
416416

417-
/** A list of actions attatched to this message to address the issue this
417+
/** A list of actions attached to this message to address the issue this
418418
* message represents.
419419
*/
420-
def actions(using Context): java.util.List[CodeAction] =
421-
java.util.Collections.emptyList
420+
def actions(using Context): List[CodeAction] = List.empty
422421

423422
override def toString = msg
424423
}

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@ extends SyntaxMsg(RepeatedModifierID) {
522522
import scala.language.unsafeNulls
523523
List(
524524
CodeAction(title = s"""Remove repeated modifier: "$modifier"""",
525-
description = java.util.Optional.empty(),
525+
description = None,
526526
patches = List(
527527
ActionPatch(SourcePosition(source, span), "")
528-
).asJava
528+
)
529529
)
530-
).asJava
530+
)
531531
}
532532

533533
class InterpolatedStringError()(implicit ctx:Context)
@@ -1874,13 +1874,13 @@ class OnlyFunctionsCanBeFollowedByUnderscore(tp: Type, tree: untpd.PostfixOp)(us
18741874
val untpd.PostfixOp(qual, Ident(nme.WILDCARD)) = tree: @unchecked
18751875
List(
18761876
CodeAction(title = "Rewrite to function value",
1877-
description = java.util.Optional.empty(),
1877+
description = None,
18781878
patches = List(
18791879
ActionPatch(SourcePosition(tree.source, Span(tree.span.start)), "(() => "),
18801880
ActionPatch(SourcePosition(tree.source, Span(qual.span.end, tree.span.end)), ")")
1881-
).asJava
1881+
)
18821882
)
1883-
).asJava
1883+
)
18841884
}
18851885

18861886
class MissingEmptyArgumentList(method: String, tree: tpd.Tree)(using Context)
@@ -1903,12 +1903,12 @@ class MissingEmptyArgumentList(method: String, tree: tpd.Tree)(using Context)
19031903
import scala.language.unsafeNulls
19041904
List(
19051905
CodeAction(title = "Insert ()",
1906-
description = java.util.Optional.empty(),
1906+
description = None,
19071907
patches = List(
19081908
ActionPatch(SourcePosition(tree.source, tree.span.endPos), "()"),
1909-
).asJava
1909+
)
19101910
)
1911-
).asJava
1911+
)
19121912
}
19131913

19141914
class DuplicateNamedTypeParameter(name: Name)(using Context)

compiler/test/dotty/tools/dotc/reporting/CodeActionTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ class CodeActionTest extends DottyTest:
6969
assertEquals(1, diagnostics.size)
7070

7171
val diagnostic = diagnostics.head
72-
val actions = diagnostic.msg.actions.asScala.toList
72+
val actions = diagnostic.msg.actions.toList
7373
assertEquals(1, actions.size)
7474

7575
// TODO account for more than 1 action
7676
val action = actions.head
7777
assertEquals(action.title, title)
78-
val patches = action.patches.asScala.toList
78+
val patches = action.patches.toList
7979
if patches.nonEmpty then
8080
patches.reduceLeft: (p1, p2) =>
8181
assert(p1.srcPos.span.end <= p2.srcPos.span.start, s"overlapping patches $p1 and $p2")

sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import scala.Tuple2;
99
import scala.collection.mutable.HashMap;
10+
import scala.jdk.javaapi.CollectionConverters;
1011

1112
import dotty.tools.dotc.core.Contexts.Context;
1213
import dotty.tools.dotc.reporting.AbstractReporter;
@@ -46,7 +47,7 @@ public void doReport(Diagnostic dia, Context ctx) {
4647
messageBuilder.append(message.message());
4748
String diagnosticCode = String.valueOf(message.errorId().errorNumber());
4849
boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx);
49-
List<CodeAction> actions = message.actions(ctx);
50+
List<CodeAction> actions = CollectionConverters.asJava(message.actions(ctx));
5051
if (shouldExplain && !message.explanation().isEmpty()) {
5152
rendered.append(explanation(message, ctx));
5253
messageBuilder.append(System.lineSeparator()).append(explanation(message, ctx));

sbt-bridge/src/dotty/tools/xsbt/Problem.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import dotty.tools.dotc.rewrites.Rewrites.ActionPatch;
99
import dotty.tools.dotc.util.SourcePosition;
1010

11+
import scala.jdk.javaapi.CollectionConverters;
12+
import scala.jdk.javaapi.OptionConverters;
13+
1114
import xsbti.Position;
1215
import xsbti.Severity;
1316

@@ -75,7 +78,7 @@ public List<xsbti.Action> actions() {
7578
// never getting called.
7679
return _actions
7780
.stream()
78-
.map(action -> new Action(action.title(), action.description(), toWorkspaceEdit(action.patches())))
81+
.map(action -> new Action(action.title(), OptionConverters.toJava(action.description()), toWorkspaceEdit(CollectionConverters.asJava(action.patches()))))
7982
.collect(toList());
8083
}
8184
}

0 commit comments

Comments
 (0)