Skip to content
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

Import meta package as a wildcard #3363

Merged
merged 1 commit into from
Nov 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,7 @@ import scala.annotation.tailrec
import scala.collection.immutable.HashMap
import scala.collection.mutable
import scala.meta.classifiers.Classifier
import scala.meta.{
Case,
CaseTree,
Ctor,
Decl,
Defn,
Importer,
Init,
Lit,
Pat,
Pkg,
Source,
Template,
Term,
Tree,
Type,
TypeCase
}
import scala.meta._
import scala.meta.tokens.{Token => T}

/** Helper functions for generating splits/policies for a given tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,7 @@ import scala.meta.internal.Scaladoc
import scala.meta.internal.parsers.ScaladocParser
import scala.meta.tokens.{Token => T}
import scala.meta.transversers.Traverser
import scala.meta.{
Case,
Ctor,
Defn,
Enumerator,
ImportExportStat,
Pat,
Pkg,
Source,
Stat,
Template,
Term,
Tree,
Type
}
import scala.meta._

/** Produces formatted output from sequence of splits.
*/
Expand Down Expand Up @@ -1317,11 +1303,10 @@ class FormatWriter(formatOps: FormatOps) {

case AlignContainer(x) if fl.formatToken.right.is[T.Comment] => x

case _: Defn | _: Case | _: Term.Apply | _: meta.Init |
_: Ctor.Primary =>
case _: Defn | _: Case | _: Term.Apply | _: Init | _: Ctor.Primary =>
getAlignContainerParent(t, Some(t))

case _: meta.Mod =>
case _: Mod =>
t.parent match {
case Some(p) => getAlignContainer(p)
case None => t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,7 @@ import scala.annotation.tailrec
import scala.language.implicitConversions
import scala.meta.classifiers.Classifier
import scala.meta.tokens.{Token => T}
import scala.meta.{
Case,
CaseTree,
Defn,
Enumerator,
ImportExportStat,
Importer,
Init,
Lit,
Mod,
Pat,
Pkg,
Template,
Term,
Tree,
Type,
TypeCase
}
import scala.meta._

object Constants {
val ShouldBeNewline = 100000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ final case class State(
private def getLineStartOwner(isComment: Boolean)(implicit
style: ScalafmtConfig,
tokens: FormatTokens
): Option[(FormatToken, meta.Tree)] = {
): Option[(FormatToken, Tree)] = {
val ft = tokens(depth)
if (ft.meta.left.hasNL) None
else if (!split.isNL) {
val ok = (prev ne State.start) &&
State.allowSplitForLineStart(split, ft, isComment)
if (ok) prev.getLineStartOwner(isComment) else None
} else {
def startsWithLeft(tree: meta.Tree): Boolean =
def startsWithLeft(tree: Tree): Boolean =
tokens.getHeadOpt(tree).contains(ft)
def optionIfStartsWithLeft(tree: meta.Tree): Option[meta.Tree] =
def optionIfStartsWithLeft(tree: Tree): Option[Tree] =
Some(tree).filter(startsWithLeft)
val owner = optionIfStartsWithLeft(ft.meta.rightOwner)
.orElse(optionIfStartsWithLeft(ft.meta.leftOwner))
Expand Down Expand Up @@ -495,11 +495,11 @@ object State {
}

@inline
private def isInterpolation(tree: meta.Tree): Boolean =
tree.is[meta.Term.Interpolate]
private def isInterpolation(tree: Tree): Boolean =
tree.is[Term.Interpolate]

@inline
private def isWithinInterpolation(tree: meta.Tree): Boolean =
private def isWithinInterpolation(tree: Tree): Boolean =
findTreeOrParentSimple(tree)(isInterpolation).isDefined

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
if style.rewrite.redundantBraces.stringInterpolation &&
processInterpolation =>
removeToken
case meta.Importer(_, List(x))
case Importer(_, List(x))
if !(x.is[Importee.Rename] || x.is[Importee.Unimport]) ||
style.dialect.allowAsForImportRename &&
(ConvertToNewScala3Syntax.enabled ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.scalafmt.rewrite

import scala.meta.Defn
import scala.meta.Template
import scala.meta.Term
import scala.meta.Type
import scala.meta._
import scala.meta.tokens.Token

import org.scalafmt.config.RewriteScala3Settings
Expand Down Expand Up @@ -59,7 +56,7 @@ private class RemoveScala3OptionalBraces(ftoks: FormatTokens)
case _: Term.Match => removeToken
case _: Type.Match => removeToken
case _: Term.Try => removeToken
case _: meta.Ctor.Secondary
case _: Ctor.Secondary
if ftoks.prevNonComment(ft).left.is[Token.Equals] =>
removeToken
case _ => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package org.scalafmt.util

import scala.annotation.tailrec
import scala.collection.mutable
import scala.meta.Lit
import scala.meta.Name
import scala.meta.Term
import scala.meta.Tree
import scala.meta._
import scala.meta.tokens.Token
import scala.meta.tokens.Token.Comment
import scala.meta.tokens.Token.LeftParen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package org.scalafmt.util

import scala.collection.immutable.Seq
import scala.meta.Decl
import scala.meta.Defn
import scala.meta.Name
import scala.meta.Pat
import scala.meta.Self
import scala.meta.Term
import scala.meta.Tree
import scala.meta.Type
import scala.meta._

case class InfixApp(lhs: Tree, op: Name, rhs: Seq[Tree], all: Tree) {

Expand Down Expand Up @@ -76,10 +68,9 @@ object WithChain {
def unapply(t: Type.With): Option[Type.With] = {
// self types, params, val/def/var/type definitions or declarations
val top = TreeOps.topTypeWith(t)
top.parent match {
case Some(_: Defn | _: Decl | _: Term.Param | _: Self | _: Type.Apply) =>
Some(top)
case _ => None
top.parent.collect {
case _: Defn | _: Decl | _: Term.Param | _: Self | _: Type.Apply =>
top
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,7 @@ package org.scalafmt.util

import scala.annotation.tailrec
import scala.collection.mutable
import scala.meta.Case
import scala.meta.CaseTree
import scala.meta.Ctor
import scala.meta.Decl
import scala.meta.Defn
import scala.meta.Enumerator
import scala.meta.Importer
import scala.meta.Init
import scala.meta.Lit
import scala.meta.Mod
import scala.meta.Name
import scala.meta.Pat
import scala.meta.Pkg
import scala.meta.Stat
import scala.meta.Template
import scala.meta.Term
import scala.meta.Tree
import scala.meta.Type
import scala.meta._
import scala.meta.classifiers.Classifier
import scala.meta.tokens.Token
import scala.meta.tokens.Token._
Expand Down Expand Up @@ -90,7 +73,7 @@ object TreeOps {
case t: Term.PartialFunction => t.cases
case t: Term.Try => t.catchp
case t: Type.Refine => t.stats
case t: scala.meta.Source => t.stats
case t: Source => t.stats
case t: Template => t.stats
case t: CaseTree if t.body.tokens.nonEmpty => Seq(t.body)
case _ => Seq.empty[Tree]
Expand Down