Treat method as simple if its code block doesn't contain any linefeeds (IDEA-136990)

This commit is contained in:
Yaroslav Lepenkin
2015-02-26 14:12:03 +03:00
parent 4454b3f3fc
commit 3317a3f0db
2 changed files with 17 additions and 12 deletions
@@ -368,18 +368,8 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
private boolean shouldHandleAsSimpleMethod(@NotNull PsiMethod method) {
if (!mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE) return false;
boolean skipElement = true;
for (PsiElement element : method.getChildren()) {
if (element instanceof PsiTypeElement) skipElement = false;
if (skipElement) continue;
if (element.textContains('\n')) {
return false;
}
}
return true;
PsiCodeBlock body = method.getBody();
return body != null && !body.textContains('\n');
}
private static int getMethodHeaderStartOffset(@NotNull PsiMethod method) {
@@ -329,4 +329,19 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
"}\n"
);
}
public void testMethodIsSimple_IfCodeBlockHasNoLinefeeds() {
getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
doClassTest(
"public ModelAndView handleRequestInternalEmptyMulti(\n" +
" final HttpServletRequest httpServletRequest,\n" +
" final HttpServletResponse response)\n" +
" throws IOException {}",
"public ModelAndView handleRequestInternalEmptyMulti(\n" +
" final HttpServletRequest httpServletRequest,\n" +
" final HttpServletResponse response)\n" +
" throws IOException {}"
);
}
}