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 249216 - Refactoring method should respect blank lines
Summary: Refactoring method should respect blank lines
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-09 04:22 UTC by iluvtr
Modified: 2016-07-07 07:19 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Netbeans config of indentation and formatting (2.03 KB, application/zip)
2014-12-22 13:12 UTC, iluvtr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description iluvtr 2014-12-09 04:22:40 UTC
When you refactor a Java class, selecting lines of code, right click 'Introduce /Method' the new method generated doesn't preserve the original blank lines in the selection.

As you know is good practice to do insert new lines in situations that deserve it to get more coherence and readability in the code.
Comment 1 Svata Dedic 2014-12-12 12:02:57 UTC
Could you please include an example (attachments) of the original code + what was the result ? Also please include your settings (indentation + formatting) for Java -- introduce method seems to work acceptably in my environment, so I need to check your specific setup. Thanks.
Comment 2 iluvtr 2014-12-22 13:10:19 UTC
Ok. Here goes code sample: Select code from the line starting with XmlElement to the line starts 'plugin', right click refactor/Introduce method

 
public class JavaApplication37 {

 
    public static void main(String[] args) { 
    }

     
    public void someMethod() {
        System.out.println("testSqlMapUpdateByPrimaryKeySelectiveElementGenerated");
        XmlElement element = new XmlElement("update");
        element.addAttribute(new Attribute("id", "actualizarCliente"));
        element.addAttribute(new Attribute("parameterType", CLASE_CLIENTE));
        element.addElement(new TextElement("update cliente "));

        XmlElement setElem = new XmlElement("set");
        element.addElement(setElem);

        XmlElement elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "cliNombre != null"));
        elemIsNotNull.addElement(new TextElement("cli_nombre = #{cliNombre,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);

        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "cliActivo != null"));
        elemIsNotNull.addElement(new TextElement("cli_activo = #{cliActivo,jdbcType=BIT},"));
        setElem.addElement(elemIsNotNull);

        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "fechaCrea != null"));
        elemIsNotNull.addElement(new TextElement("fecha_crea = #{fechaCrea,jdbcType=TIMESTAMP},"));
        setElem.addElement(elemIsNotNull);

        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "fechaModif != null"));
        elemIsNotNull.addElement(new TextElement("fecha_modif = #{fechaModif,jdbcType=TIMESTAMP},"));
        setElem.addElement(elemIsNotNull);

        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "usuarioCrea != null"));
        elemIsNotNull.addElement(new TextElement("usuario_crea = #{usuarioCrea,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);

        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "usuarioModif != null"));
        elemIsNotNull.addElement(new TextElement("usuario_modif = #{usuarioModif,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);

        element.addElement(new TextElement(
                "where cli_id = #{cliId,jdbcType=INTEGER} "
                + "and emp_id = #{empId,jdbcType=INTEGER}"));

        plugin.sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(element, tabla);

        String attrParamType = obtenerValorAtributo("parameterType", element);

        assertEquals(attrParamType, "map");

        String sqlActual = obtenerSql(element);

        String sqlEsperado = "update cliente "
                + "set cli_nombre = #{bean.cliNombre},"
                + "cli_activo = #{bean.cliActivo},"
                + "fecha_modif = now(),"
                + "usuario_modif = #{usuNombre},"
                + "estado = 1 "
                + "where cli_id = #{bean.cliId} "
                + "and emp_id = #{bean.empId}";

        System.out.println("Sql actual = " + sqlActual);
        System.out.println("Sql esperado = " + sqlEsperado);
        assertEquals(sqlEsperado, sqlActual);
    }

}
Comment 3 iluvtr 2014-12-22 13:11:02 UTC
The refactored method doesn't respect new lines:

 private XmlElement newMethod() {
        XmlElement element = new XmlElement("update");
        element.addAttribute(new Attribute("id", "actualizarCliente"));
        element.addAttribute(new Attribute("parameterType", CLASE_CLIENTE));
        element.addElement(new TextElement("update cliente "));
        XmlElement setElem = new XmlElement("set");
        element.addElement(setElem);
        XmlElement elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "cliNombre != null"));
        elemIsNotNull.addElement(new TextElement("cli_nombre = #{cliNombre,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);
        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "cliActivo != null"));
        elemIsNotNull.addElement(new TextElement("cli_activo = #{cliActivo,jdbcType=BIT},"));
        setElem.addElement(elemIsNotNull);
        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "fechaCrea != null"));
        elemIsNotNull.addElement(new TextElement("fecha_crea = #{fechaCrea,jdbcType=TIMESTAMP},"));
        setElem.addElement(elemIsNotNull);
        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "fechaModif != null"));
        elemIsNotNull.addElement(new TextElement("fecha_modif = #{fechaModif,jdbcType=TIMESTAMP},"));
        setElem.addElement(elemIsNotNull);
        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "usuarioCrea != null"));
        elemIsNotNull.addElement(new TextElement("usuario_crea = #{usuarioCrea,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);
        elemIsNotNull = new XmlElement("if");
        elemIsNotNull.addAttribute(new Attribute("test", "usuarioModif != null"));
        elemIsNotNull.addElement(new TextElement("usuario_modif = #{usuarioModif,jdbcType=VARCHAR},"));
        setElem.addElement(elemIsNotNull);
        element.addElement(new TextElement(
                "where cli_id = #{cliId,jdbcType=INTEGER} "
                        + "and emp_id = #{empId,jdbcType=INTEGER}"));
        return element;
    }
Comment 4 iluvtr 2014-12-22 13:12:55 UTC
Created attachment 151239 [details]
Netbeans config of indentation and formatting
Comment 5 iluvtr 2014-12-29 17:07:10 UTC
Hi, I already left you code sample and my configuration, please check it out
Comment 6 Jiri Prox 2015-01-05 14:06:39 UTC
repropducible
Comment 7 Martin Balin 2016-07-07 07:19:08 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