Path: blob/master/src/java.compiler/share/classes/javax/tools/StandardLocation.java
41152 views
/*1* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import javax.tools.JavaFileManager.Location;2829import java.util.concurrent.*;3031/**32* Standard locations of file objects.33*34* @author Peter von der Ahé35* @since 1.636*/37public enum StandardLocation implements Location {3839/**40* Location of new class files.41*/42CLASS_OUTPUT,4344/**45* Location of new source files.46*/47SOURCE_OUTPUT,4849/**50* Location to search for user class files.51*/52CLASS_PATH,5354/**55* Location to search for existing source files.56*/57SOURCE_PATH,5859/**60* Location to search for annotation processors.61*/62ANNOTATION_PROCESSOR_PATH,6364/**65* Location to search for modules containing annotation processors.66* @since 967*/68ANNOTATION_PROCESSOR_MODULE_PATH,6970/**71* Location to search for platform classes. Sometimes called72* the boot class path.73*/74PLATFORM_CLASS_PATH,7576/**77* Location of new native header files.78* @since 1.879*/80NATIVE_HEADER_OUTPUT,8182/**83* Location to search for the source code of modules.84* @since 985*/86MODULE_SOURCE_PATH,8788/**89* Location to search for upgradeable system modules.90* @since 991*/92UPGRADE_MODULE_PATH,9394/**95* Location to search for system modules.96* @since 997*/98SYSTEM_MODULES,99100/**101* Location to search for precompiled user modules.102* @since 9103*/104MODULE_PATH,105106/**107* Location to search for module patches.108* @since 9109*/110PATCH_MODULE_PATH;111112/**113* Returns a location object with the given name. The following114* property must hold: {@code locationFor(x) ==115* locationFor(y)} if and only if {@code x.equals(y)}.116* The returned location will be an output location if and only if117* name ends with {@code "_OUTPUT"}. It will be considered to118* be a module-oriented location if the name contains the word119* {@code "MODULE"}.120*121* @param name a name122* @return a location123*124* @revised 9125*/126public static Location locationFor(final String name) {127if (locations.isEmpty()) {128// can't use valueOf which throws IllegalArgumentException129for (Location location : values())130locations.putIfAbsent(location.getName(), location);131}132name.getClass(); /* null-check */133locations.putIfAbsent(name, new Location() {134@Override135public String getName() { return name; }136@Override137public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); }138});139return locations.get(name);140}141//where142private static final ConcurrentMap<String,Location> locations143= new ConcurrentHashMap<>();144145@Override146public String getName() { return name(); }147148@Override149public boolean isOutputLocation() {150switch (this) {151case CLASS_OUTPUT:152case SOURCE_OUTPUT:153case NATIVE_HEADER_OUTPUT:154return true;155default:156return false;157}158}159160/**161* {@inheritDoc}162* @since 9163*/164@Override165public boolean isModuleOrientedLocation() {166switch (this) {167case MODULE_SOURCE_PATH:168case ANNOTATION_PROCESSOR_MODULE_PATH:169case UPGRADE_MODULE_PATH:170case SYSTEM_MODULES:171case MODULE_PATH:172case PATCH_MODULE_PATH:173return true;174default:175return false;176}177}178}179180181