2222 */
2323public abstract class Keyword implements Documentation {
2424
25- private static final String __CBRACE__ = new com .laytonsmith .core .functions .Compiler .__cbrace__ ().getName ();
26-
27- protected Keyword () {
28- //
29- }
30-
31- /**
32- * Sent upon reaching a keyword in the parse tree. The full list of arguments at the current stack depth, as well as
33- * the keyword position will be sent, and the keyword is allowed to make any necessary changes, including throwing a
34- * {@link ConfigCompileException} if necessary.
35- *
36- * @param list The argument list at the current depth as it currently exists. Note that the list will have already
37- * been lightly processed.
38- * @param keywordPosition The keyword position
39- * @return The position at which the compiler should continue processing from. Often times this will just be
40- * {@code keywordPosition}, but may be different if need be.
41- * @throws ConfigCompileException If the tree is in an invalid state, and the keyword needs to cause an exception to
42- * be thrown.
43- */
44- public abstract int process (List <ParseTree > list , int keywordPosition ) throws ConfigCompileException ;
45-
46- /**
47- * Returns the keyword name, or null, if this class isn't tagged with the @keyword annotation.
48- *
49- * @return
50- */
51- public final String getKeywordName () {
52- keyword k = this .getClass ().getAnnotation (keyword .class );
53- return k == null ? null : k .value ();
54- }
25+ private static final String __CBRACE__ = new com .laytonsmith .core .functions .Compiler .__cbrace__ ().getName ();
26+
27+ protected Keyword () {
28+ //
29+ }
30+
31+ /**
32+ * Sent upon reaching a keyword in the parse tree. The full list of arguments at the current stack depth, as well as
33+ * the keyword position will be sent, and the keyword is allowed to make any necessary changes, including throwing a
34+ * {@link ConfigCompileException} if necessary.
35+ *
36+ * @param list The argument list at the current depth as it currently exists. Note that the list will have already
37+ * been lightly processed.
38+ * @param keywordPosition The keyword position
39+ * @return The position at which the compiler should continue processing from. Often times this will just be
40+ * {@code keywordPosition}, but may be different if need be.
41+ * @throws ConfigCompileException If the tree is in an invalid state, and the keyword needs to cause an exception to
42+ * be thrown.
43+ */
44+ public abstract int process (List <ParseTree > list , int keywordPosition ) throws ConfigCompileException ;
45+
46+ /**
47+ * Returns the keyword name, or null, if this class isn't tagged with the @keyword annotation.
48+ *
49+ * @return
50+ */
51+ public final String getKeywordName () {
52+ keyword k = this .getClass ().getAnnotation (keyword .class );
53+ return k == null ? null : k .value ();
54+ }
5555
5656 /**
5757 * Convenience function to allow keywords to more easily check if this is a valid code block. If not, a
@@ -66,10 +66,10 @@ public final String getKeywordName() {
6666 protected void validateCodeBlock (ParseTree node , String message ) throws ConfigCompileException {
6767 // Note: If any of these checks are changed, the isValidCodeBlock(ParseTree node) method has to be updated too
6868 // to keep it in sync.
69- if (node .getChildren ().size () > 1 ) {
69+ if (node .getChildren ().size () > 1 ) {
7070 throw new ConfigCompileException ("Unexpected number of arguments in code block" , node .getTarget ());
7171 }
72- if (!isCodeBlock (node )) {
72+ if (!isCodeBlock (node )) {
7373 throw new ConfigCompileException (message , node .getTarget ());
7474 }
7575 }
@@ -86,57 +86,56 @@ protected boolean isValidCodeBlock(ParseTree node) {
8686 return node .getChildren ().size () <= 1 && isCodeBlock (node );
8787 }
8888
89- /**
90- * Returns true if the node is a code block or not. The argument count to the block is not considered.
91- *
92- * @param node
93- * @return
94- */
95- protected static boolean isCodeBlock (ParseTree node ) {
96- return node .getData () instanceof CFunction && node .getData ().val ().equals (__CBRACE__ );
97- }
98-
99- /**
100- * Returns a CNull, if the node is empty, or the first argument to the node
101- *
102- * @param node
103- * @return
104- */
105- protected static ParseTree getArgumentOrNull (ParseTree node ) {
106- if (node .getChildren ().isEmpty ()) {
107- return new ParseTree (CNull .NULL , node .getFileOptions ());
108- } else {
109- return node .getChildAt (0 );
89+ /**
90+ * Returns true if the node is a code block or not. The argument count to the block is not considered.
91+ *
92+ * @param node
93+ * @return
94+ */
95+ protected static boolean isCodeBlock (ParseTree node ) {
96+ return node .getData () instanceof CFunction && node .getData ().val ().equals (__CBRACE__ );
11097 }
111- }
112-
113- @ Target (ElementType .TYPE )
114- @ Retention (RetentionPolicy .RUNTIME )
115- public static @interface keyword {
11698
11799 /**
118- * The name of the keyword.
100+ * Returns a CNull, if the node is empty, or the first argument to the node
119101 *
102+ * @param node
120103 * @return
121104 */
122- String value ();
123- }
105+ protected static ParseTree getArgumentOrNull (ParseTree node ) {
106+ if (node .getChildren ().isEmpty ()) {
107+ return new ParseTree (CNull .NULL , node .getFileOptions ());
108+ } else {
109+ return node .getChildAt (0 );
110+ }
111+ }
112+
113+ @ Target (ElementType .TYPE )
114+ @ Retention (RetentionPolicy .RUNTIME )
115+ public static @interface keyword {
124116
125- @ Override
126- @ SuppressWarnings ("unchecked" )
127- public Class <? extends Documentation >[] seeAlso () {
128- return new Class []{};
129- }
117+ /**
118+ * The name of the keyword.
119+ *
120+ * @return
121+ */
122+ String value ();
123+ }
130124
131- @ Override
132- public URL getSourceJar () {
133- return ClassDiscovery .GetClassContainer (this .getClass ());
134- }
125+ @ Override
126+ @ SuppressWarnings ("unchecked" )
127+ public Class <? extends Documentation >[] seeAlso () {
128+ return new Class []{};
129+ }
135130
136- @ Override
137- public String getName () {
138- return this .getClass (). getAnnotation ( keyword . class ). value ( );
139- }
131+ @ Override
132+ public URL getSourceJar () {
133+ return ClassDiscovery . GetClassContainer ( this .getClass ());
134+ }
140135
136+ @ Override
137+ public String getName () {
138+ return this .getClass ().getAnnotation (keyword .class ).value ();
139+ }
141140
142141}
0 commit comments