From e9df2db178e091ab9b339f805fa4efc814993c43 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 5 Mar 2008 17:37:55 +0300 Subject: [PATCH] remove redundant PyElementEx interface --- .../jetbrains/python/psi/PyArgumentList.java | 2 +- .../src/com/jetbrains/python/psi/PyClass.java | 2 +- .../jetbrains/python/psi/PyExceptBlock.java | 4 +-- .../jetbrains/python/psi/PyExpression.java | 4 +-- .../com/jetbrains/python/psi/PyFunction.java | 2 +- .../jetbrains/python/psi/PyImportElement.java | 2 +- .../com/jetbrains/python/psi/PyParameter.java | 2 +- .../jetbrains/python/psi/PyParameterList.java | 2 +- .../jetbrains/python/psi/PyPrintTarget.java | 2 +- .../com/jetbrains/python/psi/PyStatement.java | 4 +-- .../jetbrains/python/psi/PyStatementList.java | 4 +-- .../src/com/jetbrains/python/psi/PyUtil.java | 30 ++----------------- .../python/psi/impl/PyElementImpl.java | 19 ++++++------ .../structureView/PyStructureViewElement.java | 15 +++------- 14 files changed, 31 insertions(+), 63 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/PyArgumentList.java b/python/src/com/jetbrains/python/psi/PyArgumentList.java index d01c1acf6834..5d97a328a745 100644 --- a/python/src/com/jetbrains/python/psi/PyArgumentList.java +++ b/python/src/com/jetbrains/python/psi/PyArgumentList.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; * Time: 13:44:24 * To change this template use File | Settings | File Templates. */ -public interface PyArgumentList extends PyElementEx { +public interface PyArgumentList extends PyElement { @NotNull PyExpression[] getArguments(); @Nullable PyKeywordArgument getKeywordArgument(String name); diff --git a/python/src/com/jetbrains/python/psi/PyClass.java b/python/src/com/jetbrains/python/psi/PyClass.java index 9905b333e24c..3a6c2744e48f 100644 --- a/python/src/com/jetbrains/python/psi/PyClass.java +++ b/python/src/com/jetbrains/python/psi/PyClass.java @@ -26,6 +26,6 @@ import org.jetbrains.annotations.NotNull; * Time: 0:26:47 * To change this template use File | Settings | File Templates. */ -public interface PyClass extends PsiNamedElement, PyElementEx, PyDocStringOwner { +public interface PyClass extends PsiNamedElement, PyElement, PyDocStringOwner { @NotNull PyStatementList getStatementList(); } diff --git a/python/src/com/jetbrains/python/psi/PyExceptBlock.java b/python/src/com/jetbrains/python/psi/PyExceptBlock.java index 097b91a2de75..1609e49c147a 100644 --- a/python/src/com/jetbrains/python/psi/PyExceptBlock.java +++ b/python/src/com/jetbrains/python/psi/PyExceptBlock.java @@ -26,8 +26,8 @@ import org.jetbrains.annotations.NotNull; * Time: 23:37:32 * To change this template use File | Settings | File Templates. */ -public interface PyExceptBlock extends PyElementEx { - static PyExceptBlock[] EMPTY_ARRAY = new PyExceptBlock[0]; +public interface PyExceptBlock extends PyElement { + PyExceptBlock[] EMPTY_ARRAY = new PyExceptBlock[0]; @Nullable PyExpression getExceptClass(); @Nullable PyExpression getTarget(); diff --git a/python/src/com/jetbrains/python/psi/PyExpression.java b/python/src/com/jetbrains/python/psi/PyExpression.java index b69221d58299..6134192fd3a7 100644 --- a/python/src/com/jetbrains/python/psi/PyExpression.java +++ b/python/src/com/jetbrains/python/psi/PyExpression.java @@ -23,6 +23,6 @@ package com.jetbrains.python.psi; * Time: 10:41:59 * To change this template use File | Settings | File Templates. */ -public interface PyExpression extends PyElementEx { - public static PyExpression[] EMPTY_ARRAY = new PyExpression[0]; +public interface PyExpression extends PyElement { + PyExpression[] EMPTY_ARRAY = new PyExpression[0]; } diff --git a/python/src/com/jetbrains/python/psi/PyFunction.java b/python/src/com/jetbrains/python/psi/PyFunction.java index 1b18fa6882d4..a30a65513e6a 100644 --- a/python/src/com/jetbrains/python/psi/PyFunction.java +++ b/python/src/com/jetbrains/python/psi/PyFunction.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable; * Time: 23:01:03 * To change this template use File | Settings | File Templates. */ -public interface PyFunction extends PsiNamedElement, PyElementEx, PyDocStringOwner { +public interface PyFunction extends PsiNamedElement, PyElement, PyDocStringOwner { /** * Returns the AST node for the function name identifier. * diff --git a/python/src/com/jetbrains/python/psi/PyImportElement.java b/python/src/com/jetbrains/python/psi/PyImportElement.java index aa52d5f9f1b6..74f7b591d451 100644 --- a/python/src/com/jetbrains/python/psi/PyImportElement.java +++ b/python/src/com/jetbrains/python/psi/PyImportElement.java @@ -23,7 +23,7 @@ package com.jetbrains.python.psi; * Time: 22:22:17 * To change this template use File | Settings | File Templates. */ -public interface PyImportElement extends PyElementEx { +public interface PyImportElement extends PyElement { PyReferenceExpression getImportReference(); diff --git a/python/src/com/jetbrains/python/psi/PyParameter.java b/python/src/com/jetbrains/python/psi/PyParameter.java index f05746a9a69e..5edd70696549 100644 --- a/python/src/com/jetbrains/python/psi/PyParameter.java +++ b/python/src/com/jetbrains/python/psi/PyParameter.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; * Time: 23:04:33 * To change this template use File | Settings | File Templates. */ -public interface PyParameter extends PyElementEx, PsiNamedElement { +public interface PyParameter extends PyElement, PsiNamedElement { boolean isPositionalContainer(); boolean isKeywordContainer(); @Nullable PyExpression getDefaultValue(); diff --git a/python/src/com/jetbrains/python/psi/PyParameterList.java b/python/src/com/jetbrains/python/psi/PyParameterList.java index 91db5f2b09ee..1e0a971cbe6d 100644 --- a/python/src/com/jetbrains/python/psi/PyParameterList.java +++ b/python/src/com/jetbrains/python/psi/PyParameterList.java @@ -23,6 +23,6 @@ package com.jetbrains.python.psi; * Time: 23:03:11 * To change this template use File | Settings | File Templates. */ -public interface PyParameterList extends PyElementEx { +public interface PyParameterList extends PyElement { PyParameter[] getParameters(); } diff --git a/python/src/com/jetbrains/python/psi/PyPrintTarget.java b/python/src/com/jetbrains/python/psi/PyPrintTarget.java index 8541ec9072e1..c83d6dcfb683 100644 --- a/python/src/com/jetbrains/python/psi/PyPrintTarget.java +++ b/python/src/com/jetbrains/python/psi/PyPrintTarget.java @@ -23,5 +23,5 @@ package com.jetbrains.python.psi; * Time: 11:34:36 * To change this template use File | Settings | File Templates. */ -public interface PyPrintTarget extends PyElementEx { +public interface PyPrintTarget extends PyElement { } diff --git a/python/src/com/jetbrains/python/psi/PyStatement.java b/python/src/com/jetbrains/python/psi/PyStatement.java index 6947fd06ae8a..9dfc10f9ad75 100644 --- a/python/src/com/jetbrains/python/psi/PyStatement.java +++ b/python/src/com/jetbrains/python/psi/PyStatement.java @@ -23,6 +23,6 @@ package com.jetbrains.python.psi; * Time: 12:14:53 * To change this template use File | Settings | File Templates. */ -public interface PyStatement extends PyElementEx { - static PyStatement[] EMPTY_ARRAY = new PyStatement[0]; +public interface PyStatement extends PyElement { + PyStatement[] EMPTY_ARRAY = new PyStatement[0]; } diff --git a/python/src/com/jetbrains/python/psi/PyStatementList.java b/python/src/com/jetbrains/python/psi/PyStatementList.java index fd999cdb4736..0f57f8138803 100644 --- a/python/src/com/jetbrains/python/psi/PyStatementList.java +++ b/python/src/com/jetbrains/python/psi/PyStatementList.java @@ -23,8 +23,8 @@ package com.jetbrains.python.psi; * Time: 16:39:33 * To change this template use File | Settings | File Templates. */ -public interface PyStatementList extends PyElementEx { - public static PyStatementList[] EMPTY_ARRAY = new PyStatementList[0]; +public interface PyStatementList extends PyElement { + PyStatementList[] EMPTY_ARRAY = new PyStatementList[0]; PyStatement[] getStatements(); } diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index ed5446467050..0096165a94b3 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -17,11 +17,8 @@ package com.jetbrains.python.psi; import com.intellij.lang.ASTNode; -import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; @@ -39,28 +36,7 @@ public class PyUtil { private PyUtil() { } - public static FileType findPythonFileType() { - for (FileType type : FileTypeManager.getInstance() - .getRegisteredFileTypes()) { - String defaultExt = type.getDefaultExtension(); - //noinspection ConstantConditions - if (defaultExt != null && defaultExt.equalsIgnoreCase("py")) { - return type; - } - } - throw new IllegalStateException("no python language loaded??"); - } - - public static PythonLanguage getLanguage() { - for (Language language : Language.getRegisteredLanguages()) { - if (language instanceof PythonLanguage) { - return (PythonLanguage) language; - } - } - throw new IllegalStateException("No python language"); - } - - public static void ensureWritable(PsiElement element) { + public static void ensureWritable(PsiElement element) { PsiDocumentManager docmgr = PsiDocumentManager.getInstance( element.getProject()); PsiFile containingFile = element.getContainingFile(); @@ -172,13 +148,13 @@ public class PyUtil { } if (forceAdd) { PyListLiteralExpression listLiteral = - expr.getLanguage().getElementGenerator().createListLiteral(project); + PythonLanguage.getInstance().getElementGenerator().createListLiteral(project); try { listLiteral.add(add); } catch (IncorrectOperationException e) { throw new IllegalStateException(e); } - PyBinaryExpression binExpr = expr.getLanguage().getElementGenerator() + PyBinaryExpression binExpr = PythonLanguage.getInstance().getElementGenerator() .createBinaryExpression(project, "+", expr, listLiteral); ASTNode exprNode = expr.getNode(); assert exprNode != null; diff --git a/python/src/com/jetbrains/python/psi/impl/PyElementImpl.java b/python/src/com/jetbrains/python/psi/impl/PyElementImpl.java index c15f678e87d5..cd3d2accd07d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyElementImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyElementImpl.java @@ -24,15 +24,14 @@ import com.intellij.psi.PsiReference; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import com.jetbrains.python.PyTokenTypes; -import com.jetbrains.python.PythonLanguage; import com.jetbrains.python.PythonFileType; +import com.jetbrains.python.PythonLanguage; import com.jetbrains.python.psi.PyElement; -import com.jetbrains.python.psi.PyElementEx; import com.jetbrains.python.psi.PyElementType; import com.jetbrains.python.psi.PyElementVisitor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Created by IntelliJ IDEA. @@ -42,7 +41,7 @@ import com.jetbrains.python.psi.PyElementVisitor; * To change this template use File | Settings | File Templates. */ @SuppressWarnings("deprecation") -public class PyElementImpl extends ASTWrapperPsiElement implements PyElementEx { +public class PyElementImpl extends ASTWrapperPsiElement implements PyElement { public PyElementImpl(ASTNode astNode) { super(astNode); @@ -101,7 +100,7 @@ public class PyElementImpl extends ASTWrapperPsiElement implements PyElementEx { pyVisitor.visitPyElement(this); } - protected static T[] nodesToPsi(ASTNode[] nodes, T[] array) { + protected static T[] nodesToPsi(ASTNode[] nodes, T[] array) { T[] psiElements = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), nodes.length); for (int i = 0; i < nodes.length; i++) { //noinspection unchecked @@ -111,13 +110,13 @@ public class PyElementImpl extends ASTWrapperPsiElement implements PyElementEx { } @NotNull - protected T[] childrenToPsi(TokenSet filterSet, T[] array) { + protected T[] childrenToPsi(TokenSet filterSet, T[] array) { final ASTNode[] nodes = getNode().getChildren(filterSet); return nodesToPsi(nodes, array); } @Nullable - protected T childToPsi(TokenSet filterSet, int index) { + protected T childToPsi(TokenSet filterSet, int index) { final ASTNode[] nodes = getNode().getChildren(filterSet); if (nodes.length <= index) { return null; @@ -127,7 +126,7 @@ public class PyElementImpl extends ASTWrapperPsiElement implements PyElementEx { } @Nullable - protected T childToPsi(IElementType elType) { + protected T childToPsi(IElementType elType) { final ASTNode node = getNode().findChildByType(elType); if (node == null) { return null; @@ -137,7 +136,7 @@ public class PyElementImpl extends ASTWrapperPsiElement implements PyElementEx { } @NotNull - protected T childToPsiNotNull(TokenSet filterSet, int index) { + protected T childToPsiNotNull(TokenSet filterSet, int index) { final PyElement child = childToPsi(filterSet, index); if (child == null) { throw new RuntimeException("child must not be null"); diff --git a/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java b/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java index 862a188b2332..a9f1c95cfce3 100644 --- a/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java +++ b/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java @@ -23,20 +23,13 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; - +import com.jetbrains.python.psi.*; import org.jetbrains.annotations.Nullable; +import javax.swing.*; import java.util.ArrayList; import java.util.List; -import javax.swing.Icon; - -import com.jetbrains.python.psi.PyElement; -import com.jetbrains.python.psi.*; -import com.jetbrains.python.psi.PyFunction; -import com.jetbrains.python.psi.PyParameter; -import com.jetbrains.python.psi.PyParameterList; - /** * Created by IntelliJ IDEA. * User: yole @@ -68,11 +61,11 @@ public class PyStructureViewElement implements StructureViewTreeElement { } public StructureViewTreeElement[] getChildren() { - final List childrenElements = new ArrayList(); + final List childrenElements = new ArrayList(); _element.acceptChildren(new PyElementVisitor() { @Override public void visitElement(PsiElement element) { if (element instanceof PsiNamedElement && ((PsiNamedElement)element).getName() != null) { - childrenElements.add((PyElementEx)element); + childrenElements.add((PyElement)element); } else { element.acceptChildren(this);