Search in sources :

Example 81 with XmlAttributeValue

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

the class ResourceFoldingBuilder method buildFoldRegions.

@Override
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement element, @NotNull Document document, boolean quick) {
    if (!(element instanceof PsiJavaFile || element instanceof XmlFile) || quick && !UNIT_TEST_MODE || !isFoldingEnabled()) {
        return FoldingDescriptor.EMPTY;
    }
    final List<FoldingDescriptor> result = new ArrayList<FoldingDescriptor>();
    if (element instanceof PsiJavaFile) {
        final PsiJavaFile file = (PsiJavaFile) element;
        file.accept(new JavaRecursiveElementWalkingVisitor() {

            @Override
            public void visitReferenceExpression(PsiReferenceExpression expression) {
                InlinedResource inlinedResource = findJavaExpressionReference(expression);
                if (inlinedResource != NONE) {
                    result.add(inlinedResource.getDescriptor());
                }
                super.visitReferenceExpression(expression);
            }
        });
    } else {
        final XmlFile file = (XmlFile) element;
        file.accept(new XmlRecursiveElementVisitor() {

            @Override
            public void visitXmlAttributeValue(XmlAttributeValue value) {
                InlinedResource inlinedResource = findXmlValueReference(value);
                if (inlinedResource != NONE) {
                    FoldingDescriptor descriptor = inlinedResource.getDescriptor();
                    if (descriptor != null) {
                        result.add(descriptor);
                    }
                }
                super.visitXmlAttributeValue(value);
            }
        });
    }
    return result.toArray(new FoldingDescriptor[result.size()]);
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with XmlAttributeValue

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

the class AndroidValueResourcesTest method testNavigationInPlatformXml2_NavigateFromNameAttr.

public void testNavigationInPlatformXml2_NavigateFromNameAttr() throws Exception {
    VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
    assertNotNull(themes_holo);
    VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
    assertNotNull(themes);
    // In themes_holo.xml: point to value of "Theme" in the name attribute on line:
    //     <style name="Theme.Holo.NoActionBar">
    // Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
    myFixture.configureFromExistingVirtualFile(themes_holo);
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(776, 19));
    PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
    assertNotNull(targets);
    assertEquals(1, targets.length);
    PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
    assertInstanceOf(targetElement, XmlAttributeValue.class);
    XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
    assertEquals("Theme", targetAttrValue.getValue());
    assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
    assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
    assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement)

Example 83 with XmlAttributeValue

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

the class AndroidValueResourcesTest method testNavigationInPlatformXml1_NavigateFromParentAttr.

public void testNavigationInPlatformXml1_NavigateFromParentAttr() throws Exception {
    VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
    assertNotNull(themes_holo);
    VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
    assertNotNull(themes);
    // In themes_holo.xml: point to value of "Theme" in the parent attribute on line:
    //     <style name="Theme.Holo.Light" parent="Theme.Light">
    // Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
    myFixture.configureFromExistingVirtualFile(themes_holo);
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(406, 45));
    PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
    assertNotNull(targets);
    assertEquals(1, targets.length);
    PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
    assertInstanceOf(targetElement, XmlAttributeValue.class);
    XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
    assertEquals("Theme", targetAttrValue.getValue());
    assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
    assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
    assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement)

Example 84 with XmlAttributeValue

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

the class FlexMxmlColorAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!(element instanceof XmlAttribute) || !JavaScriptSupportLoader.isFlexMxmFile(element.getContainingFile())) {
        return;
    }
    if (!LineMarkerSettings.getSettings().isEnabled(new ColorLineMarkerProvider())) {
        return;
    }
    XmlAttribute attribute = (XmlAttribute) element;
    XmlAttributeDescriptor descriptor = attribute.getDescriptor();
    if (!(descriptor instanceof AnnotationBackedDescriptorImpl)) {
        return;
    }
    AnnotationBackedDescriptorImpl annotationBackedDescriptor = (AnnotationBackedDescriptorImpl) descriptor;
    String format = annotationBackedDescriptor.getFormat();
    if (!FlexCssPropertyDescriptor.COLOR_FORMAT.equals(format)) {
        return;
    }
    final String value = attribute.getValue();
    if (value == null || value.length() == 0) {
        return;
    }
    if (!JSCommonTypeNames.ARRAY_CLASS_NAME.equals(annotationBackedDescriptor.getType())) {
        XmlAttributeValue valueElement = attribute.getValueElement();
        if (valueElement != null) {
            Annotation annotation = holder.createInfoAnnotation(valueElement, null);
            annotation.setGutterIconRenderer(new MyRenderer(value, attribute));
        }
    }
}
Also used : ColorLineMarkerProvider(com.intellij.ui.ColorLineMarkerProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AnnotationBackedDescriptorImpl(com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl) Annotation(com.intellij.lang.annotation.Annotation)

Example 85 with XmlAttributeValue

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

the class DartPackagePathReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) {
    if (!(psiElement instanceof XmlAttributeValue) || !HtmlUtil.isHtmlFile(psiElement.getContainingFile()))
        return PsiReference.EMPTY_ARRAY;
    final PsiElement parent = psiElement.getParent();
    if (!(parent instanceof XmlAttribute))
        return PsiReference.EMPTY_ARRAY;
    final XmlTag tag = ((XmlAttribute) parent).getParent();
    if (tag == null)
        return PsiReference.EMPTY_ARRAY;
    final VirtualFile file = DartResolveUtil.getRealVirtualFile(psiElement.getContainingFile());
    if (file == null)
        return PsiReference.EMPTY_ARRAY;
    if (!canContainDartPackageReference(tag.getName(), ((XmlAttribute) parent).getName()))
        return PsiReference.EMPTY_ARRAY;
    if (PubspecYamlUtil.findPubspecYamlFile(psiElement.getProject(), file) == null)
        return PsiReference.EMPTY_ARRAY;
    return getDartPackageReferences(psiElement, DartUrlResolver.getInstance(psiElement.getProject(), file));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

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