Mon, 10 Dec 2012 16:21:26 +0000
8003967: detect and remove all mutable implicit static enum fields in langtools
Reviewed-by: jjg
jjg@1412 | 1 | /* |
jjg@1412 | 2 | * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
jjg@1412 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1412 | 4 | * |
jjg@1412 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1412 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1412 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@1412 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@1412 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@1412 | 10 | * |
jjg@1412 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1412 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1412 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1412 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1412 | 15 | * accompanied this code). |
jjg@1412 | 16 | * |
jjg@1412 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@1412 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1412 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1412 | 20 | * |
jjg@1412 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1412 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@1412 | 23 | * questions. |
jjg@1412 | 24 | */ |
jjg@1412 | 25 | |
jjg@1412 | 26 | package com.sun.tools.doclets.internal.toolkit.util; |
jjg@1412 | 27 | |
jjg@1412 | 28 | import java.util.Map; |
jjg@1412 | 29 | import java.util.WeakHashMap; |
jjg@1412 | 30 | |
jjg@1412 | 31 | import javax.tools.JavaFileManager; |
jjg@1412 | 32 | import javax.tools.JavaFileManager.Location; |
jjg@1412 | 33 | import javax.tools.StandardJavaFileManager; |
jjg@1412 | 34 | import javax.tools.StandardLocation; |
jjg@1412 | 35 | |
jjg@1412 | 36 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
jjg@1412 | 37 | |
jjg@1412 | 38 | /** |
jjg@1412 | 39 | * Factory for DocFile objects. |
jjg@1412 | 40 | * |
jjg@1412 | 41 | * <p><b>This is NOT part of any supported API. |
jjg@1412 | 42 | * If you write code that depends on this, you do so at your own risk. |
jjg@1412 | 43 | * This code and its internal interfaces are subject to change or |
jjg@1412 | 44 | * deletion without notice.</b> |
jjg@1412 | 45 | * |
jjg@1412 | 46 | * @since 1.8 |
jjg@1412 | 47 | */ |
jjg@1412 | 48 | abstract class DocFileFactory { |
vromero@1442 | 49 | private static final Map<Configuration, DocFileFactory> factories = |
jjg@1412 | 50 | new WeakHashMap<Configuration, DocFileFactory>(); |
jjg@1412 | 51 | |
jjg@1412 | 52 | /** |
jjg@1412 | 53 | * Get the appropriate factory, based on the file manager given in the |
jjg@1412 | 54 | * configuration. |
jjg@1412 | 55 | */ |
jjg@1412 | 56 | static synchronized DocFileFactory getFactory(Configuration configuration) { |
jjg@1412 | 57 | DocFileFactory f = factories.get(configuration); |
jjg@1412 | 58 | if (f == null) { |
jjg@1412 | 59 | JavaFileManager fm = configuration.getFileManager(); |
jjg@1412 | 60 | if (fm instanceof StandardJavaFileManager) |
jjg@1412 | 61 | f = new StandardDocFileFactory(configuration); |
jjg@1412 | 62 | else { |
jjg@1412 | 63 | try { |
jjg@1412 | 64 | Class<?> pathFileManagerClass = |
jjg@1412 | 65 | Class.forName("com.sun.tools.javac.nio.PathFileManager"); |
jjg@1412 | 66 | if (pathFileManagerClass.isAssignableFrom(fm.getClass())) |
jjg@1412 | 67 | f = new PathDocFileFactory(configuration); |
jjg@1412 | 68 | } catch (Throwable t) { |
jjg@1412 | 69 | throw new IllegalStateException(t); |
jjg@1412 | 70 | } |
jjg@1412 | 71 | } |
jjg@1413 | 72 | factories.put(configuration, f); |
jjg@1412 | 73 | } |
jjg@1412 | 74 | return f; |
jjg@1412 | 75 | } |
jjg@1412 | 76 | |
jjg@1412 | 77 | protected Configuration configuration; |
jjg@1412 | 78 | |
jjg@1412 | 79 | protected DocFileFactory(Configuration configuration) { |
jjg@1412 | 80 | this.configuration = configuration; |
jjg@1412 | 81 | } |
jjg@1412 | 82 | |
jjg@1412 | 83 | /** Create a DocFile for a directory. */ |
jjg@1412 | 84 | abstract DocFile createFileForDirectory(String file); |
jjg@1412 | 85 | |
jjg@1412 | 86 | /** Create a DocFile for a file that will be opened for reading. */ |
jjg@1412 | 87 | abstract DocFile createFileForInput(String file); |
jjg@1412 | 88 | |
jjg@1412 | 89 | /** Create a DocFile for a file that will be opened for writing. */ |
jjg@1412 | 90 | abstract DocFile createFileForOutput(DocPath path); |
jjg@1412 | 91 | |
jjg@1412 | 92 | /** |
jjg@1412 | 93 | * List the directories and files found in subdirectories along the |
jjg@1412 | 94 | * elements of the given location. |
jjg@1412 | 95 | * @param location currently, only {@link StandardLocation#SOURCE_PATH} is supported. |
jjg@1412 | 96 | * @param path the subdirectory of the directories of the location for which to |
jjg@1412 | 97 | * list files |
jjg@1412 | 98 | */ |
jjg@1412 | 99 | abstract Iterable<DocFile> list(Location location, DocPath path); |
jjg@1412 | 100 | } |