Package org.mapstruct.ap.model.common

Examples of org.mapstruct.ap.model.common.Type


        );
    }

    private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableElement method,
                                             TypeElement mapperToImplement, List<Parameter> parameters) {
        Type returnType = typeFactory.getReturnType( method );
        List<Type> exceptionTypes = typeFactory.getThrownTypes( method );
        Type usedMapperAsType = typeFactory.getType( usedMapper );
        Type mapperToImplementAsType = typeFactory.getType( mapperToImplement );

        if ( !mapperToImplementAsType.canAccess( usedMapperAsType, method ) ) {
            return null;
        }

        return SourceMethod.forReferencedMethod(
            usedMapper.equals( mapperToImplement ) ? null : usedMapperAsType,
View Full Code Here


                method
            );
            return false;
        }

        Type parameterType = sourceParameters.get( 0 ).getType();

        if ( parameterType.isIterableType() && !resultType.isIterableType() ) {
            messager.printMessage(
                Kind.ERROR,
                "Can't generate mapping method from iterable type to non-iterable type.",
                method
            );
            return false;
        }

        if ( containsTargetTypeParameter ) {
            messager.printMessage(
                Kind.ERROR,
                "Can't generate mapping method that has a parameter annotated with @TargetType.",
                method
            );
            return false;
        }

        if ( !parameterType.isIterableType() && resultType.isIterableType() ) {
            messager.printMessage(
                Kind.ERROR,
                "Can't generate mapping method from non-iterable type to iterable type.",
                method
            );
            return false;
        }

        if ( parameterType.isPrimitive() ) {
            messager.printMessage( Kind.ERROR, "Can't generate mapping method with primitive parameter type.", method );
            return false;
        }

        if ( resultType.isPrimitive() ) {
            messager.printMessage( Kind.ERROR, "Can't generate mapping method with primitive return type.", method );
            return false;
        }

        if ( parameterType.isEnumType() && !resultType.isEnumType() ) {
            messager.printMessage(
                Kind.ERROR,
                "Can't generate mapping method from enum type to non-enum type.",
                method
            );
            return false;
        }

        if ( !parameterType.isEnumType() && resultType.isEnumType() ) {
            messager.printMessage(
                Kind.ERROR,
                "Can't generate mapping method from non-enum type to enum type.",
                method
            );
View Full Code Here

    @Override
    public boolean matches(List<Type> sourceTypes, Type targetType) {
        if ( sourceTypes.size() > 1 ) {
            return false;
        }
        Type sourceType = sourceTypes.iterator().next();

        if ( getReturnType().isAssignableTo( targetType.erasure() )
            && sourceType.erasure().isAssignableTo( getParameter().getType() ) ) {
            return doTypeVarsMatch( sourceType, targetType );
        }
        if ( getReturnType().getFullyQualifiedName().equals( "java.lang.Object" )
            && sourceType.erasure().isAssignableTo( getParameter().getType() ) ) {
            // return type could be a type parameter T
            return doTypeVarsMatch( sourceType, targetType );
        }
        if ( getReturnType().isAssignableTo( targetType.erasure() )
            &&  getParameter().getType().getFullyQualifiedName().equals( "java.lang.Object" ) ) {
View Full Code Here

        public PropertyMapping build() {

            // handle target
            TargetAccessorType targetAccessorType = getTargetAcccessorType();
            Type targetType = getTargetType( targetAccessorType );

            // handle source
            String sourceElement = getSourceElement();
            Type sourceType = getSourceType();
            String sourceRefStr;
            if ( targetAccessorType == TargetAccessorType.ADDER && sourceType.isCollectionType() ) {
                // handle adder, if source is collection then use iterator element type as source type.
                // sourceRef becomes a local variable in the itereation.
                sourceType = sourceType.getTypeParameters().get( 0 );
                sourceRefStr = Executables.getElementNameForAdder( targetAccessor );
            }
            else {
                sourceRefStr = getSourceRef();
            }
View Full Code Here

        public PropertyMapping build() {

            // source
            String mappedElement = "constant '" + constantExpression + "'";
            Type sourceType = ctx.getTypeFactory().getType( String.class );

            // target
            Type targetType;
            if ( Executables.isSetterMethod( targetAccessor ) ) {
                targetType = ctx.getTypeFactory().getSingleParameter( targetAccessor ).getType();
            }
            else {
                targetType = ctx.getTypeFactory().getReturnType( targetAccessor );
View Full Code Here

        public PropertyMapping build() {

            Assignment assignment = AssignmentFactory.createDirect( javaExpression );
            assignment = new SetterWrapper( assignment, method.getThrownTypes() );

            Type targetType;
            if ( Executables.isSetterMethod( targetAccessor ) ) {
                targetType = ctx.getTypeFactory().getSingleParameter( targetAccessor ).getType();
            }
            else {
                targetType = ctx.getTypeFactory().getReturnType( targetAccessor );
View Full Code Here

            for ( AnnotationMirror methodAnnotation : methodAnnotations ) {
                addOnlyWhenQualifier( combinedAnnotations, methodAnnotation );
            }

            // then from the mapper (if declared)
            Type mapper = candidate.getDeclaringMapper();
            if ( mapper != null ) {
                List<? extends AnnotationMirror> mapperAnnotations = mapper.getTypeElement().getAnnotationMirrors();
                for ( AnnotationMirror mapperAnnotation : mapperAnnotations ) {
                    addOnlyWhenQualifier( combinedAnnotations, mapperAnnotation );
                }
            }
View Full Code Here

    @Override
    public boolean doTypeVarsMatch(Type sourceType, Type targetType) {
        boolean match = false;
        if ( ( sourceType.getTypeParameters().size() == 1 ) && ( targetType.getTypeParameters().size() == 1 ) ) {
            Type typeParam = sourceType.getTypeParameters().get( 0 );
            if ( typeParam.erasure().equals( genericParam ) && ( typeParam.getTypeParameters().size() == 1 ) ) {
                match = typeParam.getTypeParameters().get( 0 ).equals( targetType.getTypeParameters().get( 0 ) );
            }
        }
        return match;
    }
View Full Code Here

TOP

Related Classes of org.mapstruct.ap.model.common.Type

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.