OSDN Git Service

imported from subversion repository
[xerial/xerial-core.git] / src / main / java / org / xerial / silk / impl / SilkFunction.java
1 /*--------------------------------------------------------------------------\r
2  *  Copyright 2009 Taro L. Saito\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  *--------------------------------------------------------------------------*/\r
16 //--------------------------------------\r
17 // XerialJ\r
18 //\r
19 // SilkFunction.java\r
20 // Since: Jan 30, 2009 7:36:19 PM\r
21 //\r
22 // $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/silk/impl/SilkFunction.java $\r
23 // $Author: leo $\r
24 //--------------------------------------\r
25 package org.xerial.silk.impl;\r
26 \r
27 import java.util.ArrayList;\r
28 import java.util.List;\r
29 \r
30 import org.xerial.core.XerialError;\r
31 import org.xerial.core.XerialErrorCode;\r
32 import org.xerial.util.StringUtil;\r
33 \r
34 /**\r
35  * function data\r
36  * \r
37  * @author leo\r
38  * \r
39  */\r
40 public class SilkFunction implements SilkElement, SilkValue\r
41 {\r
42     private String name;\r
43     private String indent;\r
44     private ArrayList<SilkFunctionArg> argumentList = new ArrayList<SilkFunctionArg>();\r
45 \r
46     public final static int NO_INDENT = Integer.MAX_VALUE; // must be higher than other indent levels\r
47 \r
48     /**\r
49      * Return the indent level (the length of the leadning white spaces) of this\r
50      * node. If no indent is specified, return {@link SilkNode#NO_INDENT}.\r
51      * \r
52      * @return the indent level of the node, or {@link SilkNode#NO_INDENT} if no\r
53      *         indent is specified.\r
54      */\r
55     public int getIndentLevel()\r
56     {\r
57         if (indent == null)\r
58             return NO_INDENT;\r
59         else\r
60             return indent.length() - 1;\r
61     }\r
62 \r
63     public void setName(String name)\r
64     {\r
65         this.name = name;\r
66     }\r
67 \r
68     public String getName()\r
69     {\r
70         return name;\r
71     }\r
72 \r
73     public void addArgument(String argument)\r
74     {\r
75         argumentList.add(SilkFunctionArg.newArgValue(argument));\r
76     }\r
77 \r
78     public void addKeyValuePair(SilkFunctionArg argument)\r
79     {\r
80         argumentList.add(argument);\r
81     }\r
82 \r
83     public void addKeyAndValue(String key, String value)\r
84     {\r
85         argumentList.add(new SilkFunctionArg(key, value));\r
86     }\r
87 \r
88     public List<SilkFunctionArg> getArgumentList()\r
89     {\r
90         return argumentList;\r
91     }\r
92 \r
93     public String getNodeIndent()\r
94     {\r
95         return indent;\r
96     }\r
97 \r
98     public void setNodeIndent(String indent)\r
99     {\r
100         this.indent = indent;\r
101     }\r
102 \r
103     @Override\r
104     public String toString()\r
105     {\r
106         return String.format("function %s(%s)", name, StringUtil.join(argumentList, ", "));\r
107     }\r
108 \r
109     public String getValue()\r
110     {\r
111         throw new XerialError(XerialErrorCode.UNSUPPORTED, "getValue() for SilkFunction");\r
112     }\r
113 \r
114     public boolean isJSON()\r
115     {\r
116         return false;\r
117     }\r
118 \r
119     public boolean isFunction()\r
120     {\r
121         return true;\r
122     }\r
123 \r
124 }\r