Skip to content

Commit

Permalink
Remove more .nn
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Sep 23, 2024
1 parent 1c19710 commit e60dcbb
Show file tree
Hide file tree
Showing 33 changed files with 56 additions and 71 deletions.
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import BTypes.InternalName
import scala.util.chaining.*
import dotty.tools.io.JarArchive

import scala.language.unsafeNulls

/** !!! This file is now copied in `dotty.tools.io.FileWriters` in a more general way that does not rely upon
* `PostProcessorFrontendAccess`, this should probably be changed to wrap that class instead.
*
Expand Down Expand Up @@ -54,11 +52,11 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
def close(): Unit

protected def classRelativePath(className: InternalName, suffix: String = ".class"): String =
className.replace('.', '/').nn + suffix
className.replace('.', '/') + suffix
}

object ClassfileWriter {
private def getDirectory(dir: String): Path = Paths.get(dir).nn
private def getDirectory(dir: String): Path = Paths.get(dir)

def apply(): ClassfileWriter = {
val jarManifestMainClass: Option[String] = compilerSettings.mainClass.orElse {
Expand Down Expand Up @@ -137,7 +135,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel)
}
else if (file.isVirtual) new VirtualFileWriter(file)
else if (file.isDirectory) new DirEntryWriter(file.file.toPath.nn)
else if (file.isDirectory) new DirEntryWriter(file.file.toPath)
else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]")
}

Expand All @@ -151,7 +149,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
val jarWriter: JarOutputStream = {
import scala.util.Properties.*
val manifest = new Manifest
val attrs = manifest.getMainAttributes.nn
val attrs = manifest.getMainAttributes
attrs.put(MANIFEST_VERSION, "1.0")
attrs.put(ScalaCompilerVersion, versionNumberString)
mainClass.foreach(c => attrs.put(MAIN_CLASS, c))
Expand Down Expand Up @@ -184,7 +182,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
// important detail here, even on Windows, Zinc expects the separator within the jar
// to be the system default, (even if in the actual jar file the entry always uses '/').
// see https://github.com/sbt/zinc/blob/dcddc1f9cfe542d738582c43f4840e17c053ce81/internal/compiler-bridge/src/main/scala/xsbt/JarUtils.scala#L47
val pathInJar =
val pathInJar =
if File.separatorChar == '/' then relativePath
else relativePath.replace('/', File.separatorChar)
PlainFile.toPlainFile(Paths.get(s"${file.absolutePath}!$pathInJar"))
Expand Down Expand Up @@ -293,5 +291,5 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
}

/** Can't output a file due to the state of the file system. */
class FileConflictException(msg: String, cause: Throwable = null) extends IOException(msg, cause)
class FileConflictException(msg: String, cause: Throwable | Null = null) extends IOException(msg, cause)
}
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Driver {
finish(compiler, run)
catch
case ex: FatalError =>
report.error(ex.getMessage.nn) // signals that we should fail compilation.
report.error(ex.getMessage) // signals that we should fail compilation.
case ex: Throwable if ctx.usedBestEffortTasty =>
report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.")
throw ex
Expand Down Expand Up @@ -117,7 +117,7 @@ class Driver {
.distinct
val ctx1 = ctx.fresh
val fullClassPath =
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator.nn)
(newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator)
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
else ctx

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ class CheckCaptures extends Recheck, SymTransformer:
trace.force(i"rechecking $tree with pt = $pt", recheckr, show = true):
super.recheck(tree, pt)
catch case ex: NoCommonRoot =>
report.error(ex.getMessage.nn)
report.error(ex.getMessage)
tree.tpe
finally curEnv = saved
if tree.isTerm then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ClassPathFactory {
for
file <- files
a <- ClassPath.expandManifestPath(file.absolutePath)
path = java.nio.file.Paths.get(a.toURI()).nn
path = java.nio.file.Paths.get(a.toURI())
if Files.exists(path)
yield
newClassPath(AbstractFile.getFile(path))
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/CommandLineParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ object CommandLineParser:
Nil
else
def stripComment(s: String) = s.indexOf('#') match { case -1 => s case i => s.substring(0, i) }
val lines = Files.readAllLines(path).nn
val params = lines.asScala.map(stripComment).filter(!_.nn.isEmpty).mkString(" ")
val lines = Files.readAllLines(path)
val params = lines.asScala.map(stripComment).filter(!_.isEmpty).mkString(" ")
tokenize(params)

class ParseException(msg: String) extends RuntimeException(msg)
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package dotty.tools
package dotc
package core

import scala.language.unsafeNulls

import ast.{ untpd, tpd }
import Symbols.*, Contexts.*
import util.{SourceFile, ReadOnlyMap}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Decorators {
if name.length != 0 then name.getChars(0, name.length, chars, s.length)
termName(chars, 0, len)
case name: TypeName => s.concat(name.toTermName)
case _ => termName(s.concat(name.toString).nn)
case _ => termName(s.concat(name.toString))

def indented(width: Int): String =
val padding = " " * width
Expand Down Expand Up @@ -289,10 +289,10 @@ object Decorators {
case NonFatal(ex)
if !ctx.settings.YshowPrintErrors.value =>
s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..."
case _ => String.valueOf(x).nn
case _ => String.valueOf(x)

/** Returns the simple class name of `x`. */
def className: String = x.getClass.getSimpleName.nn
def className: String = x.getClass.getSimpleName

extension [T](x: T)
def assertingErrorsReported(using Context): T = {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import nme.*
object NameOps {

object compactify {
lazy val md5: MessageDigest = MessageDigest.getInstance("MD5").nn
lazy val md5: MessageDigest = MessageDigest.getInstance("MD5")

inline val CLASSFILE_NAME_CHAR_LIMIT = 240

Expand Down Expand Up @@ -43,7 +43,7 @@ object NameOps {
val suffix = s.takeRight(edge)

val cs = s.toArray
val bytes = Codec.toUTF8(CharBuffer.wrap(cs).nn)
val bytes = Codec.toUTF8(CharBuffer.wrap(cs))
md5.update(bytes)
val md5chars = md5.digest().map(b => (b & 0xFF).toHexString).mkString

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
|| ctx.settings.YdebugCyclic.value

override def fillInStackTrace(): Throwable =
if computeStackTrace then super.fillInStackTrace().nn
if computeStackTrace then super.fillInStackTrace()
else this

/** Convert to message. This takes an additional Context, so that we
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object TypeEval:
val result =
try op
catch case e: Throwable =>
throw TypeError(em"${e.getMessage.nn}")
throw TypeError(em"${e.getMessage}")
ConstantType(Constant(result))

def fieldsOf: Option[Type] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.dotc
package core.tasty

import scala.language.unsafeNulls
import scala.collection.immutable.BitSet
import scala.collection.immutable.TreeMap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object TastyPrinter:
else if arg.endsWith(".tasty") || (allowBetasty && arg.endsWith(".betasty")) then
val path = Paths.get(arg)
if Files.exists(path) then
printTasty(arg, Files.readAllBytes(path).nn, arg.endsWith(".betasty"))
printTasty(arg, Files.readAllBytes(path), arg.endsWith(".betasty"))
else
println("File not found: " + arg)
System.exit(1)
Expand Down
12 changes: 4 additions & 8 deletions compiler/src/dotty/tools/dotc/plugins/Plugins.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dotty.tools.dotc
package plugins

import scala.language.unsafeNulls

import core.*
import Contexts.*
import Decorators.em
Expand Down Expand Up @@ -47,13 +45,12 @@ trait Plugins {
goods map (_.get)
}

private var _roughPluginsList: List[Plugin] = uninitialized
private var _roughPluginsList: List[Plugin] | Null = null
protected def roughPluginsList(using Context): List[Plugin] =
if (_roughPluginsList == null) {
_roughPluginsList = loadRoughPluginsList
_roughPluginsList
}
else _roughPluginsList
_roughPluginsList.nn

/** Load all available plugins. Skips plugins that
* either have the same name as another one, or which
Expand Down Expand Up @@ -99,13 +96,12 @@ trait Plugins {
plugs
}

private var _plugins: List[Plugin] = uninitialized
private var _plugins: List[Plugin] | Null = null
def plugins(using Context): List[Plugin] =
if (_plugins == null) {
_plugins = loadPlugins
_plugins
}
else _plugins
_plugins.nn

/** A description of all the plugins that are loaded */
def pluginDescriptions(using Context): String =
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case tp: ThisType =>
nameString(tp.cls) + ".this"
case SuperType(thistpe: SingletonType, _) =>
toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super").nn)
toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super"))
case SuperType(thistpe, _) =>
"Super(" ~ toTextGlobal(thistpe) ~ ")"
case tp @ ConstantType(value) =>
Expand Down Expand Up @@ -628,7 +628,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case '"' => "\\\""
case '\'' => "\\\'"
case '\\' => "\\\\"
case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch).nn
case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch)
}

def toText(const: Constant): Text = const.tag match {
Expand All @@ -638,7 +638,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case LongTag => literalText(const.longValue.toString + "L")
case DoubleTag => literalText(const.doubleValue.toString + "d")
case FloatTag => literalText(const.floatValue.toString + "f")
case _ => literalText(String.valueOf(const.value).nn)
case _ => literalText(String.valueOf(const.value))
}

/** Usual target for `Annotation#toText`, overridden in RefinedPrinter */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/Showable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait Showable extends Any {
/** The string representation with each line after the first one indented
* by the given given margin (in spaces).
*/
def showIndented(margin: Int)(using Context): String = show.replace("\n", "\n" + " " * margin).nn
def showIndented(margin: Int)(using Context): String = show.replace("\n", "\n" + " " * margin)

/** The summarized string representation of this showable element.
* Recursion depth is limited to some smallish value. Default is
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/Texts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.annotation.internal.sharable
object Texts {

@sharable
private val ansi = java.util.regex.Pattern.compile("\u001b\\[\\d+m").nn
private val ansi = java.util.regex.Pattern.compile("\u001b\\[\\d+m")

sealed abstract class Text {

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/quoted/Interpreter.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dotty.tools.dotc
package quoted

import scala.language.unsafeNulls

import scala.collection.mutable
import scala.reflect.ClassTag

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class CyclicMsg(errorId: ErrorMessageID)(using Context) extends Message

protected def debugInfo =
if ctx.settings.YdebugCyclic.value then
"\n\nStacktrace:" ++ ex.getStackTrace().nn.mkString("\n ", "\n ", "")
"\n\nStacktrace:" ++ ex.getStackTrace().mkString("\n ", "\n ", "")
else "\n\n Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace."

protected def context: String = ex.optTrace match
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ object Scala3:
else Descriptor.None

def unescapeUnicode =
unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar).nn)
unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar))

def isJavaIdent =
symbol.nonEmpty && isJavaIdentifierStart(symbol.head) && symbol.tail.forall(isJavaIdentifierPart)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class Pickler extends Phase {
}

private def computeInternalName(cls: ClassSymbol)(using Context): String =
if cls.is(Module) then cls.binaryClassName.stripSuffix(str.MODULE_SUFFIX).nn
if cls.is(Module) then cls.binaryClassName.stripSuffix(str.MODULE_SUFFIX)
else cls.binaryClassName

override def run(using Context): Unit = {
Expand Down Expand Up @@ -413,11 +413,11 @@ class Pickler extends Phase {
)
if ctx.isBestEffort then
val outpath =
ctx.settings.outputDir.value.jpath.toAbsolutePath.nn.normalize.nn
.resolve("META-INF").nn
ctx.settings.outputDir.value.jpath.toAbsolutePath.normalize
.resolve("META-INF")
.resolve("best-effort")
Files.createDirectories(outpath)
BestEffortTastyWriter.write(outpath.nn, result)
BestEffortTastyWriter.write(outpath, result)
result
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Errors:
report.warning(show, this.pos)
end Error

override def toString() = this.getClass.getName.nn
override def toString() = this.getClass.getName

/** Access non-initialized field */
case class AccessNonInit(field: Symbol)(val trace: Trace) extends Error:
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/init/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ object Trace:
val line =
if pos.source.exists then
val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]"
val code = SyntaxHighlighting.highlight(pos.lineContent.trim.nn)
val code = SyntaxHighlighting.highlight(pos.lineContent.trim)
i"$code\t$loc"
else
tree match
case defDef: DefTree =>
// The definition can be huge, avoid printing the whole definition.
defDef.symbol.showFullName
case _ =>
tree.show.split(System.lineSeparator(), 2).nn.head.nn
tree.show.split(System.lineSeparator(), 2).head

val positionMarkerLine =
if pos.exists && pos.source.exists then
Expand All @@ -86,7 +86,7 @@ object Trace:
*/
private def positionMarker(pos: SourcePosition): String =
val trimmed = pos.source.lineContent(pos.start).takeWhile(c => c.isWhitespace).length
val padding = pos.startColumnPadding.substring(trimmed).nn
val padding = pos.startColumnPadding.substring(trimmed)
val carets =
if (pos.startLine == pos.endLine)
"^" * math.max(1, pos.endColumn - pos.startColumn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TypedFormatChecker(partsElems: List[Tree], parts: List[String], args: List
def loop(remaining: List[String], n: Int): Unit =
remaining match
case part0 :: more =>
def badPart(t: Throwable): String = "".tap(_ => report.partError(t.getMessage.nn, index = n, offset = 0))
def badPart(t: Throwable): String = "".tap(_ => report.partError(t.getMessage, index = n, offset = 0))
val part = try StringContext.processEscapes(part0) catch badPart
val matches = formatPattern.findAllMatchIn(part)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
val dotIndex = pathName.indexOf('.')
val globalRef =
if (dotIndex < 0) pathName
else pathName.substring(0, dotIndex).nn
else pathName.substring(0, dotIndex)
checkGlobalRefName(globalRef)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,9 @@ object RefChecks {
val matches = referencePattern.findAllIn(s)
for reference <- matches do
val referenceOffset = matches.start
val prefixlessReference = reference.replaceFirst("""\$\{\s*""", "").nn
val prefixlessReference = reference.replaceFirst("""\$\{\s*""", "")
val variableOffset = referenceOffset + reference.length - prefixlessReference.length
val variableName = prefixlessReference.replaceFirst("""\s*\}""", "").nn
val variableName = prefixlessReference.replaceFirst("""\s*\}""", "")
f(variableName, variableOffset)

end checkImplicitNotFoundAnnotation
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/util/ShowPickled.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object ShowPickled {
result.toInt
}

def printFile(buf: PickleBuffer, out: PrintStream = System.out.nn): Unit = {
def printFile(buf: PickleBuffer, out: PrintStream = System.out): Unit = {
out.println("Version " + buf.readNat() + "." + buf.readNat())
val index = buf.createIndex
val entryList = makeEntryList(buf, index)
Expand Down
Loading

0 comments on commit e60dcbb

Please sign in to comment.