Top Description Inners Fields Constructors Methods
com.sun.codemodel.fmt

public final Class JStaticJavaFile

extends JResourceFile
Class Inheritance
Imports
java.io.BufferedReader, .BufferedWriter, .IOException, .InputStream, .InputStreamReader, .OutputStream, .OutputStreamWriter, .PrintWriter, java.text.ParseException, java.util.Iterator, .List, com.sun.codemodel.JClass, .JPackage, .JResourceFile, .JTypeVar

Statically generated Java soruce file.

This JResourceFile implementation will generate a Java source file by copying the source code from a resource.

While copying a resource, we look for a package declaration and replace it with the target package name. This allows the static Java source code to have an arbitrary package declaration.

You can also use the getJClass method to obtain a JClass object that represents the static file. This allows the client code to refer to the class from other CodeModel generated code.

Note that because we don't parse the static Java source code, the returned JClass object doesn't respond to methods like "isInterface" or "_extends",

Author
Kohsuke Kawaguchi ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private class
public static interface
JStaticJavaFile.LineFilter

Filter that alters the Java source code.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private final String
private final JStaticJavaFile.JStaticClass
private final JStaticJavaFile.LineFilter
private final JPackage
private final JStaticJavaFile.ResourceLoader

Constructor Summary

AccessConstructor and Description
public
JStaticJavaFile(JPackage _pkg, String _className, Class<?> loadingClass, JStaticJavaFile.LineFilter _filter)

Method Summary

Modifier and TypeMethod and Description
protected void
build(OutputStream os)

Implements abstract com.sun.codemodel.JResourceFile.build.

called by JPackage to produce the file image.

private JStaticJavaFile.LineFilter
public JClass
getJClass()

Returns a class object that represents a statically generated code.

protected boolean
isResource()

Overrides com.sun.codemodel.JResourceFile.isResource.

Returns true if this file should be generated into the directory that the resource files go into.

Inherited from com.sun.codemodel.JResourceFile:
name

Field Detail

classNameback to summary
private final String className
clazzback to summary
private final JStaticJavaFile.JStaticClass clazz
filterback to summary
private final JStaticJavaFile.LineFilter filter
pkgback to summary
private final JPackage pkg
sourceback to summary
private final JStaticJavaFile.ResourceLoader source

Constructor Detail

JStaticJavaFileback to summary
public JStaticJavaFile(JPackage _pkg, String _className, Class<?> loadingClass, JStaticJavaFile.LineFilter _filter)

Method Detail

buildback to summary
protected void build(OutputStream os) throws IOException

Implements abstract com.sun.codemodel.JResourceFile.build.

Doc from com.sun.codemodel.JResourceFile.build.

called by JPackage to produce the file image.

Annotations
@Override
createLineFilterback to summary
private JStaticJavaFile.LineFilter createLineFilter()

Creates a LineFilter.

A derived class can override this method to process the contents of the source file.

getJClassback to summary
public JClass getJClass()

Returns a class object that represents a statically generated code.

isResourceback to summary
protected boolean isResource()

Overrides com.sun.codemodel.JResourceFile.isResource.

Doc from com.sun.codemodel.JResourceFile.isResource.

Returns true if this file should be generated into the directory that the resource files go into.

Returns false if this file should be generated into the directory where other source files go.

Annotations
@Override
com.sun.codemodel.fmt back to summary

public final Class JStaticJavaFile.ChainFilter

extends Object
implements LineFilter
Class Inheritance
All Implemented Interfaces
com.sun.codemodel.fmt.JStaticJavaFile.LineFilter

A LineFilter that combines two LineFilters.

Field Summary

Modifier and TypeField and Description
private final JStaticJavaFile.LineFilter
private final JStaticJavaFile.LineFilter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

firstback to summary
private final JStaticJavaFile.LineFilter first
secondback to summary
private final JStaticJavaFile.LineFilter second

Constructor Detail

ChainFilterback to summary
public ChainFilter(JStaticJavaFile.LineFilter first, JStaticJavaFile.LineFilter second)

Method Detail

processback to summary
public String process(String line) throws ParseException

Implements com.sun.codemodel.fmt.JStaticJavaFile.LineFilter.process.

Annotations
@Override
Exceptions
ParseException:

Doc from com.sun.codemodel.fmt.JStaticJavaFile.LineFilter.process.

when for some reason there's an error in the line.

com.sun.codemodel.fmt back to summary

private Class JStaticJavaFile.JStaticClass

extends JClass
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final JTypeVar[]
Inherited from com.sun.codemodel.JClass:
EMPTY_ARRAY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public JClass
_extends()

Implements abstract com.sun.codemodel.JClass._extends.

Gets the super class of this class.

public Iterator<JClass>
_implements()

Implements abstract com.sun.codemodel.JClass._implements.

Iterates all super interfaces directly implemented by this class/interface.

public JPackage
_package()

Implements abstract com.sun.codemodel.JClass._package.

Gets the package to which this class belongs.

public String
fullName()

Implements abstract com.sun.codemodel.JType.fullName.

Gets the full name of the type.

public boolean
isAbstract()

Implements abstract com.sun.codemodel.JClass.isAbstract.

Checks if this class is an abstract class.

public boolean
isInterface()

Implements abstract com.sun.codemodel.JClass.isInterface.

Checks if this object represents an interface.

public String
name()

Implements abstract com.sun.codemodel.JClass.name.

Gets the name of this class.

protected JClass
substituteParams(JTypeVar[] variables, List<JClass> bindings)

Implements abstract com.sun.codemodel.JClass.substituteParams.

Substitutes the type variables with their actual arguments.

public JTypeVar[]
typeParams()

Overrides com.sun.codemodel.JClass.typeParams.

Iterates all the type parameters of this class/interface.

Inherited from com.sun.codemodel.JClass:
arrayboxifydotclasserasuregenerategetBaseClassgetBaseClassgetPrimitiveTypegetTypeParametersisAssignableFromisParameterizednarrownarrownarrownarrownarrownarrowouterownerstaticInvokestaticInvokestaticRefstaticReftoStringunboxifywildcard

Field Detail

typeParamsback to summary
private final JTypeVar[] typeParams

Constructor Detail

JStaticClassback to summary
pack-priv JStaticClass()

Method Detail

_extendsback to summary
public JClass _extends()

Implements abstract com.sun.codemodel.JClass._extends.

Doc from com.sun.codemodel.JClass._extends.

Gets the super class of this class.

Annotations
@Override
_implementsback to summary
public Iterator<JClass> _implements()

Implements abstract com.sun.codemodel.JClass._implements.

Doc from com.sun.codemodel.JClass._implements.

Iterates all super interfaces directly implemented by this class/interface.

Annotations
@Override
_packageback to summary
public JPackage _package()

Implements abstract com.sun.codemodel.JClass._package.

Doc from com.sun.codemodel.JClass._package.

Gets the package to which this class belongs.

Todo

shall we move move this down?

Annotations
@Override
fullNameback to summary
public String fullName()

Implements abstract com.sun.codemodel.JType.fullName.

Doc from com.sun.codemodel.JType.fullName.

Gets the full name of the type. See http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#25430 for the details.

Annotations
@Override
isAbstractback to summary
public boolean isAbstract()

Implements abstract com.sun.codemodel.JClass.isAbstract.

Doc from com.sun.codemodel.JClass.isAbstract.

Checks if this class is an abstract class.

Annotations
@Override
isInterfaceback to summary
public boolean isInterface()

Implements abstract com.sun.codemodel.JClass.isInterface.

Doc from com.sun.codemodel.JClass.isInterface.

Checks if this object represents an interface.

Annotations
@Override
nameback to summary
public String name()

Implements abstract com.sun.codemodel.JClass.name.

Doc from com.sun.codemodel.JClass.name.

Gets the name of this class.

Annotations
@Override
substituteParamsback to summary
protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings)

Implements abstract com.sun.codemodel.JClass.substituteParams.

Doc from com.sun.codemodel.JClass.substituteParams.

Substitutes the type variables with their actual arguments.

For example, when this class is Map<String,Map<V>>, (where V then doing substituteParams( V, Integer ) returns a for Map<String,Map<Integer>>.

This method needs to work recursively.

Annotations
@Override
typeParamsback to summary
public JTypeVar[] typeParams()

Overrides com.sun.codemodel.JClass.typeParams.

Doc from com.sun.codemodel.JClass.typeParams.

Iterates all the type parameters of this class/interface.

For example, if this represents Set<T>, this method returns an array that contains single JTypeVar for 'T'.

Annotations
@Override
com.sun.codemodel.fmt back to summary

public Interface JStaticJavaFile.LineFilter

Known Direct Implementers
com.sun.codemodel.fmt.JStaticJavaFile.ChainFilter

Filter that alters the Java source code.

By implementing this interface, derived classes can modify the Java source file before it's written out.

Method Summary

Modifier and TypeMethod and Description
public String
process(String
a non-null valid String that corresponds to one line. No '\n' included.
line
)

Returns: null to strip the line off.

Method Detail

processback to summary
public String process(String line) throws ParseException
Parameters
line:String

a non-null valid String that corresponds to one line. No '\n' included.

Returns:String

null to strip the line off. Otherwise the returned String will be written out. Do not add '\n' at the end of this string.

Exceptions
ParseException:
when for some reason there's an error in the line.
com.sun.codemodel.fmt back to summary

pack-priv Class JStaticJavaFile.ResourceLoader

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Class<?>
pack-priv String

Constructor Summary

AccessConstructor and Description
pack-priv
ResourceLoader(String shortName, Class<?> loadingClass)

Method Summary

Modifier and TypeMethod and Description
pack-priv InputStream
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loadingClassback to summary
pack-priv Class<?> loadingClass
shortNameback to summary
pack-priv String shortName

Constructor Detail

ResourceLoaderback to summary
pack-priv ResourceLoader(String shortName, Class<?> loadingClass)

Method Detail

getResourceAsStreamback to summary
pack-priv InputStream getResourceAsStream()