Package com.iizigo.java.parser
Class JavaSourceFileProcessor<PROP extends GProp<?>>
java.lang.Object
com.iizigo.java.parser.JavaSourceFileProcessor<PROP>
- Direct Known Subclasses:
TypeFileProcessor
Abstract class for parsing a Java source file to perform syntax-check and reference validation of Java source code to the IIZI property tree as well as refactoring of the Java source code when properties are changed.
- Author:
- Christopher Mindus
Field Summary
Modifier and TypeFieldDescriptionprotected PROP
The container created from the call tocreatePropertyContainer
or after XML is loaded.protected ParsedJavaSource
The ParsedJavaSource reference, set after call to theinitialize
method, do not use prior to that, it is null.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionabstract PROP
createPropertyContainer
(ParsedJavaSource javaSource) Creates the property container for the data required by the processor when no saved XML is present at load-time.abstract void
dispose()
Called when the Java source is disposed of.protected void
getAvailableMethods
(ArrayList<String> list, IType clazz, String instanceAnnotation, String staticAnnotation) Gets the list of methods that can match the specified annotations.final IJavaSourceParser<PROP>
Returns the Engine instance that created this instance.final void
initialize
(ParsedJavaSource javaSource, GProp<?> container) Framework call to initialize, callsonInitialize
after having saved thejavaSource
andcontainer
parameters in the class members of the same names.final void
internalRestoreContainerClone
(GProp<?> container) Called when a cloned property container has been restored because a Java source file has been edited and then closed without saving.boolean
Checks if this parser needs to refactor something.boolean
Checks if reparsing is required at startup.abstract void
Called when the property container is created, either from a call tocreatePropertyContainer
or has been loaded from XML, in which case it could be initiated for specialized data for the processor, e.g.void
onJavaSourceMoved
(IFile oldFile, IFile newFile, String oldPKG, String newPKG) Called when a Java source has been moved or renamed.void
onJavaSourceRemoved
(IFile file) Called when a Java source has been removed.void
onRefactorCommit
(MultiTextEdit fileChangeRootEdit) Called when the refactoring on each source is to be performed.void
onRefactoringChange
(String classFQN, String oldFQN, String newFQN) Called from Refactoring Rename for classes or methods.void
Called when a cloned property container has been restored because a Java source file has been edited and then closed without saving.void
onRestoredState
(ICompilationUnit icu, IProgressMonitor monitor) Called to inform the processor that saved parser state is used from a previous parse operation.void
parse
(CompilationUnit compilationUnit) Called to parse the Java source at load and when the Java compiler runs, using an AST compilation unit and a flag indicating if the compilation unit contains annotations.void
reconcile
(ReconcileContext context, CompilationUnit cu) Called by the Java compilation participant let the processor handle the reconciled working copy.validateClass
(IType type, String implementsInterface, String requiredAnnotation, String annotationParam, String annotationValue) Validates the class for the interface and annotation.protected MethodLookup
validateMethod
(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.
Field Details
javaSource
The ParsedJavaSource reference, set after call to theinitialize
method, do not use prior to that, it is null.container
The container created from the call tocreatePropertyContainer
or after XML is loaded.
Constructor Details
JavaSourceFileProcessor
Default constructor.
Method Details
dispose
public abstract void dispose()Called when the Java source is disposed of.getEngine
Returns the Engine instance that created this instance.createPropertyContainer
Creates the property container for the data required by the processor when no saved XML is present at load-time. The container should NOT be added to any other property container, it should remain orphan, and it is NOT required to have an Atom name, i.e. it can be unnamed.- Parameters:
javaSource
- The Java source.- Returns:
- The container instance, or null if non is required.
initialize
Framework call to initialize, callsonInitialize
after having saved thejavaSource
andcontainer
parameters in the class members of the same names.- Parameters:
javaSource
- The Java source.container
- The property container created.
onInitialize
public abstract void onInitialize()Called when the property container is created, either from a call tocreatePropertyContainer
or has been loaded from XML, in which case it could be initiated for specialized data for the processor, e.g. setting up instance references to the children properties, reference to the processor itself.onJavaSourceMoved
Called when a Java source has been moved or renamed. ThegetSourceFile()
method in JavaSource is already moved or renamed when this method is called.Subclasses can override this method to perform reference updates.
- Parameters:
oldFile
- The old file name.newFile
- The new file name.oldPKG
- The old package name of the main class.newPKG
- The new package name of the main class.
onJavaSourceRemoved
Called when a Java source has been removed.Subclasses can override this method to perform reference updates.
- Parameters:
file
- The file.
onRefactoringChange
Called from Refactoring Rename for classes or methods. The "FQN" is for classes including packages, and enclosed classes are separated by '.' and not '$'. For methods, it's the name followed by ',' and "returnType(param1,..,paramN)" as JavaHelper.getSignature gives.- Parameters:
classFQN
- The class fully qualified name, null for classes (only for methods).oldFQN
- The old fully qualified name or "oldName,signature".newFQN
- The new fully qualified name or "newName,signature".
isReparseRequired
public boolean isReparseRequired()Checks if reparsing is required at startup.- Returns:
- false by default, override to process and return true as required.
onRestoredState
Called to inform the processor that saved parser state is used from a previous parse operation. This data is available in the property container.Subclasses should override this method to handle the event.
- Parameters:
icu
- The compilation unit.monitor
- Progress monitor.- Throws:
CoreException
- If the parser failed to restore the state.
parse
Called to parse the Java source at load and when the Java compiler runs, using an AST compilation unit and a flag indicating if the compilation unit contains annotations.- Parameters:
compilationUnit
- The compilation unit.- Throws:
CoreException
- For errors with e.g. removing markers.
reconcile
Called by the Java compilation participant let the processor handle the reconciled working copy.- Parameters:
context
- The reconcile context to act on.
internalRestoreContainerClone
Called when a cloned property container has been restored because a Java source file has been edited and then closed without saving. This is done in order to revert the reconciled changes that may apply after the original parsing.onRestoreContainerClone
public void onRestoreContainerClone()Called when a cloned property container has been restored because a Java source file has been edited and then closed without saving. This is done in order to revert the reconciled changes that may apply after the original parsing.isRefactorRequired
public boolean isRefactorRequired()Checks if this parser needs to refactor something.- Returns:
- true to let the framework perform a grouped refactoring when the RefactorCommit event is received and processed by it.
onRefactorCommit
Called when the refactoring on each source is to be performed.When this method is called, refactoring the code for a plain text file using positions would look like:
ReplaceEdit edit=new ReplaceEdit(offset,length,string); fileChangeRootEdit.addChild(edit);
- Parameters:
fileChangeRootEdit
- The root edit of the Java file change.
validateClass
public String validateClass(IType type, String implementsInterface, String requiredAnnotation, String annotationParam, String annotationValue) Validates the class for the interface and annotation.- Parameters:
implementsInterface
- The interface required, or null for none.requiredAnnotation
- The required annotation, or null for none.annotationParam
- Parameter member value pair to verify the value with for back-referencing, null for none.annotationValue
- The value to match for back-referencing, null for none.- Returns:
- null for OK, otherwise an error message, or NOT_PROCESSED.
validateMethod
protected MethodLookup validateMethod(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.- Parameters:
type
- The class.method
- The method name.isStatic
- Method must be static flag.requiredAnnotation
- The required annotation, or null for none.annotationParam
- Parameter member value pair to verify the value with for back-referencing, null for none.annotationValue
- The value to match for back-referencing, null for none.allowAll
- Flag to allow a ref "*" as back-reference.- Returns:
- The IMethod matching for OK, otherwise a String error message, or NOT_PROCESSED.
getAvailableMethods
protected void getAvailableMethods(ArrayList<String> list, IType clazz, String instanceAnnotation, String staticAnnotation) Gets the list of methods that can match the specified annotations.- Parameters:
list
- List filled in with info upon return.clazz
- The class to search in for theinstanceAnnotation
.instanceAnnotation
- The instance annotation to search the class for, null for none.staticAnnotation
- Static annotation to search classes for static methods.