MCPcopy Create free account
hub / github.com/antlr/codebuff / length

Method length

output/java8/1.4.12/Interpreter.java:1055–1071  ·  view source on GitHub ↗

Return the length of a multi-valued attribute or 1 if it is a single attribute. If v is null return 0. The implementation treats several common collections and arrays as special cases for speed.

(Object v)

Source from the content-addressed store, hash-verified

1053 */
1054
1055 public Object length(Object v) {
1056 if ( v==null ) return 0;
1057 int i = 1; // we have at least one of something. Iterator and arrays might be empty.
1058 if ( v instanceof Map ) i = ((Map<?, ?>)v).size();
1059 else if ( v instanceof Collection ) i = ((Collection<?>)v).size();
1060 else if ( v instanceof Object[] ) i = ((Object[])v).length;
1061 else if ( v.getClass().isArray() ) i = Array.getLength(v);
1062 else if ( v instanceof Iterable || v instanceof Iterator ) {
1063 Iterator<?> it = v instanceof Iterable ? ((Iterable<?>)v).iterator() : (Iterator<?>)v;
1064 i = 0;
1065 while ( it.hasNext() ) {
1066 it.next();
1067 i++;
1068 }
1069 }
1070 return i;
1071 }
1072
1073 protected String toString(STWriter out, InstanceScope scope, Object value) {
1074 if ( value!=null ) {

Callers 15

_execMethod · 0.95
findMemberMethod · 0.45
stripMethod · 0.45
writeMethod · 0.45
writeWrapMethod · 0.45
indentMethod · 0.45
setTextMethod · 0.45
getTemplateRangeMethod · 0.45
writeMethod · 0.45
toStringMethod · 0.45

Calls 5

sizeMethod · 0.65
iteratorMethod · 0.65
nextMethod · 0.65
isArrayMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected