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

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


    public void visitConnector(TreeLogger logger, JClassType type,
            ConnectorBundle bundle) throws UnableToCompleteException {
        Connect connectAnnotation = type.getAnnotation(Connect.class);
        if (connectAnnotation != null) {
            // Find all the annotated methods in all the superclasses
            JClassType connector = type;
            while (connector != null) {
                for (JMethod method : connector.getMethods()) {
                    if (method.getAnnotation(OnStateChange.class) != null) {
                        bundle.setNeedsInvoker(connector, method);
                        bundle.setNeedsOnStateChangeHandler(type, method);
                    }
                }

                connector = connector.getSuperclass();
            }
        }
    }
View Full Code Here


    @Override
    public void visitConnector(TreeLogger logger, JClassType type,
            ConnectorBundle bundle) throws UnableToCompleteException {
        if (ConnectorBundle.isConnectedComponentConnector(type)) {
            // The class in which createWidget is implemented
            JClassType createWidgetClass = ConnectorBundle.findInheritedMethod(
                    type, "createWidget").getEnclosingType();

            JMethod getWidget = ConnectorBundle.findInheritedMethod(type,
                    "getWidget");
            JClassType widgetType = getWidget.getReturnType().isClass();

            // Needs GWT constructor if createWidget is not overridden
            if (createWidgetClass.getQualifiedSourceName().equals(
                    AbstractComponentConnector.class.getCanonicalName())) {
                bundle.setNeedsGwtConstructor(widgetType);

                // Also needs widget type to find the right GWT constructor
                bundle.setNeedsReturnType(type, getWidget);
            }

            // Check state properties for @DelegateToWidget
            JMethod getState = ConnectorBundle.findInheritedMethod(type,
                    "getState");
            JClassType stateType = getState.getReturnType().isClass();

            Collection<Property> properties = bundle.getProperties(stateType);
            for (Property property : properties) {
                DelegateToWidget delegateToWidget = property
                        .getAnnotation(DelegateToWidget.class);
                if (delegateToWidget != null) {
                    // Generate meta data required for @DelegateToWidget
                    bundle.setNeedsDelegateToWidget(property, stateType);

                    // Find the delegate target method
                    String methodName = DelegateToWidget.Helper
                            .getDelegateTarget(property.getName(),
                                    delegateToWidget.value());
                    JMethod delegatedSetter = ConnectorBundle
                            .findInheritedMethod(widgetType, methodName,
                                    property.getPropertyType());
                    if (delegatedSetter == null) {
                        logger.log(
                                Type.ERROR,
                                widgetType.getName()
                                        + "."
                                        + methodName
                                        + "("
                                        + property.getPropertyType()
                                                .getSimpleSourceName()
                                        + ") required by @DelegateToWidget for "
                                        + stateType.getName() + "."
                                        + property.getName()
                                        + " can not be found.");
                        throw new UnableToCompleteException();
                    }
                    bundle.setNeedsInvoker(widgetType, delegatedSetter);
View Full Code Here

    private static Map<JType, JClassType> findCustomSerializers(
            TypeOracle oracle) throws NotFoundException {
        Map<JType, JClassType> serializers = new HashMap<JType, JClassType>();

        JClassType serializerInterface = oracle.findType(JSONSerializer.class
                .getName());
        JType[] deserializeParamTypes = new JType[] {
                oracle.findType(com.vaadin.client.metadata.Type.class.getName()),
                oracle.findType(JSONValue.class.getName()),
                oracle.findType(ApplicationConnection.class.getName()) };
        String deserializeMethodName = "deserialize";
        // Just test that the method exists
        serializerInterface.getMethod(deserializeMethodName,
                deserializeParamTypes);

        for (JClassType serializer : serializerInterface.getSubtypes()) {
            JMethod deserializeMethod = serializer.findMethod(
                    deserializeMethodName, deserializeParamTypes);
            if (deserializeMethod == null) {
                continue;
            }
View Full Code Here

        if (serializationHandledByFramework(type)) {
            return;
        }

        JClassType customSerializer = customSerializers.get(type);
        JClassType typeAsClass = type.isClass();
        JEnumType enumType = type.isEnum();
        JArrayType arrayType = type.isArray();

        if (customSerializer != null) {
            logger.log(Type.INFO, "Will serialize " + type + " using "
                    + customSerializer.getName());
            setSerializer(type, new CustomSerializer(customSerializer));
        } else if (arrayType != null) {
            logger.log(Type.INFO, "Will serialize " + type + " as an array");
            setSerializer(type, new ArraySerializer(arrayType));
            setNeedsSerialize(arrayType.getComponentType());
        } else if (enumType != null) {
            logger.log(Type.INFO, "Will serialize " + type + " as an enum");
            setSerializer(type, new EnumSerializer(enumType));
        } else if (typeAsClass != null) {
            // Bean
            checkSerializable(logger, typeAsClass);

            logger.log(Type.INFO, "Will serialize " + type + " as a bean");

            JClassType needsSuperClass = typeAsClass;
            while (needsSuperClass != null) {
                if (needsSuperClass.isPublic()) {
                    setNeedsSuperclass(needsSuperClass);
                }
                needsSuperClass = needsSuperClass.getSuperclass();
            }

            setNeedsGwtConstructor(typeAsClass);

            for (Property property : getProperties(typeAsClass)) {
View Full Code Here

        }
    }

    private void checkSerializable(TreeLogger logger, JClassType type)
            throws UnableToCompleteException {
        JClassType javaSerializable = type.getOracle().findType(
                Serializable.class.getName());
        boolean serializable = type.isAssignableTo(javaSerializable);
        if (!serializable) {
            boolean abortCompile = "true".equals(System
                    .getProperty(FAIL_IF_NOT_SERIALIZABLE));
View Full Code Here

    }

    public static JMethod findInheritedMethod(JClassType type,
            String methodName, JType... params) {

        JClassType currentType = type;
        while (currentType != null) {
            JMethod method = currentType.findMethod(methodName, params);
            if (method != null) {
                return method;
            }
            currentType = currentType.getSuperclass();
        }

        JClassType[] interfaces = type.getImplementedInterfaces();
        for (JClassType iface : interfaces) {
            JMethod method = iface.findMethod(methodName, params);
View Full Code Here

public class FrameworkGenerator extends Generator {

  @Override
  public String generate(TreeLogger logger, GeneratorContext context, String typeName)
      throws UnableToCompleteException {
    JClassType requestedType = context.getTypeOracle().findType(typeName);
    String packageName = requestedType.getPackage().getName();
    String requestedName = requestedType.getSimpleSourceName();
    String newClassName = requestedName + "Impl";

    String moduleName = createModule(logger, context, requestedType, packageName, requestedName);

    String ginjectorName =
        createGinjector(logger, context, packageName, requestedName, newClassName, moduleName);

    ClassSourceFileComposerFactory composerFactory =
        new ClassSourceFileComposerFactory(packageName, newClassName);
    composerFactory.setSuperclass(requestedType.getQualifiedSourceName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    SourceWriter writer = composerFactory
        .createSourceWriter(context, context.tryCreate(logger, packageName, newClassName));
    writer.println("public void initialize() {");
    writer.indent();
View Full Code Here

    for (FieldWriter f : needs) {
      f.write(w);
    }

    if (initializer == null) {
      JClassType type = getInstantiableType();
      if (type != null) {
        if ((type.isInterface() == null)
            && (type.findConstructor(new JType[0]) == null)) {
          logger.die(NO_DEFAULT_CTOR_ERROR, type.getQualifiedSourceName(),
              type.getName());
        }
      }
    }

    if (null == initializer) {
View Full Code Here

  public void writeFieldDefinition(IndentedWriter w, TypeOracle typeOracle,
      OwnerField ownerField, DesignTimeUtils designTime, int getterCount,
      boolean useLazyWidgetBuilders)
      throws UnableToCompleteException {

    JClassType renderablePanelType = typeOracle.findType(
        RenderablePanel.class.getName());
    boolean outputAttachDetachCallbacks = useLazyWidgetBuilders
        && getAssignableType() != null
        && getAssignableType().isAssignableTo(renderablePanelType);

    // Check initializer.
    if (initializer == null) {
      if (ownerField != null && ownerField.isProvided()) {
        initializer = String.format("owner.%s", name);
      } else {
        JClassType type = getInstantiableType();
        if (type != null) {
          if ((type.isInterface() == null)
              && (type.findConstructor(new JType[0]) == null)) {
            logger.die(NO_DEFAULT_CTOR_ERROR, type.getQualifiedSourceName(),
                type.getName());
          }
        }
        initializer = String.format("(%1$s) GWT.create(%1$s.class)",
            getQualifiedSourceName());
      }
    }

    w.newline();
    w.write("/**");
    w.write(" * Getter for %s called %s times. Type: %s. Build precedence: %s.",
        name, getterCount, getFieldType(), getBuildPrecedence());
    w.write(" */");
    if (getterCount > 1) {
      w.write("private %1$s %2$s;", getQualifiedSourceName(), name);
    }

    w.write("private %s %s {", getQualifiedSourceName(), FieldManager.getFieldGetter(name));
    w.indent();
    w.write("return %s;", (getterCount > 1) ? name : FieldManager.getFieldBuilder(name));
    w.outdent();
    w.write("}");

    w.write("private %s %s {", getQualifiedSourceName(), FieldManager.getFieldBuilder(name));
    w.indent();

    w.write("// Creation section.");
    if (getterCount > 1) {
      w.write("%s = %s;", name, initializer);
    } else {
      w.write("final %s %s = %s;", getQualifiedSourceName(), name, initializer);
    }
    if (ownerField != null && ownerField.isProvided() && !designTime.isDesignTime()) {
      w.write("assert %1$s != null : \"UiField %1$s with 'provided = true' was null\";", name);
    }

    w.write("// Setup section.");
    for (String s : statements) {
      w.write(s);
    }

    String attachedVar = null;

    if (attachStatements.size() > 0) {
      w.newline();
      w.write("// Attach section.");
      if (outputAttachDetachCallbacks) {
        // TODO(rdcastro): This is too coupled with RenderablePanel.
        // Make this nicer.
        w.write("%s.wrapInitializationCallback = ", getName());
        w.indent();
        w.indent();
        w.write(
            "new com.google.gwt.user.client.Command() {");
        w.outdent();
        w.write("@Override public void execute() {");
        w.indent();
      } else {
        attachedVar = getNextAttachVar();

        JClassType elementType = typeOracle.findType(Element.class.getName());

        String elementToAttach = getInstantiableType().isAssignableTo(elementType)
            ? name : name + ".getElement()";

        w.write("UiBinderUtil.TempAttachment %s = UiBinderUtil.attachToDom(%s);",
View Full Code Here

    Iterator<String> i = path.iterator();
    while (i.hasNext()) {
      String pathElement = i.next();

      JClassType referenceType = type.isClassOrInterface();
      if (referenceType == null) {
        logger.error("Cannot resolve member " + pathElement
            + " on non-reference type " + type.getQualifiedSourceName());
        return null;
      }
View Full Code Here

TOP

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

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.