public boolean isCollection() { return isInstanceOf(Collection.class.getName()); }
@Override public boolean isInstanceOf(String className) { return super.isInstanceOf(className) || Object.class.getName().equals(className); } }
/** * Whether the parameter type is a holder. * * @return Whether the parameter type is a holder. */ public boolean isHolder() { return ((DecoratedTypeMirror) getType()).isInstanceOf(Holder.class.getName()); }
@Override public boolean isInstanceOf(String className) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(this.originalType); return decorated.isInstanceOf(className); }
/** * Whether the return type from this REST method is XML. * * @return Whether the return type from this REST method is XML. */ public boolean isCustomType() { return ((DecoratedTypeMirror) getReturnType()).isInstanceOf(DataHandler.class.getName()); }
/** * Whether the parameter type is a holder. * * @return Whether the parameter type is a holder. */ public boolean isHolder() { return ((DecoratedTypeMirror) getType()).isInstanceOf(Holder.class.getName()); }
@Override public boolean isInstanceOf(String className) { if (super.isInstanceOf(className)) { return true; } className = className.trim(); if (className.endsWith("]")) { className = className.substring(0, className.length() - 1).trim(); if (className.endsWith("[")) { className = className.substring(0, className.length() - 1).trim(); DecoratedTypeMirror componentType = (DecoratedTypeMirror) getComponentType(); return componentType.isInstanceOf(className); } } return false; } }
/** * Whether the specified type is a known type. * * @param typeDef The type def. * @return Whether the specified type is a known type. */ protected boolean isKnownType(TypeDefinition typeDef) { return knownTypes.containsKey(typeDef.getQualifiedName()) || JAXBElement.class.getName().equals(typeDef.getQualifiedName()) || ((DecoratedTypeMirror) typeDef.getSuperclass()).isInstanceOf(JAXBElement.class.getName()); }
/** * Whether the specified declaration is throwable. * * @param declaration The declaration to determine whether it is throwable. * @return Whether the specified declaration is throwable. */ protected boolean isThrowable(TypeDeclaration declaration) { if (!(declaration instanceof ClassDeclaration)) { return false; } else if (Throwable.class.getName().equals(declaration.getQualifiedName())) { return false; } else { ClassType superClass = ((ClassDeclaration) declaration).getSuperclass(); return ((DecoratedTypeMirror) TypeMirrorDecorator.decorate(superClass)).isInstanceOf(Throwable.class.getName()); } }
/** * Whether the specified declaration is throwable. * * @param declaration The declaration to determine whether it is throwable. * @return Whether the specified declaration is throwable. */ protected boolean isThrowable(TypeDeclaration declaration) { if (!(declaration instanceof ClassDeclaration)) { return false; } else if (Throwable.class.getName().equals(declaration.getQualifiedName())) { return false; } else { ClassType superClass = ((ClassDeclaration) declaration).getSuperclass(); return ((DecoratedTypeMirror) TypeMirrorDecorator.decorate(superClass)).isInstanceOf(Throwable.class.getName()); } }
protected boolean isMap(TypeDeclaration declaration) { String fqn = declaration.getQualifiedName(); if (Map.class.getName().equals(fqn)) { return true; } else { if (declaration instanceof ClassDeclaration) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((ClassDeclaration)declaration).getSuperclass()); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } for (InterfaceType interfaceType : declaration.getSuperinterfaces()) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(interfaceType); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } } return false; }
protected boolean isMap(TypeDeclaration declaration) { String fqn = declaration.getQualifiedName(); if (Map.class.getName().equals(fqn)) { return true; } else { if (declaration instanceof ClassDeclaration) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((ClassDeclaration)declaration).getSuperclass()); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } for (InterfaceType interfaceType : declaration.getSuperinterfaces()) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(interfaceType); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } } return false; }
protected boolean isMap(TypeDeclaration declaration) { String fqn = declaration.getQualifiedName(); if (Map.class.getName().equals(fqn)) { return true; } else { if (declaration instanceof ClassDeclaration) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((ClassDeclaration)declaration).getSuperclass()); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } for (InterfaceType interfaceType : declaration.getSuperinterfaces()) { DecoratedTypeMirror decorated = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(interfaceType); if (decorated.isInstanceOf(Map.class.getName())) { return true; } } } return false; }
/** * Whether the any element is a collection. * * @return Whether the any element is a collection. */ public boolean isCollectionType() { DecoratedTypeMirror accessorType; Declaration delegate = getDelegate(); if (delegate instanceof FieldDeclaration) { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((FieldDeclaration) delegate).getType()); } else { accessorType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((PropertyDeclaration) delegate).getPropertyType()); } return accessorType.isInstanceOf(Collection.class.getName()); }
/** * Determines whether the class declaration is an instance of the declared type of the given fully-qualified name. * * @param classDeclaration The class declaration. * @param fqn The FQN. * @return Whether the class declaration is an instance of the declared type of the given fully-qualified name. */ 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); }
/** * Determines whether the class declaration is an instance of the declared type of the given fully-qualified name. * * @param classDeclaration The class declaration. * @param fqn The FQN. * @return Whether the class declaration is an instance of the declared type of the given fully-qualified name. */ 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); }
/** * Determines whether the class declaration is an instance of the declared type of the given fully-qualified name. * * @param classDeclaration The class declaration. * @param fqn The FQN. * @return Whether the class declaration is an instance of the declared type of the given fully-qualified name. */ 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); }
public ValidationResult validateRootResources(List<RootResource> rootResources) { ValidationResult result = new ValidationResult(); for (RootResource rootResource : rootResources) { for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) { if (resourceMethod.getDeclaredEntityParameters().size() > 1) { result.addError(resourceMethod, "No more than one JAX-RS entity parameter is allowed (all other parameters must be annotated with one of the JAX-RS resource parameter annotations)."); } int formParamCount = 0; for (ResourceParameter resourceParameter : resourceMethod.getResourceParameters()) { if (resourceParameter.isFormParam()) { formParamCount++; } } 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? //todo: error out with ambiguous resource methods (produce same thing at same path with same method)? } } return result; }
@Override public String convert(TypeDeclaration declaration) throws TemplateModelException { AdapterType adapterType = AdapterUtil.findAdapterType(declaration); if (adapterType != null) { return convert(adapterType.getAdaptingType()); } if (declaration instanceof ClassDeclaration) { DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(((ClassDeclaration) declaration).getSuperclass()); if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) { //for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement return convert(superType); } } String convertedPackage = convertPackage(declaration.getPackage()); ClientName specifiedName = isUseClientNameConversions() ? declaration.getAnnotation(ClientName.class) : null; String simpleName = specifiedName == null ? declaration.getSimpleName() : specifiedName.value(); return convertedPackage + getPackageSeparator() + simpleName; } }
@Override public ValidationResult validateComplexType(ComplexTypeDefinition complexType) { ValidationResult result = super.validateComplexType(complexType); for (Attribute attribute : complexType.getAttributes()) { if (capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) { result.addError(attribute, "C# can't handle properties/fields that are of the same name as their containing class."); } } if (complexType.getValue() != null) { if (capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) { result.addError(complexType.getValue(), "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side."); } } for (Element element : complexType.getElements()) { if (element.getAccessorType() instanceof MapType && !element.isAdapted()) { result.addError(element, "C# doesn't have a built-in way of serializing a Map. So you're going to have to use @XmlJavaTypeAdapter to supply " + "your own adapter for the Map, or disable the C# module."); } if (capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) { result.addError(element, "C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @org.codehaus.enunciate.ClientName annotation to rename the property/field on the client-side."); } } if (((DecoratedTypeMirror) complexType.getSuperclass()).isInstanceOf(Map.class.getName())) { result.addError(complexType, "Enunciate can't generate C# code that handles types that implement java.util.Map. I'm afraid you'll have to disable the C# module or use @XmlJavaTypeAdapter to adapt the type."); } return result; }