StandardLocation.java revision 3976:65d446c80cdf
1/*
2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.tools;
27
28import javax.tools.JavaFileManager.Location;
29
30import java.util.concurrent.*;
31
32/**
33 * Standard locations of file objects.
34 *
35 * @author Peter von der Ahé
36 * @since 1.6
37 */
38public enum StandardLocation implements Location {
39
40    /**
41     * Location of new class files.
42     */
43    CLASS_OUTPUT,
44
45    /**
46     * Location of new source files.
47     */
48    SOURCE_OUTPUT,
49
50    /**
51     * Location to search for user class files.
52     */
53    CLASS_PATH,
54
55    /**
56     * Location to search for existing source files.
57     */
58    SOURCE_PATH,
59
60    /**
61     * Location to search for annotation processors.
62     */
63    ANNOTATION_PROCESSOR_PATH,
64
65    /**
66     * Location to search for modules containing annotation processors.
67     * @spec JPMS
68     * @since 9
69     */
70    ANNOTATION_PROCESSOR_MODULE_PATH,
71
72    /**
73     * Location to search for platform classes.  Sometimes called
74     * the boot class path.
75     */
76    PLATFORM_CLASS_PATH,
77
78    /**
79     * Location of new native header files.
80     * @since 1.8
81     */
82    NATIVE_HEADER_OUTPUT,
83
84    /**
85     * Location to search for the source code of modules.
86     * @spec JPMS
87     * @since 9
88     */
89    MODULE_SOURCE_PATH,
90
91    /**
92     * Location to search for upgradeable system modules.
93     * @spec JPMS
94     * @since 9
95     */
96    UPGRADE_MODULE_PATH,
97
98    /**
99     * Location to search for system modules.
100     * @spec JPMS
101     * @since 9
102     */
103    SYSTEM_MODULES,
104
105    /**
106     * Location to search for precompiled user modules.
107     * @spec JPMS
108     * @since 9
109     */
110    MODULE_PATH;
111
112    /**
113     * Returns a location object with the given name.  The following
114     * 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 if
117     * name ends with {@code "_OUTPUT"}. It will be considered to
118     * be a module-oriented location if the name contains the word
119     * {@code "MODULE"}.
120     *
121     * @param name a name
122     * @return a location
123     *
124     * @revised 9
125     * @spec JPMS
126     */
127    public static Location locationFor(final String name) {
128        if (locations.isEmpty()) {
129            // can't use valueOf which throws IllegalArgumentException
130            for (Location location : values())
131                locations.putIfAbsent(location.getName(), location);
132        }
133        name.getClass(); /* null-check */
134        locations.putIfAbsent(name, new Location() {
135                @Override
136                public String getName() { return name; }
137                @Override
138                public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); }
139            });
140        return locations.get(name);
141    }
142    //where
143        private static final ConcurrentMap<String,Location> locations
144            = new ConcurrentHashMap<>();
145
146    @Override
147    public String getName() { return name(); }
148
149    @Override
150    public boolean isOutputLocation() {
151        switch (this) {
152            case CLASS_OUTPUT:
153            case SOURCE_OUTPUT:
154            case NATIVE_HEADER_OUTPUT:
155                return true;
156            default:
157                return false;
158        }
159    }
160
161    @Override
162    public boolean isModuleOrientedLocation() {
163        switch (this) {
164            case MODULE_SOURCE_PATH:
165            case ANNOTATION_PROCESSOR_MODULE_PATH:
166            case UPGRADE_MODULE_PATH:
167            case SYSTEM_MODULES:
168            case MODULE_PATH:
169                return true;
170            default:
171                return false;
172        }
173    }
174}
175