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

carueda / tscfg / 12366472054

17 Dec 2024 04:38AM UTC coverage: 96.788% (-0.2%) from 96.966%
12366472054

Pull #313

carueda
preliminary partial impl of #312
Pull Request #313: implement #312

13 of 14 new or added lines in 5 files covered. (92.86%)

1 existing line in 1 file now uncovered.

874 of 903 relevant lines covered (96.79%)

1.83 hits per line

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

93.75
/src/main/scala/tscfg/generators/java/javaUtil.scala
1
package tscfg.generators.java
2

3
import tscfg.util
4

5
object javaUtil {
6

7
  /** Returns a valid Java identifier from the given symbol:
8
    *
9
    *   - appends a '_' in case the symbol is a java keyword or special literal
10
    *     ("null", "true", "false");
11
    *   - otherwise, prepends a '_' in case the symbol is numerical literal;
12
    *   - otherwise, returns the given symbol if already a valid java
13
    *     identifier;
14
    *   - otherwise, prefixes the symbol with '_' if first character is valid
15
    *     but not at first position, and replaces any character that cannot be
16
    *     part of a java identifier with '_'.
17
    */
18
  def javaIdentifier(symbol: String): String = {
19
    if (javaKeywords.contains(symbol)) symbol + "_"
2✔
20
    else if (isJavaIdentifier(symbol)) symbol
2✔
21
    else {
2✔
22
      val c0 = symbol.charAt(0)
2✔
23
      if (Character.isDigit(c0)) "_" + symbol
2✔
24
      else {
2✔
25
        val first: String =
26
          if (Character.isJavaIdentifierStart(c0)) String.valueOf(c0)
2✔
UNCOV
27
          else if (Character.isJavaIdentifierPart(c0)) "_" + c0
×
28
          else "_"
2✔
29
        val rest = symbol.substring(1) map { c =>
2✔
30
          if (Character.isJavaIdentifierPart(c)) c else '_'
2✔
31
        }
32
        first + rest
2✔
33
      }
34
    }
35
  }
36

37
  def isJavaIdentifier(symbol: String): Boolean = {
38
    Character.isJavaIdentifierStart(symbol.charAt(0)) &&
2✔
39
    symbol.substring(1).forall(Character.isJavaIdentifierPart)
2✔
40
  }
41

42
  def getClassName(symbol: String): String =
43
    util.upperFirst(javaIdentifier(symbol))
2✔
44

45
  /** Set of java keywords plus the literals "null", "true", "false". (from Sect
46
    * 3.9 of the Java Language Spec, Java SE 8 Edition)
47
    */
48
  val javaKeywords: List[String] = List(
2✔
49
    "abstract",
50
    "continue",
51
    "for",
52
    "new",
53
    "switch",
54
    "assert",
55
    "default",
56
    "if",
57
    "package",
58
    "synchronized",
59
    "boolean",
60
    "do",
61
    "goto",
62
    "private",
63
    "this",
64
    "break",
65
    "double",
66
    "implements",
67
    "protected",
68
    "throw",
69
    "byte",
70
    "else",
71
    "import",
72
    "public",
73
    "throws",
74
    "case",
75
    "enum",
76
    "instanceof",
77
    "return",
78
    "transient",
79
    "catch",
80
    "extends",
81
    "int",
82
    "short",
83
    "try",
84
    "char",
85
    "final",
86
    "interface",
87
    "static",
88
    "void",
89
    "class",
90
    "finally",
91
    "long",
92
    "strictfp",
93
    "volatile",
94
    "const",
95
    "float",
96
    "native",
97
    "super",
98
    "while",
99
    "null",
100
    "true",
101
    "false"
102
  )
103
}
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