Skip to content

Commit

Permalink
ROASTER-96: Adds a blank line after imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 7, 2016
1 parent 9ce0a11 commit 427f1b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
Expand Down Expand Up @@ -178,6 +179,8 @@ private static Properties readConfigInternal()
properties.setProperty(JavaCore.COMPILER_SOURCE, CompilerOptions.VERSION_1_8);
properties.setProperty(JavaCore.COMPILER_COMPLIANCE, CompilerOptions.VERSION_1_8);
properties.setProperty(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_8);
// ROASTER-96: Add a blank line after imports. "1" is equivalent to TRUE in the formatter XML file
properties.setProperty(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_IMPORTS, "1");
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.lang.annotation.Documented;

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.junit.BeforeClass;
Expand All @@ -34,4 +36,18 @@ public void testClassCreatesStub() throws Exception
assertTrue(jc.isPublic());
}

@Test
public void testImportStatementHasEmptyLineBeforeClassDeclaration() throws Exception
{
String expected = "package org.foo;\n" +
"\n" +
"import java.lang.annotation.Documented;\n\n" +
"@Documented\n" +
"public class JavaClass {\n" +
"}";

jc.setPackage("org.foo").addAnnotation(Documented.class);
assertEquals(expected, jc.toString());
}

}

0 comments on commit 427f1b4

Please sign in to comment.