Skip to content

SourceFile converts File.separator #15064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Denotations.Denotation
import typer.Typer
import typer.ImportInfo.withRootImports
import Decorators._
import io.{AbstractFile, VirtualFile}
import io.AbstractFile
import Phases.unfusedPhases

import util._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.zip._
import scala.collection._
import scala.io.Codec

import dotty.tools.io.{ AbstractFile, VirtualFile }
import dotty.tools.io.AbstractFile

import ast.{Trees, tpd}
import core._, core.Decorators._
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/util/SourceFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.chaining.given

import java.io.File.separator
import java.nio.charset.StandardCharsets
import java.nio.file.{FileSystemException, NoSuchFileException}
import java.util.Optional
Expand Down Expand Up @@ -217,8 +218,11 @@ object SourceFile {

implicit def fromContext(using Context): SourceFile = ctx.source

/** A source file with an underlying virtual file. The name is taken as a file system path
* with the local separator converted to "/". The last element of the path will be the simple name of the file.
*/
def virtual(name: String, content: String, maybeIncomplete: Boolean = false) =
SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), content.toCharArray)
SourceFile(new VirtualFile(name.replace(separator, "/"), content.getBytes(StandardCharsets.UTF_8)), content.toCharArray)
.tap(_._maybeInComplete = maybeIncomplete)

/** Returns the relative path of `source` within the `reference` path
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/io/VirtualDirectory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extends AbstractFile {

override def fileNamed(name: String): AbstractFile =
Option(lookupName(name, directory = false)) getOrElse {
val newFile = new VirtualFile(name, path + '/' + name)
val newFile = new VirtualFile(name, s"$path/$name")
files(name) = newFile
newFile
}
Expand Down
1 change: 0 additions & 1 deletion scaladoc/src/dotty/tools/scaladoc/DocContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.nio.file.Paths
import collection.JavaConverters._
import dotty.tools.scaladoc.site.StaticSiteContext
import dotty.tools.dotc.core.Contexts._
import dotty.tools.io.VirtualFile
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.Spans
Expand Down