1 19 20 package org.netbeans.api.queries; 21 22 import java.io.File ; 23 import org.netbeans.spi.queries.CollocationQueryImplementation; 24 import org.openide.filesystems.FileUtil; 25 import org.openide.util.Lookup; 26 27 33 public final class CollocationQuery { 34 35 private static final Lookup.Result<CollocationQueryImplementation> implementations = 36 Lookup.getDefault().lookupResult(CollocationQueryImplementation.class); 37 38 private CollocationQuery() {} 39 40 49 public static boolean areCollocated(File file1, File file2) { 50 if (!file1.equals(FileUtil.normalizeFile(file1))) { 51 throw new IllegalArgumentException ("Parameter file1 was not "+ "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1)); } 54 if (!file2.equals(FileUtil.normalizeFile(file2))) { 55 throw new IllegalArgumentException ("Parameter file2 was not "+ "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2)); } 58 for (CollocationQueryImplementation cqi : implementations.allInstances()) { 59 if (cqi.areCollocated(file1, file2)) { 60 return true; 61 } 62 } 63 return false; 64 } 65 66 72 public static File findRoot(File file) { 73 if (!file.equals(FileUtil.normalizeFile(file))) { 74 throw new IllegalArgumentException ("Parameter file was not "+ "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file)); } 77 for (CollocationQueryImplementation cqi : implementations.allInstances()) { 78 File root = cqi.findRoot(file); 79 if (root != null) { 80 return root; 81 } 82 } 83 return null; 84 } 85 86 } 87 | Popular Tags |