Skip to content

Commit eb6148f

Browse files
committed
Rename MainAnnotation.{CommandInfo/ParamInfo} to Info/Parameter
1 parent feefe3f commit eb6148f

14 files changed

+68
-68
lines changed

compiler/src/dotty/tools/dotc/ast/MainProxies.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ object MainProxies {
150150
* final class f {
151151
* static def main(args: Array[String]): Unit = {
152152
* val annotation = new myMain(80)
153-
* val info = new CommandInfo(
153+
* val info = new Info(
154154
* name = "f",
155155
* documentation = "Lorem ipsum dolor sit amet consectetur adipiscing elit.",
156156
* parameters = Seq(
157-
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX"))),
158-
* new scala.annotation.MainAnnotation.ParameterInfo("y", "S", true, false, "", Seq()),
159-
* new scala.annotation.MainAnnotation.ParameterInfo("ys", "T", false, true, "all my params y", Seq())
157+
* new scala.annotation.MainAnnotation.Parameter("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX"))),
158+
* new scala.annotation.MainAnnotation.Parameter("y", "S", true, false, "", Seq()),
159+
* new scala.annotation.MainAnnotation.Parameter("ys", "T", false, true, "all my params y", Seq())
160160
* )
161161
* ),
162162
* val command = annot.command(info, args)
@@ -229,7 +229,7 @@ object MainProxies {
229229
*
230230
* A ParamInfo has the following shape
231231
* ```
232-
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX")))
232+
* new scala.annotation.MainAnnotation.Parameter("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX")))
233233
* ```
234234
*/
235235
def parameterInfos(mt: MethodType): List[Tree] =
@@ -252,7 +252,7 @@ object MainProxies {
252252
val constructorArgs = List(param, paramTypeStr, hasDefault, isRepeated, paramDoc)
253253
.map(value => Literal(Constant(value)))
254254

255-
New(TypeTree(defn.MainAnnotationParameterInfo.typeRef), List(constructorArgs :+ paramAnnots))
255+
New(TypeTree(defn.MainAnnotationParameter.typeRef), List(constructorArgs :+ paramAnnots))
256256

257257
end parameterInfos
258258

@@ -319,7 +319,7 @@ object MainProxies {
319319
val nameTree = Literal(Constant(mainFun.showName))
320320
val docTree = Literal(Constant(documentation.mainDoc))
321321
val paramInfos = Apply(ref(defn.SeqModule.termRef), parameterInfos)
322-
New(TypeTree(defn.MainAnnotationCommandInfo.typeRef), List(List(nameTree, docTree, paramInfos)))
322+
New(TypeTree(defn.MainAnnotationInfo.typeRef), List(List(nameTree, docTree, paramInfos)))
323323

324324
val annotVal = ValDef(
325325
nme.annotation,

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,8 @@ class Definitions {
852852
@tu lazy val XMLTopScopeModule: Symbol = requiredModule("scala.xml.TopScope")
853853

854854
@tu lazy val MainAnnotationClass: ClassSymbol = requiredClass("scala.annotation.MainAnnotation")
855-
@tu lazy val MainAnnotationCommandInfo: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.CommandInfo")
856-
@tu lazy val MainAnnotationParameterInfo: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.ParameterInfo")
855+
@tu lazy val MainAnnotationInfo: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.Info")
856+
@tu lazy val MainAnnotationParameter: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.Parameter")
857857
@tu lazy val MainAnnotationParameterAnnotation: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.ParameterAnnotation")
858858
@tu lazy val MainAnnotationCommand: ClassSymbol = requiredClass("scala.annotation.MainAnnotation.Command")
859859

docs/_docs/reference/experimental/main-annotation.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ When a users annotates a method with an annotation that extends `MainAnnotation`
2020
object foo {
2121
def main(args: Array[String]): Unit = {
2222
val mainAnnot = new myMain()
23-
val info = new CommandInfo(
23+
val info = new Info(
2424
name = "foo.main",
2525
documentation = "Sum all the numbers",
2626
parameters = Seq(
27-
new ParameterInfo("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum", Seq()),
28-
new ParameterInfo("second", "scala.Int", hasDefault=true, isVarargs=false, "", Seq()),
29-
new ParameterInfo("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum", Seq())
27+
new Parameter("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum", Seq()),
28+
new Parameter("second", "scala.Int", hasDefault=true, isVarargs=false, "", Seq()),
29+
new Parameter("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum", Seq())
3030
)
3131
)
3232
val mainArgsOpt = mainAnnot.command(info, args)
@@ -54,9 +54,9 @@ import scala.util.CommandLineParser.FromString[T]
5454

5555
// Result type of the annotated method is Int and arguments are parsed using FromString
5656
@experimental class myMain extends MainAnnotation[FromString, Int]:
57-
import MainAnnotation.{ CommandInfo, ParameterInfo }
57+
import MainAnnotation.{ Info, Parameter }
5858

59-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] =
59+
def command(info: Info, args: Seq[String]): Option[Seq[String]] =
6060
if args.contains("--help") then
6161
println(info.documentation)
6262
None // do not parse or run the program
@@ -80,10 +80,10 @@ import scala.util.CommandLineParser.FromString[T]
8080
else
8181
Some(args)
8282

83-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using parser: FromString[T]): () => T =
83+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using parser: FromString[T]): () => T =
8484
() => parser.fromString(arg)
8585

86-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using parser: FromString[T]): () => Seq[T] =
86+
def varargGetter[T](param: Parameter, args: Seq[String])(using parser: FromString[T]): () => Seq[T] =
8787
() => args.map(arg => parser.fromString(arg))
8888

8989
def run(program: () => Int): Unit =

library/src/scala/annotation/MainAnnotation.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ package scala.annotation
2424
* object foo {
2525
* def main(args: Array[String]): Unit = {
2626
* val mainAnnot = new myMain()
27-
* val info = new CommandInfo(
27+
* val info = new Info(
2828
* name = "foo.main",
2929
* documentation = "Sum all the numbers",
3030
* parameters = Seq(
31-
* new ParameterInfo("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum"),
32-
* new ParameterInfo("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum")
31+
* new Parameter("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum"),
32+
* new Parameter("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum")
3333
* )
3434
* )
3535
* val mainArgsOpt = mainAnnot.command(info, args)
@@ -49,7 +49,7 @@ package scala.annotation
4949
*/
5050
@experimental
5151
trait MainAnnotation[Parser[_], Result] extends StaticAnnotation:
52-
import MainAnnotation.{CommandInfo, ParameterInfo}
52+
import MainAnnotation.{Info, Parameter}
5353

5454
/** Process the command arguments before parsing them.
5555
*
@@ -62,17 +62,17 @@ trait MainAnnotation[Parser[_], Result] extends StaticAnnotation:
6262
* @param info The information about the command (name, documentation and info about parameters)
6363
* @param args The command line arguments
6464
*/
65-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]]
65+
def command(info: Info, args: Seq[String]): Option[Seq[String]]
6666

6767
/** The getter for the `idx`th argument of type `T`
6868
*
6969
* @param idx The index of the argument
7070
* @param defaultArgument Optional lambda to instantiate the default argument
7171
*/
72-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using Parser[T]): () => T
72+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using Parser[T]): () => T
7373

7474
/** The getter for a final varargs argument of type `T*` */
75-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using Parser[T]): () => Seq[T]
75+
def varargGetter[T](param: Parameter, args: Seq[String])(using Parser[T]): () => Seq[T]
7676

7777
/** Run `program` if all arguments are valid if all arguments are valid
7878
*
@@ -88,19 +88,19 @@ object MainAnnotation:
8888
/** Information about the main method
8989
*
9090
* @param name The name of the main method
91-
* @param documentation The documentation of the main method without the `@param` documentation (see ParameterInfo.documentaion)
91+
* @param documentation The documentation of the main method without the `@param` documentation (see Parameter.documentaion)
9292
* @param parameters Information about the parameters of the main method
9393
*/
94-
final class CommandInfo(
94+
final class Info(
9595
val name: String,
9696
val documentation: String,
97-
val parameters: Seq[ParameterInfo],
97+
val parameters: Seq[Parameter],
9898
):
9999

100100
/** If the method ends with a varargs parameter */
101101
def hasVarargs: Boolean = parameters.nonEmpty && parameters.last.isVarargs
102102

103-
end CommandInfo
103+
end Info
104104

105105
/** Information about a parameter of a main method
106106
*
@@ -111,7 +111,7 @@ object MainAnnotation:
111111
* @param documentation The documentation of the parameter (from `@param` documentation in the main method)
112112
* @param annotations The annotations of the parameter that extend `ParameterAnnotation`
113113
*/
114-
final class ParameterInfo(
114+
final class Parameter(
115115
val name: String,
116116
val typeName: String,
117117
val hasDefault: Boolean,
@@ -120,7 +120,7 @@ object MainAnnotation:
120120
val annotations: Seq[ParameterAnnotation],
121121
)
122122

123-
/** Marker trait for annotations that will be included in the ParameterInfo annotations. */
123+
/** Marker trait for annotations that will be included in the Parameter annotations. */
124124
trait ParameterAnnotation extends StaticAnnotation
125125

126126
end MainAnnotation

project/MiMaFilters.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object MiMaFilters {
1313
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation"),
1414
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$"),
1515
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$Command"),
16-
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$CommandInfo"),
17-
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$ParameterInfo"),
16+
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$Info"),
17+
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$Parameter"),
1818
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$ParameterAnnotation"),
1919
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.Tuples.append"),
2020
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.asQuotes"),

tests/run/main-annotation-example.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ end Test
2222

2323
@experimental
2424
class myMain extends MainAnnotation[FromString, Int]:
25-
import MainAnnotation.{ CommandInfo, ParameterInfo }
25+
import MainAnnotation.{ Info, Parameter }
2626

27-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] =
27+
def command(info: Info, args: Seq[String]): Option[Seq[String]] =
2828
if args.contains("--help") then
2929
println(info.documentation)
3030
None // do not parse or run the program
@@ -48,10 +48,10 @@ class myMain extends MainAnnotation[FromString, Int]:
4848
else
4949
Some(args)
5050

51-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using parser: FromString[T]): () => T =
51+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using parser: FromString[T]): () => T =
5252
() => parser.fromString(arg)
5353

54-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using parser: FromString[T]): () => Seq[T] =
54+
def varargGetter[T](param: Parameter, args: Seq[String])(using parser: FromString[T]): () => Seq[T] =
5555
() => args.map(arg => parser.fromString(arg))
5656

5757
def run(program: () => Int): Unit =

tests/run/main-annotation-homemade-annot-1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class mainAwait(timeout: Int = 2) extends MainAnnotation[FromString, Future[Any]
3333
import MainAnnotation.*
3434

3535
// This is a toy example, it only works with positional args
36-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] = Some(args)
36+
def command(info: Info, args: Seq[String]): Option[Seq[String]] = Some(args)
3737

38-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T =
38+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T =
3939
() => p.fromString(arg)
4040

41-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: FromString[T]): () => Seq[T] =
41+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: FromString[T]): () => Seq[T] =
4242
() => for arg <- args yield p.fromString(arg)
4343

4444
def run(f: () => Future[Any]): Unit = println(Await.result(f(), Duration(timeout, SECONDS)))

tests/run/main-annotation-homemade-annot-2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ end Test
3232
class myMain(runs: Int = 3)(after: String*) extends MainAnnotation[FromString, Any]:
3333
import MainAnnotation.*
3434

35-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] = Some(args)
35+
def command(info: Info, args: Seq[String]): Option[Seq[String]] = Some(args)
3636

37-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T =
37+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T =
3838
() => p.fromString(arg)
3939

40-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: FromString[T]): () => Seq[T] =
40+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: FromString[T]): () => Seq[T] =
4141
() => for arg <- args yield p.fromString(arg)
4242

4343
def run(f: () => Any): Unit =

tests/run/main-annotation-homemade-annot-3.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ end Test
1414
class mainNoArgs extends MainAnnotation[FromString, Any]:
1515
import MainAnnotation.*
1616

17-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] = Some(args)
17+
def command(info: Info, args: Seq[String]): Option[Seq[String]] = Some(args)
1818

19-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
19+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
2020

21-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
21+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
2222

2323
def run(program: () => Any): Unit = program()

tests/run/main-annotation-homemade-annot-4.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ end Test
1414
class mainManyArgs(i1: Int, s2: String, i3: Int) extends MainAnnotation[FromString, Any]:
1515
import MainAnnotation.*
1616

17-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] = Some(args)
17+
def command(info: Info, args: Seq[String]): Option[Seq[String]] = Some(args)
1818

19-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
19+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
2020

21-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
21+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
2222

2323

2424
def run(program: () => Any): Unit = program()

tests/run/main-annotation-homemade-annot-5.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ end Test
1616
class mainManyArgs(o: Option[Int]) extends MainAnnotation[FromString, Any]:
1717
import MainAnnotation.*
1818

19-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] = Some(args)
19+
def command(info: Info, args: Seq[String]): Option[Seq[String]] = Some(args)
2020

21-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
21+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: FromString[T]): () => T = ???
2222

23-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
23+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: FromString[T]): () => Seq[T] = ???
2424

2525
def run(program: () => Any): Unit = program()

tests/run/main-annotation-homemade-annot-6.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ command(
33
foo,
44
"Foo docs",
55
Seq(
6-
ParameterInfo(name="i", typeName="scala.Int", hasDefault=false, isVarargs=false, documentation="", annotations=List()),
7-
ParameterInfo(name="j", typeName="java.lang.String", hasDefault=true, isVarargs=false, documentation="", annotations=List())
6+
Parameter(name="i", typeName="scala.Int", hasDefault=false, isVarargs=false, documentation="", annotations=List()),
7+
Parameter(name="j", typeName="java.lang.String", hasDefault=true, isVarargs=false, documentation="", annotations=List())
88
)*
99
)
1010
run()
@@ -15,8 +15,8 @@ command(
1515
bar,
1616
"Bar docs",
1717
Seq(
18-
ParameterInfo(name="i", typeName="scala.collection.immutable.List[Int]", hasDefault=false, isVarargs=false, documentation="the first parameter", annotations=List(MyParamAnnot(3))),
19-
ParameterInfo(name="rest", typeName="scala.Int", hasDefault=false, isVarargs=true, documentation="", annotations=List())
18+
Parameter(name="i", typeName="scala.collection.immutable.List[Int]", hasDefault=false, isVarargs=false, documentation="the first parameter", annotations=List(MyParamAnnot(3))),
19+
Parameter(name="rest", typeName="scala.Int", hasDefault=false, isVarargs=true, documentation="", annotations=List())
2020
)*
2121
)
2222
varargGetter()

tests/run/main-annotation-homemade-annot-6.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ end Test
2020
class myMain extends MainAnnotation[Make, Any]:
2121
import MainAnnotation.*
2222

23-
def command(info: CommandInfo, args: Seq[String]): Option[Seq[String]] =
24-
def paramInfoString(paramInfo: ParameterInfo) =
23+
def command(info: Info, args: Seq[String]): Option[Seq[String]] =
24+
def paramInfoString(paramInfo: Parameter) =
2525
import paramInfo.*
26-
s" ParameterInfo(name=\"$name\", typeName=\"$typeName\", hasDefault=$hasDefault, isVarargs=$isVarargs, documentation=\"$documentation\", annotations=$annotations)"
26+
s" Parameter(name=\"$name\", typeName=\"$typeName\", hasDefault=$hasDefault, isVarargs=$isVarargs, documentation=\"$documentation\", annotations=$annotations)"
2727
println(
2828
s"""command(
2929
| ${args.mkString("Array(", ", ", ")")},
@@ -33,10 +33,10 @@ class myMain extends MainAnnotation[Make, Any]:
3333
|)""".stripMargin)
3434
Some(args)
3535

36-
def argGetter[T](param: ParameterInfo, arg: String, defaultArgument: Option[() => T])(using p: Make[T]): () => T =
36+
def argGetter[T](param: Parameter, arg: String, defaultArgument: Option[() => T])(using p: Make[T]): () => T =
3737
() => p.make
3838

39-
def varargGetter[T](param: ParameterInfo, args: Seq[String])(using p: Make[T]): () => Seq[T] =
39+
def varargGetter[T](param: Parameter, args: Seq[String])(using p: Make[T]): () => Seq[T] =
4040
println("varargGetter()")
4141
() => Seq(p.make, p.make)
4242

0 commit comments

Comments
 (0)