List of usage examples for org.aspectj.asm HierarchyWalker HierarchyWalker
public HierarchyWalker()
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 *//*www . ja v a 2s.c o m*/ 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)); }//from ww w. j a v a2s. c om } }); return aspects; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * useful for testing//from ww w. j av a 2 s .c o m */ public static String printHierarchy(IHierarchy h) { final StringBuffer sb = new StringBuffer(); HierarchyWalker walker = new HierarchyWalker() { int depth = 0; protected void preProcess(IProgramElement node) { sb.append(spaces(depth)); sb.append(node.getHandleIdentifier()); sb.append("\n"); depth += 2; } protected void postProcess(IProgramElement node) { depth -= 2; } String spaces(int depth) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < depth; i++) { sb.append(" "); } return sb.toString(); } }; h.getRoot().walk(walker); return sb.toString(); }
From source file:org.eclipse.ajdt.core.tests.model.AbstractModelTest.java
License:Open Source License
protected void checkHandles(IJavaProject jProject) throws Exception { final AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForJavaElement(jProject); final List<String> accumulatedErrors = new ArrayList<String>(); // check all the java handles IPackageFragment[] frags = jProject.getPackageFragments(); for (int i = 0; i < frags.length; i++) { ICompilationUnit[] units = frags[i].getCompilationUnits(); for (int j = 0; j < units.length; j++) { accumulatedErrors.addAll(walk(units[j], model)); }//from ww w . j a v a 2s . c om } // now check all the aj handles AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory() .getCompilerForProject(jProject.getProject()).getModel(); IHierarchy hierarchy = asm.getHierarchy(); hierarchy.getRoot().walk(new HierarchyWalker() { protected void preProcess(IProgramElement node) { try { HandleTestUtils.checkAJHandle(node.getHandleIdentifier(), model); } catch (JavaModelException e) { throw new RuntimeException(e); } } }); if (accumulatedErrors.size() > 0) { StringBuffer sb = new StringBuffer(); sb.append("Found errors in comparing elements:\n"); for (String msg : accumulatedErrors) { sb.append(msg + "\n"); } fail(sb.toString()); } }