Skip to content

Commit 697eb60

Browse files
committed
Simplify code
1 parent 9301261 commit 697eb60

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/main/kotlin/org/nette/helpers/utils/MethodUtil.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ import com.jetbrains.php.lang.psi.elements.Method
44
import java.util.Locale.getDefault
55

66
fun Method.asControlName(): String {
7-
if (!this.name.startsWith("createComponent") || this.name == "createComponent") {
7+
if (!isControl()) {
88
throw IllegalStateException("Method is not a control")
99
}
1010

11-
return this.name.removePrefix("createComponent").replaceFirstChar { it.lowercase(getDefault()) }
11+
return name.removePrefix("createComponent").replaceFirstChar { it.lowercase(getDefault()) }
1212
}
1313

1414
fun Method.isAnyPresenterMethod(): Boolean {
1515
return isControl() || isAction() || isRender() || isSignal() || isStartup() || isBeforeRender() || isAfterRender() || isShutdown()
1616
}
1717

1818
fun Method.isControl(): Boolean {
19-
return this.name.startsWith("createComponent") && this.name != "createComponent"
19+
return name.startsWith("createComponent") && name != "createComponent"
2020
}
2121

2222
fun Method.isAction(): Boolean {
23-
return this.name.startsWith("action") && this.name != "action"
23+
return name.startsWith("action") && name != "action"
2424
}
2525

2626
fun Method.isRender(): Boolean {
27-
return this.name.startsWith("render") && this.name != "render"
27+
return name.startsWith("render") && name != "render"
28+
}
29+
30+
fun Method.isSignal(): Boolean {
31+
return name.startsWith("handle") && name != "handle"
2832
}
2933

3034
fun Method.isStartup(): Boolean {
31-
return this.name == "startup"
35+
return name == "startup"
3236
}
3337

3438
fun Method.isBeforeRender(): Boolean {
35-
return this.name == "beforeRender"
39+
return name == "beforeRender"
3640
}
3741

3842
fun Method.isAfterRender(): Boolean {
39-
return this.name == "afterRender"
43+
return name == "afterRender"
4044
}
4145

4246
fun Method.isShutdown(): Boolean {
43-
return this.name == "shutdown"
44-
}
45-
46-
fun Method.isSignal(): Boolean {
47-
return this.name.startsWith("handle") && this.name != "handle"
47+
return name == "shutdown"
4848
}

src/main/kotlin/org/nette/helpers/utils/PhpClassUtil.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.nette.helpers.utils
33
import com.jetbrains.php.lang.psi.elements.*
44

55
fun PhpClass.isComponent(): Boolean {
6-
return this.isInstanceOf("\\Nette\\Application\\UI\\Component")
6+
return isInstanceOf("\\Nette\\Application\\UI\\Component")
77
}
88

99
fun PhpClass.isInstanceOf(fqn: String): Boolean {
@@ -25,7 +25,5 @@ fun PhpClass.isInstanceOf(fqn: String): Boolean {
2525
}
2626

2727
fun PhpClass.getControls(): List<Method> {
28-
return this.methods.filter {
29-
it.name.startsWith("createComponent") && it.name != "createComponent"
30-
}
28+
return methods.filter { it.isControl() }
3129
}

src/main/kotlin/org/nette/helpers/utils/PsiUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ import com.jetbrains.php.lang.psi.elements.Variable
1111

1212
fun PsiElement.resolvePhpClasses(): List<PhpClass> {
1313
// $this -> containing class
14-
if (this is Variable && this.name == "this") {
14+
if (this is Variable && name == "this") {
1515
PsiTreeUtil.getParentOfType(this, PhpClass::class.java)?.let { return listOf(it) }
1616
}
1717

1818
// Direct resolves
1919
if (this is ClassReference) {
20-
val resolved = this.resolve()
20+
val resolved = resolve()
2121
if (resolved is PhpClass) return listOf(resolved)
2222
}
2323

2424
if (this is NewExpression) {
25-
val resolved = this.classReference?.resolve()
25+
val resolved = classReference?.resolve()
2626
if (resolved is PhpClass) return listOf(resolved)
2727
}
2828

2929
if (this is PhpClass) return listOf(this)
3030

3131
// Resolve via type information
3232
val typed = this as? PhpTypedElement ?: return emptyList()
33-
val project = this.project
33+
val project = project
3434
val index = PhpIndex.getInstance(project)
3535
val completed = index.completeType(project, typed.type, null)
3636

0 commit comments

Comments
 (0)