Package net.officefloor.compile.classes
Class OfficeFloorJavaCompiler
- java.lang.Object
-
- net.officefloor.compile.classes.OfficeFloorJavaCompiler
-
- Direct Known Subclasses:
OfficeFloorJavaCompilerImpl
public abstract class OfficeFloorJavaCompiler extends java.lang.Object
Java compiler to avoidProxy
implementations.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
OfficeFloorJavaCompiler.ClassField
ClassField
.static interface
OfficeFloorJavaCompiler.ClassName
Class
name.static interface
OfficeFloorJavaCompiler.ConstructorWriter
Writes theConstructor
for the wrapping implementation.static interface
OfficeFloorJavaCompiler.ConstructorWriterContext
Context for theOfficeFloorJavaCompiler.ConstructorWriter
.static interface
OfficeFloorJavaCompiler.ImplementationRunnable<T extends java.lang.Throwable>
Runnable
to use with the specifiedOfficeFloorJavaCompiler
implementation.static interface
OfficeFloorJavaCompiler.JavaSource
Java source.static interface
OfficeFloorJavaCompiler.JavaSourceContext
Context for theOfficeFloorJavaCompiler.JavaSourceWriter
.static interface
OfficeFloorJavaCompiler.JavaSourceWriter
Provides means to including source.static interface
OfficeFloorJavaCompiler.MethodWriter
Writes eachMethod
required by implementing interfaces.static interface
OfficeFloorJavaCompiler.MethodWriterContext
Context for theOfficeFloorJavaCompiler.MethodWriterContext
.static interface
OfficeFloorJavaCompiler.NonCompilerOperation<T extends java.lang.Throwable>
Operation undertaken without the Java compiler being available.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_OFFICE_FLOOR_JAVA_COMPILER_IMPLEMENTATION
DefaultOfficeFloorJavaCompiler
implementationClass
name.static java.lang.String
SYSTEM_PROPERTY_JAVA_COMPILING
System
property to indicate if Java compiling active forOfficeFloor
.
-
Constructor Summary
Constructors Constructor Description OfficeFloorJavaCompiler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract OfficeFloorJavaCompiler.JavaSource
addSource(java.lang.String className, java.lang.String source)
OfficeFloorJavaCompiler.JavaSource
addSource(OfficeFloorJavaCompiler.ClassName className, java.lang.String source)
abstract OfficeFloorJavaCompiler.JavaSource
addWrapper(java.lang.Class<?>[] wrappingTypes, java.lang.Class<?> delegateType, java.lang.String delegateExtraction, OfficeFloorJavaCompiler.ConstructorWriter constructorWriter, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter)
Adds a wrapperOfficeFloorJavaCompiler.JavaSource
.OfficeFloorJavaCompiler.JavaSource
addWrapper(java.lang.Class<?> type, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter)
Adds a wrapperOfficeFloorJavaCompiler.JavaSource
.abstract java.util.Map<OfficeFloorJavaCompiler.JavaSource,java.lang.Class<?>>
compile()
Compiles all the addedOfficeFloorJavaCompiler.JavaSource
instances.abstract OfficeFloorJavaCompiler.ClassName
createClassName(java.lang.String name)
Generates a uniqueOfficeFloorJavaCompiler.ClassName
.abstract OfficeFloorJavaCompiler.ClassField
createField(java.lang.Class<?> fieldType, java.lang.String fieldName)
Creates theOfficeFloorJavaCompiler.ClassField
.abstract java.lang.String
getSourceName(java.lang.Class<?> type)
Obtains the source name for theClass
.static OfficeFloorJavaCompiler
newInstance(SourceContext sourceContext)
Creates a new instance of theOfficeFloorJavaCompiler
.static <T extends java.lang.Throwable>
voidrunWithImplementation(java.lang.String officeFloorJavaCompilerImplementationClassName, OfficeFloorJavaCompiler.ImplementationRunnable<T> runnable)
Runs with a particularOfficeFloorJavaCompiler
implementation.static <T extends java.lang.Throwable>
voidrunWithoutCompiler(OfficeFloorJavaCompiler.NonCompilerOperation<T> operation)
Undertakes theOfficeFloorJavaCompiler.NonCompilerOperation
without making the Java compiler available.abstract void
writeConstructor(java.lang.Appendable appendable, java.lang.String className, OfficeFloorJavaCompiler.ClassField... fields)
Writes theConstructor
.abstract void
writeDelegateMethodCall(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method)
Writes the delegateMethod
call.abstract void
writeMethodImplementation(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method)
Writes theMethod
implementation by invoking the delegate.abstract boolean
writeMethodSignature(java.lang.Appendable appendable, java.lang.reflect.Method method)
Writes theMethod
signature to theAppendable
.
-
-
-
Field Detail
-
SYSTEM_PROPERTY_JAVA_COMPILING
public static final java.lang.String SYSTEM_PROPERTY_JAVA_COMPILING
System
property to indicate if Java compiling active forOfficeFloor
.- See Also:
- Constant Field Values
-
DEFAULT_OFFICE_FLOOR_JAVA_COMPILER_IMPLEMENTATION
public static final java.lang.String DEFAULT_OFFICE_FLOOR_JAVA_COMPILER_IMPLEMENTATION
DefaultOfficeFloorJavaCompiler
implementationClass
name.- See Also:
- Constant Field Values
-
-
Method Detail
-
runWithImplementation
public static <T extends java.lang.Throwable> void runWithImplementation(java.lang.String officeFloorJavaCompilerImplementationClassName, OfficeFloorJavaCompiler.ImplementationRunnable<T> runnable) throws T extends java.lang.Throwable
Runs with a particularOfficeFloorJavaCompiler
implementation.- Parameters:
officeFloorJavaCompilerImplementationClassName
-Class
name of theOfficeFloorJavaCompiler
implementation.runnable
-OfficeFloorJavaCompiler.ImplementationRunnable
.- Throws:
T
- PossibleThrowable
fromOfficeFloorJavaCompiler.ImplementationRunnable
.T extends java.lang.Throwable
-
newInstance
public static OfficeFloorJavaCompiler newInstance(SourceContext sourceContext)
Creates a new instance of theOfficeFloorJavaCompiler
.- Parameters:
sourceContext
-SourceContext
.- Returns:
OfficeFloorJavaCompiler
ornull
if Java compiling not available.
-
runWithoutCompiler
public static <T extends java.lang.Throwable> void runWithoutCompiler(OfficeFloorJavaCompiler.NonCompilerOperation<T> operation) throws T extends java.lang.Throwable
Undertakes the
OfficeFloorJavaCompiler.NonCompilerOperation
without making the Java compiler available.This is useful for testing non Java compile solutions.
- Type Parameters:
T
- PossibleThrowable
type.- Parameters:
operation
-OfficeFloorJavaCompiler.NonCompilerOperation
.- Throws:
T
- Possible failure.T extends java.lang.Throwable
-
createClassName
public abstract OfficeFloorJavaCompiler.ClassName createClassName(java.lang.String name)
Generates a uniqueOfficeFloorJavaCompiler.ClassName
.- Parameters:
name
- Seed name.- Returns:
OfficeFloorJavaCompiler.ClassName
.
-
getSourceName
public abstract java.lang.String getSourceName(java.lang.Class<?> type)
Obtains the source name for theClass
.- Parameters:
type
-Class
.- Returns:
- Name used in source to reference the type.
-
createField
public abstract OfficeFloorJavaCompiler.ClassField createField(java.lang.Class<?> fieldType, java.lang.String fieldName)
Creates theOfficeFloorJavaCompiler.ClassField
.- Parameters:
fieldType
-Field
type.fieldName
-Field
name.- Returns:
OfficeFloorJavaCompiler.ClassField
.
-
writeConstructor
public abstract void writeConstructor(java.lang.Appendable appendable, java.lang.String className, OfficeFloorJavaCompiler.ClassField... fields) throws java.io.IOException
Writes theConstructor
.- Parameters:
appendable
-Appendable
.className
- Simple name of theClass
.fields
-OfficeFloorJavaCompiler.ClassField
instances.- Throws:
java.io.IOException
- If fails to write theConstructor
.
-
writeMethodSignature
public abstract boolean writeMethodSignature(java.lang.Appendable appendable, java.lang.reflect.Method method) throws java.io.IOException
Writes theMethod
signature to theAppendable
.- Parameters:
appendable
-Appendable
.method
-Method
.- Returns:
true
if returns a value (false
forvoid
Method
return).- Throws:
java.io.IOException
- If fails to write theMethod
signature.
-
writeDelegateMethodCall
public abstract void writeDelegateMethodCall(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method) throws java.io.IOException
Writes the delegateMethod
call.- Parameters:
source
-Appendable
.delegate
- Means to access delegate.method
-Method
.- Throws:
java.io.IOException
- If fails write delegateMethod
call.
-
writeMethodImplementation
public abstract void writeMethodImplementation(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method) throws java.io.IOException
Writes theMethod
implementation by invoking the delegate.- Parameters:
source
-Appendable
.delegate
- Means to access delegate.method
-Method
.- Throws:
java.io.IOException
- If fails write delegateMethod
implementation.
-
addSource
public OfficeFloorJavaCompiler.JavaSource addSource(OfficeFloorJavaCompiler.ClassName className, java.lang.String source)
- Parameters:
className
-OfficeFloorJavaCompiler.ClassName
.source
- Source for theClass
.- Returns:
OfficeFloorJavaCompiler.JavaSource
.
-
addSource
public abstract OfficeFloorJavaCompiler.JavaSource addSource(java.lang.String className, java.lang.String source)
- Parameters:
className
-Class
name.source
- Source for theClass
.- Returns:
OfficeFloorJavaCompiler.JavaSource
.
-
addWrapper
public OfficeFloorJavaCompiler.JavaSource addWrapper(java.lang.Class<?> type, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) throws java.io.IOException
Adds a wrapperOfficeFloorJavaCompiler.JavaSource
.- Parameters:
type
- Type being wrapped.methodWriter
-OfficeFloorJavaCompiler.MethodWriter
. May benull
to use default implementation.additionalSourceWriter
-OfficeFloorJavaCompiler.JavaSourceWriter
instances.- Returns:
OfficeFloorJavaCompiler.JavaSource
for the wrapper.- Throws:
java.io.IOException
- If fails to write the wrapper.
-
addWrapper
public abstract OfficeFloorJavaCompiler.JavaSource addWrapper(java.lang.Class<?>[] wrappingTypes, java.lang.Class<?> delegateType, java.lang.String delegateExtraction, OfficeFloorJavaCompiler.ConstructorWriter constructorWriter, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) throws java.io.IOException
Adds a wrapperOfficeFloorJavaCompiler.JavaSource
.- Parameters:
wrappingTypes
- Wrapping types.delegateType
- Delegate type.delegateExtraction
- Means to extract the wrapped implementation from the delegate. May benull
to use default.constructorWriter
-OfficeFloorJavaCompiler.ConstructorWriter
. May benull
to use defaultConstructor
.methodWriter
-OfficeFloorJavaCompiler.MethodWriter
. May benull
to use default implementation.additionalSourceWriter
-OfficeFloorJavaCompiler.JavaSourceWriter
instances.- Returns:
OfficeFloorJavaCompiler.JavaSource
for the wrapper.- Throws:
java.io.IOException
- If fails to write the wrapper.
-
compile
public abstract java.util.Map<OfficeFloorJavaCompiler.JavaSource,java.lang.Class<?>> compile()
Compiles all the addedOfficeFloorJavaCompiler.JavaSource
instances.- Returns:
Map
ofOfficeFloorJavaCompiler.JavaSource
to itsClass
.
-
-