Search in sources :

Example 86 with XmlAttribute

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

the class StateWriter method readDeclaration.

public void readDeclaration(XmlTag parentTag) {
    initNames();
    XmlTag[] tags = parentTag.getSubTags();
    states.ensureCapacity(tags.length);
    for (XmlTag tag : tags) {
        State state = new State(this, states.size());
        states.add(state);
        for (XmlAttribute attribute : tag.getAttributes()) {
            if (attribute.getLocalName().equals(FlexStateElementNames.NAME)) {
                state.name = attribute.getDisplayValue();
                addNameToStateMap(state.name, state);
            } else if (attribute.getLocalName().equals(FlexStateElementNames.STATE_GROUPS)) {
                XmlAttributeValue valueElement = attribute.getValueElement();
                assert valueElement != null;
                for (PsiReference reference : valueElement.getReferences()) {
                    addNameToStateMap(reference.getCanonicalText(), state);
                }
            }
        }
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag)

Example 87 with XmlAttribute

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

the class IncrementalDocumentSynchronizer method findSupportedTarget.

@Nullable
private XmlElementValueProvider findSupportedTarget() {
    PsiElement element = event.getParent();
    // if we change attribute value via line marker, so, event.getParent() will be XmlAttribute instead of XmlAttributeValue
    while (!(element instanceof XmlAttribute)) {
        element = element.getParent();
        if (element instanceof XmlTag) {
            XmlTag tag = (XmlTag) element;
            XmlElementDescriptor descriptor = tag.getDescriptor();
            if (descriptor instanceof ClassBackedElementDescriptor) {
                ClassBackedElementDescriptor classBackedElementDescriptor = (ClassBackedElementDescriptor) descriptor;
                if (classBackedElementDescriptor.isPredefined()) {
                    isStyleDataChanged = descriptor.getQualifiedName().equals(FlexPredefinedTagNames.STYLE);
                    isSkippedXml = isStyleDataChanged || (!MxmlUtil.isObjectLanguageTag(tag) && !descriptor.getQualifiedName().equals(FlexPredefinedTagNames.DECLARATIONS));
                }
            }
            return null;
        } else if (element instanceof PsiFile || element == null) {
            return null;
        }
    }
    XmlAttribute attribute = (XmlAttribute) element;
    if (JavaScriptSupportLoader.MXML_URI3.equals(attribute.getNamespace()) || attribute.getValueElement() == null) {
        return null;
    }
    XmlAttributeDescriptor xmlDescriptor = attribute.getDescriptor();
    if (!(xmlDescriptor instanceof AnnotationBackedDescriptor)) {
        return null;
    }
    AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) xmlDescriptor;
    if (descriptor.isPredefined() || MxmlUtil.isIdLanguageAttribute(attribute, descriptor)) {
        return null;
    }
    // todo incremental sync for state-specific attributes
    PsiReference[] references = attribute.getReferences();
    if (references.length > 1) {
        for (int i = references.length - 1; i > -1; i--) {
            PsiReference psiReference = references[i];
            if (psiReference instanceof FlexReferenceContributor.StateReference) {
                return null;
            }
        }
    } else {
        String prefix = attribute.getName() + '.';
        for (XmlAttribute anotherAttribute : attribute.getParent().getAttributes()) {
            if (anotherAttribute != attribute && anotherAttribute.getName().startsWith(prefix)) {
                return null;
            }
        }
    }
    XmlAttributeValueProvider valueProvider = new XmlAttributeValueProvider(attribute);
    // skip binding
    PsiLanguageInjectionHost injectedHost = valueProvider.getInjectedHost();
    if (injectedHost != null && InjectedLanguageUtil.hasInjections(injectedHost)) {
        return null;
    }
    return valueProvider;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValueProvider(com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with XmlAttribute

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

the class AndroidLintGoogleAppIndexingApiWarningInspection method getAppIndexingQuickFix.

@NotNull
static AndroidLintQuickFix[] getAppIndexingQuickFix(PsiElement startElement, String message) {
    AppIndexingApiDetector.IssueType type = AppIndexingApiDetector.IssueType.parse(message);
    switch(type) {
        case SCHEME_MISSING:
        case URL_MISSING:
            return new AndroidLintQuickFix[] { new SetAttributeQuickFix("Set scheme", ATTR_SCHEME, "http") };
        case HOST_MISSING:
            return new AndroidLintQuickFix[] { new SetAttributeQuickFix("Set host", ATTR_HOST, null) };
        case MISSING_SLASH:
            PsiElement parent = startElement.getParent();
            if (parent instanceof XmlAttribute) {
                XmlAttribute attr = (XmlAttribute) parent;
                String path = attr.getValue();
                if (path != null) {
                    return new AndroidLintQuickFix[] { new ReplaceStringQuickFix("Replace with /" + path, path, "/" + path) };
                }
            }
            break;
        default:
            break;
    }
    return AndroidLintQuickFix.EMPTY_ARRAY;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AppIndexingApiDetector(com.android.tools.lint.checks.AppIndexingApiDetector) SetAttributeQuickFix(org.jetbrains.android.inspections.lint.SetAttributeQuickFix) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with XmlAttribute

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

the class AndroidLintInvalidUsesTagAttributeInspection method getQuickFixes.

@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class);
    XmlAttributeValue attributeValue = attribute == null ? null : attribute.getValueElement();
    if (attributeValue != null && attributeValue.getTextLength() != 0) {
        String value = StringUtil.unquoteString(attributeValue.getText());
        String regexp = "(" + value + ")";
        String[] suggestions = AndroidAutoDetector.getAllowedAutomotiveAppTypes();
        List<AndroidLintQuickFix> fixes = Lists.newArrayListWithExpectedSize(suggestions.length);
        for (String suggestion : suggestions) {
            fixes.add(new ReplaceStringQuickFix("Replace with \"" + suggestion + "\"", regexp, suggestion));
        }
        return fixes.toArray(new AndroidLintQuickFix[fixes.size()]);
    } else {
        return AndroidLintQuickFix.EMPTY_ARRAY;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with XmlAttribute

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

the class AndroidLintNetworkSecurityConfigInspection method getQuickFixes.

@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    if (NetworkSecurityConfigDetector.isInvalidDigestAlgorithmMessage(message)) {
        List<String> digestAlgs = NetworkSecurityConfigDetector.getSupportedPinDigestAlgorithms();
        AndroidLintQuickFix[] digestFixes = new AndroidLintQuickFix[digestAlgs.size()];
        for (int i = 0; i < digestFixes.length; i++) {
            String algorithm = digestAlgs.get(i);
            digestFixes[i] = new ReplaceStringQuickFix(String.format("Set digest to \"%1$s\"", algorithm), null, algorithm);
        }
        return digestFixes;
    } else if (NetworkSecurityConfigDetector.isAttributeSpellingError(message)) {
        XmlTag parentTag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false);
        XmlAttribute currentAttr = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class, false);
        assert parentTag != null;
        assert currentAttr != null;
        List<String> suggestions = NetworkSecurityConfigDetector.getAttributeSpellingSuggestions(currentAttr.getName(), parentTag.getName());
        AndroidLintQuickFix[] attrFixes = new AndroidLintQuickFix[suggestions.size()];
        for (int i = 0; i < attrFixes.length; i++) {
            attrFixes[i] = new RenameAttributeQuickFix(null, /* no namespace */
            suggestions.get(i));
        }
        return attrFixes;
    } else if (NetworkSecurityConfigDetector.isTagSpellingError(message)) {
        XmlTag currentTag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false);
        assert currentTag != null;
        XmlTag parentTag = currentTag.getParentTag();
        assert parentTag != null;
        List<String> suggestions = NetworkSecurityConfigDetector.getTagSpellingSuggestions(currentTag.getName(), parentTag.getName());
        AndroidLintQuickFix[] elementQuickFixes = new AndroidLintQuickFix[suggestions.size()];
        for (int i = 0; i < elementQuickFixes.length; i++) {
            elementQuickFixes[i] = new RenameXmlTagQuickFix(suggestions.get(i));
        }
        return elementQuickFixes;
    } else {
        return AndroidLintQuickFix.EMPTY_ARRAY;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) List(java.util.List) RenameAttributeQuickFix(org.jetbrains.android.inspections.lint.RenameAttributeQuickFix) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)220 XmlTag (com.intellij.psi.xml.XmlTag)116 PsiElement (com.intellij.psi.PsiElement)60 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)57 NotNull (org.jetbrains.annotations.NotNull)44 XmlFile (com.intellij.psi.xml.XmlFile)37 Nullable (org.jetbrains.annotations.Nullable)27 Project (com.intellij.openapi.project.Project)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 TextRange (com.intellij.openapi.util.TextRange)18 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)18 ArrayList (java.util.ArrayList)18 PsiFile (com.intellij.psi.PsiFile)17 PsiReference (com.intellij.psi.PsiReference)17 IncorrectOperationException (com.intellij.util.IncorrectOperationException)10 DomElement (com.intellij.util.xml.DomElement)10 Result (com.intellij.openapi.application.Result)9 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)9 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 XmlElement (com.intellij.psi.xml.XmlElement)6