Classes generated by QueryDSL/APT and static imports

[亡魂溺海] 提交于 2019-12-24 11:54:08

问题


Apparently I can't use classes generated with APT in unit tests that use static imports. (Maven sample project can be downloaded here)

If the following sample class

import com.mysema.query.jpa.impl.JPAQuery;

public class UserStore {

    public void something() {
        new JPAQuery(null).from(QUser.user).list(QUser.user.login);
    }

}

is changed to

import static something.QUser.user;
import com.mysema.query.jpa.impl.JPAQuery;

public class UserStore {

    public void something() {
        new JPAQuery(null).from(user).list(user.login);
    }

}

the build process (mvn clean install) will fail:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.466s
[INFO] Finished at: Wed May 30 16:05:40 CEST 2012
[INFO] Final Memory: 18M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project apt-bug: Compilation failure: Compilation failure:
...

(full error message)

Does this mean that I cannot use these generated classes with static import in unit tests or is there a problem in the pom.xml files?

EDIT:

POM file: http://pastebin.com/gvycZmXD


回答1:


This might be related https://github.com/mysema/querydsl/issues/158

I have not yet had the time to investigate this.

Edit

This has apparently been fixed now in Java 7

  • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7174857
  • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7159016



回答2:


I assume the problem is located in the static import, cause the error messages says the imported QUser.user is neither a class nor an interface. This looks like the user is just an attribute of the Class QUser which would explain the error message.

/home/xxx/apt-bug/src/main/java/something/UserStore.java:3: cannot find symbol
symbol  : class QUser
location: package something
import static something.QUser.user;
                       ^
/home/xxx/apt-bug/src/main/java/something/UserStore.java:3: static import only from classes and interfaces
import static something.QUser.user;
^


来源:https://stackoverflow.com/questions/10818084/classes-generated-by-querydsl-apt-and-static-imports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!