Search in sources :

Example 11 with XPathExpression

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

Example 12 with XPathExpression

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

the class Xslt2RefactoringTest method doExtractFunction.

private void doExtractFunction() throws Throwable {
    myFixture.configureByFile(getTestFileName() + ".xsl");
    final Editor editor = myFixture.getEditor();
    assertTrue("Selection required", editor.getSelectionModel().hasSelection());
    editor.getCaretModel().moveToOffset(editor.getSelectionModel().getSelectionStart());
    final XsltExtractFunctionAction action = new XsltExtractFunctionAction() {

        @Override
        protected RefactoringOptions getSettings(XPathExpression expression, Set<XPathExpression> matchingExpressions) {
            return new RefactoringOptions() {

                @Override
                public boolean isCanceled() {
                    return false;
                }

                @Override
                public String getName() {
                    return "f:foo";
                }
            };
        }
    };
    final PsiFile file = InjectedLanguageUtil.findInjectedPsiNoCommit(myFixture.getFile(), editor.getCaretModel().getOffset());
    final Editor editorWindow = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, file);
    assertTrue(editorWindow instanceof EditorWindow);
    action.invoke(myFixture.getProject(), editorWindow, file, null);
    myFixture.checkResultByFile(getTestFileName() + "_after.xsl");
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) Set(java.util.Set) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) XsltExtractFunctionAction(org.intellij.lang.xpath.xslt.refactoring.XsltExtractFunctionAction) RefactoringOptions(org.intellij.lang.xpath.xslt.refactoring.RefactoringOptions) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 13 with XPathExpression

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

the class IntroduceParameterProcessor method findUsages.

@NotNull
protected UsageInfo[] findUsages() {
    int usageCount = myOtherExpressions.size() + 1;
    final List<PsiElement> callsToUpdate;
    if (!mySettings.isCreateDefault()) {
        assert myTemplate != null;
        final Collection<PsiReference> references = ReferencesSearch.search(myTemplate, myTemplate.getUseScope(), false).findAll();
        callsToUpdate = new ArrayList<>(references.size());
        for (PsiReference reference : references) {
            final PsiElement e = reference.getElement();
            final XmlTag tag = PsiTreeUtil.getContextOfType(e, XmlTag.class, true);
            if (tag != null && XsltSupport.isTemplateCall(tag)) {
                callsToUpdate.add(tag);
            }
        }
        usageCount += callsToUpdate.size();
    } else {
        //noinspection unchecked
        callsToUpdate = Collections.emptyList();
    }
    final UsageInfo[] usageInfos = new UsageInfo[usageCount];
    usageInfos[0] = XPathUsageInfo.create(myExpression);
    int i = 1;
    for (XPathExpression expression : myOtherExpressions) {
        usageInfos[i++] = XPathUsageInfo.create(expression);
    }
    for (PsiElement o : callsToUpdate) {
        usageInfos[i++] = new UsageInfo(o, false);
    }
    return usageInfos;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

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