• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

combinators / templating / 14735935964

29 Apr 2025 04:03PM UTC coverage: 89.583%. First build
14735935964

Pull #5

web-flow
Merge fe193a6ae into 268125b36
Pull Request #5: Scala3

27 of 30 new or added lines in 5 files covered. (90.0%)

86 of 96 relevant lines covered (89.58%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/main/scala/org/combinators/templating/persistable/JavaPersistable.scala
1
/*
2
 * Copyright 2017-2025 Jan Bessai
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package org.combinators.templating.persistable
18

19
import java.nio.file.Paths
20

21
import com.github.javaparser.ast.CompilationUnit
22
import com.github.javaparser.ast.expr.{Name, NameExpr}
23
import com.github.javaparser.ast.visitor.GenericVisitorAdapter
24

25
import scala.collection.immutable._
26
import scala.jdk.CollectionConverters._
27

28
trait JavaPersistableInstances {
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.
32
    */
1✔
33
  implicit def compilationUnitInstance: JavaPersistable.Aux[CompilationUnit] =
1✔
34
    new Persistable {
35
      type T = CompilationUnit
36
      override def rawText(compilationUnit: CompilationUnit) =
1✔
37
        compilationUnit.toString.getBytes
1✔
38
      override def path(compilationUnit: CompilationUnit) = {
1✔
39
        val pkg: Seq[String] =
1✔
40
          compilationUnit.getPackageDeclaration.orElse(null) match {
1✔
41
            case null => Seq.empty
1✔
42
            case somePkg =>
1✔
43
              somePkg.accept(
1✔
44
                new GenericVisitorAdapter[Seq[String], Unit] {
NEW
45
                  override def visit(name: NameExpr, arg: Unit): Seq[String] =
×
NEW
46
                    Seq(name.getNameAsString)
×
47
                  override def visit(name: Name, arg: Unit): Seq[String] =
1✔
48
                    Option(name.getQualifier.orElse(null))
1✔
49
                      .map((q: Name) => q.accept(this, arg))
1✔
50
                      .getOrElse(Seq.empty[String]) :+ name.getIdentifier
1✔
51
                },
52
                ()
53
              )
54
          }
55
        val clsName = s"${compilationUnit.getTypes.asScala.head.getName}.java"
1✔
56
        val fullPath = "src" +: "main" +: "java" +: pkg :+ clsName
1✔
57
        Paths.get(fullPath.head, fullPath.tail*)
1✔
58
      }
59
    }
60
}
61

62
object JavaPersistable extends JavaPersistableInstances {
63
  type Aux[TT] = Persistable { type T = TT }
64
  def apply[T](implicit persistable: Aux[T]): Aux[T] = persistable
1✔
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc