1 /* 2 * Copyright (c) 2005, 2014, 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 26 package javax.tools; 27 28 import javax.lang.model.element.NestingKind; 29 import javax.lang.model.element.Modifier; 30 import java.util.Objects; 31 32 /** 33 * File abstraction for tools operating on Java programming language 34 * source and class files. 35 * 36 * <p>All methods in this interface might throw a SecurityException if 37 * a security exception occurs. 38 * 39 * <p>Unless explicitly allowed, all methods in this interface might 40 * throw a NullPointerException if given a {@code null} argument. 41 * 42 * @author Peter von der Ahé 43 * @author Jonathan Gibbons 44 * @see JavaFileManager 45 * @since 1.6 46 */ 47 public interface JavaFileObject extends FileObject { 48 49 /** 50 * Kinds of JavaFileObjects. 51 */ 52 enum Kind { 53 /** 54 * Source files written in the Java programming language. For 55 * example, regular files ending with {@code .java}. 56 */ 57 SOURCE(".java"), 58 59 /** 60 * Class files for the Java Virtual Machine. For example, 61 * regular files ending with {@code .class}. 62 */ 63 CLASS(".class"), 64 65 /** 66 * HTML files. For example, regular files ending with {@code 67 * .html}. 68 */ 69 HTML(".html"), 70 71 /** 72 * Any other kind. 73 */ 74 OTHER(""); 75 /** 76 * The extension which (by convention) is normally used for 77 * this kind of file object. If no convention exists, the 78 * empty string ({@code ""}) is used. 79 */ 80 public final String extension; 81 private Kind(String extension) { 82 this.extension = Objects.requireNonNull(extension); 83 } 84 } 85 86 /** 87 * Returns the kind of this file object. 88 * 89 * @return the kind 90 */ 91 Kind getKind(); 92 93 /** 94 * Checks if this file object is compatible with the specified 95 * simple name and kind. A simple name is a single identifier 96 * (not qualified) as defined in 97 * <cite>The Java Language Specification</cite>, 98 * section 6.2 "Names and Identifiers". 99 * 100 * @param simpleName a simple name of a class 101 * @param kind a kind 102 * @return {@code true} if this file object is compatible; false 103 * otherwise 104 */ 105 boolean isNameCompatible(String simpleName, Kind kind); 106 107 /** 108 * Provides a hint about the nesting level of the class 109 * represented by this file object. This method may return 110 * {@link NestingKind#MEMBER} to mean 111 * {@link NestingKind#LOCAL} or {@link NestingKind#ANONYMOUS}. 112 * If the nesting level is not known or this file object does not 113 * represent a class file this method returns {@code null}. 114 * 115 * @return the nesting kind, or {@code null} if the nesting kind 116 * is not known 117 */ 118 NestingKind getNestingKind(); 119 120 /** 121 * Provides a hint about the access level of the class represented 122 * by this file object. If the access level is not known or if 123 * this file object does not represent a class file this method 124 * returns {@code null}. 125 * 126 * @return the access level 127 */ 128 Modifier getAccessLevel(); 129 130 }