From c8bba3a6654b80ef36efbc3ef274a78403fed821 Mon Sep 17 00:00:00 2001 From: sweinreuter Date: Mon, 11 Apr 2011 09:32:51 +0200 Subject: [PATCH] IDEA-67727: Quickfix --- ...risonFix.java => ExpressionReplacementFix.java} | 4 ++-- .../lang/xpath/validation/XPathAnnotator.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) rename plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/{ConsecutiveComparisonFix.java => ExpressionReplacementFix.java} (93%) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ConsecutiveComparisonFix.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpressionReplacementFix.java similarity index 93% rename from plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ConsecutiveComparisonFix.java rename to plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpressionReplacementFix.java index c5d33a8c139a..7e62ee82885c 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ConsecutiveComparisonFix.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/ExpressionReplacementFix.java @@ -24,11 +24,11 @@ import org.intellij.lang.xpath.psi.XPathBinaryExpression; import org.intellij.lang.xpath.psi.impl.XPathChangeUtil; import org.jetbrains.annotations.NotNull; -class ConsecutiveComparisonFix implements IntentionAction { +class ExpressionReplacementFix implements IntentionAction { private final String myReplacement; private final XPathBinaryExpression myExpr; - public ConsecutiveComparisonFix(String replacement, XPathBinaryExpression expr) { + public ExpressionReplacementFix(String replacement, XPathBinaryExpression expr) { myReplacement = replacement; myExpr = expr; } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java index c9f6603590e1..af95c1fcb750 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/validation/XPathAnnotator.java @@ -112,7 +112,14 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota if (operator != XPathTokenTypes.STAR && XPath2TokenTypes.KEYWORDS.contains(operator)) { final String op = o.getOperationSign(); if (o.getText().startsWith(operand.getText() + op)) { - myHolder.createErrorAnnotation(o, "Number literal must be followed by whitespace in XPath 2"); + final Annotation annotation = + myHolder.createErrorAnnotation(o, "Number literal must be followed by whitespace in XPath 2"); + + final XPathExpression rOperand = o.getROperand(); + if (rOperand != null) { + final String replacement = operand.getText() + " " + op + " " + rOperand.getText(); + annotation.registerFix(new ExpressionReplacementFix(replacement, o)); + } } } } @@ -123,7 +130,7 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota final XPathExpression rOperand = o.getROperand(); if (rOperand != null) { final String replacement = "(" + operand.getText() + ") " + o.getOperationSign() + " " + rOperand.getText(); - annotation.registerFix(new ConsecutiveComparisonFix(replacement, o)); + annotation.registerFix(new ExpressionReplacementFix(replacement, o)); } } } @@ -203,6 +210,9 @@ public final class XPathAnnotator extends XPath2ElementVisitor implements Annota private static void checkFunctionCall(AnnotationHolder holder, XPathFunctionCall call, @NotNull ContextProvider contextProvider) { final ASTNode node = call.getNode().findChildByType(XPathTokenTypes.FUNCTION_NAME); + if (node == null) { + return; + } final QName name = contextProvider.getQName(call); final XPathFunction function = call.resolve();