1 19 20 package org.netbeans.modules.j2ee.clientproject.queries; 21 22 import java.net.URL ; 23 import org.netbeans.api.project.FileOwnerQuery; 24 import org.netbeans.api.project.Project; 25 import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation; 26 import org.netbeans.modules.j2ee.clientproject.SourceRoots; 27 import org.openide.filesystems.FileObject; 28 29 public class UnitTestForSourceQueryImpl implements MultipleRootsUnitTestForSourceQueryImplementation { 30 31 private final SourceRoots sourceRoots; 32 private final SourceRoots testRoots; 33 34 public UnitTestForSourceQueryImpl(SourceRoots sourceRoots, SourceRoots testRoots) { 35 this.sourceRoots = sourceRoots; 36 this.testRoots = testRoots; 37 } 38 39 public URL [] findUnitTests(FileObject source) { 40 return find(source, sourceRoots, testRoots); } 42 43 public URL [] findSources(FileObject unitTest) { 44 return find(unitTest, testRoots, sourceRoots); } 46 47 private URL [] find(FileObject file, SourceRoots from, SourceRoots to) { 48 Project p = FileOwnerQuery.getOwner(file); 49 if (p == null) { 50 return null; 51 } 52 FileObject[] fromRoots = from.getRoots(); 53 for (int i = 0; i < fromRoots.length; i++) { 54 if (fromRoots[i].equals(file)) { 55 return to.getRootURLs(); 56 } 57 } 58 return null; 59 } 60 61 } 62 | Popular Tags |