Package com.google.gxp.compiler.reparent

Examples of com.google.gxp.compiler.reparent.Attribute


        }

        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);
        return new BoundCall(call, callee, newAttrBuilder.build());
View Full Code Here


      for (FormalParameter parameter : callee.getParameters()) {
        if (!parameter.hasDefault()) {
          if (!newAttrParams.containsKey(parameter.getPrimaryName())) {
            alertSink.add(new MissingAttributeError(call, parameter.getPrimaryName()));
          } else {
            Attribute fpAttribute = call.getAttributes().get(parameter.getPrimaryName());
            if (fpAttribute != null && fpAttribute.getCondition() != null) {
              alertSink.add(new RequiredAttributeHasCondError(call, fpAttribute));
            }
          }
        }
      }
View Full Code Here

                               "[" + namespace.getUri() + "]:" + name);
  }

  public Attribute attr(
      Namespace namespace, String name, Expression value) {
    return new Attribute(pos(), namespace + ":" + name + " attribute",
                         namespace, name, value, null, null);
  }
View Full Code Here

      List<String> fParams = Lists.newArrayList();
      String calleeName = getCalleeName(callee);
      for (FormalParameter parameter : callee.getParameters()) {
        String paramName = parameter.getPrimaryName();
        if (!Implementable.INSTANCE_PARAM_NAME.equals(paramName)) {
          Attribute value = callerAttrs.get(paramName);

          String defaultFetchString = (parameter.getType().getDefaultValue() == null)
              ? calleeName + "." + getDefaultMethodName(parameter) + "()"
              : getJavaExpression(parameter.getType().getDefaultValue());

          if (value == null) {
            fParams.add(defaultFetchString);
          } else if (value.getCondition() != null) {
            String s = "(" +
                getJavaExpression(value.getCondition()) +
                " ? " + getJavaExpression(value.getValue()) + " : " +
                defaultFetchString + ")";
            fParams.add(s);
          } else {
            fParams.add(getJavaExpression(value.getValue()));
          }
        }
      }
      return fParams;
    }
View Full Code Here

            return false;
          }

          public Boolean visitInstanceCallable(InstanceCallable callable) {
            instantiatedGxps.push(createVarName("inst"));
            Attribute thisAttr = params.get(Implementable.INSTANCE_PARAM_NAME);

            appendLine("{");
            if (thisAttr != null) {
              formatLine(call.getSourcePosition(), "%s %s = %s;",
                         toJavaType(callable.getInstanceType()),
                         instantiatedGxps.peek(),
                         thisAttr.getValue().acceptVisitor(toExpressionVisitor));
            }
            return true;
          }
        });
View Full Code Here

        if (schema != null) {
          Visitor visitor = visitor(schema);
          attr = attr.withValue(attr.getValue().acceptVisitor(visitor));
        }

        Attribute result = super.visitAttribute(attr);
        attrStack.pop();
        return result;
      }
View Full Code Here

        for (Map.Entry<String, Attribute> p : call.getAttributes().entrySet()) {
          String key = p.getKey();
          Visitor visitor = callee
              .getParameterByPrimary(key).getType()
              .acceptTypeVisitor(typeVisitor);
          Attribute value = visitor.visitAttribute(p.getValue());
          newParams.put(key, value);
        }

        Expression result = call.withParams(newParams.build());
View Full Code Here

      List<String> fParams = Lists.newArrayList();
      String calleeName = getCalleeName(callee);
      for (FormalParameter parameter : callee.getParameters()) {
        String paramName = parameter.getPrimaryName();
        if (!Implementable.INSTANCE_PARAM_NAME.equals(paramName)) {
          Attribute value = callerAttrs.get(paramName);

          String defaultFetchString = (parameter.getType().getDefaultValue() == null)
              ? calleeName + "." + getDefaultMethodName(parameter) + "()"
              : getJavaScriptExpression(parameter.getType().getDefaultValue());

          if (value == null) {
            fParams.add(defaultFetchString);
          } else if (value.getCondition() != null) {
            String s = "(" +
                getJavaScriptExpression(value.getCondition()) +
                " ? " + getJavaScriptExpression(value.getValue()) + " : " +
                defaultFetchString + ")";
            fParams.add(s);
          } else {
            fParams.add(getJavaScriptExpression(value.getValue()));
          }
        }
      }
      return fParams;
    }
View Full Code Here

            return false;
          }

          public Boolean visitInstanceCallable(InstanceCallable callable) {
            instantiatedGxps.push(createVarName("inst"));
            Attribute thisAttr = params.get(Implementable.INSTANCE_PARAM_NAME);

            appendLine("{");
            if (thisAttr != null) {
              formatLine(call.getSourcePosition(), "var %s = %s;",
                         instantiatedGxps.peek(),
                         thisAttr.getValue().acceptVisitor(toExpressionVisitor));
            }
            return true;
          }
        });
View Full Code Here

            return false;
          }

          public Boolean visitInstanceCallable(InstanceCallable callable) {
            instantiatedGxps.push(createVarName("inst"));
            Attribute thisAttr = params.get(Implementable.INSTANCE_PARAM_NAME);

            appendLine("{");
            if (thisAttr != null) {
              formatLine(call.getSourcePosition(), "%s %s = %s;",
                         toJavaType(callable.getInstanceType()),
                         instantiatedGxps.peek(),
                         thisAttr.getValue().acceptVisitor(toExpressionVisitor));
            }
            return true;
          }
        });
View Full Code Here

TOP

Related Classes of com.google.gxp.compiler.reparent.Attribute

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.