|
1 | | - |
2 | | - |
3 | 1 | package com.laytonsmith.annotations; |
4 | 2 |
|
5 | 3 | import com.laytonsmith.core.PlatformResolver; |
|
15 | 13 |
|
16 | 14 | /** |
17 | 15 | * Marks a function as an API function, which includes it in the list of functions. |
18 | | - * |
| 16 | + * |
19 | 17 | */ |
20 | 18 | @Retention(RetentionPolicy.RUNTIME) |
21 | 19 | @Target(ElementType.TYPE) |
22 | 20 | public @interface api { |
23 | | - |
24 | | - public enum Platforms{ |
25 | | - INTERPRETER_JAVA(null, "Java Interpreter"), |
26 | | - COMPILER_BASH(new BashPlatformResolver(), "Bash Compiler"); |
27 | | - private PlatformResolver resolver; |
28 | | - private String platformName; |
29 | | - /** |
30 | | - * Returns the platform specific resolver, which is able to override base functionality, |
31 | | - * which will be adjusted as needed. If the resolver is null, one does not exist, implying |
32 | | - * that the default is fine. |
33 | | - * @return |
34 | | - */ |
35 | | - public PlatformResolver getResolver(){ |
36 | | - return this.resolver; |
37 | | - } |
38 | | - public String platformName(){ |
39 | | - return this.platformName; |
40 | | - } |
41 | | - private Platforms(PlatformResolver resolver, String platformName){ |
42 | | - this.resolver = resolver; |
43 | | - this.platformName = platformName; |
44 | | - } |
45 | | - } |
46 | | - |
| 21 | + |
| 22 | + public enum Platforms { |
| 23 | + INTERPRETER_JAVA(null, "Java Interpreter"), |
| 24 | + COMPILER_BASH(new BashPlatformResolver(), "Bash Compiler"); |
| 25 | + private PlatformResolver resolver; |
| 26 | + private String platformName; |
| 27 | + |
47 | 28 | /** |
48 | | - * Returns the platform this is implemented for. The default is {@see api.Platforms#INTERPRETER_JAVA}. |
49 | | - * @return |
| 29 | + * Returns the platform specific resolver, which is able to override base functionality, which will be adjusted |
| 30 | + * as needed. If the resolver is null, one does not exist, implying that the default is fine. |
| 31 | + * |
| 32 | + * @return |
50 | 33 | */ |
51 | | - Platforms [] platform() default {api.Platforms.INTERPRETER_JAVA}; |
| 34 | + public PlatformResolver getResolver() { |
| 35 | + return this.resolver; |
| 36 | + } |
| 37 | + |
| 38 | + public String platformName() { |
| 39 | + return this.platformName; |
| 40 | + } |
| 41 | + |
| 42 | + private Platforms(PlatformResolver resolver, String platformName) { |
| 43 | + this.resolver = resolver; |
| 44 | + this.platformName = platformName; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Returns the platform this is implemented for. The default is { |
| 50 | + * |
| 51 | + * @see api.Platforms#INTERPRETER_JAVA}. |
| 52 | + * @return |
| 53 | + */ |
| 54 | + Platforms[] platform() default {api.Platforms.INTERPRETER_JAVA}; |
| 55 | + |
| 56 | + /** |
| 57 | + * Returns the environments this api element uses. The default is an empty array, but note that GlobalEnv.class is |
| 58 | + * implied for all elements, and it is not required to add that to this list. |
| 59 | + * |
| 60 | + * @return |
| 61 | + */ |
| 62 | + Class<? extends Environment.EnvironmentImpl>[] environments() default {}; |
| 63 | + |
| 64 | + /** |
| 65 | + * If this api element is enabled. The default is {@code true}, but you can temporarily disable an element by |
| 66 | + * setting this to false. |
| 67 | + * |
| 68 | + * @return |
| 69 | + */ |
| 70 | + boolean enabled() default true; |
| 71 | + |
| 72 | + /** |
| 73 | + * This is a list of valid classes that are valid to be tagged with this annotation. |
| 74 | + */ |
| 75 | + public static enum ValidClasses { |
| 76 | + FUNCTION(com.laytonsmith.core.functions.FunctionBase.class), |
| 77 | + EVENT(com.laytonsmith.core.events.Event.class); |
| 78 | + private static List<Class> classes = null; |
| 79 | + Class classType; |
| 80 | + |
| 81 | + private ValidClasses(Class c) { |
| 82 | + classType = c; |
| 83 | + } |
| 84 | + |
52 | 85 | /** |
53 | | - * Returns the environments this api element uses. The default is an empty array, but note |
54 | | - * that GlobalEnv.class is implied for all elements, and it is not required to add that to this |
55 | | - * list. |
56 | | - * @return |
| 86 | + * Returns a copy of the list of valid classes that may be tagged with the api annotation. |
| 87 | + * |
| 88 | + * @return |
57 | 89 | */ |
58 | | - Class<? extends Environment.EnvironmentImpl> [] environments() default {}; |
| 90 | + public static List<Class> Classes() { |
| 91 | + if (classes == null) { |
| 92 | + Class[] cc = new Class[ValidClasses.values().length]; |
| 93 | + for (int i = 0; i < ValidClasses.values().length; i++) { |
| 94 | + cc[i] = ValidClasses.values()[i].classType; |
| 95 | + } |
| 96 | + classes = Arrays.asList(cc); |
| 97 | + } |
| 98 | + return new ArrayList<Class>(classes); |
| 99 | + } |
| 100 | + |
59 | 101 | /** |
60 | | - * If this api element is enabled. The default is {@code true}, but you can temporarily |
61 | | - * disable an element by setting this to false. |
62 | | - * @return |
| 102 | + * Returns true if the specified class extends a valid class. |
| 103 | + * |
| 104 | + * @param c |
| 105 | + * @return |
63 | 106 | */ |
64 | | - boolean enabled() default true; |
65 | | - |
66 | | - /** |
67 | | - * This is a list of valid classes that are valid to be tagged with this annotation. |
68 | | - */ |
69 | | - public static enum ValidClasses{ |
70 | | - FUNCTION(com.laytonsmith.core.functions.FunctionBase.class), |
71 | | - EVENT(com.laytonsmith.core.events.Event.class); |
72 | | - private static List<Class> classes = null; |
73 | | - Class classType; |
74 | | - private ValidClasses(Class c){ |
75 | | - classType = c; |
76 | | - } |
77 | | - |
78 | | - /** |
79 | | - * Returns a copy of the list of valid classes that may be tagged with |
80 | | - * the api annotation. |
81 | | - * @return |
82 | | - */ |
83 | | - public static List<Class> Classes(){ |
84 | | - if(classes == null){ |
85 | | - Class[] cc = new Class[ValidClasses.values().length]; |
86 | | - for(int i = 0; i < ValidClasses.values().length; i++){ |
87 | | - cc[i] = ValidClasses.values()[i].classType; |
88 | | - } |
89 | | - classes = Arrays.asList(cc); |
90 | | - } |
91 | | - return new ArrayList<Class>(classes); |
92 | | - } |
93 | | - |
94 | | - /** |
95 | | - * Returns true if the specified class extends a valid class. |
96 | | - * @param c |
97 | | - * @return |
98 | | - */ |
99 | | - public static boolean IsValid(Class c){ |
100 | | - for(Class cc : Classes()){ |
101 | | - if(cc.isAssignableFrom(c)){ |
102 | | - return true; |
103 | | - } |
104 | | - } |
105 | | - return false; |
106 | | - } |
| 107 | + public static boolean IsValid(Class c) { |
| 108 | + for (Class cc : Classes()) { |
| 109 | + if (cc.isAssignableFrom(c)) { |
| 110 | + return true; |
| 111 | + } |
| 112 | + } |
| 113 | + return false; |
| 114 | + } |
107 | 115 | } |
108 | 116 | } |
0 commit comments