This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 241013

Summary: String annotation values are generated as evaluated expressions
Product: java Reporter: Jaroslav Tulach <jtulach>
Component: SourceAssignee: Svata Dedic <sdedic>
Status: RESOLVED WONTFIX    
Severity: normal CC: jlahoda
Priority: P3    
Version: 7.4   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description Jaroslav Tulach 2014-01-27 14:28:38 UTC
I have a hint which generates potentially long string. See contrib/project.jsjava module: http://hg.netbeans.org/main/contrib/rev/5d8e7ac3015a

To eliminate very long lines I am composing the string as a concatenation of strings, however the formatter insist on putting all the string parts on a single line. Need a way to force line break (using TreeMaker API) or change in hint's formatter to do that automatically.

My hint can be applied to:

 private native void setHandlerFunctions( Element e ) /*-{
        var that = this;
        $wnd.jQuery(e).on('hide', function (e) {
            that.@org.uberfire.client.common.Modal::onHide(Lcom/google/gwt/user/client/Event;)(e);
        });
        $wnd.jQuery(e).on('hidden', function (e) {
            that.@org.uberfire.client.common.Modal::onHidden(Lcom/google/gwt/user/client/Event;)(e);
        });
        $wnd.jQuery(e).on('show', function (e) {
            that.@org.uberfire.client.common.Modal::onShow(Lcom/google/gwt/user/client/Event;)(e);
        });
        $wnd.jQuery(e).on('shown', function (e) {
            that.@org.uberfire.client.common.Modal::onShown(Lcom/google/gwt/user/client/Event;)(e);
        });
    }-*/;

and would optimally generate something like:

    @JavaScriptBody(args = {"e"}, javacall = true, body = "\n" + 
            "        var that = this;\n" + 
            "        $wnd.jQuery(e).on('hide', function (e) {\n" + 
            "            that.@org.uberfire.client.common.Modal::onHide()(e);\n" + 
            "        });\n" + "        $wnd.jQuery(e).on('hidden', function (e) {\n" + 
            "            that.@org.uberfire.client.common.Modal::onHidden(Lcom/google/gwt/user/client/Event;)(e);\n" + 
            "        });\n" + 
            "        $wnd.jQuery(e).on('show', function (e) {\n" + 
            "            that.@org.uberfire.client.common.Modal::onShow(Lcom/google/gwt/user/client/Event;)(e);\n" + 
            "        });\n" + 
            "        $wnd.jQuery(e).on('shown', function (e) {\n" + 
            "            that.@org.uberfire.client.common.Modal::onShown(Lcom/google/gwt/user/client/Event;)(e);\n" + 
            "        });\n" + 
            "    ")
    private native void setHandlerFunctions( Element e );
Comment 1 Jaroslav Tulach 2014-01-28 10:17:36 UTC
Here is a way to enforce new lines suggested by Jan:
http://hg.netbeans.org/main/contrib/rev/363fb381d03f
Comment 2 Svata Dedic 2014-01-28 17:35:36 UTC
Isn't using an Identifier to represent a concatenation of literals a sort of hack ?
Comment 3 Svata Dedic 2014-01-29 16:22:40 UTC
The actual reason for the behaviour is the code generator VeryPretty.printAnnotationsFormatted, which parses the annotation text back in Reformatter.reformat; but the javac will evaluate compile-time constants, so the String expression is evaluated and pieces concatenated together. The result is then generated into the source.

This applies not only to long Strings, but in general to all compile-time non-literal constants.
Comment 4 Martin Balin 2016-07-07 07:17:45 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss