01: package org.incava.java;
02:
03: import java.util.*;
04: import net.sourceforge.pmd.ast.*;
05:
06: /**
07: * Miscellaneous routines for variables (declarators).
08: */
09: public class VariableUtil extends SimpleNodeUtil {
10: public static Token getName(ASTVariableDeclarator vd) {
11: ASTVariableDeclaratorId vid = (ASTVariableDeclaratorId) findChild(
12: vd, ASTVariableDeclaratorId.class);
13: Token nameTk = vid.getFirstToken();
14: return nameTk;
15: }
16:
17: public static Token[] getVariableNames(ASTVariableDeclarator[] vds) {
18: List names = new ArrayList();
19: for (int vi = 0; vi < vds.length; ++vi) {
20: ASTVariableDeclarator vd = vds[vi];
21: names.add(getName(vd));
22: }
23: return (Token[]) names.toArray(new Token[0]);
24: }
25:
26: }
|