use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class DbLanguageInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
if (!(host instanceof XmlAttributeValue)) {
return;
}
String valueText = ((XmlAttributeValue) host).getValue();
if (!DataBindingUtil.isBindingExpression(valueText)) {
return;
}
String prefix = valueText.startsWith(PREFIX_TWOWAY_BINDING_EXPR) ? PREFIX_TWOWAY_BINDING_EXPR : PREFIX_BINDING_EXPR;
PsiElement parent = host.getParent();
if (!(parent instanceof XmlAttribute))
return;
GenericAttributeValue element = DomManager.getDomManager(host.getProject()).getDomElement((XmlAttribute) parent);
if (element == null || !(element.getParent() instanceof AndroidDomElement))
return;
// Parser only parses the expression, not the prefix '@{' or the suffix '}'. Extract the start/end index of the expression.
String unescapedValue = host.getText();
int startIndex = unescapedValue.indexOf(prefix.charAt(0)) + prefix.length();
int endIndex;
if (valueText.endsWith("}")) {
endIndex = unescapedValue.lastIndexOf('}');
} else {
if (host.getNode().getLastChildNode().getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
endIndex = host.getLastChild().getStartOffsetInParent();
} else {
endIndex = unescapedValue.length();
}
}
if (endIndex == startIndex) {
// No expression found.
return;
}
injectionPlacesRegistrar.addPlace(DbLanguage.INSTANCE, TextRange.from(startIndex, endIndex - startIndex), null, null);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidFindStyleApplicationsAction method getStyleData.
@Nullable
static MyStyleData getStyleData(@NotNull XmlTag tag) {
final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (!(element instanceof Style)) {
return null;
}
final Style style = (Style) element;
final GenericAttributeValue<String> styleNameDomAttr = style.getName();
final String styleName = styleNameDomAttr.getStringValue();
final XmlAttributeValue styleNameAttrValue = styleNameDomAttr.getXmlAttributeValue();
if (styleName == null || styleName.length() == 0 || styleNameAttrValue == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(tag);
if (facet == null) {
return null;
}
return new MyStyleData(style, styleName, facet, styleNameAttrValue);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidFindStyleApplicationsProcessor method collectResDir.
private static void collectResDir(Module module, XmlAttributeValue styleNameAttrValue, String styleName, List<VirtualFile> resDirs) {
final AndroidFacet f = AndroidFacet.getInstance(module);
if (f == null) {
return;
}
final List<ValueResourceInfoImpl> resolvedStyles = f.getLocalResourceManager().findValueResourceInfos(ResourceType.STYLE.getName(), styleName, true, false);
if (resolvedStyles.size() == 1) {
final XmlAttributeValue resolvedStyleNameElement = resolvedStyles.get(0).computeXmlElement();
if (resolvedStyleNameElement != null && resolvedStyleNameElement.equals(styleNameAttrValue)) {
resDirs.addAll(f.getAllResourceDirectories());
}
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidInlineUtil method getInlinableStyleData.
@Nullable
static MyStyleData getInlinableStyleData(@NotNull XmlTag tag) {
final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (!(domElement instanceof Style)) {
return null;
}
final Style style = (Style) domElement;
final XmlAttributeValue nameAttrValue = style.getName().getXmlAttributeValue();
if (nameAttrValue == null) {
return null;
}
final String styleName = style.getName().getStringValue();
if (styleName == null || styleName.length() == 0) {
return null;
}
return new MyStyleData(styleName, style, nameAttrValue);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class InlinedResource method getResolvedString.
@Nullable
public String getResolvedString() {
if (myResourceRepository != null) {
if (myResourceRepository.hasResourceItem(myType, myKey)) {
FolderConfiguration referenceConfig = new FolderConfiguration();
// Nonexistent language qualifier: trick it to fall back to the default locale
referenceConfig.setLocaleQualifier(new LocaleQualifier("xx"));
ResourceValue value = myResourceRepository.getConfiguredValue(myType, myKey, referenceConfig);
if (value != null) {
String text = value.getValue();
if (text != null) {
if (myElement instanceof PsiMethodCallExpression) {
text = insertArguments((PsiMethodCallExpression) myElement, text);
}
if (myType == ResourceType.PLURALS && text.startsWith(STRING_PREFIX)) {
value = myResourceRepository.getConfiguredValue(ResourceType.STRING, text.substring(STRING_PREFIX.length()), referenceConfig);
if (value != null && value.getValue() != null) {
text = value.getValue();
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
}
}
if (myType == ResourceType.STRING || myElement instanceof XmlAttributeValue) {
return '"' + StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH - 2, 0) + '"';
} else if (text.length() <= 1) {
// This is similar to how IntelliJ 14 handles call parameters
return myKey + ": " + text;
} else {
return StringUtil.shortenTextWithEllipsis(text, FOLD_MAX_LENGTH, 0);
}
}
}
}
}
return null;
}
Aggregations