List of usage examples for org.aspectj.asm IProgramElement walk
public IProgramElement walk(HierarchyWalker walker);
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * find out what java elements are on a particular line *//* w w w . jav a 2 s . c o m*/ public List/*IJavaElement*/<IJavaElement> getJavaElementsForLine(ICompilationUnit icu, final int line) { IProgramElement ipe = javaElementToProgramElement(icu); final List/*IProgramElement*/<IProgramElement> elementsOnLine = new LinkedList<IProgramElement>(); // walk the program element to get all ipes on the source line ipe.walk(new CancellableHierarchyWalker() { protected void preProcess(IProgramElement node) { ISourceLocation sourceLocation = node.getSourceLocation(); if (sourceLocation != null) { if (sourceLocation.getEndLine() < line) { // we don't need to explore the rest of this branch cancel(); } else if (sourceLocation.getLine() == line) { elementsOnLine.add(node); } } } }); // now convert to IJavaElements List /*IJavaElement*/<IJavaElement> javaElements = new ArrayList<IJavaElement>(elementsOnLine.size()); for (Iterator<IProgramElement> ipeIter = elementsOnLine.iterator(); ipeIter.hasNext();) { IProgramElement ipeOnLine = ipeIter.next(); javaElements.add(programElementToJavaElement(ipeOnLine)); } return javaElements; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * walks the file and grabs all relationships for it. filter by relationship type * pass in null filter for all relationships *//*from ww w . jav a 2 s .com*/ public Map<Integer, List<IRelationship>> getRelationshipsForFile(ICompilationUnit icu, AJRelationshipType[] relType) { final Set<String> interesting; if (relType != null) { interesting = new HashSet<String>(); for (int i = 0; i < relType.length; i++) { interesting.add(relType[i].getDisplayName()); } } else { interesting = null; } // walk the hierarchy and get relationships for each node final Map<Integer, List<IRelationship>> allRelationshipsMap = new HashMap<Integer, List<IRelationship>>(); IProgramElement ipe = javaElementToProgramElement(icu); ipe.walk(new HierarchyWalker() { protected void preProcess(IProgramElement node) { List<IRelationship> orig = relationshipMap.get(node); if (orig == null) { return; } List<IRelationship> nodeRels = new ArrayList<IRelationship>(orig); if (interesting != null) { for (Iterator<IRelationship> relIter = nodeRels.iterator(); relIter.hasNext();) { IRelationship rel = (IRelationship) relIter.next(); if (!interesting.contains(rel.getName())) { relIter.remove(); } } } if (nodeRels.size() > 0) { List<IRelationship> allRelsForLine; Integer line = new Integer(node.getSourceLocation().getLine()); if (allRelationshipsMap.containsKey(line)) { allRelsForLine = allRelationshipsMap.get(line); } else { allRelsForLine = new LinkedList<IRelationship>(); allRelationshipsMap.put(line, allRelsForLine); } allRelsForLine.addAll(nodeRels); } } }); return allRelationshipsMap; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
public Set<IType> aspectsForFile(ICompilationUnit cu) { IProgramElement ipe = javaElementToProgramElement(cu); // compiler should be able to do this for us, but functionality is // not exposed. so let's do it ourselves final Set<IType> aspects = new HashSet<IType>(); ipe.walk(new HierarchyWalker() { protected void preProcess(IProgramElement node) { if (node.getKind() == IProgramElement.Kind.ASPECT) { aspects.add((IType) programElementToJavaElement(node)); }/* w w w . j a va 2s.c o m*/ } }); return aspects; }