Package com.google.gwt.core.ext.typeinfo

Examples of com.google.gwt.core.ext.typeinfo.TypeOracle


  public String generate(TreeLogger logger, GeneratorContext ctx,
      String requestedClass) throws UnableToCompleteException {

    findBaseTypes(ctx);

    TypeOracle oracle = ctx.getTypeOracle();

    // Find the requested class
    JClassType proxyInterface = oracle.findType(requestedClass);

    if (proxyInterface == null) {
      logger.log(TreeLogger.ERROR, "Unable to find metadata for type '"
          + requestedClass + "'", null);

      throw new UnableToCompleteException();
    }

    // If it's not an interface it's a custom user-made proxy class. Don't use
    // generator.
    if (proxyInterface.isInterface() == null) {
      return null;
    }

    ProxyStandard proxyStandardAnnotation = proxyInterface.getAnnotation(ProxyStandard.class);
    ProxyCodeSplit proxyCodeSplitAnnotation = proxyInterface.getAnnotation(ProxyCodeSplit.class);
    ProxyCodeSplitBundle proxyCodeSplitBundleAnnotation = proxyInterface.getAnnotation(ProxyCodeSplitBundle.class);

    int nbNonNullTags = 0;
    if (proxyStandardAnnotation != null) {
      nbNonNullTags++;
    }
    if (proxyCodeSplitAnnotation != null) {
      nbNonNullTags++;
    }
    if (proxyCodeSplitBundleAnnotation != null) {
      nbNonNullTags++;
    }

    // If there is no proxy tag, don't use generator.
    if (nbNonNullTags == 0) {
      return null;
    }

    // Make sure this proxy lies within a presenter
    JClassType presenterClass = proxyInterface.getEnclosingType();
    if (presenterClass == null
        || !presenterClass.isAssignableTo(basePresenterClass)) {
      logger.log(TreeLogger.ERROR,
          "Proxy must be enclosed in a class derived from '"
              + basePresenterClassName + "'", null);

      throw new UnableToCompleteException();
    }
    String presenterClassName = presenterClass.getName();

    // Watch out for more than one proxy tag
    if (nbNonNullTags > 1) {
      logger.log(TreeLogger.ERROR, "Proxy for '" + presenterClassName
          + "' has more than one @Proxy annotation.", null);
      throw new UnableToCompleteException();
    }

    // Find the package, build the generated class name.
    JPackage interfacePackage = proxyInterface.getPackage();
    String packageName = interfacePackage == null ? ""
        : interfacePackage.getName();
    String implClassName = presenterClassName
        + proxyInterface.getSimpleSourceName() + "Impl";
    String generatedClassName = packageName + "." + implClassName;

    // Create the printWriter
    PrintWriter printWriter = ctx.tryCreate(logger, packageName, implClassName);
    if (printWriter == null) {
      // We've already created it, so nothing to do
      return generatedClassName;
    }

    // Find ginjector
    String ginjectorClassName = null;
    try {
      ginjectorClassName = ctx.getPropertyOracle().getConfigurationProperty(
          "gin.ginjector").getValues().get(0);
    } catch (BadPropertyValueException e) {
      logger.log(TreeLogger.ERROR,
          "The required configuration property 'gin.ginjector' was not found.",
          e);
      throw new UnableToCompleteException();
    }
    JClassType ginjectorClass = oracle.findType(ginjectorClassName);
    if (ginjectorClass == null
        || !ginjectorClass.isAssignableTo(baseGinjectorClass)) {
      logger.log(TreeLogger.ERROR,
          "The configuration property 'gin.ginjector' is '"
              + ginjectorClassName + "' "
              + " which doesn't identify a type inheriting from 'Ginjector'.",
          null);
      throw new UnableToCompleteException();
    }

    // Check if this proxy is also a place.
    String nameToken = null;
    String newPlaceCode = null; // TODO Get rid of this when we remove @PlaceInstance
    String getGatekeeperMethod = null;
    String title = null;
    if (proxyInterface.isAssignableTo(basePlaceClass)) {
      NameToken nameTokenAnnotation = proxyInterface.getAnnotation(NameToken.class);
      if (nameTokenAnnotation == null) {
        logger.log(TreeLogger.ERROR,
            "The proxy for '" + presenterClassName
                + "' is a Place, but is not annotated with @' +"
                + NameToken.class.getSimpleName() + ".", null);
        throw new UnableToCompleteException();
      }
      nameToken = nameTokenAnnotation.value();

      UseGatekeeper gatekeeperAnnotation = proxyInterface.getAnnotation(UseGatekeeper.class);
      if (gatekeeperAnnotation != null) {
        String gatekeeperName = gatekeeperAnnotation.value().getCanonicalName();
        JClassType customGatekeeperClass = oracle.findType(gatekeeperName);
        if (customGatekeeperClass == null) {
          logger.log(TreeLogger.ERROR, "The class '" + gatekeeperName
              + "' provided to @" + UseGatekeeper.class.getSimpleName()
              + " can't be found.", null);
          throw new UnableToCompleteException();
        }
        if (!customGatekeeperClass.isAssignableTo(gatekeeperClass)) {
          logger.log(TreeLogger.ERROR, "The class '" + gatekeeperName
              + "' provided to @" + UseGatekeeper.class.getSimpleName()
              + " does not inherit from '" + gatekeeperClassName + "'.", null);
          throw new UnableToCompleteException();
        }
        // Find the appropriate get method in the Ginjector
        for (JMethod method : ginjectorClass.getMethods()) {
          JClassType returnType = method.getReturnType().isClassOrInterface();
          if (method.getParameters().length == 0 && returnType != null
              && returnType.isAssignableTo(customGatekeeperClass)) {
            getGatekeeperMethod = method.getName();
            break;
          }
        }
        if (getGatekeeperMethod == null) {
          logger.log(TreeLogger.ERROR,
              "The Ginjector '" + ginjectorClassName
                  + "' does not have a get() method returning '"
                  + gatekeeperName + "'. This is required when using @"
                  + UseGatekeeper.class.getSimpleName() + ".", null);
          throw new UnableToCompleteException();
        }
      }
      if (getGatekeeperMethod == null && newPlaceCode == null
          && proxyInterface.getAnnotation(NoGatekeeper.class) == null) {
        // No Gatekeeper specified, see if there is a DefaultGatekeeper defined
        // in the ginjector
        for (JMethod method : ginjectorClass.getMethods()) {
          if (method.getAnnotation(DefaultGatekeeper.class) != null) {
            JClassType returnType = method.getReturnType().isClassOrInterface();
            if (getGatekeeperMethod != null) {
              logger.log(TreeLogger.ERROR, "The Ginjector '"
                  + ginjectorClassName
                  + "' has more than one method annotated with @"
                  + DefaultGatekeeper.class.getSimpleName()
                  + ". This is not allowed.", null);
              throw new UnableToCompleteException();
            }

            if (method.getParameters().length != 0 || returnType == null
                || !returnType.isAssignableTo(gatekeeperClass)) {
              logger.log(
                  TreeLogger.ERROR,
                  "The method '"
                      + method.getName()
                      + "' in the Ginjector '"
                      + ginjectorClassName
                      + "' is annotated with @"
                      + DefaultGatekeeper.class.getSimpleName()
                      + " but has an invalid signature. It must not take any parameter and must return a class derived from '"
                      + gatekeeperClassName + "'.", null);
              throw new UnableToCompleteException();
            }

            getGatekeeperMethod = method.getName();
          }
        }
      }

      Title titleAnnotation = proxyInterface.getAnnotation(Title.class);
      if (titleAnnotation != null) {
        title = titleAnnotation.value();
      }
    }
    TitleFunctionDescription titleFunctionDescription = findTitleFunction(
        logger, presenterClass, presenterClassName, ginjectorClassName,
        ginjectorClass);
    if (titleFunctionDescription != null && title != null) {
      logger.log(TreeLogger.ERROR, "The proxy for '" + presenterClassName
          + "' is annotated with @' +" + Title.class.getSimpleName()
          + " and its presenter has a method annotated with @"
          + TitleFunction.class.getSimpleName() + ". This is not supported.",
          null);
      throw new UnableToCompleteException();
    }

    // Scan the containing class for @ProxyEvent annotated methods
    List<ProxyEventDescription> proxyEvents = findProxyEvents(logger,
        presenterClass, presenterClassName, ginjectorClassName, ginjectorClass);

    // Check if this proxy is also a TabContentProxy.
    JClassType tabContainerClass = null;
    String tabContainerClassName = null;
    Integer tabPriority = null;
    String tabLabel = null;
    TabInfoFunctionDescription tabInfoFunctionDescription = null;
    String tabNameToken = null;
    if (proxyInterface.isAssignableTo(tabContentProxyClass)) {
      TabInfo tabInfoAnnotation = proxyInterface.getAnnotation(TabInfo.class);
      tabInfoFunctionDescription = findTabInfoFunction(
          logger, presenterClass, presenterClassName, ginjectorClassName,
          ginjectorClass);
     
      // Ensure @TabInfo is there exactly once
      if (tabInfoAnnotation != null && tabInfoFunctionDescription != null) {
        logger.log(TreeLogger.ERROR, "Presenter " + presenterClassName
            + " contains both a proxy and a method annotated with @' +"
            + TabInfo.class.getSimpleName() + ". This is illegal.", null);
        throw new UnableToCompleteException();
      }
      if (tabInfoFunctionDescription != null) {
        tabInfoAnnotation = tabInfoFunctionDescription.annotation;
      }     
      if (tabInfoAnnotation == null) {
        logger.log(TreeLogger.ERROR, "The proxy for '" + presenterClassName
            + "' is a TabContentProxy, but is not annotated with @' +"
            + TabInfo.class.getSimpleName()
            + " and its presenter has no method annotated with it either.", null);
        throw new UnableToCompleteException();
      }
     
      // Extract the label if its in TabInfo
      if (tabInfoAnnotation.label().length() > 0) {
        tabLabel = tabInfoAnnotation.label();
      }
      if (tabLabel != null && tabInfoFunctionDescription != null) {
        logger.log(TreeLogger.ERROR, "The @" + TabInfo.class.getSimpleName()
            + " in " + presenterClassName + " defines the 'label' parameter and"
            + " annotates a method, this is not permitted.", null);
        throw new UnableToCompleteException();
      }
      if (tabLabel == null && tabInfoFunctionDescription == null) {
        logger.log(TreeLogger.ERROR, "The @" + TabInfo.class.getSimpleName()
            + " in " + presenterClassName + " does not define the 'label' parameter and"
            + " does not annotate a method, this is not permitted.", null);
        throw new UnableToCompleteException();
      }

      // Extract the label if its in TabInfo (it is a negative integer if not set)
      if (tabInfoAnnotation.priority() >= 0) {
        tabPriority = tabInfoAnnotation.priority();
      }
      if (tabPriority != null &&
          tabInfoFunctionDescription != null && !tabInfoFunctionDescription.returnString) {
        logger.log(TreeLogger.ERROR, "The @" + TabInfo.class.getSimpleName()
            + " in " + presenterClassName + " defines the 'priority' parameter and"
            + " annotates a method returning TabData, this is not permitted.", null);
        throw new UnableToCompleteException();
      }
      if (tabPriority == null &&
          (tabInfoFunctionDescription == null || tabInfoFunctionDescription.returnString)) {
        logger.log(TreeLogger.ERROR, "The @" + TabInfo.class.getSimpleName()
            + " in " + presenterClassName + " does not define the 'priority' parameter and"
            + " does not annotate a method returning TabData, this is not permitted.", null);
        throw new UnableToCompleteException();
      }
     
      // Find the container
      tabContainerClass = oracle.findType(tabInfoAnnotation.container().getCanonicalName());
      if (tabContainerClass == null) {
        logger.log(TreeLogger.ERROR, "The container '"
            + tabInfoAnnotation.container().getCanonicalName()
            + "' in the proxy annotation for '" + presenterClassName
            + "' was not found.", null);
View Full Code Here


   * Make sure all the required base type information is known.
   *
   * @param ctx The generator context.
   */
  private void findBaseTypes(GeneratorContext ctx) {
    TypeOracle oracle = ctx.getTypeOracle();

    // Find the required base types
    stringClass = oracle.findType("java.lang.String");
    basePresenterClass = oracle.findType(basePresenterClassName);
    baseGinjectorClass = oracle.findType(baseGinjectorClassName);
    typeClass = oracle.findType(typeClassName);
    revealContentHandlerClass = oracle.findType(revealContentHandlerClassName);
    requestTabsHandlerClass = oracle.findType(requestTabsHandlerClassName);
    providerClass = oracle.findType(providerClassName).isGenericType();
    asyncProviderClass = oracle.findType(asyncProviderClassName).isGenericType();
    basePlaceClass = oracle.findType(basePlaceClassName);
    tabContentProxyClass = oracle.findType(tabContentProxyClassName);
    gatekeeperClass = oracle.findType(gatekeeperClassName);
    placeRequestClass = oracle.findType(placeRequestClassName);
    gwtEventClass = oracle.findType(gwtEventClassName).isGenericType();
    gwtEventTypeClass = oracle.findType(gwtEventTypeClassName).isGenericType();
    eventHandlerClass = oracle.findType(eventHandlerClassName);
    setPlaceTitleHandlerClass = oracle.findType(setPlaceTitleHandlerClassName);
    tabDataClass = oracle.findType(tabDataClassName);
  }
View Full Code Here

      ProxyCodeSplitBundle proxyCodeSplitBundleAnnotation,
      JClassType ginjectorClass, String ginjectorClassName,
      JClassType presenterClass, String presenterClassName)
      throws UnableToCompleteException {

    TypeOracle oracle = ctx.getTypeOracle();

    // Create presenter provider and sets it in parent class
    if (proxyCodeSplitAnnotation == null
        && proxyCodeSplitBundleAnnotation == null) {
      // StandardProvider

      // Find the appropriate get method in the Ginjector
      String methodName = findGetMethod(providerClass, presenterClass,
          ginjectorClass);

      if (methodName == null) {
        logger.log(TreeLogger.ERROR, "The Ginjector '" + ginjectorClassName
            + "' does not have a get() method returning 'Provider<"
            + presenterClassName + ">'. This is required when using @"
            + ProxyStandard.class.getSimpleName() + ".", null);
        throw new UnableToCompleteException();
      }

      writer.println("presenter = new StandardProvider<" + presenterClassName
          + ">( ginjector." + methodName + "() );");
    } else if (proxyCodeSplitAnnotation != null) {
      // CodeSplitProvider

      // Find the appropriate get method in the Ginjector
      String methodName = findGetMethod(asyncProviderClass, presenterClass,
          ginjectorClass);

      if (methodName == null) {
        logger.log(TreeLogger.ERROR, "The Ginjector '" + ginjectorClassName
            + "' does not have a get() method returning 'AsyncProvider<"
            + presenterClassName + ">'. This is required when using @"
            + ProxyCodeSplit.class.getSimpleName() + ".", null);
        throw new UnableToCompleteException();
      }

      writer.println("presenter = new CodeSplitProvider<" + presenterClassName
          + ">( ginjector." + methodName + "() );");
    } else {
      // CodeSplitBundleProvider

      String bundleClassName = proxyCodeSplitBundleAnnotation.bundleClass().getCanonicalName();
      JClassType bundleClass = oracle.findType(bundleClassName);

      if (bundleClass == null) {
        logger.log(TreeLogger.ERROR,
            "Cannot find the bundle class '" + bundleClassName
                + ", used with @" + ProxyCodeSplitBundle.class.getSimpleName()
View Full Code Here

  public String generate(TreeLogger logger, GeneratorContext context,
      String typeName) throws UnableToCompleteException {
    this.context = context;
    this.logger = logger;

    TypeOracle oracle = context.getTypeOracle();
    JClassType toGenerate = oracle.findType(typeName).isInterface();
    if (toGenerate == null) {
      logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
      throw new UnableToCompleteException();
    }
View Full Code Here

  public String generate(TreeLogger logger, GeneratorContext context,
      String typeName) throws UnableToCompleteException {
    this.context = context;
    this.logger = logger;

    TypeOracle oracle = context.getTypeOracle();
    JClassType toGenerate = oracle.findType(typeName).isInterface();
    if (toGenerate == null) {
      logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
      throw new UnableToCompleteException();
    }

    String packageName = toGenerate.getPackage().getName();
    String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl";
    PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName);
    if (pw == null) {
      return packageName + "." + simpleSourceName;
    }

    model = new EditorModel(logger, toGenerate,
        oracle.findType(getDriverInterfaceType().getName()));

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
        packageName, simpleSourceName);
    factory.setSuperclass(Name.getSourceNameForClass(getDriverSuperclassType())
        + "<" + model.getProxyType().getParameterizedQualifiedSourceName()
View Full Code Here

      die(unexpectedInputTypeMessage(driverType, intf));
    } else if (intf.equals(driverType)) {
      die(mustExtendMessage(driverType));
    }

    TypeOracle oracle = intf.getOracle();
    editorIntf = oracle.findType(Editor.class.getName()).isGenericType();
    assert editorIntf != null : "No Editor type";
    isEditorIntf = oracle.findType(IsEditor.class.getName()).isGenericType();
    assert isEditorIntf != null : "No IsEditor type";
    compositeEditorIntf = oracle.findType(CompositeEditor.class.getName()).isGenericType();
    assert compositeEditorIntf != null : "No CompositeEditor type";

    JClassType[] interfaces = intf.getImplementedInterfaces();
    if (interfaces.length != 1) {
      die(tooManyInterfacesMessage(intf));
View Full Code Here

   * the type oracle, there's no way this test can possibly run. Bail early
   * instead of failing on the client.
   */
  private static JUnitFatalLaunchException checkTestClassInCurrentModule(
      CompilationState compilationState, String moduleName, TestCase testCase) {
    TypeOracle typeOracle = compilationState.getTypeOracle();
    String typeName = testCase.getClass().getName();
    typeName = typeName.replace('$', '.');
    JClassType foundType = typeOracle.findType(typeName);
    if (foundType != null) {
      return null;
    }
    Map<String, CompilationUnit> unitMap = compilationState.getCompilationUnitMap();
    CompilationUnit unit = unitMap.get(typeName);
View Full Code Here

      toReturn.action = action;
    }

    public void setMethod(JMethod method) {
      toReturn.method = method;
      TypeOracle oracle = method.getEnclosingType().getOracle();

      toReturn.isValueType = ModelUtils.isValueType(oracle,
          method.getReturnType());

      if (!toReturn.isValueType) {
        // See if it's a collection or a map
        JClassType returnClass = method.getReturnType().isClassOrInterface();
        JClassType collectionInterface = oracle.findType(Collection.class.getCanonicalName());
        JClassType mapInterface = oracle.findType(Map.class.getCanonicalName());
        if (collectionInterface.isAssignableFrom(returnClass)) {
          JClassType[] parameterizations = ModelUtils.findParameterizationOf(
              collectionInterface, returnClass);
          toReturn.elementType = parameterizations[0];
        } else if (mapInterface.isAssignableFrom(returnClass)) {
View Full Code Here

  public String generate(TreeLogger logger, GeneratorContext context,
      String typeName) throws UnableToCompleteException {
    this.context = context;
    this.logger = logger;

    TypeOracle oracle = context.getTypeOracle();
    JClassType toGenerate = oracle.findType(typeName).isInterface();
    if (toGenerate == null) {
      logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
      throw new UnableToCompleteException();
    }
View Full Code Here

        if (sourceWriter == null) {
            return qualifiedBeanClassName;
        }

        // scanning all types and loading configurations
        TypeOracle typeOracle = context.getTypeOracle();
        TypeScanner scanner = new TypeScanner(easyLogger, context);
        BeanConfigLoader beanConfigLoader = new BeanConfigLoader(typeOracle);
        ValidationConfigLoader validationConfigLoader = new ValidationConfigLoader(typeOracle);

        try {
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.typeinfo.TypeOracle

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.