New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wildcard generics generated code contains fully qualified names. #543

Closed
sjaakd opened this Issue May 8, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@sjaakd
Contributor

sjaakd commented May 8, 2015

Checkout generated code from org.mapstruct.ap.test.collection.wildcard.

@sjaakd sjaakd added the enhancement label May 8, 2015

@samwright

This comment has been minimized.

Show comment
Hide comment
@samwright

samwright Sep 12, 2015

This causes a compilation error if the generic boundary class is from another package and has no other usages in the mapper class, as the class isn't imported. Contrived example:

// com.example.Person.java
public class Person {}

// com.example.PersonDto.java
public class PersonDto {}

// com.example.PersonUtil.java
public class PersonUtil {
    public static PersonDto toDto(Person) { return new PersonDto(); }
}

// com.example.mappers.PersonListMapper.java
@Mapper(uses = PersonUtil.class)
public interface PersonListMapper {
    List<PersonDto> toDtoList(List<? extends Person> personList);
}

Which generates:

package com.example.mappers;

import com.example.PersonDto;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2015-09-12T18:04:28+0100",
    comments = "version: 1.0.0.CR2, compiler: javac, environment: Java 1.8.0_60 (Oracle Corporation)"
)
public class PersonListMapperImpl implements PersonListMapper {

    @Override
    public List<PersonDto> toDtoList(List<? extends com.example.Person> personList) {
        if ( personList == null ) {
            return null;
        }

        List<PersonDto> list = new ArrayList<PersonDto>();
        for ( Person person : personList ) {
            list.add( PersonMapper.toDto( person ) );
        }

        return list;
    }
}

Note that there is no import statement for Person, but the for-each uses Person without its package qualifier.

I'm guessing that if the non-qualified name is used in the generated generic boundary then the import statement would be generated, hence commenting on this ticket instead of creating a new one.

This causes a compilation error if the generic boundary class is from another package and has no other usages in the mapper class, as the class isn't imported. Contrived example:

// com.example.Person.java
public class Person {}

// com.example.PersonDto.java
public class PersonDto {}

// com.example.PersonUtil.java
public class PersonUtil {
    public static PersonDto toDto(Person) { return new PersonDto(); }
}

// com.example.mappers.PersonListMapper.java
@Mapper(uses = PersonUtil.class)
public interface PersonListMapper {
    List<PersonDto> toDtoList(List<? extends Person> personList);
}

Which generates:

package com.example.mappers;

import com.example.PersonDto;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2015-09-12T18:04:28+0100",
    comments = "version: 1.0.0.CR2, compiler: javac, environment: Java 1.8.0_60 (Oracle Corporation)"
)
public class PersonListMapperImpl implements PersonListMapper {

    @Override
    public List<PersonDto> toDtoList(List<? extends com.example.Person> personList) {
        if ( personList == null ) {
            return null;
        }

        List<PersonDto> list = new ArrayList<PersonDto>();
        for ( Person person : personList ) {
            list.add( PersonMapper.toDto( person ) );
        }

        return list;
    }
}

Note that there is no import statement for Person, but the for-each uses Person without its package qualifier.

I'm guessing that if the non-qualified name is used in the generated generic boundary then the import statement would be generated, hence commenting on this ticket instead of creating a new one.

@filiphr

This comment has been minimized.

Show comment
Hide comment
@filiphr

filiphr Jul 2, 2017

Member

This is actually a bug. I have provided a PR for its fix.

Member

filiphr commented Jul 2, 2017

This is actually a bug. I have provided a PR for its fix.

@filiphr filiphr added this to the 1.2.0.CR1 milestone Jul 2, 2017

gunnarmorling added a commit that referenced this issue Jul 6, 2017

@gunnarmorling

This comment has been minimized.

Show comment
Hide comment
@gunnarmorling

gunnarmorling Jul 6, 2017

Member

Done.

Member

gunnarmorling commented Jul 6, 2017

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment