IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Identifer.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
5{
6
10 static class Identifer
11 {
12
13 static readonly string[] RESERVED =
14 [
15 "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
16 "default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if",
17 "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private",
18 "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this",
19 "throw", "throws", "transient", "try", "void", "volatile", "while", "true", "false", "null", "_"
20 ];
21
27 public static bool IsPackageName(string name)
28 {
29 return IsPackageName(name.AsSpan());
30 }
31
37 public static bool IsPackageName(ReadOnlySpan<char> name)
38 {
39 return IsTypeName(name);
40 }
41
47 public static bool IsClassName(string name)
48 {
49 return IsClassName(name.AsSpan());
50 }
51
57 public static bool IsClassName(ReadOnlySpan<char> name)
58 {
59 return IsTypeName(name);
60 }
61
67 public static bool IsTypeName(ReadOnlySpan<char> name)
68 {
69 int next;
70 int off = 0;
71 while ((next = name[off..].IndexOf(['.'])) != -1)
72 {
73 var id = name.Slice(off, next);
74 if (IsJavaIdentifier(id) == false)
75 return false;
76
77 off = next + 1;
78 }
79
80 return IsJavaIdentifier(name[off..]);
81 }
82
86 public static bool IsJavaIdentifier(ReadOnlySpan<char> value)
87 {
88 if (value.IsWhiteSpace())
89 return false;
90
91 foreach (var i in RESERVED)
92 if (value.SequenceEqual(i))
93 return false;
94
95 // TODO this isn't fully implemented
96 return true;
97
98 //int first = Rune.GetRuneAt(value, 0);
99 //if (!Character.isJavaIdentifierStart(first))
100 // return false;
101
102 //int i = Character.charCount(first);
103 //while (i < value.length())
104 //{
105 // int cp = Character.codePointAt(value, i);
106 // if (!Character.isJavaIdentifierPart(cp))
107 // return false;
108 // i += Character.charCount(cp);
109 //}
110
111 //return true;
112 }
113
114 }
115
116}
Provides various methods for working with Java identifiers.
Definition Identifer.cs:11
static bool IsTypeName(ReadOnlySpan< char > name)
Returns true if name is a valid Java type name.
Definition Identifer.cs:67
static bool IsClassName(ReadOnlySpan< char > name)
Returns true if the given name is a legal class name.
Definition Identifer.cs:57
static bool IsPackageName(string name)
Returns true if the given name is a legal package name.
Definition Identifer.cs:27
static bool IsPackageName(ReadOnlySpan< char > name)
Returns true if the given name is a legal package name.
Definition Identifer.cs:37
static bool IsJavaIdentifier(ReadOnlySpan< char > value)
Returns true if the given string is a legal Java identifier, otherwise false.
Definition Identifer.cs:86
static bool IsClassName(string name)
Returns true if the given name is a legal class name.
Definition Identifer.cs:47