Package com.google.gxp.compiler.base

Examples of com.google.gxp.compiler.base.FormalParameter


          }
        }

        for (final Map.Entry<String, Attribute> param : params.entrySet()) {
          final String name = param.getKey();
          final FormalParameter parameter = callee.getParameter(name);
          Attribute attr = param.getValue();
          if (parameter == null) {
            alertSink.add(new BadParameterError(attr.getValue(), callee, name));
            continue;
          }
          // TODO(harryh): maybe better to use a  DefaultingExpressionVisitor
          //               here?
          if (attr.getValue() instanceof ObjectConstant) {
            ObjectConstant oc = (ObjectConstant) attr.getValue();
            // TODO(harryh): maybe this should be in Validator?
            if (!parameter.regexMatches(oc)) {
              alertSink.add(new InvalidParameterFailedRegexError(
                                calleeName, name, parameter.getRegex(), oc));
            }
            attr = parameter.hasConstructor()
                ? attr.withValue(new ConstructedConstant(oc, oc.getValue(), callee, parameter))
                : attr.withValue(parameter.getType().parseObjectConstant(name, oc, alertSink));
          }

          attr = attr.withValue(prepareExpressionAsParameterValue(parameter, attr.getValue()));

          final Attribute updatedAttr = visitAttribute(attr);

          parameter.getType().acceptTypeVisitor(new DefaultingTypeVisitor<Void>() {
            protected Void defaultVisitType(Type type) {
              newAttrBuilder.put(name, updatedAttr);
              return null;
            }

            public Void visitBundleType(BundleType type) {
              final AttributeValidator validator = type.getValidator(name);
              String innerContentTypeString = validator.getContentType();
              if (innerContentTypeString != null) {
                Schema innerSchema = schemaFactory.fromContentTypeName(innerContentTypeString);
                attrBundles.get(parameter.getPrimaryName()).put(validator,
                                                         updatedAttr.withInnerSchema(innerSchema));
              } else {
                attrBundles.get(parameter.getPrimaryName()).put(validator, updatedAttr);
              }
              return null;
            }
          });
        }

        // go through the attrBundleMap and turn each entry into an
        // AttrBundleParam and put this into the builder map.
        for (Map.Entry<String, Map<AttributeValidator, Attribute>> attrBundle :
                attrBundles.entrySet()) {
          FormalParameter parameter = callee.getParameterByPrimary(attrBundle.getKey());
          BundleType bt = (BundleType) parameter.getType();

          // special case for the (common case) of a single bundle on the
          // callee side. In this case there is no mixing of attributes
          // between bundles so the GxpAttrBundleBuilder does not need to
          // include only some attributes from passed in bundles.  See the
          // empty constructor in j/c/g/gxp/base/GxpAttrBundleBuilder.java
          Set<String> includeAttrs = (attrBundles.size() == 1)
              ? Collections.<String>emptySet() : bt.getAttrMap().keySet();

          AttrBundleParam newBundle =
              new AttrBundleParam(call, callee.getSchema(), includeAttrs,
                                  attrBundle.getValue(), call.getAttrBundles());

          newAttrBuilder.put(attrBundle.getKey(),
                             new Attribute(call, attrBundle.getKey(),
                                           newBundle, null));
        }

        // Handle content parameter
        FormalParameter contentParam = callee.getContentConsumingParameter();
        Expression content = prepareExpressionAsParameterValue(contentParam,
                                                               apply(call.getContent()));
        boolean contentIgnorable = content.alwaysOnlyWhitespace();
        if (contentParam == null) {
          if (!contentIgnorable) {
            alertSink.add(new BadNodePlacementError(content, call));
          }
        } else {
          String paramName = contentParam.getPrimaryName();
          if (!contentIgnorable && params.containsKey(paramName)) {
            alertSink.add(new MultiValueAttributeError(call, params.get(paramName)));
          } else if (!contentIgnorable
                     || (!contentParam.hasDefault() && !params.containsKey(paramName))) {
            newAttrBuilder.put(contentParam.getPrimaryName(),
                               new Attribute(call, paramName, content, null));
          }
        }

        requirements.add(callee);
View Full Code Here


                                                 template.getParameters().size()));
      } else {
        Iterator<FormalParameter> interfaceParams = implementable.getParameters().iterator();
        Iterator<Parameter> templateParams = template.getParameters().iterator();
        while (interfaceParams.hasNext()) {
          FormalParameter interfaceParam = interfaceParams.next();
          if (!Implementable.INSTANCE_PARAM_NAME.equals(interfaceParam.getPrimaryName())) {
            Parameter templateParam = templateParams.next();

            if (!interfaceParam.getPrimaryName().equals(templateParam.getPrimaryName())) {
              alertSink.add(new ParamNameMismatchError(bid, interfaceParam, templateParam));
              continue;
            }

            if (!interfaceParam.getType().matches(templateParam.getType())) {
              alertSink.add(new ParamTypeMismatchError(bid, interfaceParam, templateParam));
              continue;
            }

            if (interfaceParam.hasDefault() && templateParam.getDefaultValue() == null) {
              alertSink.add(new ParamDefaultMismatchError(templateParam));
            }

            if (interfaceParam.hasConstructor() && templateParam.getConstructor() == null) {
              alertSink.add(new ParamConstructorMismatchError(templateParam));
            }
          }
        }
      }
View Full Code Here

                         List<ThrowsDeclaration> throwsDeclarations,
                         List<Parameter> parameters,
                         List<FormalTypeParameter> formalTypeParameters) {
    TemplateName name = fqTemplateName(dottedName);
    List<Parameter> params = Lists.newArrayList(parameters);
    params.add(new Parameter(new FormalParameter(pos,
                                                 Implementable.INSTANCE_PARAM_NAME,
                                                 Implementable.INSTANCE_PARAM_NAME,
                                                 new TemplateType(pos, name.toString(), name))));

    return new Interface(pos, "<gxp:interface>", fqTemplateName(dottedName),
View Full Code Here

  }

  public Parameter param(String name, String typeStr,
                         Expression defaultValue) {
    Type type = nativeType(pos(), typeStr);
    FormalParameter formal = new FormalParameter(pos(), "<gxp:param>", name, false, type,
                                                 defaultValue, false, null, null, false,
                                                 SpaceOperatorSet.NULL);
    return new Parameter(formal, Collections.<JavaAnnotation>emptyList(),
                         defaultValue, false, null, false, str(""));
  }
View Full Code Here

      TemplateName.FullyQualified name = createRootName(node);
      ContentType contentType = createContentType(node, DEFAULT_CONTENT_TYPE);

      // add a "this" parameter to the list of Parameters
      List<Parameter> parameters = Lists.newArrayList(nodeParts.getParameters());
      FormalParameter formal = new FormalParameter(node.getSourcePosition(),
                                                   Implementable.INSTANCE_PARAM_NAME,
                                                   Implementable.INSTANCE_PARAM_NAME,
                                                   new TemplateType(node.getSourcePosition(),
                                                                    name.toString(), name));
      parameters.add(new Parameter(formal));
View Full Code Here

      if (!comment.hasStaticString()) {
        alertSink.add(new RequiresStaticContentError(node));
        comment = new StringConstant(node, null, "");
      }
      if (name != null) {
        FormalParameter formal = new FormalParameter(node, name, consumesContent, type,
                                                     defaultValue, hasDefaultFlag, regex,
                                                     constructor, hasConstructorFlag,
                                                     spaceOperators);
        output.accumulate(new Parameter(formal, javaAnnotations, defaultValue, hasDefaultFlag,
                                        constructor, hasConstructorFlag, comment));
View Full Code Here

      TemplateName.FullyQualified name = createRootName(node);
      ContentType contentType = createContentType(node, DEFAULT_CONTENT_TYPE);

      // add a "this" parameter to the list of Parameters
      List<Parameter> parameters = Lists.newArrayList(nodeParts.getParameters());
      FormalParameter formal = new FormalParameter(node.getSourcePosition(),
                                                   Implementable.INSTANCE_PARAM_NAME,
                                                   Implementable.INSTANCE_PARAM_NAME,
                                                   new TemplateType(node.getSourcePosition(),
                                                                    name.toString(), name));
      parameters.add(new Parameter(formal));
View Full Code Here

      if (!comment.hasStaticString()) {
        alertSink.add(new RequiresStaticContentError(node));
        comment = new StringConstant(node, null, "");
      }
      if (name != null) {
        FormalParameter formal = new FormalParameter(node, name, consumesContent, type,
                                                     defaultValue, hasDefaultFlag, regex,
                                                     constructor, hasConstructorFlag,
                                                     spaceOperators);
        output.accumulate(new Parameter(formal, javaAnnotations, defaultValue, hasDefaultFlag,
                                        constructor, hasConstructorFlag, comment));
View Full Code Here

TOP

Related Classes of com.google.gxp.compiler.base.FormalParameter

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.