From 9cb7cb56f1a8920e84340a76550cb96de9bb4099 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 11 May 2012 15:02:41 +0400 Subject: [PATCH] Refactoring - new interface for common method --- .../jetbrains/jet/lang/psi/JetClassBody.java | 4 ++- .../jet/lang/psi/JetClassOrObject.java | 4 +-- .../jet/lang/psi/JetDeclarationContainer.java | 29 +++++++++++++++++++ .../org/jetbrains/jet/lang/psi/JetFile.java | 5 +++- .../jet/lang/psi/JetNamespaceBody.java | 4 ++- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java 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 853d94cc51c..11da1bacd73 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java @@ -30,11 +30,13 @@ import java.util.List; /** * @author max */ -public class JetClassBody extends JetElement { +public class JetClassBody extends JetElement implements JetDeclarationContainer { public JetClassBody(@NotNull ASTNode node) { super(node); } + @Override + @NotNull public List getDeclarations() { return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java index 42e0d6d1239..a4ad2a43b6e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java @@ -26,9 +26,7 @@ import java.util.List; /** * @author max */ -public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner { - List getDeclarations(); - +public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner, JetDeclarationContainer { @Nullable JetDelegationSpecifierList getDelegationSpecifierList(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java new file mode 100644 index 00000000000..07a76741a12 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author Nikolay Krasko + */ +public interface JetDeclarationContainer { + @NotNull + List getDeclarations(); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java index 152b3d4b883..84ccdd7d97f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java @@ -33,11 +33,12 @@ import org.jetbrains.jet.plugin.JetLanguage; import java.util.List; -public class JetFile extends PsiFileBase { +public class JetFile extends PsiFileBase implements JetDeclarationContainer { public JetFile(FileViewProvider viewProvider) { super(viewProvider, JetLanguage.INSTANCE); } + @Override @NotNull public FileType getFileType() { return JetFileType.INSTANCE; @@ -48,6 +49,8 @@ public class JetFile extends PsiFileBase { return "JetFile: " + getName(); } + @NotNull + @Override public List getDeclarations() { return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java index a599f4b8e4a..bbe19cf4d8b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java @@ -25,11 +25,13 @@ import java.util.List; /** * @author max */ -public class JetNamespaceBody extends JetElement { +public class JetNamespaceBody extends JetElement implements JetDeclarationContainer { public JetNamespaceBody(@NotNull ASTNode node) { super(node); } + @NotNull + @Override public List getDeclarations() { return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class); }