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

Method last

output/java/1.4.19/Interpreter.java:1000–1015  ·  view source on GitHub ↗

Return the last attribute if multi-valued, or the attribute itself if single-valued. Unless it's a List or array, this is pretty slow as it iterates until the last element. This method is used for rendering expressions of the form .

(InstanceScope scope, Object v)

Source from the content-addressed store, hash-verified

998 */
999
1000 public Object last(InstanceScope scope, Object v) {
1001 if ( v==null ) return null;
1002 if ( v instanceof List) return ((List<?>)v).get(((List<?>)v).size()-1);
1003 else if ( v.getClass().isArray() ) {
1004 return Array.get(v, Array.getLength(v)-1);
1005 }
1006 Object last = v;
1007 v = convertAnythingIteratableToIterator(scope, v);
1008 if ( v instanceof Iterator) {
1009 Iterator<?> it = (Iterator<?>)v;
1010 while ( it.hasNext() ) {
1011 last = it.next();
1012 }
1013 }
1014 return last;
1015 }
1016
1017 /**
1018 * Return everything but the first attribute if multi-valued, or

Callers 1

_execMethod · 0.95

Calls 6

getMethod · 0.65
sizeMethod · 0.65
nextMethod · 0.65
isArrayMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected