corrected method header text range calculation to work correctly with constructors (fixes IDEA-132781)

This commit is contained in:
Yaroslav Lepenkin
2014-11-21 20:04:39 +02:00
parent a8238e931b
commit c86bb7f553
2 changed files with 34 additions and 4 deletions
@@ -381,11 +381,13 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
return true;
}
private static int getMethodHeaderStartOffset(@NotNull PsiMethod method) {
for (PsiElement element : method.getChildren()) {
if (element instanceof PsiTypeElement) {
return element.getTextRange().getStartOffset();
PsiTypeParameterList typeParameterList = PsiTreeUtil.findChildOfType(method, PsiTypeParameterList.class);
if (typeParameterList != null) {
PsiElement nextNonWsElem = PsiTreeUtil.skipSiblingsForward(typeParameterList, PsiWhiteSpace.class);
if (nextNonWsElem != null) {
return nextNonWsElem.getTextRange().getStartOffset();
}
}
return method.getTextRange().getStartOffset();
@@ -289,4 +289,32 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
"}"
);
}
public void testConstructorLeftBraceWithComment() {
getSettings().METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED;
doClassTest(
"/**\n" +
" *\n" +
" */\n" +
" public Test() {\n" +
"}\n",
"/**\n" +
" *\n" +
" */\n" +
"public Test() {\n" +
"}\n"
);
}
public void testConstructorLeftBraceWithAnnotation() {
getSettings().METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED;
doClassTest(
" @Deprecated\n" +
"public Test() {\n" +
"}\n",
"@Deprecated\n" +
"public Test() {\n" +
"}\n"
);
}
}