IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassFile.FieldOrMethod.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25
26using IKVM.Attributes;
27using IKVM.ByteCode;
28using IKVM.ByteCode.Decoding;
29
30namespace IKVM.Runtime
31{
32
33 sealed partial class ClassFile
34 {
35
36 internal abstract class FieldOrMethod : IEquatable<FieldOrMethod>
37 {
38
39 readonly ClassFile clazz;
40 protected Modifiers accessFlags;
41 protected ushort flags;
42 string name;
43 string descriptor;
44 protected string signature;
45 protected object[] annotations;
46 protected TypeAnnotationTable runtimeVisibleTypeAnnotations = TypeAnnotationTable.Empty;
47 protected TypeAnnotationTable runtimeInvisibleTypeAnnotations = TypeAnnotationTable.Empty;
48
57 internal FieldOrMethod(ClassFile clazz, string[] utf8_cp, AccessFlag accessFlags, Utf8ConstantHandle name, Utf8ConstantHandle descriptor)
58 {
59 this.clazz = clazz ?? throw new ArgumentNullException(nameof(clazz));
60 this.accessFlags = (Modifiers)accessFlags;
61 this.name = string.Intern(clazz.GetConstantPoolUtf8String(utf8_cp, name));
62 this.descriptor = clazz.GetConstantPoolUtf8String(utf8_cp, descriptor);
63
64 ValidateSig(clazz, this.descriptor);
65 this.descriptor = string.Intern(this.descriptor.Replace('/', '.'));
66 }
67
71 public ClassFile Class => clazz;
72
73 protected abstract void ValidateSig(ClassFile classFile, string descriptor);
74
75 internal string Name => name;
76
77 internal string Signature => descriptor;
78
79 internal object[] Annotations => annotations;
80
81 internal string GenericSignature => signature;
82
83 internal Modifiers Modifiers => (Modifiers)accessFlags;
84
85 internal bool IsAbstract => (accessFlags & Modifiers.Abstract) != 0;
86
87 internal bool IsFinal => (accessFlags & Modifiers.Final) != 0;
88
89 internal bool IsPublic => (accessFlags & Modifiers.Public) != 0;
90
91 internal bool IsPrivate => (accessFlags & Modifiers.Private) != 0;
92
93 internal bool IsProtected => (accessFlags & Modifiers.Protected) != 0;
94
95 internal bool IsStatic => (accessFlags & Modifiers.Static) != 0;
96
97 internal bool IsSynchronized => (accessFlags & Modifiers.Synchronized) != 0;
98
99 internal bool IsVolatile => (accessFlags & Modifiers.Volatile) != 0;
100
101 internal bool IsTransient => (accessFlags & Modifiers.Transient) != 0;
102
103 internal bool IsNative => (accessFlags & Modifiers.Native) != 0;
104
105 internal bool IsEnum => (accessFlags & Modifiers.Enum) != 0;
106
107 internal bool DeprecatedAttribute => (flags & FLAG_MASK_DEPRECATED) != 0;
108
109 internal bool IsInternal => (flags & FLAG_MASK_INTERNAL) != 0;
110
111 internal bool IsModuleInitializer => (flags & FLAG_MODULE_INITIALIZER) != 0;
112
113 internal ref readonly TypeAnnotationTable RuntimeVisibleTypeAnnotations => ref runtimeVisibleTypeAnnotations;
114
115 public sealed override int GetHashCode() => name.GetHashCode() ^ descriptor.GetHashCode();
116
117 public bool Equals(FieldOrMethod other) => ReferenceEquals(name, other.name) && ReferenceEquals(descriptor, other.descriptor);
118
119 }
120
121 }
122
123}
global::java.lang.Class Class
global::java.lang.invoke.LambdaForm.Name Name