Skip to content

Commit f8ed249

Browse files
committed
Remove ParamInfo.withAnnotations
1 parent f2339d7 commit f8ed249

File tree

6 files changed

+24
-34
lines changed

6 files changed

+24
-34
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,8 @@ object MainProxies {
152152
* args,
153153
* "f",
154154
* "Lorem ipsum dolor sit amet consectetur adipiscing elit.",
155-
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S")
156-
* .withDocumentation("my param x")
157-
* .withAnnotations(new scala.main.Alias("myX")),
158-
* new scala.annotation.MainAnnotation.ParameterInfo("ys", "T")
159-
* .withDocumentation("all my params y")
155+
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX")))
156+
* new scala.annotation.MainAnnotation.ParameterInfo("ys", "T", false, false, "all my params y", Seq())
160157
* )
161158
*
162159
* val args0: () => S = cmd.argGetter[S](0, None)
@@ -226,9 +223,7 @@ object MainProxies {
226223
*
227224
* A ParamInfo has the following shape
228225
* ```
229-
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S")
230-
* .withDocumentation("my param x")
231-
* .withAnnotations(new scala.main.Alias("myX"))
226+
* new scala.annotation.MainAnnotation.ParameterInfo("x", "S", false, false, "my param x", Seq(new scala.main.Alias("myX")))
232227
* ```
233228
*/
234229
def parameterInfos(mt: MethodType): List[Tree] =
@@ -244,15 +239,15 @@ object MainProxies {
244239
val hasDefault = defaultValueSymbols.contains(idx)
245240
val isRepeated = formal.isRepeatedParam
246241
val paramDoc = documentation.argDocs.getOrElse(param, "")
242+
val paramAnnots =
243+
val annotationTrees = paramAnnotations(idx).map(instantiateAnnotation).toList
244+
Apply(ref(defn.SeqModule.termRef), annotationTrees)
247245

248246
val constructorArgs = List(param, paramTypeStr, hasDefault, isRepeated, paramDoc)
249247
.map(value => Literal(Constant(value)))
250-
val paramInfos =
251-
New(TypeTree(defn.MainAnnotationParameterInfo.typeRef), List(constructorArgs))
252-
val paramAnnots = paramAnnotations(idx)
253-
if paramAnnots.nonEmpty then
254-
paramInfos.withProperty(defn.MainAnnotationParameterInfo_withAnnotations, paramAnnots.map(instantiateAnnotation).toList)
255-
else paramInfos
248+
249+
New(TypeTree(defn.MainAnnotationParameterInfo.typeRef), List(constructorArgs :+ paramAnnots))
250+
256251
end parameterInfos
257252

258253
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ class Definitions {
524524
@tu lazy val Seq_lengthCompare: Symbol = SeqClass.requiredMethod(nme.lengthCompare, List(IntType))
525525
@tu lazy val Seq_length : Symbol = SeqClass.requiredMethod(nme.length)
526526
@tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq)
527+
@tu lazy val SeqModule: Symbol = requiredModule("scala.collection.immutable.Seq")
528+
527529

528530
@tu lazy val StringOps: Symbol = requiredClass("scala.collection.StringOps")
529531
@tu lazy val StringOps_format: Symbol = StringOps.requiredMethod(nme.format)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ object StdNames {
467467
val dynamics: N = "dynamics"
468468
val elem: N = "elem"
469469
val elems: N = "elems"
470+
val empty: N = "empty"
470471
val emptyValDef: N = "emptyValDef"
471472
val end: N = "end"
472473
val ensureAccessible : N = "ensureAccessible"

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ object foo {
2323
args = args,
2424
commandName = "sum",
2525
documentation = "Sum all the numbers",
26-
new ParameterInfo("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum"),
27-
new ParameterInfo("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum")
26+
new ParameterInfo("first", "scala.Int", hasDefault=false, isVarargs=false, "Fist number to sum", Seq()),
27+
new ParameterInfo("rest", "scala.Int" , hasDefault=false, isVarargs=true, "The rest of the numbers to sum", Seq())
2828
)
2929
val args0 = cmd.argGetter[Int](0, None) // using cmd.Parser[Int]
3030
val args1 = cmd.varargGetter[Int] // using cmd.Parser[Int]
@@ -86,4 +86,3 @@ class myMain extends MainAnnotation:
8686
end MyCommand
8787
end myMain
8888
```
89-

library/src/scala/annotation/MainAnnotation.scala

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ end MainAnnotation
6464
@experimental
6565
object MainAnnotation:
6666

67-
final class ParameterInfo private (
67+
/** ParameterInfo with a name, the type of the parameter and if it has a default
68+
*
69+
* @param name The name of the parameter
70+
* @param typeName The type of the parameter
71+
* @param hasDefault If the parameter has a default argument
72+
* @param isVarargs If the parameter is a varargs parameter (can only be true for the last parameter)
73+
* @param documentation The documentation of the parameter (from `@param` documentation in the main method)
74+
*/
75+
final class ParameterInfo (
6876
paramName: String,
6977
paramTypeName: String,
7078
paramHasDefault: Boolean,
@@ -73,17 +81,6 @@ object MainAnnotation:
7381
paramAnnotations: Seq[ParameterAnnotation],
7482
) {
7583

76-
/** ParameterInfo with a name, the type of the parameter and if it has a default
77-
*
78-
* @param name The name of the parameter
79-
* @param typeName The type of the parameter
80-
* @param hasDefault If the parameter has a default argument
81-
* @param isVarargs If the parameter is a varargs parameter (can only be true for the last parameter)
82-
* @param documentation The documentation of the parameter (from `@param` documentation in the main method)
83-
*/
84-
def this(name: String, typeName: String, hasDefault: Boolean, isVarargs: Boolean, documentation: String) =
85-
this(name, typeName, hasDefault, isVarargs, documentation, Seq.empty)
86-
8784
/** The name of the parameter */
8885
def name: String = paramName
8986

@@ -102,10 +99,6 @@ object MainAnnotation:
10299
/** The ParameterAnnotations associated with the parameter. Defaults to Seq.empty. */
103100
def annotations: Seq[ParameterAnnotation] = paramAnnotations
104101

105-
/** Copy this ParameterInfo and sets the annotations */
106-
def withAnnotations(annotations: ParameterAnnotation*): ParameterInfo =
107-
new ParameterInfo(paramName, typeName, paramHasDefault, paramIsVarargs, documentation, annotations)
108-
109102
override def toString: String = s"$name: $typeName"
110103
}
111104

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ command(
1717
bar,
1818
"Bar docs",
1919
Seq(
20-
ParameterInfo(name="i", typeName="scala.collection.immutable.List[Int]", hasDefault=false, isVarargs=false, documentation="the first parameter", annotations=ArraySeq(MyParamAnnot(3))),
20+
ParameterInfo(name="i", typeName="scala.collection.immutable.List[Int]", hasDefault=false, isVarargs=false, documentation="the first parameter", annotations=List(MyParamAnnot(3))),
2121
ParameterInfo(name="rest", typeName="scala.Int", hasDefault=false, isVarargs=true, documentation="", annotations=List())
2222
)*
2323
)

0 commit comments

Comments
 (0)