Examples of JClassType


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

    PrintWriter printWriter = context.tryCreate(logger, packageName, className);
   
    if (printWriter != null) {
     
      try {
        JClassType type = typeOracle.getType(typeName);
        SerialTypes annotation = type.getAnnotation(SerialTypes.class);
        if (annotation == null) {
          logger.log(TreeLogger.ERROR, "No SerialTypes annotation on CometSerializer type: " + typeName);
          throw new UnableToCompleteException();
        }
       
        SerializableTypeOracleBuilder typesSentToBrowserBuilder = new SerializableTypeOracleBuilder(
                        logger, context.getPropertyOracle(), context);
        SerializableTypeOracleBuilder typesSentFromBrowserBuilder = new SerializableTypeOracleBuilder(
                        logger, context.getPropertyOracle(), context);
       
        for (Class<? extends Serializable> serializable : annotation.value()) {
          int rank = 0;
          if (serializable.isArray()) {
            while(serializable.isArray()) {
              serializable = (Class<? extends Serializable>) serializable.getComponentType();
              rank++;
            }
          }
           
          JType resolvedType = typeOracle.getType(serializable.getCanonicalName());
          while (rank > 0) {
            resolvedType = typeOracle.getArrayType(resolvedType);
            rank--;
          }
         
          typesSentToBrowserBuilder.addRootType(logger, resolvedType);
                    typesSentFromBrowserBuilder.addRootType(logger, resolvedType);
        }
       
        // Create a resource file to receive all of the serialization information
        // computed by STOB and mark it as private so it does not end up in the
        // output.
        OutputStream pathInfo = context.tryCreateResource(logger, typeName + ".rpc.log");
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(pathInfo));
        writer.write("====================================\n");
        writer.write("Types potentially sent from server:\n");
        writer.write("====================================\n\n");
        writer.flush();
       
        typesSentToBrowserBuilder.setLogOutputWriter(writer);
        SerializableTypeOracle typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

        writer.write("===================================\n");
        writer.write("Types potentially sent from browser:\n");
        writer.write("===================================\n\n");
        writer.flush();
        typesSentFromBrowserBuilder.setLogOutputWriter(writer);
          SerializableTypeOracle typesSentFromBrowser = typesSentFromBrowserBuilder.build(logger);
       
        writer.close();
       
        if (pathInfo != null) {
          context.commitResource(logger, pathInfo).setPrivate(true);
        }
       
        // Create the serializer
                final String modifiedTypeName = typeName.replace('.', '_');
                TypeSerializerCreator tsc = new TypeSerializerCreator(logger, typesSentFromBrowser, typesSentToBrowser, context, "comet." + modifiedTypeName, modifiedTypeName);
        String realize = tsc.realize(logger);
       
        // Create the CometSerializer impl
        ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);
       
        composerFactory.addImport(Serializer.class.getName());
        composerFactory.addImport(SerialMode.class.getName());
       
        composerFactory.setSuperclass(typeName);
        // TODO is the SERIALIZER required for DE RPC?
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);
        sourceWriter.print("private Serializer SERIALIZER = new " + realize + "();");
        sourceWriter.print("protected Serializer getSerializer() {return SERIALIZER;}");
        sourceWriter.print("public SerialMode getMode() {return SerialMode." + annotation.mode().name() + ";}");
                sourceWriter.print("public SerialMode getPushMode() {return SerialMode." + annotation.pushmode().name() + ";}");
        sourceWriter.commit(logger);
       
        if (annotation.mode() == SerialMode.DE_RPC) {
          RpcDataArtifact data = new RpcDataArtifact(type.getQualifiedSourceName());
          for (JType t : typesSentToBrowser.getSerializableTypes()) {
            if (!(t instanceof JClassType)) {
              continue;
            }
            JField[] serializableFields = SerializationUtils.getSerializableFields(context.getTypeOracle(), (JClassType) t);
View Full Code Here

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

        "List<HandlerRegistration> registrations = new LinkedList<HandlerRegistration>();");
  }

  private void writeHandlerForBindMethod(EventHandler annotation, SourceWriter writer,
      JMethod method, TypeOracle typeOracle) throws UnableToCompleteException {
    JClassType eventParameter = null;
    if (method.getParameterTypes().length == 1) {
      eventParameter = method.getParameterTypes()[0].isClassOrInterface();
    }
    if (annotation.handles().length == 0 && !isAConcreteGenericEvent(eventParameter)) {
      logger.log(Type.ERROR, "Method " + method.getName()
          + " annotated with @EventHandler without event classes must have exactly "
          + "one argument of a concrete type assignable to GenericEvent");
      throw new UnableToCompleteException();
    }

    List<String> eventTypes = new ArrayList<String>();
    if (annotation.handles().length != 0) {
      for (Class<? extends GenericEvent> event : annotation.handles()) {
        String eventTypeName = event.getCanonicalName();
        JClassType eventClassType = typeOracle.findType(eventTypeName);
        if (eventClassType == null) {
          logger.log(Type.ERROR, "Can't resolve " + eventTypeName);
          throw new UnableToCompleteException();
        }
        if (eventParameter != null && !eventClassType.isAssignableTo(eventParameter)) {
          logger.log(Type.ERROR, "Event " + eventTypeName + " isn't assignable to "
              + eventParameter.getName() + " in method: " + method.getName());
          throw new UnableToCompleteException();
        }
        eventTypes.add(eventClassType.getQualifiedSourceName());
      }
    } else {
      eventTypes.add(eventParameter.getQualifiedSourceName());
    }
View Full Code Here

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

  @Override
  public String generate(TreeLogger logger, GeneratorContext context,
      String typeName) throws UnableToCompleteException {
    try {
      JClassType eventBinderType = context.getTypeOracle().getType(typeName);
      JClassType targetType = getTargetType(eventBinderType, context.getTypeOracle());
      SourceWriter writer = createSourceWriter(logger, context, eventBinderType, targetType);
      if (writer != null) { // Otherwise the class was already created
        new EventBinderWriter(
            logger,
            context.getTypeOracle().getType(GenericEvent.class.getCanonicalName()))
View Full Code Here

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

    }
  }

  private JClassType getTargetType(JClassType interfaceType, TypeOracle typeOracle) {
    JClassType[] superTypes = interfaceType.getImplementedInterfaces();
    JClassType eventBinderType = typeOracle.findType(EventBinder.class.getCanonicalName());
    if (superTypes.length != 1
        || !superTypes[0].isAssignableFrom(eventBinderType)
        || superTypes[0].isParameterized() == null) {
      throw new IllegalArgumentException(
          interfaceType + " must extend EventBinder with a type parameter");
View Full Code Here

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

    }

    JClassType[] typeArgs = paramType.getTypeArgs();

    assert typeArgs.length == 1;
    JClassType toReturn = typeArgs[0].isClassOrInterface();
    if (toReturn == null) {
      logger.log(TreeLogger.ERROR,
          "A Gadget's UserPreferences type must be an interface", null);
      throw new UnableToCompleteException();
    }
View Full Code Here

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

    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();

    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
      logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
      throw new UnableToCompleteException();
    }

    // Make sure the UserPreferences type is correctly defined
    validateType(logger, sourceType);

    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName()
        + "UserPreferencesImpl";

    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
        sourceType.getPackage().getName(), generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.addImport(PreferencesUtil.class.getName());
    f.addImplementedInterface(typeName);

    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger,
        sourceType.getPackage().getName(), generatedSimpleSourceName);

    // If an implementation already exists, we don't need to do any work
    if (out != null) {
      JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace('$', '.'));
      assert preferenceType != null;

      // We really use a SourceWriter since it's convenient
      SourceWriter sw = f.createSourceWriter(context, out);

      for (JMethod m : sourceType.getOverridableMethods()) {
        JClassType extendsPreferenceType = m.getReturnType().isClassOrInterface();
        if (extendsPreferenceType == null
            || !preferenceType.isAssignableFrom(extendsPreferenceType)) {
          logger.log(TreeLogger.ERROR, "Cannot assign "
              + extendsPreferenceType.getQualifiedSourceName() + " to "
              + preferenceType.getQualifiedSourceName(), null);
          throw new UnableToCompleteException();
        }

        // private final FooProperty __propName = new FooProperty() {...}
        sw.println("private final "
            + extendsPreferenceType.getParameterizedQualifiedSourceName()
            + " __" + m.getName() + " = ");
        sw.indent();
        writeInstantiation(logger, sw, extendsPreferenceType, m);
        sw.println(";");
        sw.outdent();
View Full Code Here

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

    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();

    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
      logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
      throw new UnableToCompleteException();
    }

    // Make sure the Gadget type is correctly defined
    validateType(logger, sourceType);

    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName()
        + "GadgetImpl";

    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
        sourceType.getPackage().getName(), generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.setSuperclass(typeName);

    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger,
        sourceType.getPackage().getName(), generatedSimpleSourceName);

    // If an implementation already exists, we don't need to do any work
    if (out != null) {

      JClassType userPrefsType = GadgetUtils.getUserPrefsType(logger,
          typeOracle, sourceType);

      // We really use a SourceWriter since it's convenient
      SourceWriter sw = f.createSourceWriter(context, out);
      sw.println("public " + generatedSimpleSourceName + "() {");
      sw.indent();
      sw.println("nativeInit();");
      sw.println("init((" + userPrefsType.getQualifiedSourceName()
          + ")GWT.create(" + userPrefsType.getQualifiedSourceName()
          + ".class));");
      sw.outdent();
      sw.println("}");

      sw.println("private native void nativeInit() /*-{");
 
View Full Code Here

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

      throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG,
        "Generating userpref element for method " + m.getReadableDeclaration(),
        null);

    JClassType prefType = m.getReturnType().isClassOrInterface();

    if (prefType == null || !preferenceType.isAssignableFrom(prefType)) {
      logger.log(TreeLogger.ERROR, m.getReturnType().getQualifiedSourceName()
          + " is not assignable to " + preferenceType.getQualifiedSourceName(),
          null);
      throw new UnableToCompleteException();
    }

    DataType dataType = prefType.getAnnotation(DataType.class);

    if (dataType == null) {
      logger.log(TreeLogger.ERROR, prefType
          + " must define a DataType annotation", null);
      throw new UnableToCompleteException();
View Full Code Here

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

      logger.log(TreeLogger.ERROR, m.getName()
          + " must have exactly one parameter", null);
      throw new UnableToCompleteException();
    }

    JClassType paramType = params[0].getType().isClass();
    JClassType gadgetFeatureType = typeOracle.findType(GadgetFeature.class.getName());
    assert gadgetFeatureType != null;

    if (paramType == null || paramType.isAbstract()) {
      logger.log(TreeLogger.ERROR, "The parameter " + params[0].getName()
          + " must be a concrete class", null);
      throw new UnableToCompleteException();

    } else if (!gadgetFeatureType.isAssignableFrom(paramType)) {
      logger.log(TreeLogger.ERROR, "The parameter " + params[0].getName()
          + " must be assignable to GadgetFeature", null);
      throw new UnableToCompleteException();

    } else {
View Full Code Here

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

      GadgetUtils.writeRequirementsToElement(logger, d, modulePrefs,
          prefs.requirements());
    }

    // Write out the UserPref tags
    JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace('$', '.'));
    assert preferenceType != null;

    JClassType prefsType = GadgetUtils.getUserPrefsType(logger, typeOracle,
        type);
    for (JMethod m : prefsType.getOverridableMethods()) {
      Element userPref = (Element) module.appendChild(d.createElement("UserPref"));
      configurePreferenceElement(logger, d, userPref, preferenceType, m);
    }

    // Add required features to the manifest
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.