use of org.jetbrains.uast.UBinaryExpression in project kotlin by JetBrains.
the class SetTextDetector method checkNode.
private static void checkNode(@NonNull JavaContext context, @Nullable UElement node) {
if (node instanceof ULiteralExpression) {
Object value = ((ULiteralExpression) node).getValue();
if (value instanceof String && value.toString().matches(WORD_PATTERN)) {
context.report(SET_TEXT_I18N, node, context.getUastLocation(node), "String literal in `setText` can not be translated. Use Android " + "resources instead.");
}
} else if (node instanceof UCallExpression) {
PsiMethod calledMethod = ((UCallExpression) node).resolve();
if (calledMethod != null && TO_STRING_NAME.equals(calledMethod.getName())) {
PsiClass containingClass = UastUtils.getContainingClass(calledMethod);
if (containingClass == null) {
return;
}
PsiClass superClass = containingClass.getSuperClass();
if (superClass != null && NUMBER_CLS.equals(superClass.getQualifiedName())) {
context.report(SET_TEXT_I18N, node, context.getUastLocation(node), "Number formatting does not take into account locale settings. " + "Consider using `String.format` instead.");
}
}
} else if (node instanceof UQualifiedReferenceExpression) {
UQualifiedReferenceExpression expression = (UQualifiedReferenceExpression) node;
checkNode(context, expression.getReceiver());
checkNode(context, expression.getSelector());
} else if (node instanceof UBinaryExpression) {
UBinaryExpression expression = (UBinaryExpression) node;
if (expression.getOperator() == UastBinaryOperator.PLUS) {
context.report(SET_TEXT_I18N, node, context.getUastLocation(node), "Do not concatenate text displayed with `setText`. " + "Use resource string with placeholders.");
}
checkNode(context, expression.getLeftOperand());
checkNode(context, expression.getRightOperand());
}
}
Aggregations