Skip to content

Commit

Permalink
align if then syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kpbochenek committed Sep 1, 2020
1 parent 5ee8777 commit 939811b
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ node_modules
# Metals
.bloop/
.metals/
project/metals.sbt
metals.sbt

# Scala-IDE specific
.scala_dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ sealed trait CommunityProject:

/** Publish this project to the local Maven repository */
final def publish(): Unit =
if !published
if !published then
log(s"Publishing $project")
if publishCommand eq null
if publishCommand eq null then
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
if exitCode != 0
if exitCode != 0 then
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
published = true
end CommunityProject
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Compiler {
def newRun(using Context): Run = {
reset()
val rctx =
if ctx.settings.Ysemanticdb.value
if ctx.settings.Ysemanticdb.value then
ctx.addMode(Mode.ReadPositions)
else
ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ trait ConstraintHandling {

protected def addOneBound(param: TypeParamRef, bound: Type, isUpper: Boolean)(using Context): Boolean =
if !constraint.contains(param) then true
else if !isUpper && param.occursIn(bound)
else if !isUpper && param.occursIn(bound) then
// We don't allow recursive lower bounds when defining a type,
// so we shouldn't allow them as constraints either.
false
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object SymbolLoaders {
def enterToplevelsFromSource(
owner: Symbol, name: PreName, src: AbstractFile,
scope: Scope = EmptyScope)(using Context): Unit =
if src.exists && !src.isDirectory
if src.exists && !src.isDirectory then
val completer = new SourcefileLoader(src)
val filePath = owner.ownersIterator.takeWhile(!_.isRoot).map(_.name.toTermName).toList

Expand Down
94 changes: 47 additions & 47 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ExtractSemanticDB extends Phase:
private def traverseAnnotsOfDefinition(sym: Symbol)(using Context): Unit =
for annot <- sym.annotations do
if annot.tree.span.exists
&& annot.tree.span.hasLength
&& annot.tree.span.hasLength then
annot.tree match
case tree: Typed => () // hack for inline code
case tree => traverse(tree)
Expand All @@ -131,23 +131,23 @@ class ExtractSemanticDB extends Phase:
tree match
case tree: PackageDef =>
if !excludeDef(tree.pid.symbol)
&& tree.pid.span.hasLength
&& tree.pid.span.hasLength then
tree.pid match
case tree: Select =>
registerDefinition(tree.symbol, selectSpan(tree), Set.empty, tree.source)
traverse(tree.qualifier)
case tree => registerDefinition(tree.symbol, tree.span, Set.empty, tree.source)
tree.stats.foreach(traverse)
case tree: NamedDefTree =>
if tree.symbol.isAllOf(ModuleValCreationFlags)
if tree.symbol.isAllOf(ModuleValCreationFlags) then
return
if !excludeDef(tree.symbol)
&& tree.span.hasLength
&& tree.span.hasLength then
registerDefinition(tree.symbol, tree.adjustedNameSpan, symbolKinds(tree), tree.source)
val privateWithin = tree.symbol.privateWithin
if privateWithin.exists
if privateWithin.exists then
registerUseGuarded(None, privateWithin, spanOfSymbol(privateWithin, tree.span, tree.source), tree.source)
else if !excludeSymbol(tree.symbol)
else if !excludeSymbol(tree.symbol) then
registerSymbol(tree.symbol, symbolName(tree.symbol), symbolKinds(tree))
tree match
case tree: ValDef
Expand All @@ -158,7 +158,7 @@ class ExtractSemanticDB extends Phase:
case _ => // calls $new
case tree: ValDef
if tree.symbol.isSelfSym =>
if tree.tpt.span.hasLength
if tree.tpt.span.hasLength then
traverse(tree.tpt)
case tree: DefDef
if tree.symbol.isConstructor => // ignore typeparams for secondary ctors
Expand All @@ -171,18 +171,18 @@ class ExtractSemanticDB extends Phase:
tree.tparams.foreach(tparam => registerSymbolSimple(tparam.symbol))
tree.vparamss.foreach(_.foreach(vparam => registerSymbolSimple(vparam.symbol)))
case _ =>
if !tree.symbol.isGlobal
if !tree.symbol.isGlobal then
localBodies(tree.symbol) = tree.rhs
// ignore rhs
case PatternValDef(pat, rhs) =>
traverse(rhs)
PatternValDef.collectPats(pat).foreach(traverse)
case tree =>
if !excludeChildren(tree.symbol)
if !excludeChildren(tree.symbol) then
traverseChildren(tree)
case tree: Template =>
val ctorSym = tree.constr.symbol
if !excludeDef(ctorSym)
if !excludeDef(ctorSym) then
traverseAnnotsOfDefinition(ctorSym)
registerDefinition(ctorSym, tree.constr.span, Set.empty, tree.source)
ctorParams(tree.constr.vparamss, tree.body)
Expand All @@ -191,7 +191,7 @@ class ExtractSemanticDB extends Phase:
val selfSpan = tree.self.span
if selfSpan.exists && selfSpan.hasLength then
traverse(tree.self)
if tree.symbol.owner.is(Enum, butNot=Case)
if tree.symbol.owner.is(Enum, butNot=Case) then
tree.body.foreachUntilImport(traverse).foreach(traverse) // the first import statement
else
tree.body.foreach(traverse)
Expand All @@ -206,7 +206,7 @@ class ExtractSemanticDB extends Phase:
case _ => traverse(arg)
case tree: Assign =>
val qualSym = condOpt(tree.lhs) { case Select(qual, _) if qual.symbol.exists => qual.symbol }
if !excludeUse(qualSym, tree.lhs.symbol)
if !excludeUse(qualSym, tree.lhs.symbol) then
val lhs = tree.lhs.symbol
val setter = lhs.matchingSetter.orElse(lhs)
tree.lhs match
Expand Down Expand Up @@ -285,7 +285,7 @@ class ExtractSemanticDB extends Phase:

extension (tree: NamedDefTree):
private def adjustedNameSpan(using Context): Span =
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName then
Span(tree.span.point)
else
tree.nameSpan
Expand All @@ -304,7 +304,7 @@ class ExtractSemanticDB extends Phase:
def addOverloadIdx(sym: Symbol): Unit =
val decls =
val decls0 = sym.owner.info.decls.lookupAll(sym.name)
if sym.owner.isAllOf(JavaModule)
if sym.owner.isAllOf(JavaModule) then
decls0 ++ sym.owner.companionClass.info.decls.lookupAll(sym.name)
else
decls0
Expand Down Expand Up @@ -384,70 +384,70 @@ class ExtractSemanticDB extends Phase:
Some(Range(startLine, startCol, endLine, endCol))

private def symbolKind(sym: Symbol, symkinds: Set[SymbolKind])(using Context): SymbolInformation.Kind =
if sym.isTypeParam
if sym.isTypeParam then
SymbolInformation.Kind.TYPE_PARAMETER
else if sym.is(TermParam)
else if sym.is(TermParam) then
SymbolInformation.Kind.PARAMETER
else if sym.isTerm && sym.owner.isTerm
else if sym.isTerm && sym.owner.isTerm then
SymbolInformation.Kind.LOCAL
else if sym.isInlineMethod || sym.is(Macro)
else if sym.isInlineMethod || sym.is(Macro) then
SymbolInformation.Kind.MACRO
else if sym.isConstructor
else if sym.isConstructor then
SymbolInformation.Kind.CONSTRUCTOR
else if sym.isSelfSym
else if sym.isSelfSym then
SymbolInformation.Kind.SELF_PARAMETER
else if sym.isOneOf(Method) || symkinds.exists(_.isVarOrVal)
else if sym.isOneOf(Method) || symkinds.exists(_.isVarOrVal) then
SymbolInformation.Kind.METHOD
else if sym.isPackageObject
else if sym.isPackageObject then
SymbolInformation.Kind.PACKAGE_OBJECT
else if sym.is(Module)
else if sym.is(Module) then
SymbolInformation.Kind.OBJECT
else if sym.is(Package)
else if sym.is(Package) then
SymbolInformation.Kind.PACKAGE
else if sym.isAllOf(JavaInterface)
else if sym.isAllOf(JavaInterface) then
SymbolInformation.Kind.INTERFACE
else if sym.is(Trait)
else if sym.is(Trait) then
SymbolInformation.Kind.TRAIT
else if sym.isClass
else if sym.isClass then
SymbolInformation.Kind.CLASS
else if sym.isType
else if sym.isType then
SymbolInformation.Kind.TYPE
else if sym.is(ParamAccessor)
else if sym.is(ParamAccessor) then
SymbolInformation.Kind.FIELD
else
SymbolInformation.Kind.UNKNOWN_KIND

private def symbolProps(sym: Symbol, symkinds: Set[SymbolKind])(using Context): Int =
if sym.is(ModuleClass)
if sym.is(ModuleClass) then
return symbolProps(sym.sourceModule, symkinds)
var props = 0
if sym.isPrimaryConstructor
if sym.isPrimaryConstructor then
props |= SymbolInformation.Property.PRIMARY.value
if sym.is(Abstract) || symkinds.contains(SymbolKind.Abstract)
if sym.is(Abstract) || symkinds.contains(SymbolKind.Abstract) then
props |= SymbolInformation.Property.ABSTRACT.value
if sym.is(Final)
if sym.is(Final) then
props |= SymbolInformation.Property.FINAL.value
if sym.is(Sealed)
if sym.is(Sealed) then
props |= SymbolInformation.Property.SEALED.value
if sym.isOneOf(GivenOrImplicit)
if sym.isOneOf(GivenOrImplicit) then
props |= SymbolInformation.Property.IMPLICIT.value
if sym.is(Lazy, butNot=Module)
if sym.is(Lazy, butNot=Module) then
props |= SymbolInformation.Property.LAZY.value
if sym.isAllOf(Case | Module) || sym.is(CaseClass) || sym.isAllOf(EnumCase)
if sym.isAllOf(Case | Module) || sym.is(CaseClass) || sym.isAllOf(EnumCase) then
props |= SymbolInformation.Property.CASE.value
if sym.is(Covariant)
if sym.is(Covariant) then
props |= SymbolInformation.Property.COVARIANT.value
if sym.is(Contravariant)
if sym.is(Contravariant) then
props |= SymbolInformation.Property.CONTRAVARIANT.value
if sym.isAllOf(DefaultMethod | JavaDefined) || sym.is(Accessor) && sym.name.is(NameKinds.DefaultGetterName)
if sym.isAllOf(DefaultMethod | JavaDefined) || sym.is(Accessor) && sym.name.is(NameKinds.DefaultGetterName) then
props |= SymbolInformation.Property.DEFAULT.value
if symkinds.exists(_.isVal)
if symkinds.exists(_.isVal) then
props |= SymbolInformation.Property.VAL.value
if symkinds.exists(_.isVar)
if symkinds.exists(_.isVar) then
props |= SymbolInformation.Property.VAR.value
if sym.is(JavaStatic)
if sym.is(JavaStatic) then
props |= SymbolInformation.Property.STATIC.value
if sym.is(Enum)
if sym.is(Enum) then
props |= SymbolInformation.Property.ENUM.value
props

Expand All @@ -462,8 +462,8 @@ class ExtractSemanticDB extends Phase:

private def registerSymbol(sym: Symbol, symbolName: String, symkinds: Set[SymbolKind])(using Context): Unit =
val isLocal = symbolName.isLocal
if !isLocal || !localNames.contains(symbolName)
if isLocal
if !isLocal || !localNames.contains(symbolName) then
if isLocal then
localNames += symbolName
symbolInfos += symbolInfo(sym, symbolName, symkinds)

Expand All @@ -489,7 +489,7 @@ class ExtractSemanticDB extends Phase:
private def registerDefinition(sym: Symbol, span: Span, symkinds: Set[SymbolKind], treeSource: SourceFile)(using Context) =
val symbol = symbolName(sym)
registerOccurrence(symbol, span, SymbolOccurrence.Role.DEFINITION, treeSource)
if !sym.is(Package)
if !sym.is(Package) then
registerSymbol(sym, symbol, symkinds)

private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/semanticdb/Tools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object Tools:
val text = new String(Files.readAllBytes(scalaAbsolutePath), StandardCharsets.UTF_8)
// Assert the SemanticDB payload is in-sync with the contents of the Scala file on disk.
val md5FingerprintOnDisk = internal.MD5.compute(text)
if document.md5 != md5FingerprintOnDisk
if document.md5 != md5FingerprintOnDisk then
throw new IllegalArgumentException(s"stale semanticdb: $scalaRelativePath")
else
// Update text document to include full text contents of the file.
Expand Down Expand Up @@ -132,7 +132,7 @@ object Tools:
.append("):")
if range.endLine == range.startLine
&& range.startCharacter != range.endCharacter
&& !(occ.symbol.isConstructor && occ.role.isDefinition)
&& !(occ.symbol.isConstructor && occ.role.isDefinition) then
val line = sourceFile.lineContent(sourceFile.lineToOffset(range.startLine))
assert(range.startCharacter <= line.length && range.endCharacter <= line.length,
s"Line is only ${line.length} - start line was ${range.startLine} in source ${sourceFile.name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
/** If this is a constructor of a enum class that extends, add $name and $ordinal parameters to it. */
override def transformDefDef(tree: DefDef)(using Context): DefDef = {
val sym = tree.symbol
if (sym.isConstructor && sym.owner.derivesFromJavaEnum)
if sym.isConstructor && sym.owner.derivesFromJavaEnum then
val tree1 = cpy.DefDef(tree)(
vparamss = tree.vparamss.init :+ (tree.vparamss.last ++ addedParams(sym, isLocal=false, Param)))
sym.setParamssFromDefs(tree1.tparams, tree1.vparamss)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Constructors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
if stat.symbol.isGetter && stat.symbol.owner.is(Trait) && !stat.symbol.is(Lazy) =>
val sym = stat.symbol
assert(isRetained(sym), sym)
if (!stat.rhs.isEmpty && !isWildcardArg(stat.rhs))
if !stat.rhs.isEmpty && !isWildcardArg(stat.rhs) then
/* !!! Work around #9390
* This should really just be `sym.setter`. However, if we do that, we'll miss
* setters for mixed in `private var`s. Even though the scope clearly contains the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ class DropOuterAccessors extends MiniPhase with IdentityDenotTransformer:
when dropping outer accessors for ${ctx.owner} with
$impl""")
cpy.Template(impl)(constr = constr1, body = body1)
end transformTemplate
end transformTemplate
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
sym.sourcePos)
else
addVarArgsForwarder(sym, isJavaVarargsOverride, hasAnnotation)
else if hasAnnotation
else if hasAnnotation then
report.error("A method without repeated parameters cannot be annotated with @varargs", sym.sourcePos)
end

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Getters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Getters extends MiniPhase with SymTransformer { thisPhase =>

override def transformAssign(tree: Assign)(using Context): Tree =
val lsym = tree.lhs.symbol.asTerm
if (lsym.is(Method))
if lsym.is(Method) then
ensureSetter(lsym)
tree.lhs.becomes(tree.rhs).withSpan(tree.span)
else tree
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Pickler extends Phase {

override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
val result = super.runOn(units)
if ctx.settings.YtestPickler.value
if ctx.settings.YtestPickler.value then
testUnpickler(
using ctx.fresh
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ object Splicer {
val staticMethodCall = interpretedStaticMethodCall(fn.symbol.owner, fn.symbol)
staticMethodCall(args.flatten.map(interpretTree))
}
else if (fn.symbol.isStatic)
else if fn.symbol.isStatic then
assert(args.isEmpty)
interpretedStaticFieldAccess(fn.symbol)
else if (fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic)
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ object Inliner {
def inlineCall(tree: Tree)(using Context): Tree = {
val startId = ctx.source.nextId

if tree.symbol.denot != SymDenotations.NoDenotation && tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
if tree.symbol.denot != SymDenotations.NoDenotation
&& tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject then
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)

Expand Down Expand Up @@ -298,7 +299,7 @@ object Inliner {

val parseErrors = ctx2.reporter.allErrors.toList
res ++= parseErrors.map(e => ErrorKind.Parser -> e)
if !stopAfterParser || res.isEmpty
if !stopAfterParser || res.isEmpty then
ctx2.typer.typed(tree2)(using ctx2)
val typerErrors = ctx2.reporter.allErrors.filterNot(parseErrors.contains)
res ++= typerErrors.map(e => ErrorKind.Typer -> e)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ trait QuotesAndSplices {
case _ =>
}

if (ctx.mode.is(Mode.QuotedPattern) && level == 1)
if ctx.mode.is(Mode.QuotedPattern) && level == 1 then
def spliceOwner(ctx: Context): Symbol =
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
val name = tree.expr match {
Expand Down
Loading

0 comments on commit 939811b

Please sign in to comment.