1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/tools/StandardLocation.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,115 @@ 1.4 +/* 1.5 + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package javax.tools; 1.30 + 1.31 +import javax.tools.JavaFileManager.Location; 1.32 + 1.33 +import java.util.concurrent.*; 1.34 + 1.35 +/** 1.36 + * Standard locations of file objects. 1.37 + * 1.38 + * @author Peter von der Ahé 1.39 + * @since 1.6 1.40 + */ 1.41 +public enum StandardLocation implements Location { 1.42 + 1.43 + /** 1.44 + * Location of new class files. 1.45 + */ 1.46 + CLASS_OUTPUT, 1.47 + 1.48 + /** 1.49 + * Location of new source files. 1.50 + */ 1.51 + SOURCE_OUTPUT, 1.52 + 1.53 + /** 1.54 + * Location to search for user class files. 1.55 + */ 1.56 + CLASS_PATH, 1.57 + 1.58 + /** 1.59 + * Location to search for existing source files. 1.60 + */ 1.61 + SOURCE_PATH, 1.62 + 1.63 + /** 1.64 + * Location to search for annotation processors. 1.65 + */ 1.66 + ANNOTATION_PROCESSOR_PATH, 1.67 + 1.68 + /** 1.69 + * Location to search for platform classes. Sometimes called 1.70 + * the boot class path. 1.71 + */ 1.72 + PLATFORM_CLASS_PATH, 1.73 + 1.74 + /** 1.75 + * Location of new native header files. 1.76 + * @since 1.8 1.77 + */ 1.78 + NATIVE_HEADER_OUTPUT; 1.79 + 1.80 + /** 1.81 + * Gets a location object with the given name. The following 1.82 + * property must hold: {@code locationFor(x) == 1.83 + * locationFor(y)} if and only if {@code x.equals(y)}. 1.84 + * The returned location will be an output location if and only if 1.85 + * name ends with {@code "_OUTPUT"}. 1.86 + * 1.87 + * @param name a name 1.88 + * @return a location 1.89 + */ 1.90 + public static Location locationFor(final String name) { 1.91 + if (locations.isEmpty()) { 1.92 + // can't use valueOf which throws IllegalArgumentException 1.93 + for (Location location : values()) 1.94 + locations.putIfAbsent(location.getName(), location); 1.95 + } 1.96 + locations.putIfAbsent(name.toString(/* null-check */), new Location() { 1.97 + public String getName() { return name; } 1.98 + public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); } 1.99 + }); 1.100 + return locations.get(name); 1.101 + } 1.102 + //where 1.103 + private static final ConcurrentMap<String,Location> locations 1.104 + = new ConcurrentHashMap<String,Location>(); 1.105 + 1.106 + public String getName() { return name(); } 1.107 + 1.108 + public boolean isOutputLocation() { 1.109 + switch (this) { 1.110 + case CLASS_OUTPUT: 1.111 + case SOURCE_OUTPUT: 1.112 + case NATIVE_HEADER_OUTPUT: 1.113 + return true; 1.114 + default: 1.115 + return false; 1.116 + } 1.117 + } 1.118 +}