Search in sources :

Example 86 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.

the class AngularUiRouterTest method checkNavigation.

private void checkNavigation(PsiFile file, String state, String referencedTextExpected, String appStatesFileName) {
    referencedTextExpected = referencedTextExpected == null ? state : referencedTextExpected;
    final PsiElement inObj = getElement(file, "ui-sref=\"" + state + "\"");
    Assert.assertEquals("ui-sref", inObj.getText());
    Assert.assertTrue(inObj.getParent() instanceof XmlAttribute);
    final XmlAttributeValue element = ((XmlAttribute) inObj.getParent()).getValueElement();
    Assert.assertNotNull(element);
    final PsiReference reference = element.getReference();
    Assert.assertEquals(state, reference.getCanonicalText());
    final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
    if (results.length > 1) {
        for (ResolveResult result : results) {
            final PsiElement resolvedElement = result.getElement();
            Assert.assertEquals(appStatesFileName, resolvedElement.getContainingFile().getName());
            if (StringUtil.equals(referencedTextExpected, StringUtil.unquoteString(resolvedElement.getNavigationElement().getText()))) {
                return;
            }
        }
        Assert.assertTrue(false);
    } else {
        final PsiElement resolve = reference.resolve();
        Assert.assertNotNull(state, resolve);
        Assert.assertEquals(appStatesFileName, resolve.getContainingFile().getName());
        Assert.assertEquals(referencedTextExpected, StringUtil.unquoteString(resolve.getNavigationElement().getText()));
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 87 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.

the class AngularJSReferencesContributor method xmlAttributePattern.

private static PsiElementPattern.Capture<XmlAttributeValue> xmlAttributePattern(@NotNull final String attributeName) {
    return PlatformPatterns.psiElement(XmlAttributeValue.class).and(new FilterPattern(new ElementFilter() {

        @Override
        public boolean isAcceptable(Object element, @Nullable PsiElement context) {
            final XmlAttributeValue attributeValue = (XmlAttributeValue) element;
            final PsiElement parent = attributeValue.getParent();
            if (parent instanceof XmlAttribute && attributeName.equals(((XmlAttribute) parent).getName())) {
                return AngularIndexUtil.hasAngularJS(attributeValue.getProject());
            }
            return false;
        }

        @Override
        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    }));
}
Also used : FilterPattern(com.intellij.psi.filters.position.FilterPattern) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ElementFilter(com.intellij.psi.filters.ElementFilter) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Nullable(org.jetbrains.annotations.Nullable) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 88 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.

the class FlexResolveHelper method bindReferenceToElement.

@Override
public JSReferenceExpression bindReferenceToElement(JSReferenceExpression ref, String qName, String newName, boolean justMakeQualified, PsiNamedElement element) {
    PsiFile file;
    if (qName != null && (element instanceof XmlBackedJSClass || (element instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) || (file = element.getContainingFile()) == null || file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4))) {
        boolean qualify;
        boolean doImport;
        if (justMakeQualified || ref.getParent() instanceof JSImportStatement || element instanceof PsiDirectoryContainer || (ref.getParent() instanceof JSReferenceListMember && ref.getContainingFile().getContext() instanceof XmlAttributeValue)) {
            qualify = true;
            doImport = false;
        } else {
            doImport = JSImportHandlingUtil.evaluateImportStatus(newName, ref) == JSImportHandlingUtil.ImportStatus.ABSENT && JSImportHandlingUtil.evaluateImportStatus(ref.getReferencedName(), ref) == JSImportHandlingUtil.ImportStatus.ABSENT;
            JSQualifiedNamedElement qualifiedElement = null;
            if (element instanceof JSQualifiedNamedElement) {
                qualifiedElement = (JSQualifiedNamedElement) element;
            } else if (element instanceof JSFile) {
                qualifiedElement = JSPsiImplUtils.findQualifiedElement((JSFile) element);
            } else if (element instanceof XmlFile) {
                qualifiedElement = XmlBackedJSClassFactory.getXmlBackedClass(((XmlFile) element));
            }
            assert qualifiedElement != null : qualifiedElement.getClass();
            // at this moment package declaration is out of date so element has it's original qName
            qualify = JSResolveUtil.shortReferenceIsAmbiguousOrUnequal(newName, ref, qualifiedElement.getQualifiedName(), null);
        }
        if (qualify) {
            ASTNode newChild = JSChangeUtil.createExpressionFromText(ref.getProject(), qName);
            ref.getParent().getNode().replaceChild(ref.getNode(), newChild);
            ref = (JSReferenceExpression) newChild.getPsi();
        }
        if (doImport && qName.indexOf('.') != -1 && !StringUtil.getPackageName(qName).equals(JSResolveUtil.getPackageNameFromPlace(ref))) {
            final SmartPsiElementPointer<JSReferenceExpression> refPointer = SmartPointerManager.getInstance(ref.getProject()).createSmartPsiElementPointer(ref);
            ImportUtils.doImport(ref, qName, false);
            ref = refPointer.getElement();
        }
    }
    return ref;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) ASTNode(com.intellij.lang.ASTNode) JSFile(com.intellij.lang.javascript.psi.JSFile)

Example 89 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.

the class FxDefinitionBackedDescriptor method getDeclarationByFxDefinitionTag.

@Nullable
private static XmlAttributeValue getDeclarationByFxDefinitionTag(@NotNull final XmlTag xmlTag) {
    if (!xmlTag.isValid() || xmlTag.getParent() instanceof XmlDocument) {
        return null;
    }
    XmlTag rootTag = xmlTag;
    XmlTag parent;
    while ((parent = rootTag.getParentTag()) != null) {
        rootTag = parent;
    }
    final XmlTag[] subTags = rootTag.getSubTags();
    final XmlTag libraryTag = subTags.length > 0 && FlexPredefinedTagNames.LIBRARY.equals(subTags[0].getLocalName()) && JavaScriptSupportLoader.MXML_URI3.equals(subTags[0].getNamespace()) ? subTags[0] : null;
    final XmlTag[] definitionTags = libraryTag == null ? XmlTag.EMPTY : libraryTag.findSubTags(CodeContext.DEFINITION_TAG_NAME, JavaScriptSupportLoader.MXML_URI3);
    final String localName = xmlTag.getLocalName();
    for (final XmlTag definitionTag : definitionTags) {
        final XmlAttribute nameAttribute = definitionTag.getAttribute(MxmlLanguageTagsUtil.NAME_ATTRIBUTE);
        final XmlAttributeValue attributeValue = nameAttribute == null ? null : nameAttribute.getValueElement();
        if (attributeValue != null && localName.equals(attributeValue.getValue())) {
            return attributeValue;
        }
    }
    return null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.

the class AndroidGotoRelatedTest method testActivityToLayoutAndManifest.

public void testActivityToLayoutAndManifest() throws Exception {
    final VirtualFile layout = myFixture.copyFileToProject(BASE_PATH + "layout1.xml", "res/layout/layout.xml");
    final VirtualFile manifestFile = myFixture.copyFileToProject(BASE_PATH + "Manifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML);
    final VirtualFile activityFile = myFixture.copyFileToProject(BASE_PATH + "Activity1.java", "src/p1/p2/MyActivity.java");
    AndroidGotoRelatedProvider.ourAddDeclarationToManifest = true;
    final List<GotoRelatedItem> items;
    try {
        items = doGotoRelatedFile(activityFile);
    } finally {
        AndroidGotoRelatedProvider.ourAddDeclarationToManifest = false;
    }
    assertEquals(2, items.size());
    XmlAttributeValue manifestDeclarationTarget = null;
    PsiFile psiFileTarget = null;
    for (GotoRelatedItem item : items) {
        final PsiElement element = item.getElement();
        if (element instanceof PsiFile) {
            psiFileTarget = (PsiFile) element;
        } else if (element instanceof XmlAttributeValue) {
            manifestDeclarationTarget = (XmlAttributeValue) element;
        } else {
            fail("Unexpected element: " + element);
        }
    }
    assertEquals(layout, psiFileTarget.getVirtualFile());
    assertEquals(manifestFile, manifestDeclarationTarget.getContainingFile().getVirtualFile());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)127 XmlAttribute (com.intellij.psi.xml.XmlAttribute)57 XmlTag (com.intellij.psi.xml.XmlTag)50 NotNull (org.jetbrains.annotations.NotNull)38 PsiElement (com.intellij.psi.PsiElement)31 Nullable (org.jetbrains.annotations.Nullable)24 PsiReference (com.intellij.psi.PsiReference)20 XmlFile (com.intellij.psi.xml.XmlFile)19 TextRange (com.intellij.openapi.util.TextRange)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 DomElement (com.intellij.util.xml.DomElement)9 PsiFile (com.intellij.psi.PsiFile)8 LazyValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper)7 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 Module (com.intellij.openapi.module.Module)5 ValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)5