Class JavaSource

java.lang.Object
com.iizigo.java.JavaSource
Direct Known Subclasses:
ParsedJavaSource

public class JavaSource extends Object
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
  • Field Details Link icon

    • NOT_PROCESSED Link icon

      public static final String NOT_PROCESSED
      Special return code for "not processed".
      See Also:
    • sourceFile Link icon

      protected IFile sourceFile
      The file for ".java" SOURCE file, null if unresolved or binary.
  • Constructor Details Link icon

    • JavaSource Link icon

      protected JavaSource(JavaSource.Type type)
      Creates a Java source instance for BINARY.
    • JavaSource Link icon

      protected JavaSource(IFile sourceFile, ModuleModel model)
      Creates a Java source instance for PARSED.
  • Method Details Link icon

    • getFileName Link icon

      public String getFileName()
      Gets the file name.
    • dispose Link icon

      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 Link icon

      public boolean isDisposed()
      Checks if the instance is disposed of.
    • getJavaClassCount Link icon

      protected int getJavaClassCount()
      Gets the JavaClass count, for assertions.
    • getJavaProject Link icon

      public IJavaProject getJavaProject()
      Gets the Java project when class is UNRESOLVED or PARSED.
      Returns:
      The Java project if possible to retrieve, null otherwise.
    • getSourceFile Link icon

      public IFile getSourceFile()
      Gets the ".java" source file for PARSED.
      Returns:
      The file, null if BINARY or UNRESOLVED.
    • getProject Link icon

      public IProject getProject()
      Attempts to locate the IProject of the Java source file.
      Returns:
      The project, or null if not found.
    • getClass Link icon

      public JavaClass getClass(String className, IType javaType, IClassReferenceListener listener)
      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 Link icon

      public JavaSource.Type getType()
      Gets the file type.
    • onJavaSourceRemoved Link icon

      protected boolean onJavaSourceRemoved(IFile file)
      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 Link icon

      protected void onJavaSourceMoved(IFile newFile, String oldPKG, String newPKG)
      Called when a Java source has been moved or renamed. The getSourceFile() 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 Link icon

      protected void onRefactoringChange(String classFQN, String oldFQN, String newFQN)
      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 Link icon

      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 Link icon

      public void triggerSWTChangeEvent()
      Triggers an SWT changed event to the JavaClass listeners to perform resolve, etc.
    • clearCache Link icon

      protected void clearCache()
      Clears the cache.
    • validateClass Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      protected void getPublicOrStaticClasses(ArrayList<JavaClass> list)
      Gets all the JavaClasses available in all projects that are parsed. Matching classes are public and public static inner classes.