1 /*--------------------------------------------------------------------------
\r
2 * Copyright 2009 Taro L. Saito
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 // SilkFunction.java
\r
20 // Since: Jan 30, 2009 7:36:19 PM
\r
22 // $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/silk/impl/SilkFunction.java $
\r
24 //--------------------------------------
\r
25 package org.xerial.silk.impl;
\r
27 import java.util.ArrayList;
\r
28 import java.util.List;
\r
30 import org.xerial.core.XerialError;
\r
31 import org.xerial.core.XerialErrorCode;
\r
32 import org.xerial.util.StringUtil;
\r
40 public class SilkFunction implements SilkElement, SilkValue
\r
42 private String name;
\r
43 private String indent;
\r
44 private ArrayList<SilkFunctionArg> argumentList = new ArrayList<SilkFunctionArg>();
\r
46 public final static int NO_INDENT = Integer.MAX_VALUE; // must be higher than other indent levels
\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
52 * @return the indent level of the node, or {@link SilkNode#NO_INDENT} if no
\r
53 * indent is specified.
\r
55 public int getIndentLevel()
\r
60 return indent.length() - 1;
\r
63 public void setName(String name)
\r
68 public String getName()
\r
73 public void addArgument(String argument)
\r
75 argumentList.add(SilkFunctionArg.newArgValue(argument));
\r
78 public void addKeyValuePair(SilkFunctionArg argument)
\r
80 argumentList.add(argument);
\r
83 public void addKeyAndValue(String key, String value)
\r
85 argumentList.add(new SilkFunctionArg(key, value));
\r
88 public List<SilkFunctionArg> getArgumentList()
\r
90 return argumentList;
\r
93 public String getNodeIndent()
\r
98 public void setNodeIndent(String indent)
\r
100 this.indent = indent;
\r
104 public String toString()
\r
106 return String.format("function %s(%s)", name, StringUtil.join(argumentList, ", "));
\r
109 public String getValue()
\r
111 throw new XerialError(XerialErrorCode.UNSUPPORTED, "getValue() for SilkFunction");
\r
114 public boolean isJSON()
\r
119 public boolean isFunction()
\r