From 983be7df48ef96bc7f93e6323e80c0b4ef050f62 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Tue, 18 Jan 2005 15:37:49 +0300 Subject: [PATCH] Clearing PsiElement interface. --- openapi/src/com/intellij/lang/Language.java | 9 +++++++ .../com/intellij/lang/ParserDefinition.java | 18 +++++++++++++ openapi/src/com/intellij/lang/PsiBuilder.java | 23 ++++++++++++++++ openapi/src/com/intellij/lang/PsiParser.java | 15 +++++++++++ openapi/src/com/intellij/psi/PsiElement.java | 12 --------- .../src/com/intellij/psi/PsiErrorElement.java | 1 - .../com/intellij/psi/impl/PsiElementBase.java | 14 ---------- .../psi/impl/compiled/ClsElementImpl.java | 12 --------- .../psi/impl/file/PsiBinaryFileImpl.java | 11 -------- .../psi/impl/file/PsiDirectoryImpl.java | 15 ----------- .../psi/impl/file/PsiPackageImpl.java | 12 --------- .../intellij/psi/impl/light/LightElement.java | 11 -------- .../impl/source/tree/CompositePsiElement.java | 26 ------------------- .../psi/impl/source/tree/LeafPsiElement.java | 26 ------------------- .../impl/source/tree/PsiErrorElementImpl.java | 15 ----------- 15 files changed, 65 insertions(+), 155 deletions(-) create mode 100644 openapi/src/com/intellij/lang/ParserDefinition.java create mode 100644 openapi/src/com/intellij/lang/PsiBuilder.java create mode 100644 openapi/src/com/intellij/lang/PsiParser.java diff --git a/openapi/src/com/intellij/lang/Language.java b/openapi/src/com/intellij/lang/Language.java index 552e82f09415..475bbc35b667 100644 --- a/openapi/src/com/intellij/lang/Language.java +++ b/openapi/src/com/intellij/lang/Language.java @@ -3,6 +3,10 @@ package com.intellij.lang; import com.intellij.codeFormatting.PseudoTextBuilder; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter; +import com.intellij.lexer.Lexer; +import com.intellij.lexer.EmptyLexer; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiMethod; /** * Created by IntelliJ IDEA. @@ -20,4 +24,9 @@ public abstract class Language { return null; } + public ParserDefinition getParserDefinition() { + return null; + } + + } diff --git a/openapi/src/com/intellij/lang/ParserDefinition.java b/openapi/src/com/intellij/lang/ParserDefinition.java new file mode 100644 index 000000000000..e8c3103adc43 --- /dev/null +++ b/openapi/src/com/intellij/lang/ParserDefinition.java @@ -0,0 +1,18 @@ +package com.intellij.lang; + +import com.intellij.lexer.Lexer; +import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; + +/** + * Created by IntelliJ IDEA. + * User: max + * Date: Jan 17, 2005 + * Time: 7:57:54 PM + * To change this template use File | Settings | File Templates. + */ +public interface ParserDefinition { + Lexer createLexer(); + PsiParser createParser(); + PsiElement createElement(IElementType type, ElementFactoryHelper helper); +} diff --git a/openapi/src/com/intellij/lang/PsiBuilder.java b/openapi/src/com/intellij/lang/PsiBuilder.java new file mode 100644 index 000000000000..905a7205ccae --- /dev/null +++ b/openapi/src/com/intellij/lang/PsiBuilder.java @@ -0,0 +1,23 @@ +package com.intellij.lang; + +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.PsiElement; + +/** + * Created by IntelliJ IDEA. + * User: max + * Date: Jan 17, 2005 + * Time: 1:27:50 PM + * To change this template use File | Settings | File Templates. + */ +public interface PsiBuilder { + interface Marker {} + + Marker start(IElementType symbol); + void rollbackTo(Marker marker); + void drop(Marker marker); + void done(Marker marker); + void insertErrorElement(String messageText); + + PsiElement getTreeBuilt(); +} diff --git a/openapi/src/com/intellij/lang/PsiParser.java b/openapi/src/com/intellij/lang/PsiParser.java new file mode 100644 index 000000000000..11ac861ad861 --- /dev/null +++ b/openapi/src/com/intellij/lang/PsiParser.java @@ -0,0 +1,15 @@ +package com.intellij.lang; + +import com.intellij.psi.PsiElement; +import com.intellij.lexer.Lexer; + +/** + * Created by IntelliJ IDEA. + * User: max + * Date: Jan 17, 2005 + * Time: 2:14:05 PM + * To change this template use File | Settings | File Templates. + */ +public interface PsiParser { + PsiElement parse(Lexer lexer, PsiBuilder builder); +} diff --git a/openapi/src/com/intellij/psi/PsiElement.java b/openapi/src/com/intellij/psi/PsiElement.java index b3e5b874d965..c9e552a81254 100644 --- a/openapi/src/com/intellij/psi/PsiElement.java +++ b/openapi/src/com/intellij/psi/PsiElement.java @@ -74,22 +74,12 @@ public interface PsiElement extends UserDataHolder, Iconable { void checkAdd(PsiElement element) throws IncorrectOperationException; - void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException; - - void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException; - PsiElement addRange(PsiElement first, PsiElement last) throws IncorrectOperationException; PsiElement addRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException; PsiElement addRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException; - void checkAddRange(PsiElement first, PsiElement last) throws IncorrectOperationException; - - void checkAddRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException; - - void checkAddRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException; - void delete() throws IncorrectOperationException; void checkDelete() throws IncorrectOperationException; @@ -98,8 +88,6 @@ public interface PsiElement extends UserDataHolder, Iconable { PsiElement replace(PsiElement newElement) throws IncorrectOperationException; - void checkReplace(PsiElement newElement) throws IncorrectOperationException; - boolean isValid(); boolean isWritable(); diff --git a/openapi/src/com/intellij/psi/PsiErrorElement.java b/openapi/src/com/intellij/psi/PsiErrorElement.java index e50494ce8c86..7b14f6fc6ab8 100644 --- a/openapi/src/com/intellij/psi/PsiErrorElement.java +++ b/openapi/src/com/intellij/psi/PsiErrorElement.java @@ -6,5 +6,4 @@ package com.intellij.psi; public interface PsiErrorElement extends PsiElement{ String getErrorDescription(); - String getExpectedToken(); } \ No newline at end of file diff --git a/source/com/intellij/psi/impl/PsiElementBase.java b/source/com/intellij/psi/impl/PsiElementBase.java index d50e81669a75..09eb69c0c963 100644 --- a/source/com/intellij/psi/impl/PsiElementBase.java +++ b/source/com/intellij/psi/impl/PsiElementBase.java @@ -69,20 +69,6 @@ public abstract class PsiElementBase extends ElementBase implements PsiElement { throw new IncorrectOperationException(); } - public void checkAddRange(PsiElement first, PsiElement last) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException { throw new IncorrectOperationException(); } diff --git a/source/com/intellij/psi/impl/compiled/ClsElementImpl.java b/source/com/intellij/psi/impl/compiled/ClsElementImpl.java index 0aa436ded4f1..66ebe616b525 100644 --- a/source/com/intellij/psi/impl/compiled/ClsElementImpl.java +++ b/source/com/intellij/psi/impl/compiled/ClsElementImpl.java @@ -42,14 +42,6 @@ abstract class ClsElementImpl extends PsiElementBase implements PsiCompiledEleme throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); - } - public PsiElement add(PsiElement element) throws IncorrectOperationException { throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } @@ -74,10 +66,6 @@ abstract class ClsElementImpl extends PsiElementBase implements PsiCompiledEleme throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE); - } - protected static final String CAN_NOT_MODIFY_MESSAGE = "Cannot modify compiled element"; public abstract String getMirrorText(); diff --git a/source/com/intellij/psi/impl/file/PsiBinaryFileImpl.java b/source/com/intellij/psi/impl/file/PsiBinaryFileImpl.java index 5665713088da..0ded70917a93 100644 --- a/source/com/intellij/psi/impl/file/PsiBinaryFileImpl.java +++ b/source/com/intellij/psi/impl/file/PsiBinaryFileImpl.java @@ -190,14 +190,6 @@ public class PsiBinaryFileImpl extends PsiElementBase implements PsiBinaryFile, throw new IncorrectOperationException(); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public void delete() throws IncorrectOperationException{ checkDelete(); PsiFileImplUtil.doDelete(this); @@ -214,9 +206,6 @@ public class PsiBinaryFileImpl extends PsiElementBase implements PsiBinaryFile, return null; } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - } - public boolean isValid() { if (myFile == null) return true; // "dummy" file if (!myFile.isValid()) return false; diff --git a/source/com/intellij/psi/impl/file/PsiDirectoryImpl.java b/source/com/intellij/psi/impl/file/PsiDirectoryImpl.java index 3888228c2c18..1b78d7dce718 100644 --- a/source/com/intellij/psi/impl/file/PsiDirectoryImpl.java +++ b/source/com/intellij/psi/impl/file/PsiDirectoryImpl.java @@ -539,14 +539,6 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory { throw new IncorrectOperationException(); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public void delete() throws IncorrectOperationException { checkDelete(); //PsiDirectory parent = getParentDirectory(); @@ -587,13 +579,6 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory { return null; } - /** - * @not_implemented - */ - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - LOG.error("not implemented"); - } - public void accept(PsiElementVisitor visitor) { visitor.visitDirectory(this); } diff --git a/source/com/intellij/psi/impl/file/PsiPackageImpl.java b/source/com/intellij/psi/impl/file/PsiPackageImpl.java index ce1db1091c42..855da13e9d9e 100644 --- a/source/com/intellij/psi/impl/file/PsiPackageImpl.java +++ b/source/com/intellij/psi/impl/file/PsiPackageImpl.java @@ -271,14 +271,6 @@ public class PsiPackageImpl extends PsiElementBase implements PsiPackage { throw new IncorrectOperationException(); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public void delete() throws IncorrectOperationException { checkDelete(); PsiDirectory[] dirs = getDirectories(); @@ -298,10 +290,6 @@ public class PsiPackageImpl extends PsiElementBase implements PsiPackage { throw new IncorrectOperationException(); } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public boolean isValid() { return getDirectories().length > 0; } diff --git a/source/com/intellij/psi/impl/light/LightElement.java b/source/com/intellij/psi/impl/light/LightElement.java index 9479585fcf67..27ba0ea456d1 100644 --- a/source/com/intellij/psi/impl/light/LightElement.java +++ b/source/com/intellij/psi/impl/light/LightElement.java @@ -84,14 +84,6 @@ public abstract class LightElement extends PsiElementBase { throw new IncorrectOperationException(); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException{ - throw new IncorrectOperationException(); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException{ - throw new IncorrectOperationException(); - } - public PsiElement add(PsiElement element) throws IncorrectOperationException{ throw new IncorrectOperationException(); } @@ -116,7 +108,4 @@ public abstract class LightElement extends PsiElementBase { throw new IncorrectOperationException(); } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException{ - throw new IncorrectOperationException(); - } } diff --git a/source/com/intellij/psi/impl/source/tree/CompositePsiElement.java b/source/com/intellij/psi/impl/source/tree/CompositePsiElement.java index 615cfcf59c5d..ee5fceae3ce4 100644 --- a/source/com/intellij/psi/impl/source/tree/CompositePsiElement.java +++ b/source/com/intellij/psi/impl/source/tree/CompositePsiElement.java @@ -121,14 +121,6 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps CheckUtil.checkWritable(this); } - public final void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - - public final void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - public final PsiElement addRange(PsiElement first, PsiElement last) throws IncorrectOperationException { return SharedImplUtil.addRange(this, first, last, null, null); } @@ -143,20 +135,6 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps return SharedImplUtil.addRange(this, first, last, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE); } - public final void checkAddRange(PsiElement first, PsiElement last) throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - - public final void checkAddRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - - public final void checkAddRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - public void delete() throws IncorrectOperationException { LOG.assertTrue(getTreeParent() != null); CheckUtil.checkWritable(this); @@ -189,10 +167,6 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps return result; } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - public void accept(PsiElementVisitor visitor) { //TODO: remove this method!! visitor.visitElement(this); } diff --git a/source/com/intellij/psi/impl/source/tree/LeafPsiElement.java b/source/com/intellij/psi/impl/source/tree/LeafPsiElement.java index 9032d84cc34e..dd95e55a7ccc 100644 --- a/source/com/intellij/psi/impl/source/tree/LeafPsiElement.java +++ b/source/com/intellij/psi/impl/source/tree/LeafPsiElement.java @@ -98,14 +98,6 @@ public class LeafPsiElement extends LeafElementImpl implements PsiElement { throw new IncorrectOperationException(); } - public void checkAddBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public PsiElement addRange(PsiElement first, PsiElement last) throws IncorrectOperationException { throw new IncorrectOperationException(); } @@ -120,20 +112,6 @@ public class LeafPsiElement extends LeafElementImpl implements PsiElement { throw new IncorrectOperationException(); } - public void checkAddRange(PsiElement first, PsiElement last) throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - - public void checkAddRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) - throws IncorrectOperationException { - throw new IncorrectOperationException(); - } - public void delete() throws IncorrectOperationException { LOG.assertTrue(getTreeParent() != null); CheckUtil.checkWritable(this); @@ -161,10 +139,6 @@ public class LeafPsiElement extends LeafElementImpl implements PsiElement { return result; } - public void checkReplace(PsiElement newElement) throws IncorrectOperationException { - CheckUtil.checkWritable(this); - } - public String toString() { return "PsiElement" + "(" + getElementType().toString() + ")"; } diff --git a/source/com/intellij/psi/impl/source/tree/PsiErrorElementImpl.java b/source/com/intellij/psi/impl/source/tree/PsiErrorElementImpl.java index 8132bcb18ddd..7f739b831f39 100644 --- a/source/com/intellij/psi/impl/source/tree/PsiErrorElementImpl.java +++ b/source/com/intellij/psi/impl/source/tree/PsiErrorElementImpl.java @@ -18,21 +18,6 @@ public class PsiErrorElementImpl extends CompositePsiElement implements PsiError return myErrorDescription; } - public String getExpectedToken() { - //TODO: hack should be specified when error element is created. Just give it a try - if (myErrorDescription.indexOf("expected") >= 0) { - if (myErrorDescription.toLowerCase().indexOf("statement") >= 0) return "{}"; - int startApos = myErrorDescription.indexOf("\'"); - if (startApos >= 0) { - int stopApos = myErrorDescription.indexOf("\'", startApos + 1); - if (stopApos >= 0) { - return myErrorDescription.substring(startApos + 1, stopApos); - } - } - } - return null; - } - public void accept(PsiElementVisitor visitor){ visitor.visitErrorElement(this); }