Skip to content

Commit ab1501b

Browse files
fixed identifier issue
1 parent 2bb0f79 commit ab1501b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

identifiers.xsl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717

1818
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
1919

20+
<!-- GET VALID JAVA IDENTIFIER -->
21+
<xsl:template name="get-valid-java-identifier">
22+
<xsl:param name="name"/>
23+
<xsl:variable name="java-keywords"
24+
select="'abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while true false null record sealed non-sealed'"/>
25+
<xsl:choose>
26+
<xsl:when test="contains('0123456789', substring($name,1,1))">
27+
<xsl:text>_</xsl:text><xsl:value-of select="$name"/>
28+
</xsl:when>
29+
30+
<xsl:when test="contains(concat(' ', $java-keywords, ' '), concat(' ', $name, ' '))">
31+
<xsl:text>_</xsl:text><xsl:value-of select="$name"/>
32+
</xsl:when>
33+
<xsl:otherwise>
34+
<xsl:value-of select="$name"/>
35+
</xsl:otherwise>
36+
</xsl:choose>
37+
</xsl:template>
38+
2039
<!-- MAIN, FILE GENERATION -->
2140
<xsl:template match="/constants">
2241

@@ -53,7 +72,9 @@
5372

5473
<xsl:template match="int" mode="Java">
5574
<xsl:text>&#009;public static final int </xsl:text>
56-
<xsl:value-of select="@name"/>
75+
<xsl:call-template name="get-valid-java-identifier">
76+
<xsl:with-param name="name" select="@name"/>
77+
</xsl:call-template>
5778
<xsl:text>&#009; = </xsl:text>
5879
<xsl:value-of select="."/>
5980
<xsl:text>;</xsl:text>
@@ -62,7 +83,9 @@
6283

6384
<xsl:template match="float" mode="Java">
6485
<xsl:text>&#009;public static final double </xsl:text>
65-
<xsl:value-of select="@name"/>
86+
<xsl:call-template name="get-valid-java-identifier">
87+
<xsl:with-param name="name" select="@name"/>
88+
</xsl:call-template>
6689
<xsl:choose>
6790
<xsl:when test="@alias!='' or @alias='true'">
6891
<xsl:text>;</xsl:text>
@@ -84,7 +107,9 @@
84107

85108
<xsl:template match="string" mode="Java">
86109
<xsl:text>&#009;public static final String </xsl:text>
87-
<xsl:value-of select="@name"/>
110+
<xsl:call-template name="get-valid-java-identifier">
111+
<xsl:with-param name="name" select="@name"/>
112+
</xsl:call-template>
88113
<xsl:text>&#009; = "</xsl:text>
89114
<xsl:value-of select="."/><xsl:text>";</xsl:text>
90115
<xsl:value-of select="my:desc('//')"/>

0 commit comments

Comments
 (0)