Search in sources :

Example 1 with PackageFragmentRootWalker

use of org.eclipse.xtext.ui.resource.PackageFragmentRootWalker in project xtext-eclipse by eclipse.

the class PackageFragmentRootWalkerTest method testTraversePackageFragmentRoot.

@Test
public void testTraversePackageFragmentRoot() throws Exception {
    IJavaProject project = createJavaProject("foo");
    String jarName = "JarWalkerTest.jar";
    IFile file = project.getProject().getFile(jarName);
    file.create(getClass().getResourceAsStream(jarName), true, new NullProgressMonitor());
    addJarToClasspath(project, file);
    final Set<IPath> pathes = new HashSet<IPath>();
    PackageFragmentRootWalker<Void> walker = new PackageFragmentRootWalker<Void>() {

        @Override
        protected Void handle(IJarEntryResource jarEntry, TraversalState state) {
            pathes.add(jarEntry.getFullPath());
            return null;
        }
    };
    for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
        if (root.getElementName().equals(jarName))
            walker.traverse(root, false);
    }
    assertEquals(3, pathes.size());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) PackageFragmentRootWalker(org.eclipse.xtext.ui.resource.PackageFragmentRootWalker) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IJarEntryResource (org.eclipse.jdt.core.IJarEntryResource)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 PackageFragmentRootWalker (org.eclipse.xtext.ui.resource.PackageFragmentRootWalker)1 Test (org.junit.Test)1