1 package com.puppycrawl.tools.checkstyle.checks.xpath; 20 21 import java.lang.reflect.InvocationTargetException ; 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 29 import org.apache.commons.beanutils.BeanUtils; 30 31 import com.puppycrawl.tools.checkstyle.api.DetailAST; 32 33 39 public class AttributeAxisIterator 40 implements Iterator 41 { 42 43 private Iterator mIter = (new ArrayList ()).iterator(); 44 45 50 public AttributeAxisIterator(DetailAST aAST) 51 { 52 Map props = new HashMap (); 53 try { 55 props = BeanUtils.describe(aAST); 56 } 57 catch (IllegalAccessException e) { 58 e.printStackTrace(); 60 } 61 catch (InvocationTargetException e) { 62 e.printStackTrace(); 64 } 65 catch (NoSuchMethodException e) { 66 e.printStackTrace(); 68 } 69 final List attributes = new ArrayList (props.size()); 72 final Set values = props.keySet(); 73 for (Iterator iter = values.iterator(); iter.hasNext();) { 74 final String name = (String ) iter.next(); 75 final String value = (String ) props.get(name); 76 attributes.add(new Attribute(aAST, name, value)); 77 } 78 mIter = attributes.iterator(); 79 } 80 81 82 public Object next() 83 { 84 return mIter.next(); 85 } 86 87 88 public boolean hasNext() 89 { 90 return mIter.hasNext(); 91 } 92 93 94 public void remove() 95 { 96 mIter.remove(); 97 } 98 } | Popular Tags |