private ITreeNode createFunctionNode(final String label,
final OtpErlangObject erlangObject) {
final ITreeNode node = new TreeNode();
if (erlangObject instanceof OtpErlangTuple) {
final OtpErlangTuple functionTuple = (OtpErlangTuple) erlangObject;
final OtpErlangAtom moduleName = (OtpErlangAtom) functionTuple
.elementAt(INDEX_FUNCTION_MODULE);
final OtpErlangAtom functionName = (OtpErlangAtom) functionTuple
.elementAt(INDEX_FUNCTION_NAME);
// args or arity node
final TreeNode argsNode = new TreeNode();
argsNode.setImage(Activator.getImage(Images.INFO_NODE));
final OtpErlangObject arityOrArgs = functionTuple
.elementAt(INDEX_FUNCTION_ARGS);
int arityValue = -1;
if (arityOrArgs instanceof OtpErlangList) {
// last element is a list of arguments
final OtpErlangList arguments = (OtpErlangList) arityOrArgs;
final StringBuilder builder = new StringBuilder("arguments: ");
for (int i = 1; i < arguments.arity(); i++) {
builder.append(arguments.elementAt(i)).append(", ");
}
arityValue = arguments.arity() - 1;
argsNode.setLabel(builder.substring(0, builder.length() - 2));
} else {
// last element is arity
try {
if (functionTuple.elementAt(INDEX_FUNCTION_ARGS) instanceof OtpErlangInt) {
arityValue = ((OtpErlangInt) functionTuple
.elementAt(INDEX_FUNCTION_ARGS)).intValue();
} else {
arityValue = (int) ((OtpErlangLong) functionTuple
.elementAt(INDEX_FUNCTION_ARGS)).longValue();
}
argsNode.setLabel("arity: " + arityValue);
} catch (final OtpErlangRangeException e) {
ErlLogger.error(e);