Uast, Lint: Update and fix tests

This commit is contained in:
Yan Zhulanow
2016-04-06 19:53:11 +03:00
parent 21a2115501
commit c13c24becc
34 changed files with 1073 additions and 289 deletions
@@ -37,7 +37,7 @@ interface UDeclaration : UElement, UNamed {
*/
open fun matchesNameWithContaining(containingClassFqName: String, name: String): Boolean {
if (!matchesName(name)) return false
val containingClass = parent as? UClass ?: return false
val containingClass = this.getContainingClass() ?: return false
return containingClass.matchesFqName(containingClassFqName)
}
@@ -30,7 +30,8 @@ interface ULiteralExpression : UExpression {
/**
* Returns true if the literal is a `null`-literal, false otherwise.
*/
val isNull: Boolean
open val isNull: Boolean
get() = value == null
/**
* Returns true if the literal is a [String] literal, false otherwise.
@@ -44,24 +45,23 @@ interface ULiteralExpression : UExpression {
val isBoolean: Boolean
get() = evaluate() is Boolean
/**
* Returns the string representation of the literal expression.
*
* @return the string representation, or "null" if the literal is a "null"-literal.
*/
fun asString(): String {
val value = value
return if (value == null)
"null"
else
value.toString()
}
override fun accept(visitor: UastVisitor) {
visitor.visitLiteralExpression(this)
visitor.afterVisitLiteralExpression(this)
}
override fun logString() = "ULiteralExpression (${asString()})"
override fun renderString() = if (value is String) "\"$value\"" else asString()
override fun renderString(): String {
val value = value
return when (value) {
null -> "null"
is Char -> "'$value'"
is String -> '"' + value.replace("\\", "\\\\")
.replace("\r", "\\r").replace("\n", "\\n")
.replace("\t", "\\t").replace("\b", "\\b")
.replace("\"", "\\\"") + '"'
else -> value.toString()
}
}
override fun logString() = "ULiteralExpression (${renderString()})"
}