use of com.android.tools.idea.lang.databinding.psi.PsiDbConstantValue in project android by JetBrains.
the class DataBindingUtil method getBindingExprDefault.
@Nullable
public static String getBindingExprDefault(@NotNull XmlAttribute psiAttribute) {
XmlAttributeValue attrValue = psiAttribute.getValueElement();
if (attrValue instanceof PsiLanguageInjectionHost) {
final Ref<PsiElement> injections = Ref.create();
InjectedLanguageUtil.enumerate(attrValue, (injectedPsi, places) -> {
if (injectedPsi instanceof DbFile) {
injections.set(injectedPsi);
}
});
if (injections.get() != null) {
PsiDbDefaults defaults = PsiTreeUtil.getChildOfType(injections.get(), PsiDbDefaults.class);
if (defaults != null) {
PsiDbConstantValue constantValue = defaults.getConstantValue();
ASTNode stringLiteral = constantValue.getNode().findChildByType(DbTokenTypes.STRING_LITERAL);
if (stringLiteral == null) {
return constantValue.getText();
} else {
String text = stringLiteral.getText();
if (text.length() > 1) {
// return unquoted string literal.
return text.substring(1, text.length() - 1);
} else {
return text;
}
}
}
}
}
return null;
}
Aggregations