Got rid of returning empty range list in position strategies (in places where they don't depend on syntax errors).

This commit is contained in:
Evgeny Gerashchenko
2012-04-29 13:43:18 +04:00
parent 0fd34a455f
commit abdf34418a
3 changed files with 13 additions and 11 deletions
@@ -247,12 +247,12 @@ public interface Errors {
public List<TextRange> mark(@NotNull JetDeclarationWithBody element) { public List<TextRange> mark(@NotNull JetDeclarationWithBody element) {
JetExpression bodyExpression = element.getBodyExpression(); JetExpression bodyExpression = element.getBodyExpression();
if (!(bodyExpression instanceof JetBlockExpression)) { if (!(bodyExpression instanceof JetBlockExpression)) {
return Collections.emptyList(); return markElement(element);
} }
JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression; JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression;
TextRange lastBracketRange = blockExpression.getLastBracketRange(); TextRange lastBracketRange = blockExpression.getLastBracketRange();
if (lastBracketRange == null) { if (lastBracketRange == null) {
return Collections.emptyList(); return markElement(element);
} }
return markRange(lastBracketRange); return markRange(lastBracketRange);
} }
@@ -403,7 +403,7 @@ public interface Errors {
JetClass klass = (JetClass)jetDeclaration; JetClass klass = (JetClass)jetDeclaration;
PsiElement nameAsDeclaration = klass.getNameIdentifier(); PsiElement nameAsDeclaration = klass.getNameIdentifier();
if (nameAsDeclaration == null) { if (nameAsDeclaration == null) {
return markRange(klass.getTextRange()); return markElement(klass);
} }
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) { if (primaryConstructorParameterList == null) {
@@ -416,7 +416,7 @@ public interface Errors {
} }
else { else {
// safe way // safe way
return markRange(jetDeclaration.getTextRange()); return markElement(jetDeclaration);
} }
} }
}); });
@@ -59,10 +59,9 @@ public class PositioningStrategies {
returnTypeRef = accessor.getReturnTypeReference(); returnTypeRef = accessor.getReturnTypeReference();
nameNode = accessor.getNamePlaceholder().getNode(); nameNode = accessor.getNamePlaceholder().getNode();
} }
if (returnTypeRef != null) return Collections.singletonList(returnTypeRef.getTextRange()); if (returnTypeRef != null) return markElement(returnTypeRef);
if (nameNode != null) return Collections.singletonList(nameNode.getTextRange()); if (nameNode != null) return markNode(nameNode);
return super.mark(declaration); return markElement(declaration);
} }
private ASTNode getNameNode(JetNamedDeclaration function) { private ASTNode getNameNode(JetNamedDeclaration function) {
@@ -100,9 +99,9 @@ public class PositioningStrategies {
assert modifierList != null; assert modifierList != null;
ASTNode node = modifierList.getModifierNode(token); ASTNode node = modifierList.getModifierNode(token);
assert node != null; assert node != null;
return Collections.singletonList(node.getTextRange()); return markNode(node);
} }
return Collections.emptyList(); return markElement(modifierListOwner);
} }
}; };
} }
@@ -34,7 +34,10 @@ public class UnresolvedReferenceDiagnosticFactory extends DiagnosticFactory1<Jet
@Override @Override
public List<TextRange> mark(@NotNull JetReferenceExpression element) { public List<TextRange> mark(@NotNull JetReferenceExpression element) {
if (element instanceof JetArrayAccessExpression) { if (element instanceof JetArrayAccessExpression) {
return ((JetArrayAccessExpression) element).getBracketRanges(); List<TextRange> ranges = ((JetArrayAccessExpression) element).getBracketRanges();
if (!ranges.isEmpty()) {
return ranges;
}
} }
return Collections.singletonList(element.getTextRange()); return Collections.singletonList(element.getTextRange());
} }