Пример #1
0
  public ComponentDescriptor analyze(ASTType astType) {
    Application applicationAnnotation = astType.getAnnotation(Application.class);

    PackageClass inputType = astType.getPackageClass();
    PackageClass applicationClassName;

    if (StringUtils.isBlank(applicationAnnotation.name())) {
      applicationClassName = inputType.append("Application");
    } else {
      applicationClassName = inputType.replaceName(applicationAnnotation.name());
    }

    ComponentDescriptor applicationDescriptor =
        new ComponentDescriptor(android.app.Application.class.getName(), applicationClassName);

    // analyze delegate
    AnalysisContext analysisContext =
        analysisContextFactory.buildAnalysisContext(buildVariableBuilderMap());

    // application generation profile
    setupApplicationProfile(applicationDescriptor, astType, analysisContext);

    // add manifest elements
    setupManifest(
        applicationAnnotation,
        applicationDescriptor.getPackageClass().getFullyQualifiedName(),
        applicationAnnotation.label());

    return applicationDescriptor;
  }
Пример #2
0
  private void setupApplicationProfile(
      ComponentDescriptor applicationDescriptor, ASTType astType, AnalysisContext context) {

    ASTMethod onCreateASTMethod = getASTMethod("onCreate");
    // onCreate
    applicationDescriptor.setInitMethodBuilder(
        OnCreate.class,
        componentBuilderFactory.buildOnCreateMethodBuilder(
            onCreateASTMethod, new NoOpLayoutBuilder()));

    applicationDescriptor.setInjectionNodeFactory(
        componentBuilderFactory.buildInjectionNodeFactory(astType, context));

    // onLowMemory
    applicationDescriptor.addGenerators(buildEventMethod(OnLowMemory.class, "onLowMemory"));
    // onTerminate
    applicationDescriptor.addGenerators(buildEventMethod(OnTerminate.class, "onTerminate"));
    // onConfigurationChanged
    ASTMethod onConfigurationChangedASTMethod =
        getASTMethod("onConfigurationChanged", Configuration.class);
    applicationDescriptor.addGenerators(
        componentBuilderFactory.buildMethodCallbackGenerator(
            OnConfigurationChanged.class,
            componentBuilderFactory.buildMirroredMethodGenerator(
                onConfigurationChangedASTMethod, true)));

    applicationDescriptor.addGenerators(contextScopeComponentBuilder);

    applicationDescriptor.addRegistration(observesExpressionDecorator);
  }