Package com.iizigo.java
Class JavaSource
java.lang.Object
com.iizigo.java.JavaSource
- Direct Known Subclasses:
ParsedJavaSource
Class handling a Java Source. The Java source in this case is used for Classes only, with optional implemented interfaces. It has listeners attached to it and can have several instances of JavaClass, the smallest implementation of a Java class. In a JavaSource, there is always a main JavaClass.
When ClassReference wants to have a reference to a class that is not found, a JavaSource will be created with a null
file resource.
- Author:
- Christopher Mindus
Nested Class Summary
Field Summary
Constructor Summary
ModifierConstructorDescriptionprotected
JavaSource
(JavaSource.Type type) Creates a Java source instance for BINARY.protected
JavaSource
(IFile sourceFile, ModuleModel model) Creates a Java source instance for PARSED.Method Summary
Modifier and TypeMethodDescriptionprotected void
Clears the cache.protected boolean
dispose()
Disposes of the Java source and all its classes.getClass
(String className, IType javaType, IClassReferenceListener listener) Called to add a new class name or to get an existing one.Gets the file name.protected int
Gets the JavaClass count, for assertions.Gets the Java project when class is UNRESOLVED or PARSED.Attempts to locate the IProject of the Java source file.protected void
Gets all the JavaClasses available in all projects that are parsed.Gets the ".java" source file for PARSED.getType()
Gets the file type.boolean
Checks if the instance is disposed of.protected void
onJavaSourceMoved
(IFile newFile, String oldPKG, String newPKG) Called when a Java source has been moved or renamed.protected boolean
onJavaSourceRemoved
(IFile file) Called when a Java source has been removed.protected void
onRefactoringChange
(String classFQN, String oldFQN, String newFQN) Called from Refactoring Rename for classes or methods.void
When a SOURCE file is touched, e.g.void
Triggers an SWT changed event to the JavaClass listeners to perform resolve, etc.validateClass
(IType type, String implementsInterface, String requiredAnnotation, String annotationParam, String annotationValue) Validates the class for the interface and annotation.protected String
validateClassProcessors
(IType type, String implementsInterface, String requiredAnnotation, String annotationParam, String annotationValue) Validates the class for the interface and annotation.validateMethod
(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.protected MethodLookup
validateMethodProcessors
(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.
Field Details
NOT_PROCESSED
Special return code for "not processed".- See Also:
sourceFile
The file for ".java" SOURCE file, null if unresolved or binary.
Constructor Details
JavaSource
Creates a Java source instance for BINARY.JavaSource
Creates a Java source instance for PARSED.
Method Details
getFileName
Gets the file name.dispose
protected boolean dispose()Disposes of the Java source and all its classes. No call to Java Manager. is done, this call is initiated from there.- Returns:
- true if disposed of, false if already disposed of.
isDisposed
public boolean isDisposed()Checks if the instance is disposed of.getJavaClassCount
protected int getJavaClassCount()Gets the JavaClass count, for assertions.getJavaProject
Gets the Java project when class is UNRESOLVED or PARSED.- Returns:
- The Java project if possible to retrieve, null otherwise.
getSourceFile
Gets the ".java" source file for PARSED.- Returns:
- The file, null if BINARY or UNRESOLVED.
getProject
Attempts to locate the IProject of the Java source file.- Returns:
- The project, or null if not found.
getClass
Called to add a new class name or to get an existing one.- Parameters:
className
- The fully qualified class name.javaType
- The resolved type or null if not resolved.listener
- The listener for the JavaClass.- Returns:
- A new or existing instance of the JavaClass for the type, with a reference listener.
getType
Gets the file type.onJavaSourceRemoved
Called when a Java source has been removed.- Parameters:
file
- The file handle.- Returns:
- true if the file belonged to this class, false otherwise.
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.- Parameters:
newFile
- The new file name.oldPKG
- The old class name of the main class.newPKG
- The new class name of the main class.
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".
resolveClassReferences
public void resolveClassReferences()When a SOURCE file is touched, e.g. changed or added in the workspace, this method attempts to resolve the class references.When a Java file is touched, it's package name will attempt to resolve UNRESOLVED classes.
triggerSWTChangeEvent
public void triggerSWTChangeEvent()Triggers an SWT changed event to the JavaClass listeners to perform resolve, etc.clearCache
protected void clearCache()Clears the cache.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.
validateClassProcessors
protected String validateClassProcessors(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.
validateMethod
public MethodLookup validateMethod(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.- Parameters:
type
- Type containing method.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 method look-up.
validateMethodProcessors
protected MethodLookup validateMethodProcessors(IType type, String method, boolean isStatic, String requiredAnnotation, String annotationParam, String annotationValue, boolean allowAll) Validates the method for the annotation.- Parameters:
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 method look-up or null if not processed.
getPublicOrStaticClasses
Gets all the JavaClasses available in all projects that are parsed. Matching classes are public and public static inner classes.