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

Method convertToAttributeList

output/java/1.4.13/ST.java:387–422  ·  view source on GitHub ↗
(Object curvalue)

Source from the content-addressed store, hash-verified

385 }
386
387 protected static AttributeList convertToAttributeList(Object curvalue) {
388 AttributeList multi;
389 if ( curvalue==null ) {
390 multi = new AttributeList(); // make list to hold multiple values
391 multi.add(curvalue); // add previous single-valued attribute
392 }
393 else if ( curvalue instanceof AttributeList ) { // already a list made by ST
394 multi = (AttributeList)curvalue;
395 }
396 else if ( curvalue instanceof List ) { // existing attribute is non-ST List
397 // must copy to an ST-managed list before adding new attribute
398 // (can't alter incoming attributes)
399 List<?> listAttr = (List<?>)curvalue;
400 multi = new AttributeList(listAttr.size());
401 multi.addAll(listAttr);
402 }
403 else if ( curvalue instanceof Object[] ) { // copy array to list
404 Object[] a = (Object[])curvalue;
405 multi = new AttributeList(a.length);
406 multi.addAll(Arrays.asList(a)); // asList doesn't copy as far as I can tell
407 }
408 else if ( curvalue.getClass().isArray() ) { // copy primitive array to list
409 int length = Array.getLength(curvalue);
410 multi = new AttributeList(length);
411 for (int i = 0; i< length; i++) {
412 multi.add(Array.get(curvalue, i));
413 }
414 }
415 else {
416 // curvalue nonlist and we want to add an attribute
417 // must convert curvalue existing to list
418 multi = new AttributeList(); // make list to hold multiple values
419 multi.add(curvalue); // add previous single-valued attribute
420 }
421 return multi;
422 }
423
424 public String getName() {
425 return impl.name;

Callers 1

addMethod · 0.95

Calls 6

addMethod · 0.65
sizeMethod · 0.65
addAllMethod · 0.65
getMethod · 0.65
asListMethod · 0.45
isArrayMethod · 0.45

Tested by

no test coverage detected