REVIEW: JetClassBody#getDeclarations() by stub

This commit is contained in:
Pavel V. Talanov
2014-03-28 21:33:08 +04:00
parent 741dba111b
commit 40369f1e3b
2 changed files with 18 additions and 2 deletions
@@ -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<PsiJetPlaceHolderStub<JetClassBody>> 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<PsiJetPlaceHolderStub<JetCl
@Override
@NotNull
public List<JetDeclaration> getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
return Arrays.asList(getStubOrPsiChildren(DECLARATION_TYPES, JetDeclaration.ARRAY_FACTORY));
}
@Override
@@ -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<JetDeclaration> ARRAY_FACTORY = new ArrayFactory<JetDeclaration>() {
@NotNull
@Override
public JetDeclaration[] create(int count) {
return count == 0 ? EMPTY_ARRAY : new JetDeclaration[count];
}
};
}