Search in sources :

Example 1 with XPathBinaryExpression

use of org.intellij.lang.xpath.psi.XPathBinaryExpression in project intellij-community by JetBrains.

the class HardwiredNamespacePrefix method createVisitor.

protected Visitor createVisitor(final InspectionManager manager, final boolean isOnTheFly) {
    return new Visitor(manager, isOnTheFly) {

        protected void checkExpression(XPathExpression expression) {
            if (!(expression instanceof XPathBinaryExpression)) {
                return;
            }
            final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
            if (expr.getOperator() == XPathTokenTypes.EQ) {
                final XPathExpression lop = expr.getLOperand();
                final XPathExpression rop = expr.getROperand();
                if (isNameComparison(lop, rop)) {
                    assert rop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(rop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameComparison(rop, lop)) {
                    assert lop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(lop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameFunctionCall(lop)) {
                // TODO
                } else if (isNameFunctionCall(rop)) {
                // TODO
                }
            }
        }
    };
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor)

Example 2 with XPathBinaryExpression

use of org.intellij.lang.xpath.psi.XPathBinaryExpression in project intellij-community by JetBrains.

the class XPath2ExpressionTest method doTest.

protected XPathType doTest(boolean symmetric) throws Throwable {
    myFixture.configureByFile(getTestFileName() + ".xpath2");
    final XPathExpression expression = getExpression();
    // all these cases must be green
    myFixture.checkHighlighting();
    if (symmetric && expression instanceof XPathBinaryExpression) {
        final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
        if (expr.getLOperand().getType() != expr.getROperand().getType()) {
            myFixture.configureByText(XPathFileType.XPATH2, expr.getROperand().getText() + " " + expr.getOperationSign() + " " + expr.getLOperand().getText());
            assertEquals(getExpression().getType(), expression.getType());
            myFixture.checkHighlighting();
        }
    }
    final XPathType type = expression.getType();
    if (type instanceof XPath2SequenceType) {
        return ((XPath2SequenceType) type).getType();
    }
    return type;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathType(org.intellij.lang.xpath.psi.XPathType) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) XPath2SequenceType(org.intellij.lang.xpath.psi.XPath2SequenceType)

Example 3 with XPathBinaryExpression

use of org.intellij.lang.xpath.psi.XPathBinaryExpression in project intellij-community by JetBrains.

the class RemoveExplicitConversionFix method invokeImpl.

public void invokeImpl(Project project, PsiFile file) throws IncorrectOperationException {
    PsiElement myElement = getStartElement();
    final XPathExpression arg0 = ((XPathFunctionCall) myElement).getArgumentList()[0];
    final XPathExpression outer = PsiTreeUtil.getParentOfType(myElement, XPathExpression.class);
    if (arg0 instanceof XPathBinaryExpression && outer instanceof XPathBinaryExpression) {
        // TODO make this smarter by determining operator precedence
        replace("(" + arg0.getText() + ")");
    } else {
        replace(arg0.getText());
    }
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XPathBinaryExpression (org.intellij.lang.xpath.psi.XPathBinaryExpression)3 XPathExpression (org.intellij.lang.xpath.psi.XPathExpression)3 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 PsiElement (com.intellij.psi.PsiElement)1 XPath2SequenceType (org.intellij.lang.xpath.psi.XPath2SequenceType)1 XPathType (org.intellij.lang.xpath.psi.XPathType)1