Skip to content

Commit 7552226

Browse files
committed
Scalafmt the source
1 parent 4718a68 commit 7552226

14 files changed

Lines changed: 266 additions & 126 deletions

.scalafmt.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version = 3.9.4
2+
rewrite.rules = [ AvoidInfix, SortImports ]
3+
runner.dialect = scala36
4+
project {
5+
git = true
6+
excludeFilters = [
7+
plugin/src/sbt-test
8+
]
9+
layout = StandardConvention
10+
}

src/main/scala/org/combinators/templating/persistable/JavaPersistable.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@ import scala.collection.immutable._
2626
import scala.jdk.CollectionConverters._
2727

2828
trait JavaPersistableInstances {
29-
/** Persistable instance for a compilation unit.
30-
* Derives path and file names from the package and the name of the first declared type.
29+
30+
/** Persistable instance for a compilation unit. Derives path and file names
31+
* from the package and the name of the first declared type.
3132
*/
3233
implicit def compilationUnitInstance: JavaPersistable.Aux[CompilationUnit] =
3334
new Persistable {
3435
type T = CompilationUnit
35-
override def rawText(compilationUnit: CompilationUnit) = compilationUnit.toString.getBytes
36+
override def rawText(compilationUnit: CompilationUnit) =
37+
compilationUnit.toString.getBytes
3638
override def path(compilationUnit: CompilationUnit) = {
3739
val pkg: Seq[String] =
3840
compilationUnit.getPackageDeclaration.orElse(null) match {
3941
case null => Seq.empty
4042
case somePkg =>
41-
somePkg.accept(new GenericVisitorAdapter[Seq[String], Unit] {
42-
override def visit(name: NameExpr, arg: Unit): Seq[String] = Seq(name.getNameAsString)
43-
override def visit(name: Name, arg: Unit): Seq[String] =
44-
Option(name.getQualifier.orElse(null))
45-
.map((q: Name) => q.accept(this, arg))
46-
.getOrElse(Seq.empty[String]) :+ name.getIdentifier
47-
},
43+
somePkg.accept(
44+
new GenericVisitorAdapter[Seq[String], Unit] {
45+
override def visit(name: NameExpr, arg: Unit): Seq[String] =
46+
Seq(name.getNameAsString)
47+
override def visit(name: Name, arg: Unit): Seq[String] =
48+
Option(name.getQualifier.orElse(null))
49+
.map((q: Name) => q.accept(this, arg))
50+
.getOrElse(Seq.empty[String]) :+ name.getIdentifier
51+
},
4852
()
4953
)
5054
}

src/main/scala/org/combinators/templating/persistable/Persistable.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,27 @@ import java.io.File
2121

2222
/** Type class for persistable objects (inhabitants). */
2323
trait Persistable {
24+
2425
/** The type of the object to persist */
2526
type T
27+
2628
/** Serialized representation of the object */
2729
def rawText(elem: T): Array[Byte]
28-
/** Path where to store the object `elem` (relative to some later specified root) */
30+
31+
/** Path where to store the object `elem` (relative to some later specified
32+
* root)
33+
*/
2934
def path(elem: T): Path
3035

31-
/**
32-
* Computes the full path where to place `elem` relative to `basePath`.
36+
/** Computes the full path where to place `elem` relative to `basePath`.
3337
*/
3438
def fullPath(basePath: Path, elem: T): Path = {
3539
basePath.resolve(path(elem))
3640
}
3741

38-
39-
/**
40-
* Persists this object to an object dependent path under `basePath` and returns the persisted file.
41-
* Overwrites any pre-existing files under `basePath` / `path`.
42+
/** Persists this object to an object dependent path under `basePath` and
43+
* returns the persisted file. Overwrites any pre-existing files under
44+
* `basePath` / `path`.
4245
*/
4346
def persistOverwriting(basePath: Path, elem: T): File = {
4447
val fp = fullPath(basePath, elem)
@@ -48,9 +51,9 @@ trait Persistable {
4851
fp.toFile
4952
}
5053

51-
/**
52-
* Persists this object to an object dependent path under `basePath` and returns the persisted file.
53-
* Throws an `FileAlreadyExistsException` if the file already exists.
54+
/** Persists this object to an object dependent path under `basePath` and
55+
* returns the persisted file. Throws an `FileAlreadyExistsException` if the
56+
* file already exists.
5457
*/
5558
def persist(basePath: Path, elem: T): File = {
5659
val fp = fullPath(basePath, elem)
@@ -64,4 +67,4 @@ object Persistable {
6467
type Aux[TT] = Persistable { type T = TT }
6568

6669
def apply[T](implicit persistable: Aux[T]): Aux[T] = persistable
67-
}
70+
}

src/main/scala/org/combinators/templating/persistable/PythonWithPathPersistable.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import org.combinators.templating.twirl.Python
2424
case class PythonWithPath(code: Python, persistTo: Path)
2525

2626
trait PythonWithPathPersistableInstances {
27+
2728
/** Persistable instance for [PythonWithPath]. */
28-
implicit def pythonWithPathPersistable: PythonWithPathPersistable.Aux[PythonWithPath] = new Persistable {
29+
implicit def pythonWithPathPersistable
30+
: PythonWithPathPersistable.Aux[PythonWithPath] = new Persistable {
2931
type T = PythonWithPath
3032
def rawText(elem: PythonWithPath): Array[Byte] = elem.code.getCode.getBytes
3133
def path(elem: PythonWithPath): Path = elem.persistTo

src/main/scala/org/combinators/templating/persistable/ResourcePersistable.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,27 @@ import java.nio.file.{Files, Path, Paths}
2020

2121
/** A persistable resource on the classpath.
2222
*
23-
* @param name the name by which to locate the resource within the classpath.
24-
* @param persistTo the name of the file where to store the resource.
25-
* @param classToLoadResource the class which will be used to load the resource (@see
23+
* @param name
24+
* the name by which to locate the resource within the classpath.
25+
* @param persistTo
26+
* the name of the file where to store the resource.
27+
* @param classToLoadResource
28+
* the class which will be used to load the resource (@see
2629
*/
27-
case class BundledResource(name: String, persistTo: Path, classToLoadResource: Class[?] = classOf[BundledResource])
30+
case class BundledResource(
31+
name: String,
32+
persistTo: Path,
33+
classToLoadResource: Class[?] = classOf[BundledResource]
34+
)
2835

2936
trait ResourcePersistableInstances {
3037
def bundledResourceInstance: ResourcePersistable.Aux = new Persistable {
3138
override type T = BundledResource
3239
override def path(elem: BundledResource): Path = elem.persistTo
3340
override def rawText(elem: BundledResource): Array[Byte] =
34-
Files.readAllBytes(Paths.get(elem.classToLoadResource.getResource(elem.name).toURI))
41+
Files.readAllBytes(
42+
Paths.get(elem.classToLoadResource.getResource(elem.name).toURI)
43+
)
3544
}
3645
}
3746

src/main/scala/org/combinators/templating/twirl/Java.scala

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import java.io.StringReader
2020

2121
import com.github.javaparser._
2222
import com.github.javaparser.ast.`type`.Type
23-
import com.github.javaparser.ast.body.{BodyDeclaration, ConstructorDeclaration, FieldDeclaration, MethodDeclaration}
23+
import com.github.javaparser.ast.body.{
24+
BodyDeclaration,
25+
ConstructorDeclaration,
26+
FieldDeclaration,
27+
MethodDeclaration
28+
}
2429
import com.github.javaparser.ast.expr.{Expression, Name, NameExpr, SimpleName}
2530
import com.github.javaparser.ast.stmt.Statement
2631
import com.github.javaparser.ast.{CompilationUnit, ImportDeclaration, Node}
@@ -31,7 +36,8 @@ import scala.collection.immutable._
3136
import scala.jdk.CollectionConverters._
3237

3338
/** A Java fragment. */
34-
class Java private(elements: Seq[Java], text: String) extends BufferedContent[Java](elements, text) {
39+
class Java private (elements: Seq[Java], text: String)
40+
extends BufferedContent[Java](elements, text) {
3541
def this(text: String) = this(Nil, Formats.safe(text))
3642
def this(elements: Seq[Java]) = this(elements, "")
3743

@@ -44,7 +50,8 @@ class Java private(elements: Seq[Java], text: String) extends BufferedContent[Ja
4450
def compilationUnit(): CompilationUnit = StaticJavaParser.parse(fullText)
4551

4652
/** Parses an import declaration. */
47-
def importDeclaration(): ImportDeclaration = StaticJavaParser.parseImport(fullText)
53+
def importDeclaration(): ImportDeclaration =
54+
StaticJavaParser.parseImport(fullText)
4855

4956
/** Parses this element as a single statement. */
5057
def statement(): Statement = StaticJavaParser.parseStatement(fullText)
@@ -54,7 +61,8 @@ class Java private(elements: Seq[Java], text: String) extends BufferedContent[Ja
5461
StaticJavaParser.parseBlock(s"{ $fullText }").getStatements.asScala.to(Seq)
5562

5663
/** Parses this element as an expression. */
57-
def expression[T <: Expression](): T = StaticJavaParser.parseExpression[T](fullText)
64+
def expression[T <: Expression](): T =
65+
StaticJavaParser.parseExpression[T](fullText)
5866

5967
/** Parses this element as a (potentially qualified) name. */
6068
def name(): Name = StaticJavaParser.parseName(fullText)
@@ -65,12 +73,22 @@ class Java private(elements: Seq[Java], text: String) extends BufferedContent[Ja
6573
/** Parses this element as a (unqualified) name expression. */
6674
def nameExpression(): NameExpr = expression()
6775

68-
/** Parses this element as a class body declaration (e.g. a method or a field). */
69-
def classBodyDeclaration(): BodyDeclaration[?] = StaticJavaParser.parseBodyDeclaration(fullText)
76+
/** Parses this element as a class body declaration (e.g. a method or a
77+
* field).
78+
*/
79+
def classBodyDeclaration(): BodyDeclaration[?] =
80+
StaticJavaParser.parseBodyDeclaration(fullText)
7081

7182
/** Parses this element as multiple class body declarations. */
7283
def classBodyDeclarations(): Seq[BodyDeclaration[?]] =
73-
StaticJavaParser.parse(s"class C { $fullText }").getTypes.asScala.head.getMembers.asScala.to(Seq)
84+
StaticJavaParser
85+
.parse(s"class C { $fullText }")
86+
.getTypes
87+
.asScala
88+
.head
89+
.getMembers
90+
.asScala
91+
.to(Seq)
7492

7593
/** Parses this element as multiple field declarations. */
7694
def fieldDeclarations(): Seq[FieldDeclaration] =
@@ -84,19 +102,25 @@ class Java private(elements: Seq[Java], text: String) extends BufferedContent[Ja
84102
def constructors(): Seq[ConstructorDeclaration] =
85103
classBodyDeclarations().map(_.asInstanceOf[ConstructorDeclaration])
86104

87-
/** Parses this element as an interface body declaration (e.g. a method signature). */
88-
def interfaceBodyDeclaration(): BodyDeclaration[?] = StaticJavaParser.parseBodyDeclaration(fullText)
105+
/** Parses this element as an interface body declaration (e.g. a method
106+
* signature).
107+
*/
108+
def interfaceBodyDeclaration(): BodyDeclaration[?] =
109+
StaticJavaParser.parseBodyDeclaration(fullText)
89110

90111
/** Parses this element as a type (e.g. the in X foo = (X)bar). */
91112
def tpe(): Type = StaticJavaParser.parseType(fullText)
92113
}
93114

94115
/** Helper for Java utility methods. */
95116
object Java {
117+
96118
/** Creates a Java fragment with initial content specified. */
97119
def apply(text: String): Java = new Java(text)
98120

99-
/** Creates a Java fragment with initial content from the given `text` separated by `separator`. */
121+
/** Creates a Java fragment with initial content from the given `text`
122+
* separated by `separator`.
123+
*/
100124
def apply(text: Seq[String], separator: String = ";"): Java = {
101125
apply(text.mkString(separator))
102126
}
@@ -105,19 +129,22 @@ object Java {
105129
def apply(node: Node): Java = Java(node.toString)
106130

107131
/** Creates a Java fragment with initial content from the asts `nodes`. */
108-
def apply(nodes: Seq[Node]): Java = new Java(Seq((nodes map apply)*))
132+
def apply(nodes: Seq[Node]): Java = new Java(Seq((nodes.map(apply))*))
109133
}
110134

111135
object JavaFormat extends Format[Java] {
136+
112137
/** Integrates `text` without performing any escaping process.
113138
*
114-
* @param text Text to integrate
139+
* @param text
140+
* Text to integrate
115141
*/
116142
def raw(text: String): Java = Java(text)
117143

118144
/** Escapes `text` using Java String rules.
119145
*
120-
* @param text Text to integrate
146+
* @param text
147+
* Text to integrate
121148
*/
122149
def escape(text: String): Java = Java(StringEscapeUtils.escapeJava(text))
123150

src/main/scala/org/combinators/templating/twirl/Python.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import play.twirl.api.{BufferedContent, Format, Formats}
2121

2222
import scala.collection.immutable
2323

24-
/**
25-
* A Python fragment.
24+
/** A Python fragment.
2625
*/
27-
class Python private(elements: immutable.Seq[Python], text: String) extends BufferedContent[Python](elements, text) {
26+
class Python private (elements: immutable.Seq[Python], text: String)
27+
extends BufferedContent[Python](elements, text) {
2828
def this(text: String) = this(Nil, Formats.safe(text))
2929
def this(elements: immutable.Seq[Python]) = this(elements, "")
3030

@@ -48,33 +48,36 @@ class Python private(elements: immutable.Seq[Python], text: String) extends Buff
4848
def getCode: String = fullText
4949
}
5050

51-
/**
52-
* Helper for Python utility methods.
51+
/** Helper for Python utility methods.
5352
*/
5453
object Python {
54+
5555
/** Creates a Python fragment with initial content specified. */
5656
def apply(text: String): Python = {
5757
new Python(text)
5858
}
5959

60-
/** Creates a Python fragment with initial content from the given `text` separated by `separator`. */
60+
/** Creates a Python fragment with initial content from the given `text`
61+
* separated by `separator`.
62+
*/
6163
def apply(text: Seq[String], separator: String = ";"): Python = {
6264
apply(text.mkString(separator))
6365
}
6466
}
6567

6668
object PythonFormat extends Format[Python] {
67-
/**
68-
* Integrates `text` without performing any escaping process.
69+
70+
/** Integrates `text` without performing any escaping process.
6971
*
70-
* @param text Text to integrate
72+
* @param text
73+
* Text to integrate
7174
*/
7275
def raw(text: String): Python = Python(text)
7376

74-
/**
75-
* Escapes `text` using Python String rules.
77+
/** Escapes `text` using Python String rules.
7678
*
77-
* @param text Text to integrate
79+
* @param text
80+
* Text to integrate
7881
*/
7982
def escape(text: String): Python = Python(StringEscapeUtils.escapeJava(text))
8083

@@ -85,4 +88,3 @@ object PythonFormat extends Format[Python] {
8588
def fill(elements: immutable.Seq[Python]): Python = new Python(elements)
8689

8790
}
88-

0 commit comments

Comments
 (0)