From 7ddeac904c3159b161ea47c1bdf4ed1d4ea555e4 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 27 Dec 2010 17:06:19 +0300 Subject: [PATCH] JavaASTFactory elimination --- .../java/stubs/JavaAnnotationElementType.java | 9 +- .../impl/java/stubs/JavaClassElementType.java | 3 +- .../JavaClassInitializerElementType.java | 9 +- .../JavaClassReferenceListElementType.java | 3 +- .../java/stubs/JavaFieldStubElementType.java | 3 +- .../java/stubs/JavaImportListElementType.java | 9 +- .../stubs/JavaImportStatementElementType.java | 3 +- .../java/stubs/JavaMethodElementType.java | 3 +- .../stubs/JavaModifierListElementType.java | 9 +- .../java/stubs/JavaParameterElementType.java | 9 +- .../stubs/JavaParameterListElementType.java | 9 +- .../impl/java/stubs/JavaStubElementType.java | 5 +- .../impl/java/stubs/JavaStubElementTypes.java | 124 ++++++-- .../stubs/JavaTypeParameterElementType.java | 9 +- .../JavaTypeParameterListElementType.java | 11 +- .../psi/impl/source/JavaFileElementType.java | 6 + .../source/PsiDiamondTypeElementImpl.java | 17 +- .../psi/impl/source/PsiTypeElementImpl.java | 7 +- .../psi/impl/source/tree/JavaASTFactory.java | 288 +----------------- .../impl/source/tree/JavaDocElementType.java | 98 ++++-- .../psi/impl/source/tree/JavaElementType.java | 168 +++++----- .../parser-full/expressionParsing/New15.txt | 2 +- .../psi/parser-partial/references/Type7.txt | 2 +- .../src/com/intellij/lang/ASTFactory.java | 19 +- .../src/com/intellij/util/ReflectionUtil.java | 43 ++- 25 files changed, 428 insertions(+), 440 deletions(-) rename platform/lang-impl/src/com/intellij/psi/impl/source/tree/PlainTextFileElement.java => java/java-impl/src/com/intellij/psi/impl/source/PsiDiamondTypeElementImpl.java (58%) diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationElementType.java index 06b3daf2291f..488e2cfb5874 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -25,11 +24,13 @@ import com.intellij.psi.impl.compiled.ClsAnnotationImpl; import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl; import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex; import com.intellij.psi.impl.source.tree.LightTreeUtil; +import com.intellij.psi.impl.source.tree.java.AnnotationElement; import com.intellij.psi.impl.source.tree.java.PsiAnnotationImpl; import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -41,6 +42,12 @@ public class JavaAnnotationElementType extends JavaStubElementType { +public abstract class JavaClassElementType extends JavaStubElementType { public JavaClassElementType(@NotNull @NonNls final String id) { super(id); } diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaClassInitializerElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaClassInitializerElementType.java index 68172243fb68..4df4d55be21e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaClassInitializerElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaClassInitializerElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -22,10 +21,12 @@ import com.intellij.lang.LighterAST; import com.intellij.psi.PsiClassInitializer; import com.intellij.psi.impl.java.stubs.impl.PsiClassInitializerStubImpl; import com.intellij.psi.impl.source.PsiClassInitializerImpl; +import com.intellij.psi.impl.source.tree.java.ClassInitializerElement; import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -37,6 +38,12 @@ public class JavaClassInitializerElementType extends JavaStubElementType { +public abstract class JavaClassReferenceListElementType extends JavaStubElementType { public JavaClassReferenceListElementType(@NotNull @NonNls String id) { super(id, true); } diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaFieldStubElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaFieldStubElementType.java index 047c5db51e96..8a9f5814c8a2 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaFieldStubElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaFieldStubElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -48,7 +47,7 @@ import java.io.IOException; /* * @author max */ -public class JavaFieldStubElementType extends JavaStubElementType { +public abstract class JavaFieldStubElementType extends JavaStubElementType { private static final int INITIALIZER_LENGTH_LIMIT = 1000; public JavaFieldStubElementType(@NotNull @NonNls final String id) { diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaImportListElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaImportListElementType.java index 8edc6d1dfb47..344bc51e482f 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaImportListElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaImportListElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -22,10 +21,12 @@ import com.intellij.lang.LighterASTNode; import com.intellij.psi.PsiImportList; import com.intellij.psi.impl.java.stubs.impl.PsiImportListStubImpl; import com.intellij.psi.impl.source.PsiImportListImpl; +import com.intellij.psi.impl.source.tree.java.ImportListElement; import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -37,6 +38,12 @@ public class JavaImportListElementType extends JavaStubElementType { +public abstract class JavaImportStatementElementType extends JavaStubElementType { public JavaImportStatementElementType(@NonNls @NotNull final String id) { super(id); } diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaMethodElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaMethodElementType.java index b4a5b418c77b..bf4819fbca3a 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaMethodElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaMethodElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -49,7 +48,7 @@ import java.util.List; /* * @author max */ -public class JavaMethodElementType extends JavaStubElementType { +public abstract class JavaMethodElementType extends JavaStubElementType { public JavaMethodElementType(@NonNls final String name) { super(name); } diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaModifierListElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaModifierListElementType.java index 05311733f461..5e1a2d1fa230 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaModifierListElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaModifierListElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -25,10 +24,12 @@ import com.intellij.psi.impl.compiled.ClsModifierListImpl; import com.intellij.psi.impl.java.stubs.impl.PsiModifierListStubImpl; import com.intellij.psi.impl.source.PsiModifierListImpl; import com.intellij.psi.impl.source.tree.JavaElementType; +import com.intellij.psi.impl.source.tree.java.ModifierListElement; import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -40,6 +41,12 @@ public class JavaModifierListElementType extends JavaStubElementType extends ILightStubElementType { +public abstract class JavaStubElementType + extends ILightStubElementType implements ICompositeElementType { private final boolean myLeftBound; protected JavaStubElementType(@NotNull @NonNls final String debugName) { diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java index 09341620fc05..74b0d5d6acb6 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java @@ -13,40 +13,122 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.intellij.psi.impl.java.stubs; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.impl.source.JavaFileElementType; +import com.intellij.psi.impl.source.tree.java.*; +import com.intellij.psi.tree.IStubFileElementType; +import org.jetbrains.annotations.NotNull; /* * @author max */ -package com.intellij.psi.impl.java.stubs; - -import com.intellij.psi.impl.source.JavaFileElementType; -import com.intellij.psi.tree.IStubFileElementType; - public interface JavaStubElementTypes { - JavaClassElementType CLASS = new JavaClassElementType("CLASS"); - JavaClassElementType ANONYMOUS_CLASS = new JavaClassElementType("ANONYMOUS_CLASS"); - JavaClassElementType ENUM_CONSTANT_INITIALIZER = new JavaClassElementType("ENUM_CONSTANT_INITIALIZER"); - JavaModifierListElementType MODIFIER_LIST = new JavaModifierListElementType(); - JavaMethodElementType METHOD = new JavaMethodElementType("METHOD"); - JavaMethodElementType ANNOTATION_METHOD = new JavaMethodElementType("ANNOTATION_METHOD"); - JavaFieldStubElementType FIELD = new JavaFieldStubElementType("FIELD"); - JavaFieldStubElementType ENUM_CONSTANT = new JavaFieldStubElementType("ENUM_CONSTANT"); - JavaAnnotationElementType ANNOTATION = new JavaAnnotationElementType(); - JavaClassReferenceListElementType EXTENDS_LIST = new JavaClassReferenceListElementType("EXTENDS_LIST"); - JavaClassReferenceListElementType IMPLEMENTS_LIST = new JavaClassReferenceListElementType("IMPLEMENTS_LIST"); - JavaClassReferenceListElementType THROWS_LIST = new JavaClassReferenceListElementType("THROWS_LIST"); - JavaClassReferenceListElementType EXTENDS_BOUND_LIST = new JavaClassReferenceListElementType("EXTENDS_BOUND_LIST"); - JavaParameterElementType PARAMETER = new JavaParameterElementType(); JavaParameterListElementType PARAMETER_LIST = new JavaParameterListElementType(); JavaTypeParameterElementType TYPE_PARAMETER = new JavaTypeParameterElementType(); JavaTypeParameterListElementType TYPE_PARAMETER_LIST = new JavaTypeParameterListElementType(); JavaClassInitializerElementType CLASS_INITIALIZER = new JavaClassInitializerElementType(); JavaImportListElementType IMPORT_LIST = new JavaImportListElementType(); - JavaImportStatementElementType IMPORT_STATEMENT = new JavaImportStatementElementType("IMPORT_STATEMENT"); - JavaImportStatementElementType IMPORT_STATIC_STATEMENT = new JavaImportStatementElementType("IMPORT_STATIC_STATEMENT"); + + JavaClassElementType CLASS = new JavaClassElementType("CLASS") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new ClassElement(this); + } + }; + JavaClassElementType ANONYMOUS_CLASS = new JavaClassElementType("ANONYMOUS_CLASS") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new AnonymousClassElement(); + } + }; + JavaClassElementType ENUM_CONSTANT_INITIALIZER = new JavaClassElementType("ENUM_CONSTANT_INITIALIZER") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new EnumConstantInitializerElement(); + } + }; + + JavaMethodElementType METHOD = new JavaMethodElementType("METHOD") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new MethodElement(); + } + }; + JavaMethodElementType ANNOTATION_METHOD = new JavaMethodElementType("ANNOTATION_METHOD") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new AnnotationMethodElement(); + } + }; + + JavaFieldStubElementType FIELD = new JavaFieldStubElementType("FIELD") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new FieldElement(); + } + }; + JavaFieldStubElementType ENUM_CONSTANT = new JavaFieldStubElementType("ENUM_CONSTANT") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new EnumConstantElement(); + } + }; + + JavaClassReferenceListElementType EXTENDS_LIST = new JavaClassReferenceListElementType("EXTENDS_LIST") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new ExtendsListElement(); + } + }; + JavaClassReferenceListElementType IMPLEMENTS_LIST = new JavaClassReferenceListElementType("IMPLEMENTS_LIST") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new ImplementsListElement(); + } + }; + JavaClassReferenceListElementType THROWS_LIST = new JavaClassReferenceListElementType("THROWS_LIST") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new PsiThrowsListImpl(); + } + }; + JavaClassReferenceListElementType EXTENDS_BOUND_LIST = new JavaClassReferenceListElementType("EXTENDS_BOUND_LIST") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new TypeParameterExtendsBoundsListElement(); + } + }; + + JavaImportStatementElementType IMPORT_STATEMENT = new JavaImportStatementElementType("IMPORT_STATEMENT") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new ImportStatementElement(); + } + }; + JavaImportStatementElementType IMPORT_STATIC_STATEMENT = new JavaImportStatementElementType("IMPORT_STATIC_STATEMENT") { + @NotNull + @Override + public ASTNode createCompositeNode() { + return new ImportStaticStatementElement(); + } + }; IStubFileElementType JAVA_FILE = new JavaFileElementType(); } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaTypeParameterElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaTypeParameterElementType.java index aca86f78eba8..fc07905e2255 100644 --- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaTypeParameterElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaTypeParameterElementType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.psi.impl.java.stubs; import com.intellij.lang.ASTNode; @@ -26,11 +25,13 @@ import com.intellij.psi.impl.compiled.ClsTypeParameterImpl; import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterStubImpl; import com.intellij.psi.impl.source.tree.LightTreeUtil; import com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl; +import com.intellij.psi.impl.source.tree.java.TypeParameterElement; import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -42,6 +43,12 @@ public class JavaTypeParameterElementType extends JavaStubElementType parseContentsLight(final ASTNode chameleon) { final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/PlainTextFileElement.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiDiamondTypeElementImpl.java similarity index 58% rename from platform/lang-impl/src/com/intellij/psi/impl/source/tree/PlainTextFileElement.java rename to java/java-impl/src/com/intellij/psi/impl/source/PsiDiamondTypeElementImpl.java index d02536b84f1f..d484a809ab3d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/PlainTextFileElement.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiDiamondTypeElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -13,13 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.intellij.psi.impl.source; -package com.intellij.psi.impl.source.tree; +import com.intellij.psi.impl.source.tree.JavaElementType; -import com.intellij.psi.PlainTextTokenTypes; +public class PsiDiamondTypeElementImpl extends PsiTypeElementImpl { + @SuppressWarnings({"UnusedDeclaration"}) + public PsiDiamondTypeElementImpl() { + super(JavaElementType.DIAMOND_TYPE); + } -public class PlainTextFileElement extends FileElement{ - public PlainTextFileElement(CharSequence text) { - super(PlainTextTokenTypes.PLAIN_TEXT_FILE, text); + @Override + public String toString() { + return "PsiTypeElement:DIAMOND"; } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java index 7850bce446f4..a277f80d2a3e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/PsiTypeElementImpl.java @@ -44,8 +44,13 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl private volatile PsiType myCachedType = null; private volatile PatchedSoftReference myCachedDetachedType = null; + @SuppressWarnings({"UnusedDeclaration"}) public PsiTypeElementImpl() { - super(JavaElementType.TYPE); + this(JavaElementType.TYPE); + } + + protected PsiTypeElementImpl(final IElementType type) { + super(type); } public void clearCaches() { diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java index 916dbe16cef6..088e7a03b0dc 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java @@ -13,292 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.impl.source.tree; import com.intellij.lang.ASTFactory; -import com.intellij.psi.PlainTextTokenTypes; -import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; -import com.intellij.psi.impl.source.*; -import com.intellij.psi.impl.source.javadoc.*; -import com.intellij.psi.impl.source.tree.java.*; +import com.intellij.psi.impl.source.Constants; +import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl; +import com.intellij.psi.impl.source.javadoc.PsiDocTokenImpl; +import com.intellij.psi.impl.source.tree.java.PsiIdentifierImpl; +import com.intellij.psi.impl.source.tree.java.PsiJavaTokenImpl; +import com.intellij.psi.impl.source.tree.java.PsiKeywordImpl; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.IFileElementType; -import com.intellij.psi.tree.ILazyParseableElementType; import com.intellij.psi.tree.java.IJavaDocElementType; import com.intellij.psi.tree.java.IJavaElementType; +/** + * @author max + */ public class JavaASTFactory extends ASTFactory implements Constants { - @Override - public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) { - if (type == JavaStubElementTypes.JAVA_FILE) { - return new JavaFileElement(text); - } - else if (type == PlainTextTokenTypes.PLAIN_TEXT_FILE) { - return new PlainTextFileElement(text); - } - else if (type == CODE_FRAGMENT) { - return new CodeFragmentElement(text); - } - else if (type == DUMMY_HOLDER) { - return new DummyHolderElement(text); - } - else if(type instanceof IFileElementType) { - return new FileElement(type, text); - } - else if (type == JavaDocElementType.DOC_COMMENT) { - return new PsiDocCommentImpl(text); + public CompositeElement createComposite(final IElementType type) { + if (type == DOC_TAG_VALUE_TOKEN) { + return new PsiDocTagValueImpl(); } return null; } - public CompositeElement createComposite(final IElementType type) { - //TODO: Replace whole method with type.createPsiElement(); - if (type == TYPE_PARAMETER_LIST) { - return new TypeParameterListElement(); - } - else if (type == TYPE_PARAMETER) { - return new TypeParameterElement(); - } - else if (type == EXTENDS_BOUND_LIST) { - return new TypeParameterExtendsBoundsListElement(); - } - else if (type == ERROR_ELEMENT) { - return new PsiErrorElementImpl(); - } - else if (type == DOC_TAG) { - return new PsiDocTagImpl(); - } - else if (type == DOC_TAG_VALUE_TOKEN) { - return new PsiDocTagValueImpl(); - } - else if (type == DOC_METHOD_OR_FIELD_REF) { - return new PsiDocMethodOrFieldRef(); - } - else if (type == DOC_PARAMETER_REF) { - return new PsiDocParamRef(); - } - else if (type == DOC_INLINE_TAG) { - return new PsiInlineDocTagImpl(); - } - else if (type == CLASS) { - return new ClassElement(type); - } - else if (type == ANONYMOUS_CLASS) { - return new AnonymousClassElement(); - } - else if (type == ENUM_CONSTANT_INITIALIZER) { - return new EnumConstantInitializerElement(); - } - else if (type == FIELD) { - return new FieldElement(); - } - else if (type == ENUM_CONSTANT) { - return new EnumConstantElement(); - } - else if (type == METHOD) { - return new MethodElement(); - } - else if (type == LOCAL_VARIABLE) { - return new PsiLocalVariableImpl(); - } - else if (type == PARAMETER) { - return new ParameterElement(); - } - else if (type == PARAMETER_LIST) { - return new ParameterListElement(); - } - else if (type == CLASS_INITIALIZER) { - return new ClassInitializerElement(); - } - else if (type == PACKAGE_STATEMENT) { - return new PsiPackageStatementImpl(); - } - else if (type == IMPORT_LIST) { - return new ImportListElement(); - } - else if (type == IMPORT_STATEMENT) { - return new ImportStatementElement(); - } - else if (type == IMPORT_STATIC_STATEMENT) { - return new ImportStaticStatementElement(); - } - else if (type == IMPORT_STATIC_REFERENCE) { - return new PsiImportStaticReferenceElementImpl(); - } - else if (type == JAVA_CODE_REFERENCE) { - return new PsiJavaCodeReferenceElementImpl(); - } - else if (type == REFERENCE_PARAMETER_LIST) { - return new PsiReferenceParameterListImpl(); - } - else if (type == TYPE) { - return new PsiTypeElementImpl(); - } - else if (type == MODIFIER_LIST) { - return new ModifierListElement(); - } - else if (type == EXTENDS_LIST) { - return new ExtendsListElement(); - } - else if (type == IMPLEMENTS_LIST) { - return new ImplementsListElement(); - } - else if (type == THROWS_LIST) { - return new PsiThrowsListImpl(); - } - else if (type == EXPRESSION_LIST) { - return new PsiExpressionListImpl(); - } - else if (type == REFERENCE_EXPRESSION) { - return new PsiReferenceExpressionImpl(); - } - else if (type == LITERAL_EXPRESSION) { - return new PsiLiteralExpressionImpl(); - } - else if (type == THIS_EXPRESSION) { - return new PsiThisExpressionImpl(); - } - else if (type == SUPER_EXPRESSION) { - return new PsiSuperExpressionImpl(); - } - else if (type == PARENTH_EXPRESSION) { - return new PsiParenthesizedExpressionImpl(); - } - else if (type == METHOD_CALL_EXPRESSION) { - return new PsiMethodCallExpressionImpl(); - } - else if (type == TYPE_CAST_EXPRESSION) { - return new PsiTypeCastExpressionImpl(); - } - else if (type == PREFIX_EXPRESSION) { - return new PsiPrefixExpressionImpl(); - } - else if (type == POSTFIX_EXPRESSION) { - return new PsiPostfixExpressionImpl(); - } - else if (type == BINARY_EXPRESSION) { - return new PsiBinaryExpressionImpl(); - } - else if (type == CONDITIONAL_EXPRESSION) { - return new PsiConditionalExpressionImpl(); - } - else if (type == ASSIGNMENT_EXPRESSION) { - return new PsiAssignmentExpressionImpl(); - } - else if (type == NEW_EXPRESSION) { - return new PsiNewExpressionImpl(); - } - else if (type == ARRAY_ACCESS_EXPRESSION) { - return new PsiArrayAccessExpressionImpl(); - } - else if (type == ARRAY_INITIALIZER_EXPRESSION) { - return new PsiArrayInitializerExpressionImpl(); - } - else if (type == INSTANCE_OF_EXPRESSION) { - return new PsiInstanceOfExpressionImpl(); - } - else if (type == CLASS_OBJECT_ACCESS_EXPRESSION) { - return new PsiClassObjectAccessExpressionImpl(); - } - else if (type == EMPTY_EXPRESSION) { - return new PsiEmptyExpressionImpl(); - } - else if (type == EMPTY_STATEMENT) { - return new PsiEmptyStatementImpl(); - } - else if (type == BLOCK_STATEMENT) { - return new PsiBlockStatementImpl(); - } - else if (type == EXPRESSION_STATEMENT) { - return new PsiExpressionStatementImpl(); - } - else if (type == EXPRESSION_LIST_STATEMENT) { - return new PsiExpressionListStatementImpl(); - } - else if (type == DECLARATION_STATEMENT) { - return new PsiDeclarationStatementImpl(); - } - else if (type == IF_STATEMENT) { - return new PsiIfStatementImpl(); - } - else if (type == WHILE_STATEMENT) { - return new PsiWhileStatementImpl(); - } - else if (type == FOR_STATEMENT) { - return new PsiForStatementImpl(); - } - else if (type == FOREACH_STATEMENT) { - return new PsiForeachStatementImpl(); - } - else if (type == DO_WHILE_STATEMENT) { - return new PsiDoWhileStatementImpl(); - } - else if (type == SWITCH_STATEMENT) { - return new PsiSwitchStatementImpl(); - } - else if (type == SWITCH_LABEL_STATEMENT) { - return new PsiSwitchLabelStatementImpl(); - } - else if (type == BREAK_STATEMENT) { - return new PsiBreakStatementImpl(); - } - else if (type == CONTINUE_STATEMENT) { - return new PsiContinueStatementImpl(); - } - else if (type == RETURN_STATEMENT) { - return new PsiReturnStatementImpl(); - } - else if (type == THROW_STATEMENT) { - return new PsiThrowStatementImpl(); - } - else if (type == SYNCHRONIZED_STATEMENT) { - return new PsiSynchronizedStatementImpl(); - } - else if (type == ASSERT_STATEMENT) { - return new PsiAssertStatementImpl(); - } - else if (type == TRY_STATEMENT) { - return new PsiTryStatementImpl(); - } - else if (type == LABELED_STATEMENT) { - return new PsiLabeledStatementImpl(); - } - else if (type == CATCH_SECTION) { - return new PsiCatchSectionImpl(); - } - else if (type == ANNOTATION_METHOD) { - return new AnnotationMethodElement(); - } - else if (type == ANNOTATION) { - return new AnnotationElement(); - } - else if (type == ANNOTATION_ARRAY_INITIALIZER) { - return new PsiArrayInitializerMemberValueImpl(); - } - else if (type == NAME_VALUE_PAIR) { - return new PsiNameValuePairImpl(); - } - else if (type == ANNOTATION_PARAMETER_LIST) { - return new PsiAnnotationParameterListImpl(); - } - else if (type == METHOD_RECEIVER) { - return new PsiMethodReceiverImpl(); - } - else if (type == CODE_BLOCK) { - // deep code block parsing - return new PsiCodeBlockImpl(null); - } - - return new CompositePsiElement(type){}; - } - - public LeafElement createLeaf(final IElementType type, CharSequence text) { + @Override + public LeafElement createLeaf(final IElementType type, final CharSequence text) { if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) { return new PsiCommentImpl(type, text); } @@ -315,6 +57,6 @@ public class JavaASTFactory extends ASTFactory implements Constants { return new PsiDocTokenImpl(type, text); } - return new LeafPsiElement(type, text); + return null; } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java index fc7ea27a3459..1199dc098e12 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java @@ -20,70 +20,106 @@ import com.intellij.lang.StdLanguages; import com.intellij.lexer.JavaLexer; import com.intellij.openapi.project.Project; import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.source.javadoc.PsiDocCommentImpl; +import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; +import com.intellij.psi.impl.source.javadoc.PsiDocParamRef; +import com.intellij.psi.impl.source.javadoc.PsiDocTagImpl; import com.intellij.psi.impl.source.parsing.JavaParsingContext; +import com.intellij.psi.impl.source.tree.java.PsiInlineDocTagImpl; +import com.intellij.psi.tree.ICompositeElementType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.ILazyParseableElementType; import com.intellij.psi.tree.IReparseableElementType; import com.intellij.psi.tree.java.IJavaDocElementType; import com.intellij.util.CharTable; +import com.intellij.util.ReflectionUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Constructor; public interface JavaDocElementType { - //chameleon - IElementType DOC_TAG = new IJavaDocElementType("DOC_TAG"); - IElementType DOC_TAG_VALUE = new IJavaDocElementType("DOC_TAG_VALUE"); - IElementType DOC_INLINE_TAG = new IJavaDocElementType("DOC_INLINE_TAG"); - IElementType DOC_METHOD_OR_FIELD_REF = new IJavaDocElementType("DOC_METHOD_OR_FIELD_REF"); - IElementType DOC_PARAMETER_REF = new IJavaDocElementType("DOC_PARAMETER_REF"); + class JavaDocCompositeElementType extends IJavaDocElementType implements ICompositeElementType { + private final Constructor myConstructor; - ILazyParseableElementType DOC_REFERENCE_HOLDER = new ILazyParseableElementType("DOC_REFERENCE_HOLDER", StdLanguages.JAVA){ - public ASTNode parseContents(ASTNode chameleon) { + private JavaDocCompositeElementType(@NonNls final String debugName, final Class nodeClass) { + super(debugName); + myConstructor = ReflectionUtil.getDefaultConstructor(nodeClass); + } + + @NotNull + @Override + public ASTNode createCompositeNode() { + return ReflectionUtil.createInstance(myConstructor); + } + } + + class JavaDocLazyElementType extends ILazyParseableElementType { + private JavaDocLazyElementType(@NonNls final String debugName) { + super(debugName, StdLanguages.JAVA); + } + + @Override + public ASTNode createNode(final CharSequence text) { + return new LazyParseablePsiElement(this, text); + } + } + + IElementType DOC_TAG = new JavaDocCompositeElementType("DOC_TAG", PsiDocTagImpl.class); + IElementType DOC_INLINE_TAG = new JavaDocCompositeElementType("DOC_INLINE_TAG", PsiInlineDocTagImpl.class); + IElementType DOC_METHOD_OR_FIELD_REF = new JavaDocCompositeElementType("DOC_METHOD_OR_FIELD_REF", PsiDocMethodOrFieldRef.class); + IElementType DOC_PARAMETER_REF = new JavaDocCompositeElementType("DOC_PARAMETER_REF", PsiDocParamRef.class); + + ILazyParseableElementType DOC_REFERENCE_HOLDER = new JavaDocLazyElementType("DOC_REFERENCE_HOLDER") { + public ASTNode parseContents(final ASTNode chameleon) { final CharSequence chars = chameleon.getChars(); - final PsiManager manager = chameleon.getTreeParent().getPsi().getManager(); + final PsiElement psi = chameleon.getTreeParent().getPsi(); + assert psi != null : chameleon; + final PsiManager manager = psi.getManager(); final CharTable table = SharedImplUtil.findCharTableByTree(chameleon); //no language features from higher java language versions are present in javadoc - JavaParsingContext context = new JavaParsingContext(table, LanguageLevel.JDK_1_3); + final JavaParsingContext context = new JavaParsingContext(table, LanguageLevel.JDK_1_3); return context.getJavadocParsing().parseJavaDocReference(chars, new JavaLexer(LanguageLevel.JDK_1_3), false, manager); } - - @Override - public ASTNode createNode(CharSequence text) { - return new LazyParseablePsiElement(this, text); - } }; - ILazyParseableElementType DOC_TYPE_HOLDER = new ILazyParseableElementType("DOC_TYPE_HOLDER", StdLanguages.JAVA){ - public ASTNode parseContents(ASTNode chameleon) { + ILazyParseableElementType DOC_TYPE_HOLDER = new JavaDocLazyElementType("DOC_TYPE_HOLDER") { + public ASTNode parseContents(final ASTNode chameleon) { final CharSequence chars = chameleon.getChars(); - final PsiManager manager = chameleon.getTreeParent().getPsi().getManager(); + final PsiElement psi = chameleon.getTreeParent().getPsi(); + assert psi != null : chameleon; + final PsiManager manager = psi.getManager(); final CharTable table = SharedImplUtil.findCharTableByTree(chameleon); //no language features from higher java language versions are present in javadoc - JavaParsingContext context = new JavaParsingContext(table, LanguageLevel.JDK_1_3); + final JavaParsingContext context = new JavaParsingContext(table, LanguageLevel.JDK_1_3); return context.getJavadocParsing().parseJavaDocReference(chars, new JavaLexer(LanguageLevel.JDK_1_3), true, manager); } - - @Override - public ASTNode createNode(CharSequence text) { - return new LazyParseablePsiElement(this, text); - } }; - ILazyParseableElementType DOC_COMMENT = new IReparseableElementType("DOC_COMMENT", StdLanguages.JAVA){ - public ASTNode parseContents(ASTNode chameleon) { + ILazyParseableElementType DOC_COMMENT = new IReparseableElementType("DOC_COMMENT", StdLanguages.JAVA) { + @Override + public ASTNode createNode(final CharSequence text) { + return new PsiDocCommentImpl(text); + } + + public ASTNode parseContents(final ASTNode chameleon) { final CharSequence chars = chameleon.getChars(); - final PsiManager manager = chameleon.getTreeParent().getPsi().getManager(); + final PsiElement psi = chameleon.getTreeParent().getPsi(); + assert psi != null : chameleon; + final PsiManager manager = psi.getManager(); //no higher java language level features are allowed in javadoc final JavaParsingContext context = new JavaParsingContext(SharedImplUtil.findCharTableByTree(chameleon), LanguageLevel.JDK_1_3); return context.getJavadocParsing().parseDocCommentText(manager, chars, 0, chars.length()); } - public boolean isParsable(CharSequence buffer, final Project project) { + public boolean isParsable(final CharSequence buffer, final Project project) { final JavaLexer lexer = new JavaLexer(LanguageLevel.JDK_1_5); - lexer.start(buffer); - if(lexer.getTokenType() != DOC_COMMENT) return false; + if (lexer.getTokenType() != DOC_COMMENT) return false; lexer.advance(); - if(lexer.getTokenType() != null) return false; + if (lexer.getTokenType() != null) return false; return true; } }; diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java index 6fb19b8624c9..d0aa75ef2141 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java @@ -28,35 +28,54 @@ import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiManager; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; -import com.intellij.psi.impl.source.JavaDummyElement; +import com.intellij.psi.impl.source.*; import com.intellij.psi.impl.source.parsing.JavaParsingContext; import com.intellij.psi.impl.source.parsing.Parsing; -import com.intellij.psi.impl.source.tree.java.PsiCodeBlockImpl; +import com.intellij.psi.impl.source.tree.java.*; import com.intellij.psi.text.BlockSupport; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.IErrorCounterReparseableElementType; -import com.intellij.psi.tree.ILazyParseableElementType; -import com.intellij.psi.tree.ILightLazyParseableElementType; +import com.intellij.psi.tree.*; import com.intellij.psi.tree.java.IJavaElementType; import com.intellij.psi.util.PsiUtil; import com.intellij.util.CharTable; +import com.intellij.util.ReflectionUtil; import com.intellij.util.diff.FlyweightCapableTreeStructure; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Constructor; + import static com.intellij.lang.PsiBuilderUtil.expect; public interface JavaElementType { + class JavaCompositeElementType extends IJavaElementType implements ICompositeElementType { + private final Constructor myConstructor; + + private JavaCompositeElementType(@NonNls final String debugName, final Class nodeClass) { + super(debugName); + myConstructor = ReflectionUtil.getDefaultConstructor(nodeClass); + } + + private JavaCompositeElementType(@NonNls final String debugName, final Class nodeClass, final boolean leftBound) { + super(debugName, leftBound); + myConstructor = ReflectionUtil.getDefaultConstructor(nodeClass); + } + + @NotNull + @Override + public ASTNode createCompositeNode() { + return ReflectionUtil.createInstance(myConstructor); + } + } + IElementType CLASS = JavaStubElementTypes.CLASS; IElementType ANONYMOUS_CLASS = JavaStubElementTypes.ANONYMOUS_CLASS; IElementType ENUM_CONSTANT_INITIALIZER = JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER; - IElementType TYPE_PARAMETER_LIST = JavaStubElementTypes.TYPE_PARAMETER_LIST; IElementType TYPE_PARAMETER = JavaStubElementTypes.TYPE_PARAMETER; - IElementType IMPORT_LIST = JavaStubElementTypes.IMPORT_LIST; IElementType IMPORT_STATEMENT = JavaStubElementTypes.IMPORT_STATEMENT; IElementType IMPORT_STATIC_STATEMENT = JavaStubElementTypes.IMPORT_STATIC_STATEMENT; - IElementType MODIFIER_LIST = JavaStubElementTypes.MODIFIER_LIST; IElementType ANNOTATION = JavaStubElementTypes.ANNOTATION; IElementType EXTENDS_LIST = JavaStubElementTypes.EXTENDS_LIST; @@ -65,71 +84,65 @@ public interface JavaElementType { IElementType ENUM_CONSTANT = JavaStubElementTypes.ENUM_CONSTANT; IElementType METHOD = JavaStubElementTypes.METHOD; IElementType ANNOTATION_METHOD = JavaStubElementTypes.ANNOTATION_METHOD; - IElementType CLASS_INITIALIZER = JavaStubElementTypes.CLASS_INITIALIZER; IElementType PARAMETER = JavaStubElementTypes.PARAMETER; IElementType PARAMETER_LIST = JavaStubElementTypes.PARAMETER_LIST; IElementType EXTENDS_BOUND_LIST = JavaStubElementTypes.EXTENDS_BOUND_LIST; IElementType THROWS_LIST = JavaStubElementTypes.THROWS_LIST; - IElementType IMPORT_STATIC_REFERENCE = new IJavaElementType("IMPORT_STATIC_REFERENCE"); - IElementType TYPE = new IJavaElementType("TYPE"); - IElementType DIAMOND_TYPE = new IJavaElementType("DIAMOND_TYPE"); - IElementType REFERENCE_PARAMETER_LIST = new IJavaElementType("REFERENCE_PARAMETER_LIST", true); - IElementType JAVA_CODE_REFERENCE = new IJavaElementType("JAVA_CODE_REFERENCE"); - IElementType PACKAGE_STATEMENT = new IJavaElementType("PACKAGE_STATEMENT"); + IElementType IMPORT_STATIC_REFERENCE = new JavaCompositeElementType("IMPORT_STATIC_REFERENCE", PsiImportStaticReferenceElementImpl.class); + IElementType TYPE = new JavaCompositeElementType("TYPE", PsiTypeElementImpl.class); + IElementType DIAMOND_TYPE = new JavaCompositeElementType("DIAMOND_TYPE", PsiDiamondTypeElementImpl.class); + IElementType REFERENCE_PARAMETER_LIST = new JavaCompositeElementType("REFERENCE_PARAMETER_LIST", PsiReferenceParameterListImpl.class, true); + IElementType JAVA_CODE_REFERENCE = new JavaCompositeElementType("JAVA_CODE_REFERENCE", PsiJavaCodeReferenceElementImpl.class); + IElementType PACKAGE_STATEMENT = new JavaCompositeElementType("PACKAGE_STATEMENT", PsiPackageStatementImpl.class); + IElementType LOCAL_VARIABLE = new JavaCompositeElementType("LOCAL_VARIABLE", PsiLocalVariableImpl.class); + IElementType REFERENCE_EXPRESSION = new JavaCompositeElementType("REFERENCE_EXPRESSION", PsiReferenceExpressionImpl.class); + IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class); + IElementType THIS_EXPRESSION = new JavaCompositeElementType("THIS_EXPRESSION", PsiThisExpressionImpl.class); + IElementType SUPER_EXPRESSION = new JavaCompositeElementType("SUPER_EXPRESSION", PsiSuperExpressionImpl.class); + IElementType PARENTH_EXPRESSION = new JavaCompositeElementType("PARENTH_EXPRESSION", PsiParenthesizedExpressionImpl.class); + IElementType METHOD_CALL_EXPRESSION = new JavaCompositeElementType("METHOD_CALL_EXPRESSION", PsiMethodCallExpressionImpl.class); + IElementType TYPE_CAST_EXPRESSION = new JavaCompositeElementType("TYPE_CAST_EXPRESSION", PsiTypeCastExpressionImpl.class); + IElementType PREFIX_EXPRESSION = new JavaCompositeElementType("PREFIX_EXPRESSION", PsiPrefixExpressionImpl.class); + IElementType POSTFIX_EXPRESSION = new JavaCompositeElementType("POSTFIX_EXPRESSION", PsiPostfixExpressionImpl.class); + IElementType BINARY_EXPRESSION = new JavaCompositeElementType("BINARY_EXPRESSION", PsiBinaryExpressionImpl.class); + IElementType CONDITIONAL_EXPRESSION = new JavaCompositeElementType("CONDITIONAL_EXPRESSION", PsiConditionalExpressionImpl.class); + IElementType ASSIGNMENT_EXPRESSION = new JavaCompositeElementType("ASSIGNMENT_EXPRESSION", PsiAssignmentExpressionImpl.class); + IElementType NEW_EXPRESSION = new JavaCompositeElementType("NEW_EXPRESSION", PsiNewExpressionImpl.class); + IElementType ARRAY_ACCESS_EXPRESSION = new JavaCompositeElementType("ARRAY_ACCESS_EXPRESSION", PsiArrayAccessExpressionImpl.class); + IElementType ARRAY_INITIALIZER_EXPRESSION = new JavaCompositeElementType("ARRAY_INITIALIZER_EXPRESSION", PsiArrayInitializerExpressionImpl.class); + IElementType INSTANCE_OF_EXPRESSION = new JavaCompositeElementType("INSTANCE_OF_EXPRESSION", PsiInstanceOfExpressionImpl.class); + IElementType CLASS_OBJECT_ACCESS_EXPRESSION = new JavaCompositeElementType("CLASS_OBJECT_ACCESS_EXPRESSION", PsiClassObjectAccessExpressionImpl.class); + IElementType EMPTY_EXPRESSION = new JavaCompositeElementType("EMPTY_EXPRESSION", PsiEmptyExpressionImpl.class, true); + IElementType EXPRESSION_LIST = new JavaCompositeElementType("EXPRESSION_LIST", PsiExpressionListImpl.class, true); + IElementType EMPTY_STATEMENT = new JavaCompositeElementType("EMPTY_STATEMENT", PsiEmptyStatementImpl.class); + IElementType BLOCK_STATEMENT = new JavaCompositeElementType("BLOCK_STATEMENT", PsiBlockStatementImpl.class); + IElementType EXPRESSION_STATEMENT = new JavaCompositeElementType("EXPRESSION_STATEMENT", PsiExpressionStatementImpl.class); + IElementType EXPRESSION_LIST_STATEMENT = new JavaCompositeElementType("EXPRESSION_LIST_STATEMENT", PsiExpressionListStatementImpl.class); + IElementType DECLARATION_STATEMENT = new JavaCompositeElementType("DECLARATION_STATEMENT", PsiDeclarationStatementImpl.class); + IElementType IF_STATEMENT = new JavaCompositeElementType("IF_STATEMENT", PsiIfStatementImpl.class); + IElementType WHILE_STATEMENT = new JavaCompositeElementType("WHILE_STATEMENT", PsiWhileStatementImpl.class); + IElementType FOR_STATEMENT = new JavaCompositeElementType("FOR_STATEMENT", PsiForStatementImpl.class); + IElementType FOREACH_STATEMENT = new JavaCompositeElementType("FOREACH_STATEMENT", PsiForeachStatementImpl.class); + IElementType DO_WHILE_STATEMENT = new JavaCompositeElementType("DO_WHILE_STATEMENT", PsiDoWhileStatementImpl.class); + IElementType SWITCH_STATEMENT = new JavaCompositeElementType("SWITCH_STATEMENT", PsiSwitchStatementImpl.class); + IElementType SWITCH_LABEL_STATEMENT = new JavaCompositeElementType("SWITCH_LABEL_STATEMENT", PsiSwitchLabelStatementImpl.class); + IElementType BREAK_STATEMENT = new JavaCompositeElementType("BREAK_STATEMENT", PsiBreakStatementImpl.class); + IElementType CONTINUE_STATEMENT = new JavaCompositeElementType("CONTINUE_STATEMENT", PsiContinueStatementImpl.class); + IElementType RETURN_STATEMENT = new JavaCompositeElementType("RETURN_STATEMENT", PsiReturnStatementImpl.class); + IElementType THROW_STATEMENT = new JavaCompositeElementType("THROW_STATEMENT", PsiThrowStatementImpl.class); + IElementType SYNCHRONIZED_STATEMENT = new JavaCompositeElementType("SYNCHRONIZED_STATEMENT", PsiSynchronizedStatementImpl.class); + IElementType TRY_STATEMENT = new JavaCompositeElementType("TRY_STATEMENT", PsiTryStatementImpl.class); + IElementType LABELED_STATEMENT = new JavaCompositeElementType("LABELED_STATEMENT", PsiLabeledStatementImpl.class); + IElementType ASSERT_STATEMENT = new JavaCompositeElementType("ASSERT_STATEMENT", PsiAssertStatementImpl.class); + IElementType CATCH_SECTION = new JavaCompositeElementType("CATCH_SECTION", PsiCatchSectionImpl.class); + IElementType ANNOTATION_ARRAY_INITIALIZER = new JavaCompositeElementType("ANNOTATION_ARRAY_INITIALIZER", PsiArrayInitializerMemberValueImpl.class); + IElementType NAME_VALUE_PAIR = new JavaCompositeElementType("NAME_VALUE_PAIR", PsiNameValuePairImpl.class, true); + IElementType ANNOTATION_PARAMETER_LIST = new JavaCompositeElementType("ANNOTATION_PARAMETER_LIST", PsiAnnotationParameterListImpl.class, true); + IElementType METHOD_RECEIVER = new JavaCompositeElementType("METHOD_RECEIVER", PsiMethodReceiverImpl.class); - IElementType LOCAL_VARIABLE = new IJavaElementType("LOCAL_VARIABLE"); - IElementType REFERENCE_EXPRESSION = new IJavaElementType("REFERENCE_EXPRESSION"); - IElementType LITERAL_EXPRESSION = new IJavaElementType("LITERAL_EXPRESSION"); - IElementType THIS_EXPRESSION = new IJavaElementType("THIS_EXPRESSION"); - IElementType SUPER_EXPRESSION = new IJavaElementType("SUPER_EXPRESSION"); - IElementType PARENTH_EXPRESSION = new IJavaElementType("PARENTH_EXPRESSION"); - IElementType METHOD_CALL_EXPRESSION = new IJavaElementType("METHOD_CALL_EXPRESSION"); - IElementType TYPE_CAST_EXPRESSION = new IJavaElementType("TYPE_CAST_EXPRESSION"); - IElementType PREFIX_EXPRESSION = new IJavaElementType("PREFIX_EXPRESSION"); - IElementType POSTFIX_EXPRESSION = new IJavaElementType("POSTFIX_EXPRESSION"); - IElementType BINARY_EXPRESSION = new IJavaElementType("BINARY_EXPRESSION"); - IElementType CONDITIONAL_EXPRESSION = new IJavaElementType("CONDITIONAL_EXPRESSION"); - IElementType ASSIGNMENT_EXPRESSION = new IJavaElementType("ASSIGNMENT_EXPRESSION"); - IElementType NEW_EXPRESSION = new IJavaElementType("NEW_EXPRESSION"); - IElementType ARRAY_ACCESS_EXPRESSION = new IJavaElementType("ARRAY_ACCESS_EXPRESSION"); - IElementType ARRAY_INITIALIZER_EXPRESSION = new IJavaElementType("ARRAY_INITIALIZER_EXPRESSION"); - IElementType INSTANCE_OF_EXPRESSION = new IJavaElementType("INSTANCE_OF_EXPRESSION"); - IElementType CLASS_OBJECT_ACCESS_EXPRESSION = new IJavaElementType("CLASS_OBJECT_ACCESS_EXPRESSION"); - IElementType EMPTY_EXPRESSION = new IJavaElementType("EMPTY_EXPRESSION", true); - - IElementType EXPRESSION_LIST = new IJavaElementType("EXPRESSION_LIST", true); - - IElementType EMPTY_STATEMENT = new IJavaElementType("EMPTY_STATEMENT"); - IElementType BLOCK_STATEMENT = new IJavaElementType("BLOCK_STATEMENT"); - IElementType EXPRESSION_STATEMENT = new IJavaElementType("EXPRESSION_STATEMENT"); - IElementType EXPRESSION_LIST_STATEMENT = new IJavaElementType("EXPRESSION_LIST_STATEMENT"); - IElementType DECLARATION_STATEMENT = new IJavaElementType("DECLARATION_STATEMENT"); - IElementType IF_STATEMENT = new IJavaElementType("IF_STATEMENT"); - IElementType WHILE_STATEMENT = new IJavaElementType("WHILE_STATEMENT"); - IElementType FOR_STATEMENT = new IJavaElementType("FOR_STATEMENT"); - IElementType FOREACH_STATEMENT = new IJavaElementType("FOREACH_STATEMENT"); - IElementType DO_WHILE_STATEMENT = new IJavaElementType("DO_WHILE_STATEMENT"); - IElementType SWITCH_STATEMENT = new IJavaElementType("SWITCH_STATEMENT"); - IElementType SWITCH_LABEL_STATEMENT = new IJavaElementType("SWITCH_LABEL_STATEMENT"); - IElementType BREAK_STATEMENT = new IJavaElementType("BREAK_STATEMENT"); - IElementType CONTINUE_STATEMENT = new IJavaElementType("CONTINUE_STATEMENT"); - IElementType RETURN_STATEMENT = new IJavaElementType("RETURN_STATEMENT"); - IElementType THROW_STATEMENT = new IJavaElementType("THROW_STATEMENT"); - IElementType SYNCHRONIZED_STATEMENT = new IJavaElementType("SYNCHRONIZED_STATEMENT"); - IElementType TRY_STATEMENT = new IJavaElementType("TRY_STATEMENT"); - IElementType LABELED_STATEMENT = new IJavaElementType("LABELED_STATEMENT"); - IElementType ASSERT_STATEMENT = new IJavaElementType("ASSERT_STATEMENT"); - - IElementType CATCH_SECTION = new IJavaElementType("CATCH_SECTION"); - - IElementType ANNOTATION_ARRAY_INITIALIZER = new IJavaElementType("ANNOTATION_ARRAY_INITIALIZER"); - IElementType NAME_VALUE_PAIR = new IJavaElementType("NAME_VALUE_PAIR", true); - IElementType ANNOTATION_PARAMETER_LIST = new IJavaElementType("ANNOTATION_PARAMETER_LIST", true); - IElementType METHOD_RECEIVER = new IJavaElementType("METHOD_RECEIVER"); - - class ICodeBlockElementType extends IErrorCounterReparseableElementType { + class ICodeBlockElementType extends IErrorCounterReparseableElementType implements ICompositeElementType { private ICodeBlockElementType() { super("CODE_BLOCK", StdLanguages.JAVA); } @@ -139,6 +152,12 @@ public interface JavaElementType { return new PsiCodeBlockImpl(text); } + @NotNull + @Override + public ASTNode createCompositeNode() { + return new PsiCodeBlockImpl(null); + } + @Override public ASTNode parseContents(final ASTNode chameleon) { if (JavaParserDefinition.USE_NEW_PARSER) { @@ -277,7 +296,17 @@ public interface JavaElementType { } }; - IElementType DUMMY_ELEMENT = new ILazyParseableElementType("DUMMY_ELEMENT", StdLanguages.JAVA) { + class JavaDummyElementType extends ILazyParseableElementType implements ICompositeElementType { + private JavaDummyElementType() { + super("DUMMY_ELEMENT", StdLanguages.JAVA); + } + + @NotNull + @Override + public ASTNode createCompositeNode() { + return new CompositePsiElement(this) { }; + } + @Nullable @Override public ASTNode parseContents(final ASTNode chameleon) { @@ -285,5 +314,6 @@ public interface JavaElementType { final JavaDummyElement dummyElement = (JavaDummyElement)chameleon; return JavaParserUtil.parseFragment(chameleon, dummyElement.getParser(), dummyElement.consumeAll(), dummyElement.getLanguageLevel()); } - }; + } + IElementType DUMMY_ELEMENT = new JavaDummyElementType(); } diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/New15.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/New15.txt index 1bf67cbcd3bd..dbcf30f8fbcb 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/New15.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/New15.txt @@ -33,7 +33,7 @@ PsiJavaFile:New15.java PsiReferenceParameterList PsiJavaToken:LT('<') PsiTypeElement: - PsiElement(DIAMOND_TYPE) + PsiTypeElement:DIAMOND PsiJavaToken:GT('>') PsiExpressionList diff --git a/java/java-tests/testData/psi/parser-partial/references/Type7.txt b/java/java-tests/testData/psi/parser-partial/references/Type7.txt index a57c77f85835..6333941d2878 100644 --- a/java/java-tests/testData/psi/parser-partial/references/Type7.txt +++ b/java/java-tests/testData/psi/parser-partial/references/Type7.txt @@ -5,6 +5,6 @@ PsiJavaFile:Type7.java PsiReferenceParameterList PsiJavaToken:LT('<') PsiTypeElement: - PsiElement(DIAMOND_TYPE) + PsiTypeElement:DIAMOND PsiJavaToken:GT('>') \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/lang/ASTFactory.java b/platform/lang-impl/src/com/intellij/lang/ASTFactory.java index 578740165158..89746e962cf6 100644 --- a/platform/lang-impl/src/com/intellij/lang/ASTFactory.java +++ b/platform/lang-impl/src/com/intellij/lang/ASTFactory.java @@ -20,6 +20,7 @@ import com.intellij.lexer.LexerUtil; import com.intellij.psi.TokenType; import com.intellij.psi.impl.source.CharTableImpl; import com.intellij.psi.impl.source.CodeFragmentElement; +import com.intellij.psi.impl.source.DummyHolderElement; import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; import com.intellij.psi.impl.source.tree.*; import com.intellij.psi.tree.*; @@ -39,14 +40,18 @@ public abstract class ASTFactory { @Nullable public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) { - return DEFAULT.createLazy(type, text); + return null; } @Nullable - public abstract CompositeElement createComposite(final IElementType type); + public CompositeElement createComposite(final IElementType type) { + return null; + } @Nullable - public abstract LeafElement createLeaf(final IElementType type, final CharSequence text); + public LeafElement createLeaf(final IElementType type, final CharSequence text) { + return null; + } // factory methods @@ -58,6 +63,9 @@ public abstract class ASTFactory { if (type == TokenType.CODE_FRAGMENT) { return new CodeFragmentElement(null); } + else if (type == TokenType.DUMMY_HOLDER) { + return new DummyHolderElement(text); + } final LazyParseableElement customLazy = factory(type).createLazy(type, text); return customLazy != null ? customLazy : DEFAULT.createLazy(type, text); @@ -69,10 +77,6 @@ public abstract class ASTFactory { return (CompositeElement)((ICompositeElementType)type).createCompositeNode(); } - if (type == TokenType.CODE_FRAGMENT) { - return new CodeFragmentElement(null); - } - final CompositeElement customComposite = factory(type).createComposite(type); return customComposite != null ? customComposite : DEFAULT.createComposite(type); } @@ -159,6 +163,7 @@ public abstract class ASTFactory { return new PsiCommentImpl(type, text); } } + return new LeafPsiElement(type, text); } } diff --git a/platform/util/src/com/intellij/util/ReflectionUtil.java b/platform/util/src/com/intellij/util/ReflectionUtil.java index 0bff817da623..d1963db97dce 100644 --- a/platform/util/src/com/intellij/util/ReflectionUtil.java +++ b/platform/util/src/com/intellij/util/ReflectionUtil.java @@ -81,15 +81,10 @@ public class ReflectionUtil { return null; } -//void f() {} sdfg public static String declarationToString(final GenericDeclaration anInterface) { - return anInterface.toString() - + Arrays.asList(anInterface.getTypeParameters()) - + - - " loaded by " + ((Class)anInterface).getClassLoader(); + + " loaded by " + ((Class)anInterface).getClassLoader(); } public static Class getRawType(Type type) { @@ -160,9 +155,7 @@ public class ReflectionUtil { private static void collectFields(final Class clazz, final ArrayList result) { final Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - result.add(field); - } + result.addAll(Arrays.asList(fields)); final Class superClass = clazz.getSuperclass(); if (superClass != null) { collectFields(superClass, result); @@ -270,4 +263,36 @@ public class ReflectionUtil { } return type; } + + @NotNull + public static Constructor getDefaultConstructor(final Class aClass) { + try { + final Constructor constructor = aClass.getConstructor(); + constructor.setAccessible(true); + return constructor; + } + catch (NoSuchMethodException e) { + LOG.error("No default constructor in " + aClass, e); + return null; + } + } + + @NotNull + public static T createInstance(final Constructor constructor, final Object... args) { + try { + return constructor.newInstance(args); + } + catch (InstantiationException e) { + LOG.error(e); + return null; + } + catch (IllegalAccessException e) { + LOG.error(e); + return null; + } + catch (InvocationTargetException e) { + LOG.error(e); + return null; + } + } }