Package org.mapstruct.ap.model.common

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


            List<Type> sourceTypeParams = method.getSourceParameters().iterator().next().getType().getTypeParameters();
            List<Type> resultTypeParams = method.getResultType().getTypeParameters();

            // find mapping method or conversion for key
            Type keySourceType = sourceTypeParams.get( 0 );
            Type keyTargetType = resultTypeParams.get( 0 );

            Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment(
                method,
                "map key",
                keySourceType,
                keyTargetType,
                null, // there is no targetPropertyName
                keyDateFormat,
                keyQualifiers,
                "entry.getKey()"
            );

            if ( keyAssignment == null ) {
                String message = String.format(
                    "Can't create implementation of method %s. Found no method nor "
                        + "built-in conversion for mapping source key type to target key type.", method
                );
                ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() );
            }

            // find mapping method or conversion for value
            Type valueSourceType = sourceTypeParams.get( 1 );
            Type valueTargetType = resultTypeParams.get( 1 );

            Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment(
                method,
                "map value",
                valueSourceType,
View Full Code Here


            this.qualifiers = qualifiers;
            return this;
        }

        public IterableMappingMethod build() {
            Type sourceElementType =
                method.getSourceParameters().iterator().next().getType().getTypeParameters().get( 0 );
            Type targetElementType =
                method.getResultType().getTypeParameters().get( 0 );
            String conversionStr =
                Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() );

View Full Code Here

        return conversions.get( new Key( sourceType, targetType ) );
    }

    private Key forClasses(Class<?> sourceClass, Class<?> targetClass) {
        Type sourceType = typeFactory.getType( sourceClass );
        Type targetType = typeFactory.getType( targetClass );

        return new Key( sourceType, targetType );
    }
View Full Code Here

                    || cmStrategy == CollectionMappingStrategy.ADDER_PREFERRED ) {

                    // first check if there's a setter method.
                    ExecutableElement adderMethod = null;
                    if ( Executables.isSetterMethod( candidate ) ) {
                        Type targetType = ctx.getTypeFactory().getSingleParameter( candidate ).getType();
                        // ok, the current accessor is a setter. So now the strategy determines what to use
                        if ( cmStrategy == CollectionMappingStrategy.ADDER_PREFERRED ) {
                            adderMethod = method.getResultType().getAdderForType( targetType, targetPropertyName );
                        }
                    }
                    else if ( Executables.isGetterMethod( candidate ) ) {
                        // the current accessor is a getter (no setter available). But still, an add method is according
                        // to the above strategy (SETTER_PREFERRED || ADDER_PREFERRED) preferred over the getter.
                        Type targetType = ctx.getTypeFactory().getReturnType( candidate );
                        adderMethod = method.getResultType().getAdderForType( targetType, targetPropertyName );
                    }
                    if ( adderMethod != null ) {
                        // an adder has been found (according strategy) so overrule current choice.
                        candidate = adderMethod;
View Full Code Here

    public static Decorator getInstance(Elements elementUtils, TypeFactory typeFactory, TypeElement mapperElement,
                                        DecoratedWithPrism decoratorPrism, List<MappingMethod> methods,
                                        boolean hasDelegateConstructor,
                                        boolean suppressGeneratorTimestamp) {
        Type decoratorType = typeFactory.getType( decoratorPrism.value() );

        return new Decorator(
            typeFactory,
            elementUtils.getPackageOf( mapperElement ).getQualifiedName().toString(),
            mapperElement.getSimpleName().toString() + IMPLEMENTATION_SUFFIX,
            decoratorType.getName(),
            mapperElement.getKind() == ElementKind.INTERFACE ? mapperElement.getSimpleName().toString() : null,
            methods,
            Arrays.asList(
                new Field( typeFactory.getType( mapperElement ), "delegate" ),
                new DecoratorConstructor(
View Full Code Here

        Map<TypeVariable, TypeMirror> genericTypesMap = new HashMap<TypeVariable, TypeMirror>();

        int i = 0;
        for ( VariableElement candidateParameter : candidateParameters ) {
            TypeMatcher parameterMatcher = new TypeMatcher( Assignability.VISITED_ASSIGNABLE_FROM, genericTypesMap );
            Type sourceType = sourceTypes.get( i++ );
            if ( !parameterMatcher.visit( candidateParameter.asType(), sourceType.getTypeMirror() ) ) {
                if (sourceType.isPrimitive() ) {
                    // the candidate source is primitive, so promote to its boxed type and check again (autobox)
                    TypeMirror boxedType = typeUtils.boxedClass( (PrimitiveType) sourceType.getTypeMirror() ).asType();
                    if ( !parameterMatcher.visit( candidateParameter.asType(), boxedType ) ) {
                        return false;
                    }
                }
                else {
View Full Code Here

                if ( elementUtils.overrides( method, mappingMethod.getExecutable(), decoratorElement ) ) {
                    implementationRequired = false;
                    break;
                }
            }
            Type declaringMapper = mappingMethod.getDeclaringMapper();
            if ( implementationRequired ) {
                if ( ( declaringMapper == null ) || declaringMapper.equals( typeFactory.getType( element ) ) ) {
                    mappingMethods.add( new DelegatingMethod( mappingMethod ) );
                }
            }
        }
View Full Code Here

        SortedSet<Type> extraImports = new TreeSet<Type>();

        MapperConfig mapperPrism = MapperConfig.getInstanceOn( element );

        for ( TypeMirror extraImport : mapperPrism.imports() ) {
            Type type = typeFactory.getType( extraImport );
            extraImports.add( type );
        }

        return extraImports;
    }
View Full Code Here

            return new SourceReference( parameter, entries, isValid );
        }

        private List<PropertyEntry> getSourceEntries(Type type, String[] entryNames) {
            List<PropertyEntry> sourceEntries = new ArrayList<PropertyEntry>();
            Type newType = type;
            for ( String entryName : entryNames ) {
                boolean matchFound = false;
                List<ExecutableElement> getters = newType.getGetters();
                for ( ExecutableElement getter : getters ) {
                    if ( Executables.getPropertyName( getter ).equals( entryName ) ) {
                        newType = typeFactory.getType( getter.getReturnType() );
                        sourceEntries.add( new PropertyEntry( entryName, getter, newType ) );
                        matchFound = true;
View Full Code Here

        }
    }

    private SourceMethod getMethodRequiringImplementation(ExecutableElement method, List<Parameter> parameters,
                                                          boolean containsTargetTypeParameter) {
        Type returnType = typeFactory.getReturnType( method );
        List<Type> exceptionTypes = typeFactory.getThrownTypes( method );
        List<Parameter> sourceParameters = extractSourceParameters( parameters );
        Parameter targetParameter = extractTargetParameter( parameters );
        Type resultType = selectResultType( returnType, targetParameter );

        boolean isValid = checkParameterAndReturnType(
            method,
            sourceParameters,
            targetParameter,
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.