@@ -8,7 +8,7 @@ import Symbols._
8
8
import Contexts .Context
9
9
import Flags .EmptyFlags
10
10
import dotc .util .SourceFile
11
- import dotc .util .Positions .Position
11
+ import dotc .util .Positions ._
12
12
import dotc .parsing .Parsers .Parser
13
13
import dotty .tools .dottydoc .model .comment .CommentUtils ._
14
14
@@ -38,14 +38,22 @@ object Comments {
38
38
private def decomposeUseCase (start : Int , end : Int ): UseCase = {
39
39
val codeStart = skipWhitespace(raw, start + " @usecase" .length)
40
40
val codeEnd = skipToEol(raw, codeStart)
41
- val code = raw.substring(codeStart, codeEnd)
42
- val codePos = Position (codeStart, codeEnd)
41
+ val code = raw.substring(codeStart, codeEnd) + " = ??? "
42
+ val codePos = subPos (codeStart, codeEnd)
43
43
val commentStart = skipLineLead(raw, codeEnd + 1 ) min end
44
44
val comment = " /** " + raw.substring(commentStart, end) + " */"
45
- val commentPos = Position (commentStart, end)
45
+ val commentPos = subPos (commentStart, end)
46
46
47
- UseCase (Comment (commentPos, comment), code + " = ??? " , codePos)
47
+ UseCase (Comment (commentPos, comment), code, codePos)
48
48
}
49
+
50
+ private def subPos (start : Int , end : Int ) =
51
+ if (pos == NoPosition ) NoPosition
52
+ else {
53
+ val start1 = pos.start + start
54
+ val end1 = pos.end + end
55
+ pos withStart start1 withPoint start1 withEnd end1
56
+ }
49
57
}
50
58
51
59
case class UseCase (comment : Comment , code : String , codePos : Position )(implicit ctx : Context ) {
@@ -56,9 +64,11 @@ object Comments {
56
64
val tree = new Parser (new SourceFile (" <usecase>" , code)).localDef(codePos.start, EmptyFlags )
57
65
58
66
tree match {
59
- case tree : untpd.DefDef => tree
67
+ case tree : untpd.DefDef =>
68
+ val newName = (tree.name.show + " $" + codePos.start).toTermName
69
+ untpd.DefDef (newName, tree.tparams, tree.vparamss, tree.tpt, tree.rhs)
60
70
case _ =>
61
- ctx.error(" proper def was not found in `@usecase`" , codePos)
71
+ ctx.error(" proper definition was not found in `@usecase`" , codePos)
62
72
tree
63
73
}
64
74
}
@@ -67,11 +77,14 @@ object Comments {
67
77
var tpdCode : tpd.DefDef = _
68
78
69
79
def typeTree ()(implicit ctx : Context ): Unit = untpdCode match {
70
- case df : untpd.DefDef => ctx.typer.typedDefDef(df, symbol) match {
71
- case tree : tpd.DefDef => tpdCode = tree
72
- case _ => ctx.error(" proper def was not found in `@usecase`" , codePos)
73
- }
74
- case _ => ctx.error(" proper def was not found in `@usecase`" , codePos)
80
+ case df : untpd.DefDef =>
81
+ ctx.typer.typedDefDef(df, symbol) match {
82
+ case tree : tpd.DefDef => tpdCode = tree
83
+ case _ =>
84
+ ctx.error(" proper def could not be typed from `@usecase`" , codePos)
85
+ }
86
+ case _ =>
87
+ ctx.error(" proper def was not found in `@usecase`" , codePos)
75
88
}
76
89
}
77
90
}
0 commit comments