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

Method addAggr

output/java/1.4.17/ST.java:294–328  ·  view source on GitHub ↗

Split aggrName.{propName1,propName2} into list [propName1, propName2] and the aggrName. Spaces are allowed around ','.

(String aggrSpec, Object ... values)

Source from the content-addressed store, hash-verified

292 */
293
294 public synchronized ST addAggr(String aggrSpec, Object ... values) {
295 int dot = aggrSpec.indexOf(".{");
296 if ( values==null || values.length==0 ) {
297 throw new IllegalArgumentException("missing values for aggregate attribute format: "+
298 aggrSpec);
299 }
300
301 int finalCurly = aggrSpec.indexOf('}');
302 if ( dot<0 || finalCurly<0 ) {
303 throw new IllegalArgumentException("invalid aggregate attribute format: "+
304 aggrSpec);
305 }
306
307 String aggrName = aggrSpec.substring(0, dot);
308 String propString = aggrSpec.substring(dot+2, aggrSpec.length()-1);
309 propString = propString.trim();
310 String[] propNames = propString.split("\\ *,\\ *");
311 if ( propNames==null || propNames.length==0 ) {
312 throw new IllegalArgumentException("invalid aggregate attribute format: "+
313 aggrSpec);
314 }
315
316 if ( values.length!=propNames.length ) {
317 throw new IllegalArgumentException("number of properties and values mismatch for aggregate attribute format: "+aggrSpec);
318 }
319
320 int i = 0;
321 Aggregate aggr = new Aggregate();
322 for (String p : propNames) {
323 Object v = values[i++];
324 aggr.properties.put(p, v);
325 }
326 add(aggrName, aggr); // now add as usual
327 return this;
328 }
329
330 /** Remove an attribute value entirely (can't remove attribute definitions). */
331

Callers

nothing calls this directly

Calls 5

addMethod · 0.95
putMethod · 0.65
indexOfMethod · 0.45
lengthMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected