Class SimpleJavaFileObject
- java.lang.Object
-
- javax.tools.SimpleJavaFileObject
- All Implemented Interfaces:
-
FileObject
,JavaFileObject
public class SimpleJavaFileObject extends Object implements JavaFileObject
Provides simple implementations for most methods in JavaFileObject. This class is designed to be subclassed and used as a basis for JavaFileObject implementations. Subclasses can override the implementation and specification of any method of this class as long as the general contract of JavaFileObject is obeyed.
- Since:
- 1.6
Nested Classes
Nested classes/interfaces declared in interface javax.tools.JavaFileObject
JavaFileObject.Kind
Fields
Modifier and Type | Field | Description |
---|---|---|
protected JavaFileObject.Kind | kind | The kind of this file object. |
protected URI | uri | A URI for this file object. |
Constructors
Modifier | Constructor | Description |
---|---|---|
protected | SimpleJavaFileObject(URI uri,
JavaFileObject.Kind kind) | Construct a SimpleJavaFileObject of the given kind and with the given URI. |
Methods
Modifier and Type | Method | Description |
---|---|---|
boolean | delete() | This implementation does nothing. |
Modifier | getAccessLevel() | This implementation returns |
CharSequence | getCharContent(boolean ignoreEncodingErrors) | This implementation always throws UnsupportedOperationException. |
JavaFileObject.Kind | getKind() | Returns the kind of this file object. |
long | getLastModified() | This implementation returns |
NestingKind | getNestingKind() | This implementation returns |
boolean | isNameCompatible(String simpleName,
JavaFileObject.Kind kind) | This implementation compares the path of its URI to the given simple name. |
InputStream | openInputStream() | This implementation always throws UnsupportedOperationException. |
OutputStream | openOutputStream() | This implementation always throws UnsupportedOperationException. |
Reader | openReader(boolean ignoreEncodingErrors) | Wraps the result of getCharContent(boolean) in a Reader. |
Writer | openWriter() | Wraps the result of openOutputStream in a Writer. |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javax.tools.FileObject
getName, toUri
Fields
uri
protected final URI uri
A URI for this file object.
kind
protected final JavaFileObject.Kind kind
The kind of this file object.
Constructors
SimpleJavaFileObject
protected SimpleJavaFileObject(URI uri, JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.
- Parameters:
-
uri
- the URI for this file object -
kind
- the kind of this file object
Methods
openInputStream
public InputStream openInputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
openInputStream
in interfaceFileObject
- Returns:
- an InputStream
- Throws:
-
IOException
- if an I/O error occurred
openOutputStream
public OutputStream openOutputStream() throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
openOutputStream
in interfaceFileObject
- Returns:
- an OutputStream
- Throws:
-
IOException
- if an I/O error occurred
openReader
public Reader openReader(boolean ignoreEncodingErrors) throws IOException
Wraps the result of getCharContent(boolean) in a Reader. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
openReader
in interfaceFileObject
- Parameters:
-
ignoreEncodingErrors
- ignore encoding errors if true - Returns:
- a Reader wrapping the result of getCharContent
- Throws:
-
IllegalStateException
- if this file object was opened for writing and does not support reading -
UnsupportedOperationException
- if this kind of file object does not support character access -
IOException
- if an I/O error occurred
getCharContent
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
getCharContent
in interfaceFileObject
- Parameters:
-
ignoreEncodingErrors
- ignore encoding errors if true - Returns:
- a CharSequence if available;
null
otherwise - Throws:
-
IOException
- if an I/O error occurred
openWriter
public Writer openWriter() throws IOException
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
openWriter
in interfaceFileObject
- Returns:
- a Writer wrapping the result of openOutputStream
- Throws:
-
IllegalStateException
- if this file object was opened for reading and does not support writing -
UnsupportedOperationException
- if this kind of file object does not support character access -
IOException
- if an I/O error occurred
getLastModified
public long getLastModified()
This implementation returns 0L
. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
getLastModified
in interfaceFileObject
- Returns:
0L
delete
public boolean delete()
This implementation does nothing. Subclasses can change this behavior as long as the contract of FileObject
is obeyed.
- Specified by:
-
delete
in interfaceFileObject
- Returns:
false
getKind
public JavaFileObject.Kind getKind()
Description copied from interface: JavaFileObject
Returns the kind of this file object.
- Specified by:
-
getKind
in interfaceJavaFileObject
- Returns:
this.kind
isNameCompatible
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind)
This implementation compares the path of its URI to the given simple name. This method returns true if the given kind is equal to the kind of this object, and if the path is equal to simpleName + kind.extension
or if it ends with
"/" + simpleName + kind.extension
.
This method calls getKind()
and FileObject.toUri()
and does not access the fields uri
and kind
directly.
Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
- Specified by:
-
isNameCompatible
in interfaceJavaFileObject
- Parameters:
-
simpleName
- a simple name of a class -
kind
- a kind - Returns:
-
true
if this file object is compatible; false otherwise
getNestingKind
public NestingKind getNestingKind()
This implementation returns null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
- Specified by:
-
getNestingKind
in interfaceJavaFileObject
- Returns:
- the nesting kind, or
null
if the nesting kind is not known
getAccessLevel
public Modifier getAccessLevel()
This implementation returns null
. Subclasses can change this behavior as long as the contract of JavaFileObject
is obeyed.
- Specified by:
-
getAccessLevel
in interfaceJavaFileObject
- Returns:
- the access level
© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/tools/SimpleJavaFileObject.html