Search in sources :

Example 6 with XPathExpression

use of org.intellij.lang.xpath.psi.XPathExpression 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 7 with XPathExpression

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

the class MakeTypeExplicitFix method invokeImpl.

public void invokeImpl(Project project, PsiFile file) throws IncorrectOperationException {
    XPathExpression myElement = (XPathExpression) getStartElement();
    if (myType == XPathType.BOOLEAN) {
        if (myElement.getType() == XPathType.STRING) {
            final String text;
            if (ExpectedTypeUtil.isExplicitConversion(myElement)) {
                final XPathExpression expr = ExpectedTypeUtil.unparenthesize(myElement);
                assert expr != null;
                text = ((XPathFunctionCall) expr).getArgumentList()[0].getText();
            } else {
                text = myElement.getText();
            }
            replace("string-length(" + text + ") > 0");
            return;
        } else if (myElement.getType() == XPathType.NODESET) {
            replace("count(" + myElement.getText() + ") > 0");
            return;
        }
    }
    replace(myType.getName() + "(" + myElement.getText() + ")");
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression)

Example 8 with XPathExpression

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

the class XsltVariableImpl method getType.

@NotNull
public XPathType getType() {
    final XPathType declaredType = XsltCodeInsightUtil.getDeclaredType(getTag());
    if (declaredType != null) {
        return declaredType;
    }
    final XmlAttribute attr = getTag().getAttribute("type", XsltSupport.PLUGIN_EXTENSIONS_NS);
    if (attr != null) {
        return XPathType.fromString(attr.getValue());
    }
    final XPathExpression value = getValue();
    if (value instanceof XPathVariableReference) {
        // recursive reference <xsl:variable name="foo" select="$foo" />
        final XPathVariableReference reference = (XPathVariableReference) value;
        if (reference.resolve() == this) {
            return XPathType.UNKNOWN;
        }
    }
    return value != null ? value.getType() : XPathType.UNKNOWN;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathType(org.intellij.lang.xpath.psi.XPathType) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XPathVariableReference(org.intellij.lang.xpath.psi.XPathVariableReference) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with XPathExpression

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

the class XPath2ExpressionTest method getExpression.

private XPathExpression getExpression() throws NoSuchMethodException {
    final XPathFile file = (XPathFile) myFixture.getFile();
    final XPathExpression expression = file.getExpression();
    assertNotNull(expression);
    return expression;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression)

Example 10 with XPathExpression

use of org.intellij.lang.xpath.psi.XPathExpression 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)

Aggregations

XPathExpression (org.intellij.lang.xpath.psi.XPathExpression)13 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)4 XmlTag (com.intellij.psi.xml.XmlTag)3 XPathBinaryExpression (org.intellij.lang.xpath.psi.XPathBinaryExpression)3 EditorWindow (com.intellij.injected.editor.EditorWindow)2 Editor (com.intellij.openapi.editor.Editor)2 SelectionModel (com.intellij.openapi.editor.SelectionModel)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiFile (com.intellij.psi.PsiFile)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XPathFile (org.intellij.lang.xpath.XPathFile)2 XPathType (org.intellij.lang.xpath.psi.XPathType)2 XPathVariableReference (org.intellij.lang.xpath.psi.XPathVariableReference)2 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 ASTNode (com.intellij.lang.ASTNode)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 PsiReference (com.intellij.psi.PsiReference)1