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);
}
}
}
}
}
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;
}
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;
}
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;
}
}
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;
}
}
Aggregations