Examples of DecoratedTypeMirror


Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

          }
        }

        ResourceEntityParameter entityParam = resourceMethod.getEntityParameter();
        if (entityParam != null && (formParamCount > 0)) {
          DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(entityParam.getType());
          if (!decorated.isInstanceOf(MultivaluedMap.class.getName())) {
            result.addError(entityParam, "An entity parameter must be of type MultivaluedMap<String, String> if there is another parameter annotated with @FormParam.");
          }
        }

        //todo: warn about resource methods that are not public?
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

   * @param type The type.
   * @return Whether it's convertable.
   */
  protected boolean isConvertableToStringByJAXRS(TypeMirror type) {
    //unwrap the lists first.
    DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(type);
    if (decorated.isInstanceOf("java.util.List") || decorated.isInstanceOf("java.util.Set") || decorated.isInstanceOf("java.util.SortedSet")) {
      Collection<TypeMirror> typeArgs = ((DeclaredType) type).getActualTypeArguments();
      if (typeArgs != null && typeArgs.size() == 1) {
        type = typeArgs.iterator().next();
      }
      else {
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

   */
  protected boolean isInstanceOf(ClassDeclaration classDeclaration, String fqn) {
    AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
    Types utils = env.getTypeUtils();
    DeclaredType declaredType = utils.getDeclaredType(env.getTypeDeclaration(classDeclaration.getQualifiedName()));
    DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaredType);
    return decorated.isInstanceOf(fqn);
  }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

        if (webMessage instanceof WebResult) {
          WebResult webResult = (WebResult) webMessage;
          if ("".equals(webResult.getElementName())) {
            result.addError(webResult.getWebMethod(), "A web result that is a header must specify a name with the @WebResult annotation.");
          }
          DecoratedTypeMirror type = (DecoratedTypeMirror) webResult.getType();

          if ((type.isCollection()) || (type.isArray())) {
            String description = type.isCollection() ? "an instance of java.util.Collection" : "an array";
            result.addWarning(webMethod, "The header return value that is " + description + " may not (de)serialize " +
              "correctly.  The spec is unclear as to how this should be handled.");
          }
        }
        else {
          WebParam webParam = (WebParam) webMessage;
          if ("".equals(webParam.getElementName())) {
            result.addError(webParam, "A header parameter must specify a name using the @WebParam annotation.");
          }

          DecoratedTypeMirror type = (DecoratedTypeMirror) webParam.getType();

          if (type.isCollection() || (type.isArray())) {
            String description = type.isCollection() ? "an instance of java.util.Collection" : "an array";
            result.addWarning(webParam, "The header parameter that is " + description + " may not (de)serialize correctly.  " +
              "The spec is unclear as to how this should be handled.");
          }
        }
      }

      if (parameterStyle == SOAPBinding.ParameterStyle.BARE) {
        if (webMessage instanceof WebParam) {
          DecoratedTypeMirror paramType = (DecoratedTypeMirror) ((WebParam) webMessage).getType();
          if (paramType.isArray()) {
            result.addError(webMethod, "A BARE web method must not have an array as a parameter.");
          }
        }
        else if (webMessage instanceof RequestWrapper) {
          //todo: throw a runtime exception?  This is a problem with the engine, not the user.
          result.addError(webMethod, "A BARE web method shouldn't have a request wrapper.");
        }
        else if (webMessage instanceof ResponseWrapper) {
          //todo: throw a runtime exception?  This is a problem with the engine, not the user.
          result.addError(webMethod, "A BARE web method shouldn't have a response wrapper.");
        }
      }
      else if (soapBindingStyle == SOAPBinding.Style.RPC) {
        Collection<WebMessagePart> parts = webMessage.getParts();
        for (WebMessagePart part : parts) {
          if (part instanceof WebParam) {
            WebParam webParam = (WebParam) part;
            DecoratedTypeMirror paramType = (DecoratedTypeMirror) webParam.getType();
            if (paramType.isCollection() || paramType.isArray()) {
              String description = paramType.isCollection() ? "An instance of java.util.Collection" : "An array";
              result.addWarning(webParam, description + " as an RPC-style web message part may " +
                "not be (de)serialized as you expect.  The spec is unclear as to how this should be handled.");
            }
          }
        }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

      //make sure all @XmlElement classes are an instance of the parameterized type.
      TypeMirror itemType = element.getCollectionItemType();
      if (itemType instanceof DeclaredType && ((DeclaredType) itemType).getDeclaration() != null) {
        String fqn = ((DeclaredType) itemType).getDeclaration().getQualifiedName();
        for (XmlElement xmlElement : xmlElements.value()) {
          DecoratedTypeMirror elementCandidate;
          try {
            Class clazz = xmlElement.type();
            AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
            DeclaredType declaredType = env.getTypeUtils().getDeclaredType(env.getTypeDeclaration(clazz.getName()));
            elementCandidate = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaredType);
          }
          catch (MirroredTypeException e) {
            elementCandidate = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(e.getTypeMirror());
          }
          if (!elementCandidate.isInstanceOf(fqn)) {
            result.addError(element, elementCandidate + " is not an instance of " + fqn);
          }
        }
      }
      else {
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

      if (!(componentType instanceof PrimitiveType) || (((PrimitiveType) componentType).getKind() != PrimitiveType.Kind.BYTE)) {
        return super.convert(componentType);
      }
    }
    else if (typeMirror instanceof DeclaredType) {
      DecoratedTypeMirror decoratedTypeMirror = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror);
      if (decoratedTypeMirror.isCollection()) {
        DeclaredType declaredType = (DeclaredType) typeMirror;
        Iterator<TypeMirror> actualTypeArguments = declaredType.getActualTypeArguments().iterator();
        if (actualTypeArguments.hasNext()) {
          return super.convert(actualTypeArguments.next());
        }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

    private final TypeMirror targetType;

    private JsonPropertyDeclaration(final PropertyDeclaration propertyDeclaration) {
      super(propertyDeclaration.getGetter(), propertyDeclaration.getSetter());

      DecoratedTypeMirror decoratedPropertyType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getPropertyType());
      isList = decoratedPropertyType.isCollection() || decoratedPropertyType.isArray();

      if (decoratedPropertyType.isCollection() && getPropertyType() instanceof DeclaredType) {
        final DeclaredType declaredType = (DeclaredType) getPropertyType();
        final Collection<TypeMirror> actualTypeArguments = declaredType.getActualTypeArguments();
        if(actualTypeArguments != null && actualTypeArguments.size() == 1) {
          targetType = TypeMirrorDecorator.decorate(actualTypeArguments.iterator().next());
        } else {
          targetType = getPropertyType();
        }
      } else if (decoratedPropertyType.isArray() && getPropertyType() instanceof ArrayType) {
        final ArrayType arrayType = (ArrayType) getPropertyType();
        targetType = TypeMirrorDecorator.decorate(arrayType.getComponentType());
      } else {
        targetType = getPropertyType();
      }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

   * @return The xml type for the specified type mirror.
   * @throws XmlTypeException If the type is invalid or unknown as an xml type.
   */
  public static XmlType getXmlType(TypeMirror typeMirror) throws XmlTypeException {
    XmlTypeVisitor visitor = new XmlTypeVisitor();
    DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(typeMirror);
    visitor.isInCollection = decorated.isCollection();
    visitor.isInArray = decorated.isArray();
    unwrapComponentType(typeMirror).accept(visitor);

    if (visitor.getErrorMessage() != null) {
      throw new XmlTypeException(visitor.getErrorMessage());
    }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

  public boolean isCollectionType() {
    if (isXmlList()) {
      return false;
    }

    DecoratedTypeMirror accessorType;
    if (isAdapted()) {
      accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAdapterType().getAdaptingType(getAccessorType()));
    }
    else {
      accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAccessorType());
    }

    if (accessorType.isArray()) {
      TypeMirror componentType = ((ArrayType) accessorType).getComponentType();
      //special case for byte[]
      return !(componentType instanceof PrimitiveType) || !(((PrimitiveType) componentType).getKind() == PrimitiveType.Kind.BYTE);
    }

    return accessorType.isCollection();
  }
View Full Code Here

Examples of net.sf.jelly.apt.decorations.type.DecoratedTypeMirror

   * parameterized collection type.
   *
   * @return the type parameter of the collection.
   */
  public TypeMirror getCollectionItemType() {
    DecoratedTypeMirror accessorType;
    if (isAdapted()) {
      accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAdapterType().getAdaptingType(getAccessorType()));
    }
    else {
      accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(getAccessorType());
    }

    if (accessorType.isArray()) {
      return ((ArrayType) accessorType).getComponentType();
    }
    else if (accessorType.isCollection()) {
      Iterator<TypeMirror> itemTypes = ((DeclaredType) accessorType).getActualTypeArguments().iterator();
      if (!itemTypes.hasNext()) {
        AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
        Types typeUtils = env.getTypeUtils();
        return TypeMirrorDecorator.decorate(typeUtils.getDeclaredType(env.getTypeDeclaration(java.lang.Object.class.getName())));
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.