Suggestions from expression itself to have higher priority + fixed incorect upper case naming
This commit is contained in:
@@ -34,13 +34,13 @@ public object KotlinNameSuggester {
|
||||
public fun suggestNamesByExpressionAndType(expression: JetExpression, bindingContext: BindingContext, validator: (String) -> Boolean, defaultName: String?): Collection<String> {
|
||||
val result = LinkedHashSet<String>()
|
||||
|
||||
result.addNamesByExpression(expression, validator)
|
||||
|
||||
val type = bindingContext.getType(expression)
|
||||
if (type != null) {
|
||||
result.addNamesByType(type, validator)
|
||||
}
|
||||
|
||||
result.addNamesByExpression(expression, validator)
|
||||
|
||||
if (result.isEmpty()) {
|
||||
result.addName(defaultName, validator)
|
||||
}
|
||||
@@ -284,15 +284,7 @@ public object KotlinNameSuggester {
|
||||
if (expression == null) return
|
||||
|
||||
when (expression) {
|
||||
is JetSimpleNameExpression -> {
|
||||
val referenceName = expression.getReferencedName()
|
||||
if (referenceName == referenceName.toUpperCase()) {
|
||||
addName(referenceName, validator)
|
||||
}
|
||||
else {
|
||||
addCamelNames(referenceName, validator)
|
||||
}
|
||||
}
|
||||
is JetSimpleNameExpression -> addCamelNames(expression.getReferencedName(), validator)
|
||||
|
||||
is JetQualifiedExpression -> addNamesByExpression(expression.getSelectorExpression(), validator)
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
fun main(args: Array<String>) {
|
||||
val any = doSomething("one" + 1,
|
||||
val doSomething = doSomething("one" + 1,
|
||||
"two",
|
||||
3 * 4)
|
||||
val t = if (any != null) any else throw NullPointerException("Expression 'doSomething(\"one\" + 1, ...' must not be null")
|
||||
val t = if (doSomething != null) doSomething else throw NullPointerException("Expression 'doSomething(\"one\" + 1, ...' must not be null")
|
||||
}
|
||||
|
||||
fun doSomething(vararg a: Any): Any? = null
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun main(args: Array<String>) {
|
||||
var a: String? = "A"
|
||||
val s = a
|
||||
doSomething(if (s != null) s else throw NullPointerException("Expression 'a' must not be null"))
|
||||
val a1 = a
|
||||
doSomething(if (a1 != null) a1 else throw NullPointerException("Expression 'a' must not be null"))
|
||||
}
|
||||
|
||||
fun doSomething(a: Any){}
|
||||
|
||||
+2
-2
@@ -2,6 +2,6 @@ val a: String?
|
||||
get() = ""
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
val x = if (s != null) s else throw NullPointerException("Expression 'a' must not be null")
|
||||
val a1 = a
|
||||
val x = if (a1 != null) a1 else throw NullPointerException("Expression 'a' must not be null")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a: String? = "A"
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
val t = if (s != null) s else throw NullPointerException("Expression 'a' must not be null")
|
||||
val a1 = a
|
||||
val t = if (a1 != null) a1 else throw NullPointerException("Expression 'a' must not be null")
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ var a: String?
|
||||
set(v) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
doSomething(if (s != null) s else throw NullPointerException("Expression 'a' must not be null"))
|
||||
val a1 = a
|
||||
doSomething(if (a1 != null) a1 else throw NullPointerException("Expression 'a' must not be null"))
|
||||
}
|
||||
|
||||
fun doSomething(a: Any){}
|
||||
|
||||
@@ -6,6 +6,6 @@ fun bar() {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = foo()
|
||||
if (s != null) s else bar()
|
||||
val foo = foo()
|
||||
if (foo != null) foo else bar()
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,6 +6,6 @@ fun bar() {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = foo()
|
||||
if (s != null) s else bar()
|
||||
val foo = foo()
|
||||
if (foo != null) foo else bar()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun main(args: Array<String>) {
|
||||
var a: String? = "A"
|
||||
val s = a
|
||||
if (s != null) s else "bar"
|
||||
val a1 = a
|
||||
if (a1 != null) a1 else "bar"
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,6 +2,6 @@ val a: String?
|
||||
get() = ""
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
if (s != null) s else "bar"
|
||||
val a1 = a
|
||||
if (a1 != null) a1 else "bar"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a: String? = "A"
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
if (s != null) s else "bar"
|
||||
val a1 = a
|
||||
if (a1 != null) a1 else "bar"
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,6 +3,6 @@ var a: String?
|
||||
set(v) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
if (s != null) s else "bar"
|
||||
val a1 = a
|
||||
if (a1 != null) a1 else "bar"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
fun foo(): String? = "foo"
|
||||
fun main(args: Array<String>) {
|
||||
val s = foo()
|
||||
if (s != null) s.length()
|
||||
val foo = foo()
|
||||
if (foo != null) foo.length()
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
fun foo(): String? = "foo"
|
||||
fun main(args: Array<String>) {
|
||||
val s = foo()
|
||||
if (s != null) s.length()
|
||||
val foo = foo()
|
||||
if (foo != null) foo.length()
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,6 +9,6 @@ class Foo {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = Foo()
|
||||
val s = a.b
|
||||
doSomething(if (s != null) s.length() else null)
|
||||
val b = a.b
|
||||
doSomething(if (b != null) b.length() else null)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ fun doSomething<T>(a: T) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
var a: String? = "A"
|
||||
val s = a
|
||||
doSomething(if (s != null) s.length() else null)
|
||||
val a1 = a
|
||||
doSomething(if (a1 != null) a1.length() else null)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,6 +4,6 @@ val a: String?
|
||||
get() = ""
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
doSomething(if (s != null) s.length() else null)
|
||||
val a1 = a
|
||||
doSomething(if (a1 != null) a1.length() else null)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var a: String? = "A"
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
if (s != null) s.length()
|
||||
val a1 = a
|
||||
if (a1 != null) a1.length()
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,6 +3,6 @@ var a: String?
|
||||
set(v) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = a
|
||||
if (s != null) s.length()
|
||||
val a1 = a
|
||||
if (a1 != null) a1.length()
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
class J {
|
||||
|
||||
public static class A {
|
||||
public A(int i, @NotNull String s, @NotNull B B) {
|
||||
public A(int i, @NotNull String s, @NotNull B b) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -6,6 +6,6 @@ fun test() {
|
||||
val a: A<Int> = 2 + A(1)
|
||||
}
|
||||
|
||||
fun Int.plus(A: A<Int>): A<Int> {
|
||||
fun Int.plus(a: A<Int>): A<Int> {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@ fun test() {
|
||||
val a: A<Int> = 2.foo(A(1))
|
||||
}
|
||||
|
||||
fun Int.foo(A: A<Int>): A<Int> {
|
||||
fun Int.foo(a: A<Int>): A<Int> {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,6 +8,6 @@ fun foo(t: T): Int {
|
||||
fun bar(x: Int = foo(T(T(2).t + 1)))
|
||||
|
||||
fun test() {
|
||||
val i = T(2).t
|
||||
foo(T(i + 1))
|
||||
val t = T(2).t
|
||||
foo(T(t + 1))
|
||||
}
|
||||
@@ -7,6 +7,6 @@ fun foo(i: Int): Int {
|
||||
fun test() {
|
||||
var x = 1
|
||||
val i = ++x
|
||||
val i1 = x++
|
||||
foo(i * i1)
|
||||
val x1 = x++
|
||||
foo(i * x1)
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@ fun a(op: (Int) -> Int) {}
|
||||
fun b() {
|
||||
a {it}
|
||||
a {
|
||||
val i = it
|
||||
i
|
||||
val it1 = it
|
||||
it1
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
fun main(args: Array<String>) {
|
||||
with(A()) {
|
||||
val i = prop
|
||||
println(i)
|
||||
println(i)
|
||||
val prop = prop
|
||||
println(prop)
|
||||
println(prop)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun bar(): Int = 1
|
||||
|
||||
fun foo() {
|
||||
val i = bar();
|
||||
val bar = bar();
|
||||
}
|
||||
+1
-1
@@ -3,6 +3,6 @@ fun baz()
|
||||
|
||||
fun foo() {
|
||||
if (true) {
|
||||
val i = bar();
|
||||
val bar = bar();
|
||||
} else baz()
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
fun main(args: Array<String>) {
|
||||
val myA = A()
|
||||
val i = myA.prop
|
||||
println(i)
|
||||
println(i)
|
||||
val prop = myA.prop
|
||||
println(prop)
|
||||
println(prop)
|
||||
}
|
||||
|
||||
class A {
|
||||
|
||||
@@ -7,7 +7,7 @@ class Foo() {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val f = Foo()
|
||||
val i = Bar().f()
|
||||
println(i)
|
||||
println(i)
|
||||
val f1 = Bar().f()
|
||||
println(f1)
|
||||
println(f1)
|
||||
}
|
||||
+2
-2
@@ -4,7 +4,7 @@ class A {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = A()
|
||||
val i = a.test()
|
||||
val test = a.test()
|
||||
|
||||
val b = i
|
||||
val b = test
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ class A {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = A()
|
||||
val i = a.test()
|
||||
val test = a.test()
|
||||
|
||||
val b = i
|
||||
val b = test
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ interface T {
|
||||
interface U: T
|
||||
|
||||
fun test(t: T): Int {
|
||||
val i = t.foo()
|
||||
val foo = t.foo()
|
||||
return if (t is U)
|
||||
i + 1
|
||||
else i
|
||||
foo + 1
|
||||
else foo
|
||||
}
|
||||
+3
-3
@@ -6,9 +6,9 @@ fun foo(body: A.() -> Unit) {}
|
||||
|
||||
fun bar() {
|
||||
foo {
|
||||
val i = value
|
||||
print(i)
|
||||
print(i)
|
||||
val value = value
|
||||
print(value)
|
||||
print(value)
|
||||
}
|
||||
|
||||
foo {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
fun foo(): Int {
|
||||
val s: String? = ""
|
||||
val i = s!!.length
|
||||
val length = s!!.length
|
||||
return if (true) {
|
||||
i
|
||||
length
|
||||
} else {
|
||||
i
|
||||
length
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user