use property syntax
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
384b6410f2
commit
f74c0950d2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -89,7 +89,7 @@ open class KtClass : KtClassOrObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KtClass.createPrimaryConstructorIfAbsent(): KtPrimaryConstructor {
|
fun KtClass.createPrimaryConstructorIfAbsent(): KtPrimaryConstructor {
|
||||||
val constructor = getPrimaryConstructor()
|
val constructor = primaryConstructor
|
||||||
if (constructor != null) return constructor
|
if (constructor != null) return constructor
|
||||||
var anchor: PsiElement? = typeParameterList
|
var anchor: PsiElement? = typeParameterList
|
||||||
if (anchor == null) anchor = nameIdentifier
|
if (anchor == null) anchor = nameIdentifier
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -181,7 +181,7 @@ class KtPsiFactory(private val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createCompanionObject(): KtObjectDeclaration {
|
fun createCompanionObject(): KtObjectDeclaration {
|
||||||
return createClass("class A {\n companion object{\n}\n}").getCompanionObjects().first()
|
return createClass("class A {\n companion object{\n}\n}").companionObjects.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createFileAnnotation(annotationText: String): KtAnnotationEntry {
|
fun createFileAnnotation(annotationText: String): KtAnnotationEntry {
|
||||||
@@ -293,7 +293,7 @@ class KtPsiFactory(private val project: Project) {
|
|||||||
fun createCallableReferenceExpression(text: String) = createExpression(text) as? KtCallableReferenceExpression
|
fun createCallableReferenceExpression(text: String) = createExpression(text) as? KtCallableReferenceExpression
|
||||||
|
|
||||||
fun createSecondaryConstructor(decl: String): KtSecondaryConstructor {
|
fun createSecondaryConstructor(decl: String): KtSecondaryConstructor {
|
||||||
return createClass("class Foo {\n $decl \n}").getSecondaryConstructors().first()
|
return createClass("class Foo {\n $decl \n}").secondaryConstructors.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createModifierList(modifier: KtModifierKeywordToken): KtModifierList {
|
fun createModifierList(modifier: KtModifierKeywordToken): KtModifierList {
|
||||||
@@ -326,7 +326,7 @@ class KtPsiFactory(private val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createParameter(text : String): KtParameter {
|
fun createParameter(text : String): KtParameter {
|
||||||
return createClass("class A($text)").getPrimaryConstructorParameters().first()
|
return createClass("class A($text)").primaryConstructorParameters.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createParameterList(text: String): KtParameterList {
|
fun createParameterList(text: String): KtParameterList {
|
||||||
@@ -401,15 +401,15 @@ class KtPsiFactory(private val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createPrimaryConstructor(): KtPrimaryConstructor {
|
fun createPrimaryConstructor(): KtPrimaryConstructor {
|
||||||
return createClass("class A()").getPrimaryConstructor()!!
|
return createClass("class A()").primaryConstructor!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPrimaryConstructor(modifiers: String?): KtPrimaryConstructor {
|
fun createPrimaryConstructor(modifiers: String?): KtPrimaryConstructor {
|
||||||
return modifiers?.let { createClass("class A $modifiers constructor()").getPrimaryConstructor() } ?: createPrimaryConstructor()
|
return modifiers?.let { createClass("class A $modifiers constructor()").primaryConstructor } ?: createPrimaryConstructor()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createConstructorKeyword(): PsiElement =
|
fun createConstructorKeyword(): PsiElement =
|
||||||
createClass("class A constructor()").getPrimaryConstructor()!!.getConstructorKeyword()!!
|
createClass("class A constructor()").primaryConstructor!!.getConstructorKeyword()!!
|
||||||
|
|
||||||
fun createLabeledExpression(labelName: String): KtLabeledExpression
|
fun createLabeledExpression(labelName: String): KtLabeledExpression
|
||||||
= createExpression("$labelName@ 1") as KtLabeledExpression
|
= createExpression("$labelName@ 1") as KtLabeledExpression
|
||||||
@@ -456,16 +456,16 @@ class KtPsiFactory(private val project: Project) {
|
|||||||
fun createArgument(text: String) = createCallArguments("($text)").arguments.first()!!
|
fun createArgument(text: String) = createCallArguments("($text)").arguments.first()!!
|
||||||
|
|
||||||
fun createSuperTypeCallEntry(text: String): KtSuperTypeCallEntry {
|
fun createSuperTypeCallEntry(text: String): KtSuperTypeCallEntry {
|
||||||
return createClass("class A: $text").getSuperTypeListEntries().first() as KtSuperTypeCallEntry
|
return createClass("class A: $text").superTypeListEntries.first() as KtSuperTypeCallEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSuperTypeEntry(text: String): KtSuperTypeEntry {
|
fun createSuperTypeEntry(text: String): KtSuperTypeEntry {
|
||||||
return createClass("class A: $text").getSuperTypeListEntries().first() as KtSuperTypeEntry
|
return createClass("class A: $text").superTypeListEntries.first() as KtSuperTypeEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
fun creareDelegatedSuperTypeEntry(text: String): KtConstructorDelegationCall {
|
fun creareDelegatedSuperTypeEntry(text: String): KtConstructorDelegationCall {
|
||||||
val colonOrEmpty = if (text.isEmpty()) "" else ": "
|
val colonOrEmpty = if (text.isEmpty()) "" else ": "
|
||||||
return createClass("class A { constructor()$colonOrEmpty$text {}").getSecondaryConstructors().first().getDelegationCall()
|
return createClass("class A { constructor()$colonOrEmpty$text {}").secondaryConstructors.first().getDelegationCall()
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassHeaderBuilder {
|
class ClassHeaderBuilder {
|
||||||
|
|||||||
Reference in New Issue
Block a user