SSR: remove extra semicolon (IDEA-227210)

GitOrigin-RevId: 33a0b298fe7796738cb092a5bce0e934debab5cd
This commit is contained in:
Bas Leijdekkers
2019-11-20 11:10:01 +01:00
committed by intellij-monorepo-bot
parent 1c43cee370
commit 80b440df83
2 changed files with 51 additions and 28 deletions

View File

@@ -961,27 +961,26 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
}
private static int removeExtraSemicolon(ParameterInfo info, int offset, StringBuilder result, MatchResult match) {
if (info.isStatementContext()) {
final int index = offset + info.getStartIndex();
final PsiElement matchElement = (match == null) ? null : match.getMatch();
if (result.charAt(index) == ';' &&
( matchElement == null ||
( result.charAt(index-1)=='}' &&
!(matchElement instanceof PsiDeclarationStatement) && // array init in dcl
!(matchElement instanceof PsiNewExpression) && // array initializer
!(matchElement instanceof PsiArrayInitializerExpression)
) ||
( match.isMultipleMatch() // ; in comment
? match.getChildren().get(match.getChildren().size() - 1).getMatch() instanceof PsiComment
: matchElement instanceof PsiComment
)
)
) {
result.deleteCharAt(index);
--offset;
}
if (!info.isStatementContext()) {
return offset;
}
final int index = offset + info.getStartIndex();
if (result.charAt(index) != ';') {
return offset;
}
final PsiElement matchElement;
if (match == null) matchElement = null;
else if (match.isMultipleMatch()) matchElement = match.getChildren().get(match.size() - 1).getMatch();
else matchElement = match.getMatch();
if (matchElement == null || matchElement instanceof PsiComment ||
result.charAt(index - 1) == '}' &&
!(matchElement instanceof PsiDeclarationStatement) && // array init in dcl
!(matchElement instanceof PsiNewExpression) && // array initializer
!(matchElement instanceof PsiArrayInitializerExpression)) {
result.deleteCharAt(index);
--offset;
}
return offset;
}