From 40369f1e3b5954a15799103e86a19b260dc9c58c Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Fri, 28 Mar 2014 21:33:08 +0400 Subject: [PATCH] REVIEW: JetClassBody#getDeclarations() by stub --- .../src/org/jetbrains/jet/lang/psi/JetClassBody.java | 8 ++++++-- .../org/jetbrains/jet/lang/psi/JetDeclaration.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java index f1983adb012..965c08abdc7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.TokenSet; -import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; @@ -27,9 +26,14 @@ import org.jetbrains.jet.lang.psi.stubs.PsiJetPlaceHolderStub; import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import org.jetbrains.jet.lexer.JetTokens; +import java.util.Arrays; import java.util.List; public class JetClassBody extends JetElementImplStub> implements JetDeclarationContainer { + private static final TokenSet DECLARATION_TYPES = + TokenSet.create(JetStubElementTypes.CLASS, JetStubElementTypes.OBJECT_DECLARATION, JetStubElementTypes.CLASS_OBJECT, + JetStubElementTypes.FUNCTION, JetStubElementTypes.PROPERTY); + public JetClassBody(@NotNull ASTNode node) { super(node); } @@ -41,7 +45,7 @@ public class JetClassBody extends JetElementImplStub getDeclarations() { - return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class); + return Arrays.asList(getStubOrPsiChildren(DECLARATION_TYPES, JetDeclaration.ARRAY_FACTORY)); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java index 692c18d5085..99b87041e73 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java @@ -16,5 +16,17 @@ package org.jetbrains.jet.lang.psi; +import com.intellij.util.ArrayFactory; +import org.jetbrains.annotations.NotNull; + public interface JetDeclaration extends JetExpression, JetModifierListOwner { + JetDeclaration[] EMPTY_ARRAY = new JetDeclaration[0]; + + ArrayFactory ARRAY_FACTORY = new ArrayFactory() { + @NotNull + @Override + public JetDeclaration[] create(int count) { + return count == 0 ? EMPTY_ARRAY : new JetDeclaration[count]; + } + }; }