1 19 20 package org.netbeans.api.java.queries; 21 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 import java.util.regex.Pattern ; 25 import org.netbeans.spi.java.queries.SourceLevelQueryImplementation; 26 import org.openide.filesystems.FileObject; 27 import org.openide.util.Lookup; 28 29 35 public class SourceLevelQuery { 36 37 private static final Logger LOGGER = Logger.getLogger(SourceLevelQuery.class.getName()); 38 39 private static final Pattern SOURCE_LEVEL = Pattern.compile("\\d+\\.\\d+"); 40 41 private static final Lookup.Result<? extends SourceLevelQueryImplementation> implementations = 42 Lookup.getDefault().lookupResult (SourceLevelQueryImplementation.class); 43 44 private SourceLevelQuery() { 45 } 46 47 55 public static String getSourceLevel(FileObject javaFile) { 56 for (SourceLevelQueryImplementation sqi : implementations.allInstances()) { 57 String s = sqi.getSourceLevel(javaFile); 58 if (s != null) { 59 if (!SOURCE_LEVEL.matcher(s).matches()) { 60 LOGGER.log(Level.WARNING, "#83994: Ignoring bogus source level {0} for {1} from {2}", new Object [] {s, javaFile, sqi}); 61 continue; 62 } 63 LOGGER.log(Level.FINE, "Found source level {0} for {1} from {2}", new Object [] {s, javaFile, sqi}); 64 return s; 65 } 66 } 67 LOGGER.log(Level.FINE, "No source level found for {0}", javaFile); 68 return null; 69 } 70 71 } 72 | Popular Tags |