IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
AnnotationDefaultAttribute.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2014 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.Runtime;
27
28namespace IKVM.Attributes
29{
30
31 [AttributeUsage(AttributeTargets.Method)]
32 public sealed class AnnotationDefaultAttribute : Attribute
33 {
34
35 public const byte TAG_ENUM = (byte)'e';
36 public const byte TAG_CLASS = (byte)'c';
37 public const byte TAG_ANNOTATION = (byte)'@';
38 public const byte TAG_ARRAY = (byte)'[';
39 public const byte TAG_ERROR = (byte)'?';
40
41 internal static object Escape(object obj)
42 {
43 return EscapeOrUnescape(obj, true);
44 }
45
46 internal static object Unescape(object obj)
47 {
48 return EscapeOrUnescape(obj, false);
49 }
50
51 static object EscapeOrUnescape(object obj, bool escape)
52 {
53 var str = obj as string;
54 if (str != null)
55 return escape ? UnicodeUtil.EscapeInvalidSurrogates(str) : UnicodeUtil.UnescapeInvalidSurrogates(str);
56
57 var arr = obj as object[];
58 if (arr != null)
59 for (int i = 0; i < arr.Length; i++)
60 arr[i] = EscapeOrUnescape(arr[i], escape);
61
62 return obj;
63 }
64
65 object defaultValue;
66
67 // element_value encoding:
68 // primitives:
69 // boxed values
70 // string:
71 // string
72 // enum:
73 // new object[] { (byte)'e', "<EnumType>", "<enumvalue>" }
74 // class:
75 // new object[] { (byte)'c', "<Type>" }
76 // annotation:
77 // new object[] { (byte)'@', "<AnnotationType>", ("name", (element_value))* }
78 // array:
79 // new object[] { (byte)'[', (element_value)* }
80 // error:
81 // new object[] { (byte)'?', "<exceptionClass>", "<exceptionMessage>" }
82 public AnnotationDefaultAttribute(object defaultValue)
83 {
84 this.defaultValue = Unescape(defaultValue);
85 }
86
87 public object Value => defaultValue;
88
89 }
90
91}