FileDocCategorySizeDatePackage
SimpleJavaFileObject.javaAPI DocJava SE 6 API6333Tue Jun 10 00:27:02 BST 2008javax.tools

SimpleJavaFileObject

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.
author
Peter von der Ahé
since
1.6

Fields Summary
protected final URI
uri
A URI for this file object.
protected final javax.tools.JavaFileObject.Kind
kind
The kind of this file object.
Constructors Summary
protected SimpleJavaFileObject(URI uri, javax.tools.JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.

param
uri the URI for this file object
param
kind the kind of this file object

        // null checks
        uri.getClass();
        kind.getClass();
        if (uri.getPath() == null)
            throw new IllegalArgumentException("URI must have a path: " + uri);
        this.uri = uri;
        this.kind = kind;
    
Methods Summary
public booleandelete()
This implementation does nothing. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

return
{@code false}

        return false;
    
public javax.lang.model.element.ModifiergetAccessLevel()
This implementation returns {@code null}. Subclasses can change this behavior as long as the contract of {@link JavaFileObject} is obeyed.

 return null; 
public java.lang.CharSequencegetCharContent(boolean ignoreEncodingErrors)
This implementation always throws {@linkplain UnsupportedOperationException}. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

        throw new UnsupportedOperationException();
    
public javax.tools.JavaFileObject.KindgetKind()

return
{@code this.kind}

        return kind;
    
public longgetLastModified()
This implementation returns {@code 0L}. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

return
{@code 0L}

        return 0L;
    
public java.lang.StringgetName()

        return toUri().getPath();
    
public javax.lang.model.element.NestingKindgetNestingKind()
This implementation returns {@code null}. Subclasses can change this behavior as long as the contract of {@link JavaFileObject} is obeyed.

 return null; 
public booleanisNameCompatible(java.lang.String simpleName, javax.tools.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 {@code simpleName + kind.extension} or if it ends with {@code "/" + simpleName + kind.extension}.

This method calls {@link #getKind} and {@link #toUri} and does not access the fields {@link #uri} and {@link #kind} directly.

Subclasses can change this behavior as long as the contract of {@link JavaFileObject} is obeyed.

        String baseName = simpleName + kind.extension;
        return kind.equals(getKind())
            && (baseName.equals(toUri().getPath())
                || toUri().getPath().endsWith("/" + baseName));
    
public java.io.InputStreamopenInputStream()
This implementation always throws {@linkplain UnsupportedOperationException}. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

        throw new UnsupportedOperationException();
    
public java.io.OutputStreamopenOutputStream()
This implementation always throws {@linkplain UnsupportedOperationException}. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

        throw new UnsupportedOperationException();
    
public java.io.ReaderopenReader(boolean ignoreEncodingErrors)
Wraps the result of {@linkplain #getCharContent} in a Reader. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

param
ignoreEncodingErrors {@inheritDoc}
return
a Reader wrapping the result of getCharContent
throws
IllegalStateException {@inheritDoc}
throws
UnsupportedOperationException {@inheritDoc}
throws
IOException {@inheritDoc}

        CharSequence charContent = getCharContent(ignoreEncodingErrors);
        if (charContent == null)
            throw new UnsupportedOperationException();
        if (charContent instanceof CharBuffer) {
            CharBuffer buffer = (CharBuffer)charContent;
            if (buffer.hasArray())
                return new CharArrayReader(buffer.array());
        }
        return new StringReader(charContent.toString());
    
public java.io.WriteropenWriter()
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of {@link FileObject} is obeyed.

return
a Writer wrapping the result of openOutputStream
throws
IllegalStateException {@inheritDoc}
throws
UnsupportedOperationException {@inheritDoc}
throws
IOException {@inheritDoc}

        return new OutputStreamWriter(openOutputStream());
    
public java.lang.StringtoString()

        return uri + " from " + getClass().getSimpleName();
    
public java.net.URItoUri()

        return uri;