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.
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.
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.
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); } }
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; }
Created attachment 151239 [details] Netbeans config of indentation and formatting
Hi, I already left you code sample and my configuration, please check it out
repropducible
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