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.ObjectJava compiler to avoidProxyimplementations.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceOfficeFloorJavaCompiler.ClassFieldClassField.static interfaceOfficeFloorJavaCompiler.ClassNameClassname.static interfaceOfficeFloorJavaCompiler.ConstructorWriterWrites theConstructorfor the wrapping implementation.static interfaceOfficeFloorJavaCompiler.ConstructorWriterContextContext for theOfficeFloorJavaCompiler.ConstructorWriter.static interfaceOfficeFloorJavaCompiler.ImplementationRunnable<T extends java.lang.Throwable>Runnableto use with the specifiedOfficeFloorJavaCompilerimplementation.static interfaceOfficeFloorJavaCompiler.JavaSourceJava source.static interfaceOfficeFloorJavaCompiler.JavaSourceContextContext for theOfficeFloorJavaCompiler.JavaSourceWriter.static interfaceOfficeFloorJavaCompiler.JavaSourceWriterProvides means to including source.static interfaceOfficeFloorJavaCompiler.MethodWriterWrites eachMethodrequired by implementing interfaces.static interfaceOfficeFloorJavaCompiler.MethodWriterContextContext for theOfficeFloorJavaCompiler.MethodWriterContext.static interfaceOfficeFloorJavaCompiler.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.StringDEFAULT_OFFICE_FLOOR_JAVA_COMPILER_IMPLEMENTATIONDefaultOfficeFloorJavaCompilerimplementationClassname.static java.lang.StringSYSTEM_PROPERTY_JAVA_COMPILINGSystemproperty 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.JavaSourceaddSource(java.lang.String className, java.lang.String source)OfficeFloorJavaCompiler.JavaSourceaddSource(OfficeFloorJavaCompiler.ClassName className, java.lang.String source)abstract OfficeFloorJavaCompiler.JavaSourceaddWrapper(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.JavaSourceaddWrapper(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.JavaSourceinstances.abstract OfficeFloorJavaCompiler.ClassNamecreateClassName(java.lang.String name)Generates a uniqueOfficeFloorJavaCompiler.ClassName.abstract OfficeFloorJavaCompiler.ClassFieldcreateField(java.lang.Class<?> fieldType, java.lang.String fieldName)Creates theOfficeFloorJavaCompiler.ClassField.abstract java.lang.StringgetSourceName(java.lang.Class<?> type)Obtains the source name for theClass.static OfficeFloorJavaCompilernewInstance(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 particularOfficeFloorJavaCompilerimplementation.static <T extends java.lang.Throwable>
voidrunWithoutCompiler(OfficeFloorJavaCompiler.NonCompilerOperation<T> operation)Undertakes theOfficeFloorJavaCompiler.NonCompilerOperationwithout making the Java compiler available.abstract voidwriteConstructor(java.lang.Appendable appendable, java.lang.String className, OfficeFloorJavaCompiler.ClassField... fields)Writes theConstructor.abstract voidwriteDelegateMethodCall(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method)Writes the delegateMethodcall.abstract voidwriteMethodImplementation(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method)Writes theMethodimplementation by invoking the delegate.abstract booleanwriteMethodSignature(java.lang.Appendable appendable, java.lang.reflect.Method method)Writes theMethodsignature to theAppendable.
-
-
-
Field Detail
-
SYSTEM_PROPERTY_JAVA_COMPILING
public static final java.lang.String SYSTEM_PROPERTY_JAVA_COMPILING
Systemproperty 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
DefaultOfficeFloorJavaCompilerimplementationClassname.- 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.ThrowableRuns with a particularOfficeFloorJavaCompilerimplementation.- Parameters:
officeFloorJavaCompilerImplementationClassName-Classname of theOfficeFloorJavaCompilerimplementation.runnable-OfficeFloorJavaCompiler.ImplementationRunnable.- Throws:
T- PossibleThrowablefromOfficeFloorJavaCompiler.ImplementationRunnable.T extends java.lang.Throwable
-
newInstance
public static OfficeFloorJavaCompiler newInstance(SourceContext sourceContext)
Creates a new instance of theOfficeFloorJavaCompiler.- Parameters:
sourceContext-SourceContext.- Returns:
OfficeFloorJavaCompilerornullif 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.NonCompilerOperationwithout making the Java compiler available.This is useful for testing non Java compile solutions.
- Type Parameters:
T- PossibleThrowabletype.- 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-Fieldtype.fieldName-Fieldname.- Returns:
OfficeFloorJavaCompiler.ClassField.
-
writeConstructor
public abstract void writeConstructor(java.lang.Appendable appendable, java.lang.String className, OfficeFloorJavaCompiler.ClassField... fields) throws java.io.IOExceptionWrites theConstructor.- Parameters:
appendable-Appendable.className- Simple name of theClass.fields-OfficeFloorJavaCompiler.ClassFieldinstances.- 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.IOExceptionWrites theMethodsignature to theAppendable.- Parameters:
appendable-Appendable.method-Method.- Returns:
trueif returns a value (falseforvoidMethodreturn).- Throws:
java.io.IOException- If fails to write theMethodsignature.
-
writeDelegateMethodCall
public abstract void writeDelegateMethodCall(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method) throws java.io.IOExceptionWrites the delegateMethodcall.- Parameters:
source-Appendable.delegate- Means to access delegate.method-Method.- Throws:
java.io.IOException- If fails write delegateMethodcall.
-
writeMethodImplementation
public abstract void writeMethodImplementation(java.lang.Appendable source, java.lang.String delegate, java.lang.reflect.Method method) throws java.io.IOExceptionWrites theMethodimplementation by invoking the delegate.- Parameters:
source-Appendable.delegate- Means to access delegate.method-Method.- Throws:
java.io.IOException- If fails write delegateMethodimplementation.
-
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-Classname.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 benullto use default implementation.additionalSourceWriter-OfficeFloorJavaCompiler.JavaSourceWriterinstances.- Returns:
OfficeFloorJavaCompiler.JavaSourcefor 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 benullto use default.constructorWriter-OfficeFloorJavaCompiler.ConstructorWriter. May benullto use defaultConstructor.methodWriter-OfficeFloorJavaCompiler.MethodWriter. May benullto use default implementation.additionalSourceWriter-OfficeFloorJavaCompiler.JavaSourceWriterinstances.- Returns:
OfficeFloorJavaCompiler.JavaSourcefor 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.JavaSourceinstances.- Returns:
MapofOfficeFloorJavaCompiler.JavaSourceto itsClass.
-
-