Package net.officefloor.compile.classes
Class OfficeFloorJavaCompiler
java.lang.Object
net.officefloor.compile.classes.OfficeFloorJavaCompiler
- Direct Known Subclasses:
OfficeFloorJavaCompilerImpl
Java compiler to avoid
Proxy implementations.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceClassField.static interfaceClassname.static interfaceWrites theConstructorfor the wrapping implementation.static interfaceContext for theOfficeFloorJavaCompiler.ConstructorWriter.static interfaceRunnableto use with the specifiedOfficeFloorJavaCompilerimplementation.static interfaceJava source.static interfaceContext for theOfficeFloorJavaCompiler.JavaSourceWriter.static interfaceProvides means to including source.static interfaceWrites eachMethodrequired by implementing interfaces.static interfaceContext for theOfficeFloorJavaCompiler.MethodWriterContext.static interfaceOperation undertaken without the Java compiler being available. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefaultOfficeFloorJavaCompilerimplementationClassname.static final StringSystemproperty to indicate if Java compiling active forOfficeFloor. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract OfficeFloorJavaCompiler.JavaSourceaddSource(OfficeFloorJavaCompiler.ClassName className, String source) abstract OfficeFloorJavaCompiler.JavaSourceaddWrapper(Class<?>[] wrappingTypes, Class<?> delegateType, String delegateExtraction, OfficeFloorJavaCompiler.ConstructorWriter constructorWriter, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) Adds a wrapperOfficeFloorJavaCompiler.JavaSource.addWrapper(Class<?> type, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) Adds a wrapperOfficeFloorJavaCompiler.JavaSource.abstract Map<OfficeFloorJavaCompiler.JavaSource,Class<?>> compile()Compiles all the addedOfficeFloorJavaCompiler.JavaSourceinstances.abstract OfficeFloorJavaCompiler.ClassNamecreateClassName(String name) Generates a uniqueOfficeFloorJavaCompiler.ClassName.abstract OfficeFloorJavaCompiler.ClassFieldcreateField(Class<?> fieldType, String fieldName) Creates theOfficeFloorJavaCompiler.ClassField.abstract StringgetSourceName(Class<?> type) Obtains the source name for theClass.static OfficeFloorJavaCompilernewInstance(SourceContext sourceContext) Creates a new instance of theOfficeFloorJavaCompiler.static <T extends Throwable>
voidrunWithImplementation(String officeFloorJavaCompilerImplementationClassName, OfficeFloorJavaCompiler.ImplementationRunnable<T> runnable) Runs with a particularOfficeFloorJavaCompilerimplementation.static <T extends Throwable>
voidUndertakes theOfficeFloorJavaCompiler.NonCompilerOperationwithout making the Java compiler available.abstract voidwriteConstructor(Appendable appendable, String className, OfficeFloorJavaCompiler.ClassField... fields) Writes theConstructor.abstract voidwriteDelegateMethodCall(Appendable source, String delegate, Method method) Writes the delegateMethodcall.abstract voidwriteMethodImplementation(Appendable source, String delegate, Method method) Writes theMethodimplementation by invoking the delegate.abstract booleanwriteMethodSignature(Appendable appendable, Method method) Writes theMethodsignature to theAppendable.
-
Field Details
-
SYSTEM_PROPERTY_JAVA_COMPILING
Systemproperty to indicate if Java compiling active forOfficeFloor.- See Also:
-
DEFAULT_OFFICE_FLOOR_JAVA_COMPILER_IMPLEMENTATION
DefaultOfficeFloorJavaCompilerimplementationClassname.- See Also:
-
-
Constructor Details
-
OfficeFloorJavaCompiler
public OfficeFloorJavaCompiler()
-
-
Method Details
-
runWithImplementation
public static <T extends Throwable> void runWithImplementation(String officeFloorJavaCompilerImplementationClassName, OfficeFloorJavaCompiler.ImplementationRunnable<T> runnable) throws T Runs with a particularOfficeFloorJavaCompilerimplementation.- Type Parameters:
T- Throwable type.- Parameters:
officeFloorJavaCompilerImplementationClassName-Classname of theOfficeFloorJavaCompilerimplementation.runnable-OfficeFloorJavaCompiler.ImplementationRunnable.- Throws:
T- PossibleThrowablefromOfficeFloorJavaCompiler.ImplementationRunnable.
-
newInstance
Creates a new instance of theOfficeFloorJavaCompiler.- Parameters:
sourceContext-SourceContext.- Returns:
OfficeFloorJavaCompilerornullif Java compiling not available.
-
runWithoutCompiler
public static <T extends Throwable> void runWithoutCompiler(OfficeFloorJavaCompiler.NonCompilerOperation<T> operation) throws T 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.
-
createClassName
Generates a uniqueOfficeFloorJavaCompiler.ClassName.- Parameters:
name- Seed name.- Returns:
OfficeFloorJavaCompiler.ClassName.
-
getSourceName
Obtains the source name for theClass.- Parameters:
type-Class.- Returns:
- Name used in source to reference the type.
-
createField
public abstract OfficeFloorJavaCompiler.ClassField createField(Class<?> fieldType, String fieldName) Creates theOfficeFloorJavaCompiler.ClassField.- Parameters:
fieldType-Fieldtype.fieldName-Fieldname.- Returns:
OfficeFloorJavaCompiler.ClassField.
-
writeConstructor
public abstract void writeConstructor(Appendable appendable, String className, OfficeFloorJavaCompiler.ClassField... fields) throws IOException Writes theConstructor.- Parameters:
appendable-Appendable.className- Simple name of theClass.fields-OfficeFloorJavaCompiler.ClassFieldinstances.- Throws:
IOException- If fails to write theConstructor.
-
writeMethodSignature
public abstract boolean writeMethodSignature(Appendable appendable, Method method) throws IOException Writes theMethodsignature to theAppendable.- Parameters:
appendable-Appendable.method-Method.- Returns:
trueif returns a value (falseforvoidMethodreturn).- Throws:
IOException- If fails to write theMethodsignature.
-
writeDelegateMethodCall
public abstract void writeDelegateMethodCall(Appendable source, String delegate, Method method) throws IOException Writes the delegateMethodcall.- Parameters:
source-Appendable.delegate- Means to access delegate.method-Method.- Throws:
IOException- If fails write delegateMethodcall.
-
writeMethodImplementation
public abstract void writeMethodImplementation(Appendable source, String delegate, Method method) throws IOException Writes theMethodimplementation by invoking the delegate.- Parameters:
source-Appendable.delegate- Means to access delegate.method-Method.- Throws:
IOException- If fails write delegateMethodimplementation.
-
addSource
public OfficeFloorJavaCompiler.JavaSource addSource(OfficeFloorJavaCompiler.ClassName className, String source) - Parameters:
className-OfficeFloorJavaCompiler.ClassName.source- Source for theClass.- Returns:
OfficeFloorJavaCompiler.JavaSource.
-
addSource
- Parameters:
className-Classname.source- Source for theClass.- Returns:
OfficeFloorJavaCompiler.JavaSource.
-
addWrapper
public OfficeFloorJavaCompiler.JavaSource addWrapper(Class<?> type, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) throws 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:
IOException- If fails to write the wrapper.
-
addWrapper
public abstract OfficeFloorJavaCompiler.JavaSource addWrapper(Class<?>[] wrappingTypes, Class<?> delegateType, String delegateExtraction, OfficeFloorJavaCompiler.ConstructorWriter constructorWriter, OfficeFloorJavaCompiler.MethodWriter methodWriter, OfficeFloorJavaCompiler.JavaSourceWriter... additionalSourceWriter) throws 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:
IOException- If fails to write the wrapper.
-
compile
Compiles all the addedOfficeFloorJavaCompiler.JavaSourceinstances.- Returns:
MapofOfficeFloorJavaCompiler.JavaSourceto itsClass.
-