use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class CreateFlexSkinIntention method getHostComponentClass.
@Nullable
private JSClass getHostComponentClass() {
final XmlTag tag = myElement instanceof XmlTag ? ((XmlTag) myElement).getParentTag() : myElement instanceof XmlAttributeValue ? (XmlTag) myElement.getParent().getParent() : null;
final XmlElementDescriptor descriptor = tag == null ? null : tag.getDescriptor();
if (descriptor instanceof ClassBackedElementDescriptor) {
final PsiElement declaration = descriptor.getDeclaration();
if (declaration instanceof JSClass) {
return (JSClass) declaration;
}
}
return null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class NlIdPropertyItem method setValue.
@Override
public void setValue(Object value) {
String newId = value != null ? stripIdPrefix(value.toString()) : "";
String oldId = getValue();
XmlTag tag = getTag();
if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty() && !oldId.equals(newId) && tag != null && tag.isValid()) {
// Offer rename refactoring?
XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
if (attribute != null) {
Module module = getModel().getModule();
Project project = module.getProject();
XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null && valueElement.isValid()) {
// Exact replace only, no comment/text occurrence changes since it is non-interactive
ValueResourceElementWrapper wrapper = new ValueResourceElementWrapper(valueElement);
RenameProcessor processor = new RenameProcessor(project, wrapper, NEW_ID_PREFIX + newId, false, /*comments*/
false);
processor.setPreviewUsages(false);
// Do a quick usage search to see if we need to ask about renaming
UsageInfo[] usages = processor.findUsages();
if (usages.length > 0) {
int choice = ourRefactoringChoice;
if (choice == REFACTOR_ASK) {
DialogBuilder builder = createDialogBuilder(project);
builder.setTitle("Update Usages?");
// UGH!
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("<html>" + "Update usages as well?<br>" + "This will update all XML references and Java R field references.<br>" + "<br>" + "</html>");
panel.add(label, BorderLayout.CENTER);
JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
panel.add(checkBox, BorderLayout.SOUTH);
builder.setCenterPanel(panel);
builder.setDimensionServiceKey("idPropertyDimension");
builder.removeAllActions();
DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
yesAction.setText(Messages.YES_BUTTON);
builder.addActionDescriptor(dialogWrapper -> new AbstractAction(Messages.NO_BUTTON) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
}
});
builder.addCancelAction();
int exitCode = builder.show();
choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO : ourRefactoringChoice;
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourRefactoringChoice = checkBox.isSelected() ? choice : REFACTOR_ASK;
if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
return;
}
}
if (choice == REFACTOR_YES) {
processor.run();
return;
}
}
}
}
}
super.setValue(!StringUtil.isEmpty(newId) ? NEW_ID_PREFIX + newId : null);
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class AngularAttributeIndexer method map.
@NotNull
@Override
public Map<String, AngularNamedItemDefinition> map(@NotNull FileContent inputData) {
final Map<String, AngularNamedItemDefinition> map = new HashMap<>();
final PsiFile file = inputData.getPsiFile();
if (file instanceof XmlFile) {
file.accept(new XmlRecursiveElementWalkingVisitor() {
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
if (myAttributeName.equals(DirectiveUtil.normalizeAttributeName(attribute.getName()))) {
final XmlAttributeValue element = attribute.getValueElement();
if (element == null) {
map.put("", new AngularNamedItemDefinition("", attribute.getTextRange().getStartOffset()));
} else {
final String name = StringUtil.unquoteString(element.getText());
map.put(name, new AngularNamedItemDefinition(name, element.getTextRange().getStartOffset()));
}
}
}
});
}
return map;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class DataBindingConverter method createReferences.
@NotNull
@Override
public PsiReference[] createReferences(final GenericDomValue<PsiClass> value, final PsiElement element, final ConvertContext context) {
assert element instanceof XmlAttributeValue;
final XmlAttributeValue attrValue = (XmlAttributeValue) element;
final String strValue = attrValue.getValue();
final int start = attrValue.getValueTextRange().getStartOffset() - attrValue.getTextRange().getStartOffset();
List<PsiReference> result = new ArrayList<>();
final String[] nameParts = strValue.split("[$.]");
Module module = context.getModule();
if (nameParts.length == 0 || module == null) {
return PsiReference.EMPTY_ARRAY;
}
int offset = start;
// Check if the first namePart is an alias.
DataBindingInfo bindingInfo = getDataBindingInfo(context);
// for iterating over the nameParts.
int idx = 0;
// difference in lengths of the "type" and the "alias". Used in range computation later.
int diff = 0;
String fullType = strValue.replace('$', '.');
if (bindingInfo != null) {
String alias = nameParts[idx];
PsiDataBindingResourceItem anImport = getImport(alias, bindingInfo);
if (anImport != null) {
// Found an import matching the first namePart. Add a reference from this to the type.
idx++;
TextRange range = new TextRange(offset, offset += alias.length());
// Skip the next dot or dollar separator (if any)
offset++;
String type = anImport.getTypeDeclaration();
result.add(new AliasedReference(element, range, type, module));
fullType = type + fullType.substring(alias.length());
diff = type.length() - alias.length();
} else {
// Check java.lang and primitives
if (nameParts.length == 1) {
if (alias.length() > 0) {
if (Character.isLowerCase(alias.charAt(0))) {
final PsiPrimitiveType primitive = PsiJavaParserFacadeImpl.getPrimitiveType(alias);
if (primitive != null) {
result.add(new PsiReferenceBase<PsiElement>(element, true) {
@Nullable
@Override
public PsiElement resolve() {
return myElement;
}
@NotNull
@Override
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
});
}
} else {
// java.lang
PsiClass aClass = JavaPsiFacade.getInstance(context.getProject()).findClass(JAVA_LANG + alias, GlobalSearchScope.moduleWithLibrariesScope(module));
if (aClass != null) {
final TextRange range = new TextRange(offset, offset += alias.length());
result.add(new ClassReference(element, range, aClass));
}
}
idx++;
}
}
}
}
for (; idx < nameParts.length; idx++, offset++) {
final String packageName = nameParts[idx];
if (packageName.length() > 0) {
final TextRange range = new TextRange(offset, offset += packageName.length());
result.add(new AliasedReference(element, range, fullType.substring(0, diff + offset - start), module));
}
}
return result.toArray(new PsiReference[result.size()]);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidXmlDocumentationProvider method generateDoc.
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
if (element instanceof ProvidedDocumentationPsiElement) {
return ((ProvidedDocumentationPsiElement) element).getDocumentation();
}
if (element instanceof LazyValueResourceElementWrapper) {
LazyValueResourceElementWrapper wrapper = (LazyValueResourceElementWrapper) element;
ValueResourceInfo resourceInfo = wrapper.getResourceInfo();
ResourceType type = resourceInfo.getType();
String name = resourceInfo.getName();
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module == null) {
return null;
}
AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
return null;
}
ResourceUrl url;
ResourceUrl originalUrl = originalElement != null ? ResourceUrl.parse(originalElement.getText()) : null;
if (originalUrl != null && name.equals(originalUrl.name)) {
url = originalUrl;
} else {
boolean isFramework = false;
if (originalUrl != null) {
isFramework = originalUrl.framework;
} else {
// Figure out if this resource is a framework file.
// We really should store that info in the ValueResourceInfo instances themselves.
// For now, attempt to figure it out
SystemResourceManager systemResourceManager = facet.getSystemResourceManager();
VirtualFile containingFile = resourceInfo.getContainingFile();
if (systemResourceManager != null) {
VirtualFile parent = containingFile.getParent();
if (parent != null) {
VirtualFile resDir = parent.getParent();
if (resDir != null) {
isFramework = systemResourceManager.isResourceDir(resDir);
}
}
}
}
url = ResourceUrl.create(type, name, isFramework, false);
}
return generateDoc(element, url);
} else if (element instanceof MyResourceElement) {
return getResourceDocumentation(element, ((MyResourceElement) element).myResource);
} else if (element instanceof XmlAttributeValue) {
return getResourceDocumentation(element, ((XmlAttributeValue) element).getValue());
}
if (originalElement instanceof XmlToken) {
XmlToken token = (XmlToken) originalElement;
if (token.getTokenType() == XML_ATTRIBUTE_VALUE_START_DELIMITER) {
PsiElement next = token.getNextSibling();
if (next instanceof XmlToken) {
token = (XmlToken) next;
}
} else if (token.getTokenType() == XML_ATTRIBUTE_VALUE_END_DELIMITER) {
PsiElement prev = token.getPrevSibling();
if (prev instanceof XmlToken) {
token = (XmlToken) prev;
}
}
if (token.getTokenType() == XML_ATTRIBUTE_VALUE_TOKEN) {
String documentation = getResourceDocumentation(originalElement, token.getText());
if (documentation != null) {
return documentation;
}
} else if (token.getTokenType() == XML_DATA_CHARACTERS) {
String text = token.getText().trim();
String documentation = getResourceDocumentation(originalElement, text);
if (documentation != null) {
return documentation;
}
}
}
if (element instanceof PomTargetPsiElement && originalElement != null) {
final PomTarget target = ((PomTargetPsiElement) element).getTarget();
if (target instanceof DomAttributeChildDescription) {
synchronized (ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY) {
return generateDocForXmlAttribute((DomAttributeChildDescription) target, originalElement);
}
}
}
if (element instanceof MyDocElement) {
return ((MyDocElement) element).myDocumentation;
}
return null;
}
Aggregations