Package com.google.gwt.inject.rebind.util

Examples of com.google.gwt.inject.rebind.util.NameGenerator


  }

  private void outputInterfaceMethods(GinjectorBindings bindings, TypeLiteral<?> ginjectorInterface,
      SourceWriteUtil sourceWriteUtil, SourceWriter writer)
      throws NoSourceNameException, UnableToCompleteException {
    NameGenerator nameGenerator = bindings.getNameGenerator();

    // Implement a provider method for each zero-arg method in the ginjector
    // interface.
    for (MethodLiteral<?, Method> method :
        constructorInjectCollector.getMethods(ginjectorInterface)) {

      Key<?> methodKey = guiceUtil.getKey(method);
      Binding binding = bindings.getBinding(methodKey);
      if (binding == null) {
        // This should not happen, but fail with a meaningful message if it
        // does.
        logger.log(TreeLogger.Type.ERROR, "Unable to find a binding for the required key "
            + methodKey);
        throw new UnableToCompleteException();
      }

      if (!reachabilityAnalyzer.isReachable(binding)) {
        // Sanity-check reachability: every binding in the Ginjector ought to be
        // reachable.
        PrettyPrinter.log(logger, TreeLogger.Type.ERROR,
            "The key %s is required by the Ginjector, but is not reachable.", methodKey);
        throw new UnableToCompleteException();
      }

      FragmentPackageName fragmentPackageName = fragmentPackageNameFactory.create(
          binding.getGetterMethodPackage());

      String body = String.format("return %s.%s().%s();",
          ginjectorNameGenerator.getFieldName(bindings),
          nameGenerator.getFragmentGetterMethodName(fragmentPackageName),
          nameGenerator.getGetterMethodName(guiceUtil.getKey(method)));

      String readableDeclaration = ReflectUtil.signatureBuilder(method)
          .removeAbstractModifier()
          .build();
      sourceWriteUtil.writeMethod(writer, readableDeclaration, body.toString());
    }

    // Implements methods of the form "void foo(BarType bar)", which run member
    // injection on the given BarType.
    for (MethodLiteral<?, Method> method : memberInjectCollector.getMethods(ginjectorInterface)) {
      Key<?> injectee = guiceUtil.getKey(method);

      if (!reachabilityAnalyzer.isReachableMemberInject(bindings, injectee.getTypeLiteral())) {
        // Sanity-check reachability: every member injection in the Ginjector
        // ought to be reachable.
        PrettyPrinter.log(logger, TreeLogger.Type.ERROR,
            "Method injection of %s is required by the Ginjector, but is not reachable.",
            injectee.getTypeLiteral());
        throw new UnableToCompleteException();
      }

      FragmentPackageName fragmentPackageName = fragmentPackageNameFactory.create(
          ReflectUtil.getUserPackageName(injectee.getTypeLiteral()));

      String body = String.format("%s.%s().%s(param);",
          ginjectorNameGenerator.getFieldName(bindings),
          nameGenerator.getFragmentGetterMethodName(fragmentPackageName),
          nameGenerator.getMemberInjectMethodName(injectee.getTypeLiteral()));

      String readableDeclaration = ReflectUtil.signatureBuilder(method)
          .withParameterNames(new String[]{"param"})
          .removeAbstractModifier()
          .build();
View Full Code Here


   * getters are used by each fragment of the injector to retrieve objects
   * created by other fragments.
   */
  private void outputBindings(GinjectorBindings bindings, FragmentMap fragments,
      SourceWriter writer) {
    NameGenerator nameGenerator = bindings.getNameGenerator();

    // The initialize*() methods contain code that needs to run before the root
    // injector is returned to the client, but after the injector hierarchy is
    // fully constructed.

    // Collects the text of the body of initializeEagerSingletons().
    StringBuilder initializeEagerSingletonsBody = new StringBuilder();

    // Collects the text of the body of initializeStaticInjections().
    StringBuilder initializeStaticInjectionsBody = new StringBuilder();

    SourceWriteUtil sourceWriteUtil = sourceWriteUtilFactory.create(bindings);

    // Output child modules.
    for (GinjectorBindings child : bindings.getChildren()) {
      String className = ginjectorNameGenerator.getClassName(child);
      String canonicalClassName = ginjectorNameGenerator.getCanonicalClassName(child);
      String fieldName = ginjectorNameGenerator.getFieldName(child);
      String getterName = nameGenerator.getChildInjectorGetterMethodName(className);

      writer.beginJavaDocComment();
      writer.print("Child injector for %s", child.getModule());
      writer.endJavaDocComment();
      writer.println("private %s %s = null;", canonicalClassName, fieldName);
View Full Code Here

      // binding for the injector).
      errorManager.logError("Injector interface not bound in the root module.");
      return;
    }

    NameGenerator nameGenerator = bindings.getNameGenerator();
    String fieldName = nameGenerator.getGinjectorInterfaceFieldName();
    String getterName = nameGenerator.getGinjectorInterfaceGetterMethodName();

    writer.beginJavaDocComment();
    writer.print("The implementation of " + boundGinjectorInterface);
    writer.endJavaDocComment();
    writer.println("private final %s %s;", boundGinjectorInterface.getCanonicalName(), fieldName);
View Full Code Here

  private void outputFragments(GinjectorBindings bindings,
      FragmentMap fragments, StringBuilder initializeEagerSingletonsBody,
      StringBuilder initializeStaticInjectionsBody, SourceWriteUtil sourceWriteUtil,
      SourceWriter writer) {
    String implClassName = ginjectorNameGenerator.getClassName(bindings);
    NameGenerator nameGenerator = bindings.getNameGenerator();

    for (FragmentPackageName fragmentPackageName : fragments.getFragmentPackages()) {
      String fragmentCanonicalClassName =
          nameGenerator.getFragmentCanonicalClassName(implClassName,
              fragmentPackageName);
      String fieldName = nameGenerator.getFragmentFieldName(fragmentPackageName);
      String getterName = nameGenerator.getFragmentGetterMethodName(fragmentPackageName);

      // Create the field.
      writer.beginJavaDocComment();
      writer.print("Injector fragment for %s", fragmentPackageName);
      writer.endJavaDocComment();
View Full Code Here

  /**
   * Adds member injections to each fragment.
   */
  private void outputMemberInjections(GinjectorBindings bindings, FragmentMap fragments,
      SourceWriteUtil sourceWriteUtil) {
    NameGenerator nameGenerator = bindings.getNameGenerator();
    for (TypeLiteral<?> type : bindings.getMemberInjectRequests()) {
      if (!reachabilityAnalyzer.isReachableMemberInject(bindings, type)) {
        continue;
      }

View Full Code Here

      return "null /* No binding found */";
    }
    FragmentPackageName childKeyPackageName =
        fragmentPackageNameFactory.create(childKeyBinding.getGetterMethodPackage());

    NameGenerator nameGenerator = bindings.getNameGenerator();
    NameGenerator childNameGenerator = childBindings.getNameGenerator();

    String childInjectorClassName = ginjectorNameGenerator.getClassName(childBindings);
    String childGetter = nameGenerator.getChildInjectorGetterMethodName(childInjectorClassName);
    String fragmentGetter = childNameGenerator.getFragmentGetterMethodName(childKeyPackageName);
    String getter = childNameGenerator.getGetterMethodName(key);

    return String.format("injector.%s().%s().%s()", childGetter, fragmentGetter, getter);
  }
View Full Code Here

    return String.format("injector.%s().%s().%s()", childGetter, fragmentGetter, getter);
  }

  public String callMethod(String methodName, String methodFragmentPackage,
      Iterable<String> parameters) {
    NameGenerator nameGenerator = bindings.getNameGenerator();
    StringBuilder resultBuilder = new StringBuilder();

    FragmentPackageName methodFragmentPackageName =
        fragmentPackageNameFactory.create(methodFragmentPackage);

    if (!methodFragmentPackageName.equals(fragmentPackageName)) {
      String fragmentGetter = nameGenerator.getFragmentGetterMethodName(methodFragmentPackageName);
      resultBuilder.append("injector.").append(fragmentGetter).append("().");
    }

    return resultBuilder.append(methodName).append("(")
        .append(SourceWriteUtil.join(", ", parameters)).append(")").toString();
View Full Code Here

      errorManager.logError(
          "Internal Gin error: %s is not a parent of %s.", parentBindings, bindings);
      return "null /* Internal error: unreachable parent bindings */";
    }

    NameGenerator parentNameGenerator = parentBindings.getNameGenerator();
    String fragmentGetter = parentNameGenerator.getFragmentGetterMethodName(parentKeyPackageName);
    String getter = parentNameGenerator.getGetterMethodName(key);

    return result.append(String.format(".%s().%s()", fragmentGetter, getter)).toString();
  }
View Full Code Here

    Capture<FieldLiteral<SuperClass>> fieldCapture = new Capture<FieldLiteral<SuperClass>>();
    Capture<MethodLiteral<SuperClass, Method>> methodCapture =
        new Capture<MethodLiteral<SuperClass, Method>>();

    NameGenerator nameGenerator = createMock(NameGenerator.class, "nameGenerator");
    expect(nameGenerator
        .convertToValidMemberName(
            "injectStatic_com.google.gwt.inject.rebind.output."
            + "GinjectorBindingsOutputterTest$SubClass"))
        .andStubReturn("test_injectSubClass");
    expect(nameGenerator
        .convertToValidMemberName(
            "injectStatic_com.google.gwt.inject.rebind.output.subpackage."
            + "SubPackageClass"))
        .andStubReturn("test_injectSubPackageClass");
View Full Code Here

TOP

Related Classes of com.google.gwt.inject.rebind.util.NameGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.