Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12db79c

Browse files
committed
Insert/ in doc-source-url if relative path follows word character
1 parentbf45e19 commit12db79c

File tree

4 files changed

+65
-20
lines changed

4 files changed

+65
-20
lines changed

‎src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala‎

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,21 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
318318

319319
if (!settings.docsourceurl.isDefault)
320320
inSource.map {case (file, line)=>
321-
// file path is relative to source root (-sourcepath)
322-
valsrc=Paths.get(settings.sourcepath.value).toUri
323-
valpath= file.file.toPath.toUri
324-
valfilePathExt= src.relativize(path)
325-
valrawPath:String= filePathExt.getRawPath
321+
valfilePathExt= {
322+
// file path is relative to source root (-sourcepath); use an absolute path otherwise
323+
valsp= settings.sourcepath.value
324+
valfileUri= file.file.toPath.toUri
325+
if (sp.isEmpty) fileUri.getRawPath
326+
elsePaths.get(sp).toUri.relativize(fileUri).getRawPath
327+
}
326328
val (filePath, fileExt)=
327-
rawPath.lastIndexOf('.')match {
328-
case-1=> (rawPath,"")
329-
case i=>rawPath.splitAt(i)
329+
filePathExt.lastIndexOf('.')match {
330+
case-1=> (filePathExt,"")
331+
case i=>filePathExt.splitAt(i)
330332
}
331333
valtplOwner=this.inTemplate.qualifiedName
332334
valtplName=this.name
333-
defsubstitute(name:String):String= namematch {
334-
caseFILE_PATH=> filePath
335-
caseFILE_EXT=> fileExt
336-
caseFILE_PATH_EXT=> filePathExt.toString
337-
caseFILE_LINE=> line.toString
338-
caseTPL_OWNER=> tplOwner
339-
caseTPL_NAME=> tplName
340-
}
341-
valpatchedString= tokens.replaceAllIn(settings.docsourceurl.value, m=> quoteReplacement(substitute(m.group(1))) )
335+
valpatchedString= expandUrl(settings.docsourceurl.value, filePath, fileExt, filePathExt, line, tplOwner, tplName)
342336
newURI(patchedString).toURL
343337
}
344338
elseNone
@@ -1061,11 +1055,38 @@ object ModelFactory {
10611055
valdefaultGroupDesc=None
10621056
valdefaultGroupPriority=1000
10631057

1064-
valtokens=raw"€\{($FILE_PATH|$FILE_EXT|$FILE_PATH_EXT|$FILE_LINE|$TPL_OWNER|$TPL_NAME)\}".r
1058+
valtokens=raw"(?:(.?)€\{($FILE_PATH|$FILE_PATH_EXT)\}|\.?€\{($FILE_EXT)\}|€\{($FILE_LINE|$TPL_OWNER|$TPL_NAME)\})".r
10651059
finalvalFILE_PATH="FILE_PATH"
10661060
finalvalFILE_EXT="FILE_EXT"
10671061
finalvalFILE_PATH_EXT="FILE_PATH_EXT"
10681062
finalvalFILE_LINE="FILE_LINE"
10691063
finalvalTPL_OWNER="TPL_OWNER"
10701064
finalvalTPL_NAME="TPL_NAME"
1065+
1066+
valWordChar=raw"\w".r
1067+
1068+
defexpandUrl(urlTemplate:String,filePath:String,fileExt:String,filePathExt:String,line:Int,tplOwner:String,tplName:String):String= {
1069+
valabsolute= filePath.startsWith("/")
1070+
1071+
defsubst(groups:List[String]):String= {
1072+
// If a relative path follows a word character, insert a `/`
1073+
defsep:String= groups.headmatch {
1074+
casenull=>""
1075+
case"/"if absolute=>""
1076+
case c@WordChar()if!absolute=> c+"/"
1077+
case c=> c
1078+
}
1079+
1080+
groups.tail.find(_!=null).getmatch {
1081+
caseFILE_PATH=>s"$sep$filePath"
1082+
caseFILE_EXT=> fileExt
1083+
caseFILE_PATH_EXT=>s"$sep$filePathExt"
1084+
caseFILE_LINE=> line.toString
1085+
caseTPL_OWNER=> tplOwner
1086+
caseTPL_NAME=> tplName
1087+
}
1088+
}
1089+
1090+
tokens.replaceAllIn(urlTemplate, m=> quoteReplacement(subst(m.subgroups)))
1091+
}
10711092
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagescala.tools.nsc.doc.html
2+
3+
importorg.junit.Assert.assertEquals
4+
importorg.junit.Test
5+
6+
importscala.tools.nsc.doc.model.ModelFactory._
7+
importscala.util.matching.Regex.quoteReplacement
8+
9+
classModelFactoryTest {
10+
deft(expected:String,template:String,
11+
filePath:String=null,fileExt:String=null,line:Int=0,tplOwner:String=null,tplName:String=null)=
12+
assertEquals(expected, expandUrl(template, filePath, fileExt, filePath+ fileExt, line, tplOwner, tplName))
13+
14+
@TestdefsourceUrlReplace():Unit= {
15+
t("/base/p/file.scala","/base€{FILE_PATH_EXT}", filePath="/p/file", fileExt=".scala")
16+
t("/base/p/file.scala","/base/€{FILE_PATH_EXT}", filePath="/p/file", fileExt=".scala")
17+
18+
t("/base/p/file.scala","/base€{FILE_PATH_EXT}", filePath="p/file", fileExt=".scala")
19+
t("/base/p/file.scala","/base/€{FILE_PATH_EXT}", filePath="p/file", fileExt=".scala")
20+
21+
t("/base/p/file.scala","/base/€{FILE_PATH}€{FILE_EXT}", filePath="/p/file", fileExt=".scala")
22+
t("/base/p/file.scala","/base/€{FILE_PATH}.€{FILE_EXT}", filePath="/p/file", fileExt=".scala")
23+
}
24+
}

‎test/scaladoc/run/doc-source-url-java.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Test extends ScaladocModelTest {
2626

2727
overridedefmodel:Option[Universe]= newDocFactory.makeUniverse(Left(List(resourceFile)))
2828

29-
defscaladocSettings="-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE}"
29+
defscaladocSettings="-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE} -sourcepath ."
3030

3131
deftestModel(rootPackage:Package)= {
3232
importaccess._

‎test/scaladoc/run/doc-source-url.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Test extends ScaladocModelTest {
2626

2727
overridedefmodel:Option[Universe]= newDocFactory.makeUniverse(Left(List(resourceFile)))
2828

29-
defscaladocSettings="-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE}"
29+
defscaladocSettings="-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE} -sourcepath ."
3030

3131
deftestModel(rootPackage:Package)= {
3232
importaccess._

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp