diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt index 7464f8d3222..a869198cc52 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClass.kt @@ -39,7 +39,7 @@ public open class KtClass : KtClassOrObject { public fun getColon(): PsiElement? = findChildByType(KtTokens.COLON) - public fun getProperties(): List = getBody()?.getProperties().orEmpty() + public fun getProperties(): List = getBody()?.properties.orEmpty() public fun isInterface(): Boolean = _stub?.isInterface() ?: (findChildByType(KtTokens.INTERFACE_KEYWORD) != null) @@ -83,7 +83,7 @@ public open class KtClass : KtClassOrObject { return StringUtil.join(parts, ".") } - public fun getCompanionObjects(): List = getBody()?.getAllCompanionObjects().orEmpty() + public fun getCompanionObjects(): List = getBody()?.allCompanionObjects.orEmpty() public fun getClassOrInterfaceKeyword(): PsiElement? = findChildByType(TokenSet.create(KtTokens.CLASS_KEYWORD, KtTokens.INTERFACE_KEYWORD)) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassBody.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassBody.kt index 15c54919891..ed17b4cb856 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassBody.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassBody.kt @@ -14,97 +14,47 @@ * limitations under the License. */ -package org.jetbrains.kotlin.psi; +package org.jetbrains.kotlin.psi -import com.google.common.collect.Lists; -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.tree.TokenSet; -import kotlin.CollectionsKt; -import kotlin.jvm.functions.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.KtNodeTypes; -import org.jetbrains.kotlin.lexer.KtTokens; -import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; -import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; +import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement +import com.intellij.psi.tree.TokenSet +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub +import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes +import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.* +import java.util.* -import java.util.Arrays; -import java.util.List; +class KtClassBody : KtElementImplStub>, KtDeclarationContainer { + constructor(node: ASTNode) : super(node) + constructor(stub: KotlinPlaceHolderStub) : super(stub, CLASS_BODY) -import static org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.*; + override fun getDeclarations() = Arrays.asList(*getStubOrPsiChildren(DECLARATION_TYPES, KtDeclaration.ARRAY_FACTORY)) -public class KtClassBody extends KtElementImplStub> implements KtDeclarationContainer { + override fun accept(visitor: KtVisitor, data: D) = visitor.visitClassBody(this, data) - public KtClassBody(@NotNull ASTNode node) { - super(node); - } + val anonymousInitializers: List + get() = findChildrenByType(KtNodeTypes.ANONYMOUS_INITIALIZER) - public KtClassBody(@NotNull KotlinPlaceHolderStub stub) { - super(stub, CLASS_BODY); - } + internal val secondaryConstructors: List + get() = getStubOrPsiChildrenAsList(KtStubElementTypes.SECONDARY_CONSTRUCTOR) - @Override - @NotNull - public List getDeclarations() { - return Arrays.asList(getStubOrPsiChildren(DECLARATION_TYPES, KtDeclaration.ARRAY_FACTORY)); - } + val properties: List + get() = getStubOrPsiChildrenAsList(KtStubElementTypes.PROPERTY) - @Override - public R accept(@NotNull KtVisitor visitor, D data) { - return visitor.visitClassBody(this, data); - } + val allCompanionObjects: List + get() = getStubOrPsiChildrenAsList(KtStubElementTypes.OBJECT_DECLARATION).filter { it.isCompanion() } - @NotNull - public List getAnonymousInitializers() { - return findChildrenByType(KtNodeTypes.ANONYMOUS_INITIALIZER); - } + val rBrace: PsiElement? + get() = node.getChildren(TokenSet.create(KtTokens.RBRACE)).singleOrNull()?.psi - @NotNull - /* package-protected */ List getSecondaryConstructors() { - return getStubOrPsiChildrenAsList(KtStubElementTypes.SECONDARY_CONSTRUCTOR); - } - - @NotNull - public List getProperties() { - return getStubOrPsiChildrenAsList(KtStubElementTypes.PROPERTY); - } - - @NotNull - public List getAllCompanionObjects() { - List result = Lists.newArrayList(); - for (KtObjectDeclaration declaration : getStubOrPsiChildrenAsList(KtStubElementTypes.OBJECT_DECLARATION)) { - if (declaration.isCompanion()) { - result.add(declaration); - } - } - return result; - } - - @Nullable - public PsiElement getRBrace() { - ASTNode[] children = getNode().getChildren(TokenSet.create(KtTokens.RBRACE)); - return children.length == 1 ? children[0].getPsi() : null; - } - - @Nullable - public PsiElement getLBrace() { - ASTNode[] children = getNode().getChildren(TokenSet.create(KtTokens.LBRACE)); - return children.length == 1 ? children[0].getPsi() : null; - } + val lBrace: PsiElement? + get() = node.getChildren(TokenSet.create(KtTokens.LBRACE)).singleOrNull()?.psi /** * @return annotations that do not belong to any declaration due to incomplete code or syntax errors */ - @NotNull - public List getDanglingAnnotations() { - return CollectionsKt.flatMap( - getStubOrPsiChildrenAsList(MODIFIER_LIST), - new Function1>() { - @Override - public Iterable invoke(KtModifierList modifierList) { - return modifierList.getAnnotationEntries(); - } - }); - } + val danglingAnnotations: List + get() = getStubOrPsiChildrenAsList(MODIFIER_LIST).flatMap { it.annotationEntries } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt index 7823afcbaff..6e3e747ca3e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt @@ -61,7 +61,7 @@ abstract public class KtClassOrObject : } } - public fun getAnonymousInitializers(): List = getBody()?.getAnonymousInitializers().orEmpty() + public fun getAnonymousInitializers(): List = getBody()?.anonymousInitializers.orEmpty() public fun getNameAsDeclaration(): KtObjectDeclarationName? = findChildByType(KtNodeTypes.OBJECT_DECLARATION_NAME) as KtObjectDeclarationName? @@ -72,7 +72,7 @@ abstract public class KtClassOrObject : public fun addDeclaration(declaration: KtDeclaration): KtDeclaration { val body = getOrCreateBody() - val anchor = PsiTreeUtil.skipSiblingsBackward(body.getRBrace() ?: body.getLastChild()!!, javaClass()) + val anchor = PsiTreeUtil.skipSiblingsBackward(body.rBrace ?: body.getLastChild()!!, javaClass()) return body.addAfter(declaration, anchor) as KtDeclaration } @@ -105,7 +105,7 @@ abstract public class KtClassOrObject : public fun hasPrimaryConstructor(): Boolean = hasExplicitPrimaryConstructor() || !hasSecondaryConstructors() private fun hasSecondaryConstructors(): Boolean = !getSecondaryConstructors().isEmpty() - public fun getSecondaryConstructors(): List = getBody()?.getSecondaryConstructors().orEmpty() + public fun getSecondaryConstructors(): List = getBody()?.secondaryConstructors.orEmpty() public fun isAnnotation(): Boolean = hasModifier(KtTokens.ANNOTATION_KEYWORD) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 3570f1abb28..bb15633c32c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -608,12 +608,12 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val classBody = classOrObject.getOrCreateBody() return if (declaration is KtNamedFunction) { val anchor = PsiTreeUtil.skipSiblingsBackward( - classBody.getRBrace() ?: classBody.getLastChild()!!, + classBody.rBrace ?: classBody.getLastChild()!!, javaClass() ) classBody.addAfter(declaration, anchor) as KtNamedDeclaration } - else classBody.addAfter(declaration, classBody.getLBrace()!!) as KtNamedDeclaration + else classBody.addAfter(declaration, classBody.lBrace!!) as KtNamedDeclaration } private fun getTypeParameterRenames(scope: KtScope): Map {