'hasSyntaxErrors' check moved from Diagnostic to PositioningStrategy

This makes possible to mark diagnostic errors when syntax error are present (by overriding isValid in PositioningStrategy subclasses).
This commit is contained in:
Wojciech Lopata
2013-03-05 18:51:57 +01:00
committed by Evgeny Gerashchenko
parent 7e5794cc7f
commit 09c3edcbc7
3 changed files with 16 additions and 15 deletions
@@ -71,20 +71,7 @@ public abstract class AbstractDiagnostic<E extends PsiElement> implements Parame
@Override
public boolean isValid() {
if (!getFactory().isValid(this)) return false;
if (hasSyntaxErrors(psiElement)) return false;
if (psiElement.getNode().findChildByType(JetNodeTypes.IDE_TEMPLATE_EXPRESSION) != null) return false;
return true;
}
private static boolean hasSyntaxErrors(@NotNull PsiElement psiElement) {
if (psiElement instanceof PsiErrorElement) return true;
PsiElement lastChild = psiElement.getLastChild();
if (lastChild != null && hasSyntaxErrors(lastChild)) return true;
PsiElement[] children = psiElement.getChildren();
if (children.length > 0 && hasSyntaxErrors(children[children.length - 1])) return true;
return false;
}
}
@@ -139,7 +139,7 @@ public class PositioningStrategies {
}
@Override
public boolean isValid(@NotNull PsiNameIdentifierOwner element) {
return element.getNameIdentifier() != null;
return element.getNameIdentifier() != null && super.isValid(element);
}
};
@@ -299,6 +299,8 @@ public class PositioningStrategies {
@Override
public boolean isValid(@NotNull JetDeclarationWithBody element) {
if (!super.isValid(element)) return false;
JetExpression bodyExpression = element.getBodyExpression();
if (!(bodyExpression instanceof JetBlockExpression)) return false;
if (((JetBlockExpression) bodyExpression).getLastBracketRange() == null) return false;
@@ -32,7 +32,7 @@ public class PositioningStrategy<E extends PsiElement> {
}
public boolean isValid(@NotNull E element) {
return true;
return !hasSyntaxErrors(element);
}
@NotNull
@@ -49,4 +49,16 @@ public class PositioningStrategy<E extends PsiElement> {
protected static List<TextRange> markRange(@NotNull TextRange range) {
return Collections.singletonList(range);
}
protected static boolean hasSyntaxErrors(@NotNull PsiElement psiElement) {
if (psiElement instanceof PsiErrorElement) return true;
PsiElement lastChild = psiElement.getLastChild();
if (lastChild != null && hasSyntaxErrors(lastChild)) return true;
PsiElement[] children = psiElement.getChildren();
if (children.length > 0 && hasSyntaxErrors(children[children.length - 1])) return true;
return false;
}
}