java.lang.Object
javax.tools.SimpleJavaFileObject
- All Implemented Interfaces:
FileObject,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 Class Summary
Nested classes/interfaces declared in interface javax.tools.JavaFileObject
JavaFileObject.Kind -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JavaFileObject.KindThe kind of this file object.protected final URIA URI for this file object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimpleJavaFileObject(URI uri, JavaFileObject.Kind kind) Construct a SimpleJavaFileObject of the given kind and with the given URI. -
Method Summary
Modifier and TypeMethodDescriptionbooleandelete()This implementation does nothing.This implementation returnsnull.getCharContent(boolean ignoreEncodingErrors) This implementation always throws UnsupportedOperationException.getKind()Returns the kind of this file object.longThis implementation returns0L.getName()Returns a user-friendly name for this file object.This implementation returnsnull.booleanisNameCompatible(String simpleName, JavaFileObject.Kind kind) This implementation compares the path of its URI to the given simple name.This implementation always throws UnsupportedOperationException.This implementation always throws UnsupportedOperationException.openReader(boolean ignoreEncodingErrors) Wraps the result of getCharContent(boolean) in a Reader.Wraps the result of openOutputStream in a Writer.toUri()Returns a URI identifying this file object.
-
Field Details
-
uri
A URI for this file object. -
kind
The kind of this file object.
-
-
Constructor Details
-
SimpleJavaFileObject
Construct a SimpleJavaFileObject of the given kind and with the given URI.- Parameters:
uri- the URI for this file objectkind- the kind of this file object
-
-
Method Details
-
toUri
Description copied from interface:FileObjectReturns a URI identifying this file object.- Specified by:
toUriin interfaceFileObject- Returns:
- a URI
-
getName
Description copied from interface:FileObjectReturns a user-friendly name for this file object. The exact value returned is not specified but implementations should take care to preserve names as given by the user. For example, if the user writes the filename"BobsApp\Test.java"on the command line, this method should return"BobsApp\Test.java"whereas the toUri method might returnfile:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java.- Specified by:
getNamein interfaceFileObject- Returns:
- a user-friendly name
-
openInputStream
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
openInputStreamin interfaceFileObject- Returns:
- an InputStream
- Throws:
IOException- if an I/O error occurred
-
openOutputStream
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
openOutputStreamin interfaceFileObject- Returns:
- an OutputStream
- Throws:
IOException- if an I/O error occurred
-
openReader
Wraps the result of getCharContent(boolean) in a Reader. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
openReaderin 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 readingUnsupportedOperationException- if this kind of file object does not support character accessIOException- if an I/O error occurred
-
getCharContent
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
getCharContentin interfaceFileObject- Parameters:
ignoreEncodingErrors- ignore encoding errors if true- Returns:
- a CharSequence if available;
nullotherwise - Throws:
IOException- if an I/O error occurred
-
openWriter
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
openWriterin interfaceFileObject- Returns:
- a Writer wrapping the result of openOutputStream
- Throws:
IllegalStateException- if this file object was opened for reading and does not support writingUnsupportedOperationException- if this kind of file object does not support character accessIOException- if an I/O error occurred
-
getLastModified
public long getLastModified()This implementation returns0L. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
getLastModifiedin interfaceFileObject- Returns:
0L
-
delete
public boolean delete()This implementation does nothing. Subclasses can change this behavior as long as the contract ofFileObjectis obeyed.- Specified by:
deletein interfaceFileObject- Returns:
false
-
getKind
Description copied from interface:JavaFileObjectReturns the kind of this file object.- Specified by:
getKindin interfaceJavaFileObject- Returns:
this.kind
-
isNameCompatible
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 tosimpleName + kind.extensionor if it ends with"/" + simpleName + kind.extension.This method calls
getKind()andtoUri()and does not access the fieldsuriandkinddirectly.Subclasses can change this behavior as long as the contract of
JavaFileObjectis obeyed.- Specified by:
isNameCompatiblein interfaceJavaFileObject- Parameters:
simpleName- a simple name of a classkind- a kind- Returns:
trueif this file object is compatible;falseotherwise
-
getNestingKind
This implementation returnsnull. Subclasses can change this behavior as long as the contract ofJavaFileObjectis obeyed.- Specified by:
getNestingKindin interfaceJavaFileObject- Returns:
- the nesting kind, or
nullif the nesting kind is not known
-
getAccessLevel
This implementation returnsnull. Subclasses can change this behavior as long as the contract ofJavaFileObjectis obeyed.- Specified by:
getAccessLevelin interfaceJavaFileObject- Returns:
- the access level
-