Class GeneratorUtils


  • public class GeneratorUtils
    extends Object
    Utilities for code generation
    • Constructor Detail

      • GeneratorUtils

        public GeneratorUtils()
    • Method Detail

      • getOnStartupMethodForNonEditors

        public static ExecutableElement getOnStartupMethodForNonEditors​(TypeElement classElement,
                                                                        ProcessingEnvironment processingEnvironment)
        Finds the @OnStartup method suitable for workbench classes that are not @WorkbenchEditor. The method must be public, non-static, have a return-type of void and either take zero parameters or one parameter of type PlaceRequest.

        If no such method is found, returns null. If methods annotated with @OnStartup are found but they do not satisfy all the requirements, they are marked with errors explaining the problem.

      • getOnStartupMethodForEditors

        public static ExecutableElement getOnStartupMethodForEditors​(TypeElement classElement,
                                                                     ProcessingEnvironment processingEnvironment)
        Finds the @OnStartup method suitable for @WorkbenchEditor classes. The method must be public, non-static, have a return-type of void and either take one parameter of type Path or two parameters of type (Path, PlaceRequest).

        If no such method is found, returns null. If methods annotated with @OnStartup are found but they do not satisfy all the requirements, they are marked with errors explaining the problem.

      • getOnMayCloseMethodName

        public static String getOnMayCloseMethodName​(TypeElement classElement,
                                                     ProcessingEnvironment processingEnvironment)
                                              throws GenerationException
        Get the method name annotated with @OnMayClose. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnCloseMethodName

        public static String getOnCloseMethodName​(TypeElement classElement,
                                                  ProcessingEnvironment processingEnvironment)
                                           throws GenerationException
        Get the method name annotated with @OnClose. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnShutdownMethodName

        public static String getOnShutdownMethodName​(TypeElement classElement,
                                                     ProcessingEnvironment processingEnvironment)
                                              throws GenerationException
        Get the method name annotated with @OnShutdown. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnOpenMethodName

        public static String getOnOpenMethodName​(TypeElement classElement,
                                                 ProcessingEnvironment processingEnvironment)
                                          throws GenerationException
        Get the method name annotated with @OnOpen. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnLostFocusMethodName

        public static String getOnLostFocusMethodName​(TypeElement classElement,
                                                      ProcessingEnvironment processingEnvironment)
                                               throws GenerationException
        Get the method name annotated with @OnLostFocus. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnFocusMethodName

        public static String getOnFocusMethodName​(TypeElement classElement,
                                                  ProcessingEnvironment processingEnvironment)
                                           throws GenerationException
        Get the method name annotated with @OnFocus. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getDefaultPositionMethodName

        public static String getDefaultPositionMethodName​(TypeElement classElement,
                                                          ProcessingEnvironment processingEnvironment)
                                                   throws GenerationException
        Get the method name annotated with @DefaultPosition. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getTitleMethodName

        public static String getTitleMethodName​(TypeElement classElement,
                                                ProcessingEnvironment processingEnvironment)
                                         throws GenerationException
        Get the method name annotated with @WorkbenchPartTitle. The method must be public, non-static, have a return-type of java.lang.String and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getTitleWidgetMethodName

        public static ExecutableElement getTitleWidgetMethodName​(TypeElement classElement,
                                                                 ProcessingEnvironment processingEnvironment)
                                                          throws GenerationException
        Get the method name annotated with @WorkbenchPartTitleDecoration. The method must be public, non-static, have a return-type of com.google.gwt.user.client.ui.IsWidget and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getWidgetMethodName

        public static ExecutableElement getWidgetMethodName​(TypeElement classElement,
                                                            ProcessingEnvironment processingEnvironment)
                                                     throws GenerationException
        Get the method name annotated with @WorkbenchPartView. The method must be public, non-static, have a return-type of IsWidget and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getIsWidget

        public static boolean getIsWidget​(TypeElement classElement,
                                          ProcessingEnvironment processingEnvironment)
        Check whether the provided type extends IsWidget.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
      • getIsElement

        public static boolean getIsElement​(TypeMirror type,
                                           ProcessingEnvironment processingEnvironment)
        Check whether the provided type extends IsElement.
        Parameters:
        type -
        processingEnvironment -
        Returns:
      • getPopupMethodName

        public static String getPopupMethodName​(TypeElement classElement,
                                                ProcessingEnvironment processingEnvironment)
                                         throws GenerationException
        Get the method name annotated with @WorkbenchPartView. The method must be public, non-static, have a return-type of PopupPanel and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getIsPopup

        public static boolean getIsPopup​(TypeElement classElement,
                                         ProcessingEnvironment processingEnvironment)
        Check whether the provided type extends PopupPanel.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
      • getIsDirtyMethodName

        public static String getIsDirtyMethodName​(TypeElement classElement,
                                                  ProcessingEnvironment processingEnvironment)
                                           throws GenerationException
        Get the method name annotated with @IsDirty. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOnSaveMethodName

        public static String getOnSaveMethodName​(TypeElement classElement,
                                                 ProcessingEnvironment processingEnvironment)
                                          throws GenerationException
        Get the method name annotated with @OnSave. The method must be public, non-static, have a return-type of void and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getMenuBarMethodName

        public static String getMenuBarMethodName​(TypeElement classElement,
                                                  ProcessingEnvironment processingEnvironment)
                                           throws GenerationException
        Get the method name annotated with @WorkbenchMenu. The method must be public, non-static, have a return-type of WorkbenchMenuBar and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getToolBarMethodName

        public static String getToolBarMethodName​(TypeElement classElement,
                                                  ProcessingEnvironment processingEnvironment)
                                           throws GenerationException
        Get the method name annotated with @WorkbenchToolBar. The method must be public, non-static, have a return-type of WorkbenchToolBar and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getPerspectiveMethodName

        public static String getPerspectiveMethodName​(TypeElement classElement,
                                                      ProcessingEnvironment processingEnvironment)
                                               throws GenerationException
        Get the method name annotated with @Perspective. The method must be public, non-static, have a return-type of PerspectiveDefinition and take zero parameters.
        Parameters:
        classElement -
        processingEnvironment -
        Returns:
        null if none found
        Throws:
        GenerationException
      • getOwningPerspectivePlaceRequest

        public static String getOwningPerspectivePlaceRequest​(TypeElement screenOrEditorClass,
                                                              ProcessingEnvironment processingEnvironment)
                                                       throws GenerationException
        Returns the identifier (PlaceRequest ID) of the perspective that owns the given part.
        Parameters:
        screenOrEditorClass - a type annotated with either @WorkbenchScreen or @WorkbenchEditor. Not null.
        processingEnvironment - the current annotation processing environment.
        Returns:
        Throws:
        GenerationException - if the owningPerspective parameter is present, but points to something other than a @WorkbenchPerspective class.
      • extractValue

        public static Collection<String> extractValue​(AnnotationValue value)
        Provides a uniform way of working with single- and multi-valued AnnotationValue objects.
        Returns:
        the annotation values as strings. For multi-valued annotation params, the collection's iteration order matches the order the values appeared in the source code. Single-valued params are wrapped in a single-element collection. In either case, don't attempt to modify the returned collection.
      • extractAnnotationsFromAnnotation

        public static List<AnnotationMirror> extractAnnotationsFromAnnotation​(Elements elementUtils,
                                                                              Element element,
                                                                              String annotationName,
                                                                              String paramName)
        Pulls nested annotations out of the annotation that contains them.
        Parameters:
        elementUtils - the current Elements object from this round of annotation processing.
        element - The element targeted by the containing annotation.
        annotationName - The containing annotation's fully-qualified name.
        paramName - The name of the parameter on the containing annotation. The parameter's type must be an array of annotations.
      • formatAssociatedResources

        public static String formatAssociatedResources​(Collection<String> resourceTypes)
      • debugLoggingEnabled

        public static boolean debugLoggingEnabled()
      • getAllQualifiersDeclarationFromType

        public static List<String> getAllQualifiersDeclarationFromType​(TypeElement element)
        This method builds a list of all qualifier annotations source-code declaration that annotates the passed element.
        Parameters:
        element - TypeElement which will be scanned for qualifier annotations.
        Returns:
        A list of the annotations source-code declarations.