use of com.intellij.psi.xml.XmlAttributeValue 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.XmlAttributeValue 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.XmlAttributeValue in project android by JetBrains.
the class StringResourceSafeDeleteProcessorDelegate method getElementsToSearch.
@NotNull
@Override
public Collection<? extends PsiElement> getElementsToSearch(@NotNull PsiElement element, @Nullable Module module, @NotNull Collection<PsiElement> elementsToDelete) {
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
XmlAttribute attribute = tag.getAttribute(ATTR_NAME);
assert attribute != null;
Collection<PsiElement> elements = new ArrayList<>();
// Find usages of the string element's name attribute value, such as @string/string_name references in XML files
elements.add(attribute.getValueElement());
// R.string.string_name references in Java files that are not LightElements
Collection<PsiField> fields = Arrays.stream(AndroidResourceUtil.findResourceFieldsForValueResource(tag, true)).filter(field -> !(field instanceof LightElement)).collect(Collectors.toList());
elements.addAll(fields);
return elements;
} else if (element instanceof XmlAttributeValue) {
return getElementsToSearch(element.getParent().getParent(), module, elementsToDelete);
} else {
return Collections.emptyList();
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidResourceRenameResourceProcessor method getResourceName.
/** Looks up the resource name for the given refactored element. Uses the same
* instanceof chain checkups as is done in {@link #canProcessElement} */
@Nullable
private static String getResourceName(PsiElement originalElement) {
PsiElement element = LazyValueResourceElementWrapper.computeLazyElement(originalElement);
if (element == null) {
return null;
}
if (element instanceof PsiFile) {
PsiFile file = (PsiFile) element;
LocalResourceManager manager = LocalResourceManager.getInstance(element);
if (manager != null) {
String type = manager.getFileResourceType(file);
if (type != null) {
String name = file.getName();
return AndroidCommonUtils.getResourceName(type, name);
}
}
return LintUtils.getBaseName(file.getName());
} else if (element instanceof PsiField) {
PsiField field = (PsiField) element;
return field.getName();
} else if (element instanceof XmlAttributeValue) {
if (AndroidResourceUtil.isIdDeclaration((XmlAttributeValue) element)) {
return AndroidResourceUtil.getResourceNameByReferenceText(((XmlAttributeValue) element).getValue());
}
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag != null) {
DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (domElement instanceof ResourceElement) {
return ((ResourceElement) domElement).getName().getValue();
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidResourceRenameResourceProcessor method prepareRenaming.
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
final PsiElement element1 = LazyValueResourceElementWrapper.computeLazyElement(element);
if (element1 == null) {
return;
}
// TODO: support renaming alternative value resources
AndroidFacet facet = AndroidFacet.getInstance(element1);
assert facet != null;
if (element1 instanceof PsiFile) {
prepareResourceFileRenaming((PsiFile) element1, newName, allRenames, facet);
} else if (element1 instanceof PsiClass) {
PsiClass cls = (PsiClass) element1;
if (AndroidDomUtil.isInheritor(cls, CLASS_VIEW)) {
prepareCustomViewRenaming(cls, newName, allRenames, facet);
}
} else if (element1 instanceof XmlAttributeValue) {
XmlAttributeValue value = (XmlAttributeValue) element1;
if (AndroidResourceUtil.isIdDeclaration(value)) {
prepareIdRenaming(value, newName, allRenames, facet);
} else {
prepareValueResourceRenaming(element1, newName, allRenames, facet);
}
} else if (element1 instanceof PsiField) {
prepareResourceFieldRenaming((PsiField) element1, newName, allRenames);
}
}
Aggregations