IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
JavaTypeName.cs
Go to the documentation of this file.
1using System;
2
4
6{
7
11 readonly struct JavaTypeName
12 {
13
14 public static JavaTypeName Empty => new(ReadOnlyMemory<char>.Empty);
15
16 public static implicit operator string(JavaTypeName typeName) => typeName.ToString();
17 public static implicit operator JavaTypeName(string typeName) => new(typeName);
18
19 public static implicit operator ReadOnlyMemory<char>(JavaTypeName typeName) => typeName.value;
20 public static implicit operator JavaTypeName(ReadOnlyMemory<char> typeName) => new(typeName);
21
22 public static bool operator ==(JavaTypeName a, JavaTypeName b) => a.value.Span.Equals(b.value.Span, StringComparison.Ordinal);
23 public static bool operator !=(JavaTypeName a, JavaTypeName b) => a.value.Span.Equals(b.value.Span, StringComparison.Ordinal) == false;
24
25 readonly ReadOnlyMemory<char> value;
26
31 public JavaTypeName(string value) :
32 this(value.AsMemory())
33 {
34 if (value is null)
35 throw new ArgumentNullException(nameof(value));
36 }
37
42 public JavaTypeName(ReadOnlyMemory<char> value)
43 {
44 this.value = value;
45 }
46
53 this(package.IsEmpty ? name.Value : (package + '.' + name).AsMemory())
54 {
55
56 }
57
61 public ReadOnlyMemory<char> Value => value;
62
66 public bool IsEmpty => value.IsEmpty;
67
72
78 {
79 var i = value.Span.LastIndexOf('.');
80 if (i != -1)
81 return new JavaPackageName(value.Slice(0, i));
82 else
83 return new JavaPackageName("");
84 }
85
90
97 {
98 var index = value.Span.LastIndexOf('.');
99 return index != -1 ? new JavaUnqualifiedTypeName(value.Slice(index + 1)) : new JavaUnqualifiedTypeName(value);
100 }
101
106
112 {
113 if (IsEmpty)
117
118 var index = value.Span.LastIndexOfAny('.', '$');
119 return index != -1 ? new JavaSimpleTypeName(value.Slice(index + 1)) : new JavaSimpleTypeName(value);
120 }
121
127 public bool IsMemberOf(JavaPackageName packageName) => PackageName == packageName;
128
133
138
143
148
153
155 {
156 var b = value.Span.LastIndexOf('$');
157 return b != -1 ? new JavaTypeName(value.Slice(0, b)) : Empty;
158 }
159
165 public bool Equals(JavaTypeName other) => value.Span.Equals(other.value.Span, StringComparison.Ordinal);
166
172 public override bool Equals(object obj) => false;
173
178 public override int GetHashCode() => value.Span.GetHashCodeExtension();
179
184 public override string ToString() => value.Span.ToString();
185
186 }
187
188}
Provides methods to parse a Java package name.
Provides methods to parse a Java class simple name.
Provides methods to parse a Java class name.
override int GetHashCode()
Gets the hash code of this type name.
override bool Equals(object obj)
Returns true if the two objects are equal.
JavaUnqualifiedTypeName UnqualifiedName
Gets the unqualified type name.
static bool operator!=(JavaTypeName a, JavaTypeName b)
override string ToString()
Returns a string instance of the type name.
JavaPackageName PackageName
Gets the package name.
JavaPackageName GetPackageName()
Gets the package name.
bool IsMemberOf(JavaPackageName packageName)
Returns true if this type is a member of the given package.
bool Equals(JavaTypeName other)
Returns true if the two objects are equal.
JavaTypeName(JavaPackageName package, JavaUnqualifiedTypeName name)
Initializes a new instance.
bool IsInnerClass
Returns true if this name represents an inner class of another class.
JavaTypeName(string value)
Initializes a new instance.
static bool operator==(JavaTypeName a, JavaTypeName b)
bool IsAnonymousClass
Returns true if this name represents an anonymous class.
JavaTypeName(ReadOnlyMemory< char > value)
Initializes a new instance.
JavaSimpleTypeName SimpleName
Gets the simple name.
readonly ReadOnlyMemory< char > value
ReadOnlyMemory< char > Value
Gets the underlying value of the type name.
JavaUnqualifiedTypeName GetUnqualifiedName()
Gets the unqualified type name.
bool IsNestedClass
Returns true if this name represents a nested class.
JavaSimpleTypeName GetSimpleName()
Gets the simple name.
JavaTypeName Parent
If this class name is a nested, inner or anonymous class, returns the parent class name,...
bool IsEmpty
Returns true if this represents the empty type name.
bool IsLocalClass
Returns true if this name represents a local class.
Provides methods to parse a Java class name without package.
bool IsAnonymousClass
Returns true if this name represents an anonymous class.
bool IsInnerClass
Returns true if this name represents an inner class of another class.
bool IsLocalClass
Returns true if this name represents a local class.
bool IsNestedClass
Returns true if this name represents a nested class.