You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Simo Tuokko (JIRA)" <ji...@apache.org> on 2016/06/04 18:42:59 UTC

[jira] [Updated] (GROOVY-7854) Annotation value cannot be concatenated constant

     [ https://issues.apache.org/jira/browse/GROOVY-7854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simo Tuokko updated GROOVY-7854:
--------------------------------
    Description: 
Following code as .java class works ok:

{code:title=UserDAO.java|borderStyle=solid}
public abstract class UserDAO {
    public static final String Select_User_join_Addresses_Features_Images =
        "select "+
        "u.*, a.*, f.*, i.* "+
        "from users u "+
        "left outer join addresses a on (u.id = a.user_id) "+
        "left outer join userfeatures f on (u.id = f.user_id) "+
        "left outer join images i on (u.id = i.user_id) ";

    public static final String Select_User_by_id =
            Select_User_join_Addresses_Features_Images + "where u.id = :id";

    public static final String Select_User_by_email =
            Select_User_join_Addresses_Features_Images + "where u.email = lower(:email)";

    @SqlQuery(Select_User_by_id)
    abstract FoldingList<User> findById(@Bind("id") long id);
}
{code}

However if I write and compile it as Groovy, I get "Expected 'UserDAO.Select_User_by_id' to be an inline constant of type java.lang.String not a property expression" error from compiler.

Also if works if those constant String are in separate .java class that is accessed from annotation (within a .groovy class), but not if they are in separate .groovy file.

So the difference seems to be that constant strings are not concatenated at compile-time in Groovy, but in Java they are? Is this by design or is it a bug that can be fixed?

  was:
Following code as .java class works ok:

{code:title=UserDAO.java|borderStyle=solid}
public abstract class UserDAO {
    public static final String Select_User_join_Addresses_Features_Images =
        "select "+
        "u.*, a.*, f.* i.* "+
        "from users u "+
        "left outer join addresses a on (u.id = a.user_id) "+
        "left outer join userfeatures f on (u.id = f.user_id) "+
        "left outer join images i on (u.id = i.user_id) ";

    public static final String Select_User_by_id =
            Select_User_join_Addresses_Features_Images + "where u.id = :id";

    public static final String Select_User_by_email =
            Select_User_join_Addresses_Features_Images + "where u.email = lower(:email)";

    @SqlQuery(Select_User_by_id)
    abstract FoldingList<User> findById(@Bind("id") long id);
}
{code}

However if I write and compile it as Groovy, I get "Expected 'UserDAO.Select_User_by_id' to be an inline constant of type java.lang.String not a property expression" error from compiler.

Also if works if those constant String are in separate .java class that is accessed from annotation (within a .groovy class), but not if they are in separate .groovy file.

So the difference seems to be that constant strings are not concatenated at compile-time in Groovy, but in Java they are? Is this by design or is it a bug that can be fixed?


> Annotation value cannot be concatenated constant
> ------------------------------------------------
>
>                 Key: GROOVY-7854
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7854
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>         Environment: - OS X 
> - Java(TM) SE Runtime Environment (build 1.8.0_66-b17) 
> - IntelliJ Idea 14 CE \w Groovy plugin 
> - Gradle 2.2
>            Reporter: Simo Tuokko
>             Fix For: 2.3.6
>
>
> Following code as .java class works ok:
> {code:title=UserDAO.java|borderStyle=solid}
> public abstract class UserDAO {
>     public static final String Select_User_join_Addresses_Features_Images =
>         "select "+
>         "u.*, a.*, f.*, i.* "+
>         "from users u "+
>         "left outer join addresses a on (u.id = a.user_id) "+
>         "left outer join userfeatures f on (u.id = f.user_id) "+
>         "left outer join images i on (u.id = i.user_id) ";
>     public static final String Select_User_by_id =
>             Select_User_join_Addresses_Features_Images + "where u.id = :id";
>     public static final String Select_User_by_email =
>             Select_User_join_Addresses_Features_Images + "where u.email = lower(:email)";
>     @SqlQuery(Select_User_by_id)
>     abstract FoldingList<User> findById(@Bind("id") long id);
> }
> {code}
> However if I write and compile it as Groovy, I get "Expected 'UserDAO.Select_User_by_id' to be an inline constant of type java.lang.String not a property expression" error from compiler.
> Also if works if those constant String are in separate .java class that is accessed from annotation (within a .groovy class), but not if they are in separate .groovy file.
> So the difference seems to be that constant strings are not concatenated at compile-time in Groovy, but in Java they are? Is this by design or is it a bug that can be fixed?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)