diff --git a/java/java-psi-api/src/com/intellij/psi/PsiNameValuePair.java b/java/java-psi-api/src/com/intellij/psi/PsiNameValuePair.java index b694a8639065..5e9c14c80f5a 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiNameValuePair.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiNameValuePair.java @@ -36,7 +36,7 @@ public interface PsiNameValuePair extends PsiElement { ArrayFactory ARRAY_FACTORY = new ArrayFactory() { @Override public PsiNameValuePair[] create(final int count) { - return count == 0 ? PsiNameValuePair.EMPTY_ARRAY : new PsiNameValuePair[count]; + return count == 0 ? EMPTY_ARRAY : new PsiNameValuePair[count]; } }; @@ -56,6 +56,9 @@ public interface PsiNameValuePair extends PsiElement { @Nullable @NonNls String getName(); + @Nullable + String getLiteralValue(); + /** * Returns the value for the element. * diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsNameValuePairImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsNameValuePairImpl.java index b2d0d74ddbcf..0dd8ac610255 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsNameValuePairImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsNameValuePairImpl.java @@ -89,6 +89,11 @@ public class ClsNameValuePairImpl extends ClsElementImpl implements PsiNameValue return myNameIdentifier.getText(); } + @Override + public String getLiteralValue() { + return null; + } + @Override public PsiAnnotationMemberValue getValue() { return myMemberValue; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/ClsStubPsiFactory.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/ClsStubPsiFactory.java index 26ee6cd70883..56de53194ae3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/ClsStubPsiFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/ClsStubPsiFactory.java @@ -87,4 +87,14 @@ public class ClsStubPsiFactory extends StubPsiFactory { public PsiTypeParameterList createTypeParameterList(PsiTypeParameterListStub stub) { return new ClsTypeParametersListImpl(stub); } + + @Override + public PsiAnnotationParameterList createAnnotationParameterList(PsiAnnotationParameterListStub stub) { + return null; // todo + } + + @Override + public PsiNameValuePair createNameValuePair(PsiNameValuePairStub stub) { + return null; // todo + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationParameterListType.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationParameterListType.java new file mode 100644 index 000000000000..9cd6fde8273e --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaAnnotationParameterListType.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.LighterAST; +import com.intellij.lang.LighterASTNode; +import com.intellij.psi.PsiAnnotationParameterList; +import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationParameterListStubImpl; +import com.intellij.psi.impl.source.tree.java.AnnotationParamListElement; +import com.intellij.psi.impl.source.tree.java.PsiAnnotationParamListImpl; +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; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public class JavaAnnotationParameterListType extends JavaStubElementType { + + protected JavaAnnotationParameterListType() { + super("ANNOTATION_PARAMETER_LIST", true); + } + + @Override + public PsiAnnotationParameterList createPsi(@NotNull ASTNode node) { + return new PsiAnnotationParamListImpl(node); + } + + @NotNull + @Override + public ASTNode createCompositeNode() { + return new AnnotationParamListElement(); + } + + @Override + public PsiAnnotationParameterListStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { + return new PsiAnnotationParameterListStubImpl(parentStub); + } + + @Override + public PsiAnnotationParameterList createPsi(@NotNull PsiAnnotationParameterListStub stub) { + return getPsiFactory(stub).createAnnotationParameterList(stub); + } + + @Override + public void serialize(PsiAnnotationParameterListStub stub, StubOutputStream dataStream) throws IOException { + } + + @Override + public PsiAnnotationParameterListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + return new PsiAnnotationParameterListStubImpl(parentStub); + } + + @Override + public void indexStub(PsiAnnotationParameterListStub stub, IndexSink sink) { + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaNameValuePairType.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaNameValuePairType.java new file mode 100644 index 000000000000..e3de244398f7 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaNameValuePairType.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.LighterAST; +import com.intellij.lang.LighterASTNode; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.PsiNameValuePair; +import com.intellij.psi.impl.cache.RecordUtil; +import com.intellij.psi.impl.java.stubs.impl.PsiNameValuePairStubImpl; +import com.intellij.psi.impl.source.tree.JavaElementType; +import com.intellij.psi.impl.source.tree.java.NameValuePairElement; +import com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl; +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; +import java.util.List; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public class JavaNameValuePairType extends JavaStubElementType { + + protected JavaNameValuePairType() { + super("NAME_VALUE_PAIR", true); + } + + @Override + public PsiNameValuePair createPsi(@NotNull ASTNode node) { + return new PsiNameValuePairImpl(node); + } + + @NotNull + @Override + public ASTNode createCompositeNode() { + return new NameValuePairElement(); + } + + @Override + public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { + String name = null; + String value = null; + List children = tree.getChildren(node); + for (LighterASTNode child : children) { + if (child.getTokenType() == JavaTokenType.IDENTIFIER) { + name = RecordUtil.intern(tree.getCharTable(), child); + } + else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) { + value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0)); + value = StringUtil.stripQuotesAroundValue(value); + } + } + return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value)); + } + + @Override + public PsiNameValuePair createPsi(@NotNull PsiNameValuePairStub stub) { + return getPsiFactory(stub).createNameValuePair(stub); + } + + @Override + public void serialize(PsiNameValuePairStub stub, StubOutputStream dataStream) throws IOException { + dataStream.writeName(stub.getName()); + dataStream.writeName(stub.getValue()); + } + + @Override + public PsiNameValuePairStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + StringRef name = dataStream.readName(); + return new PsiNameValuePairStubImpl(parentStub, name, dataStream.readName()); + } + + @Override + public void indexStub(PsiNameValuePairStub stub, IndexSink sink) { + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java index 74b0d5d6acb6..01970b332286 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementTypes.java @@ -27,6 +27,8 @@ import org.jetbrains.annotations.NotNull; public interface JavaStubElementTypes { JavaModifierListElementType MODIFIER_LIST = new JavaModifierListElementType(); JavaAnnotationElementType ANNOTATION = new JavaAnnotationElementType(); + JavaAnnotationParameterListType ANNOTATION_PARAMETER_LIST = new JavaAnnotationParameterListType(); + JavaNameValuePairType NAME_VALUE_PAIR = new JavaNameValuePairType(); JavaParameterElementType PARAMETER = new JavaParameterElementType(); JavaParameterListElementType PARAMETER_LIST = new JavaParameterListElementType(); JavaTypeParameterElementType TYPE_PARAMETER = new JavaTypeParameterElementType(); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationParameterListStub.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationParameterListStub.java new file mode 100644 index 000000000000..2b6e2fa325f4 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiAnnotationParameterListStub.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs; + +import com.intellij.psi.PsiAnnotationParameterList; +import com.intellij.psi.stubs.StubElement; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public interface PsiAnnotationParameterListStub extends StubElement { +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiNameValuePairStub.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiNameValuePairStub.java new file mode 100644 index 000000000000..8b3e7ecfcf7f --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/PsiNameValuePairStub.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs; + +import com.intellij.psi.PsiNameValuePair; +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public interface PsiNameValuePairStub extends StubElement { + + String getName(); + + @Nullable + String getValue(); +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/SourceStubPsiFactory.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/SourceStubPsiFactory.java index d088eb9a6c97..1b5a5f763bfd 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/SourceStubPsiFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/SourceStubPsiFactory.java @@ -21,10 +21,7 @@ package com.intellij.psi.impl.java.stubs; import com.intellij.psi.*; import com.intellij.psi.impl.source.*; -import com.intellij.psi.impl.source.tree.java.PsiAnnotationImpl; -import com.intellij.psi.impl.source.tree.java.PsiTypeParameterExtendsBoundsListImpl; -import com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl; -import com.intellij.psi.impl.source.tree.java.PsiTypeParameterListImpl; +import com.intellij.psi.impl.source.tree.java.*; public class SourceStubPsiFactory extends StubPsiFactory { @Override @@ -106,4 +103,14 @@ public class SourceStubPsiFactory extends StubPsiFactory { public PsiTypeParameterList createTypeParameterList(PsiTypeParameterListStub stub) { return new PsiTypeParameterListImpl(stub); } + + @Override + public PsiAnnotationParameterList createAnnotationParameterList(PsiAnnotationParameterListStub stub) { + return new PsiAnnotationParamListImpl(stub); + } + + @Override + public PsiNameValuePair createNameValuePair(PsiNameValuePairStub stub) { + return new PsiNameValuePairImpl(stub); + } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/StubPsiFactory.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/StubPsiFactory.java index 81556ecbc1a0..5b733ceffc6d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/StubPsiFactory.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/StubPsiFactory.java @@ -47,4 +47,8 @@ public abstract class StubPsiFactory { public abstract PsiTypeParameter createTypeParameter(PsiTypeParameterStub stub); public abstract PsiTypeParameterList createTypeParameterList(PsiTypeParameterListStub stub); + + public abstract PsiAnnotationParameterList createAnnotationParameterList(PsiAnnotationParameterListStub stub); + + public abstract PsiNameValuePair createNameValuePair(PsiNameValuePairStub stub); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationParameterListStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationParameterListStubImpl.java new file mode 100644 index 000000000000..151286f097f1 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationParameterListStubImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs.impl; + +import com.intellij.psi.PsiAnnotationParameterList; +import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; +import com.intellij.psi.impl.java.stubs.PsiAnnotationParameterListStub; +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public class PsiAnnotationParameterListStubImpl extends StubBase implements PsiAnnotationParameterListStub { + + public PsiAnnotationParameterListStubImpl(StubElement parent) { + super(parent, JavaStubElementTypes.ANNOTATION_PARAMETER_LIST); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java index 1b8b8fe41ad9..98b4c09d8e07 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiAnnotationStubImpl.java @@ -20,6 +20,7 @@ package com.intellij.psi.impl.java.stubs.impl; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Pair; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; @@ -29,6 +30,10 @@ import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PatchedSoftReference; +import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.Nullable; + +import java.util.List; public class PsiAnnotationStubImpl extends StubBase implements PsiAnnotationStub { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl"); @@ -37,8 +42,18 @@ public class PsiAnnotationStubImpl extends StubBase implements Ps private PatchedSoftReference myParsedFromRepository; public PsiAnnotationStubImpl(final StubElement parent, final String text) { + this(parent, text, null); + } + + public PsiAnnotationStubImpl(final StubElement parent, final String text, @Nullable List> attributes) { super(parent, JavaStubElementTypes.ANNOTATION); myText = text; + if (attributes != null) { + PsiAnnotationParameterListStubImpl list = new PsiAnnotationParameterListStubImpl(this); + for (Pair attribute : attributes) { + new PsiNameValuePairStubImpl(list, StringRef.fromString(attribute.first), StringRef.fromString(attribute.second)); + } + } } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiNameValuePairStubImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiNameValuePairStubImpl.java new file mode 100644 index 000000000000..d5eccdea4ab5 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/java/stubs/impl/PsiNameValuePairStubImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.java.stubs.impl; + +import com.intellij.psi.PsiNameValuePair; +import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; +import com.intellij.psi.impl.java.stubs.PsiNameValuePairStub; +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; +import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public class PsiNameValuePairStubImpl extends StubBase implements PsiNameValuePairStub { + + @Nullable private final StringRef myName; + @Nullable private final StringRef myValue; + + public PsiNameValuePairStubImpl(StubElement parent, @Nullable StringRef name, @Nullable StringRef value) { + super(parent, JavaStubElementTypes.NAME_VALUE_PAIR); + myName = name; + myValue = value; + } + + @Override + public String getName() { + return myName == null ? "value" : myName.getString(); + } + + @Override + public String getValue() { + return myValue == null ? null : myValue.getString(); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaFileElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaFileElementType.java index f1075285c64e..4a91aa5f3317 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaFileElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/JavaFileElementType.java @@ -37,7 +37,7 @@ import java.io.IOException; * @author max */ public class JavaFileElementType extends ILightStubFileElementType { - public static final int STUB_VERSION = 10; + public static final int STUB_VERSION = 12; public JavaFileElementType() { super("java.FILE", JavaLanguage.INSTANCE); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java index 62ea98ac674f..db208fff0ad0 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java @@ -66,6 +66,8 @@ public interface JavaElementType { IElementType IMPORT_STATIC_STATEMENT = JavaStubElementTypes.IMPORT_STATIC_STATEMENT; IElementType MODIFIER_LIST = JavaStubElementTypes.MODIFIER_LIST; IElementType ANNOTATION = JavaStubElementTypes.ANNOTATION; + IElementType NAME_VALUE_PAIR = JavaStubElementTypes.NAME_VALUE_PAIR; + IElementType ANNOTATION_PARAMETER_LIST = JavaStubElementTypes.ANNOTATION_PARAMETER_LIST; IElementType EXTENDS_LIST = JavaStubElementTypes.EXTENDS_LIST; IElementType IMPLEMENTS_LIST = JavaStubElementTypes.IMPLEMENTS_LIST; IElementType FIELD = JavaStubElementTypes.FIELD; @@ -77,6 +79,7 @@ public interface JavaElementType { IElementType PARAMETER_LIST = JavaStubElementTypes.PARAMETER_LIST; IElementType EXTENDS_BOUND_LIST = JavaStubElementTypes.EXTENDS_BOUND_LIST; IElementType THROWS_LIST = JavaStubElementTypes.THROWS_LIST; + IElementType LITERAL_EXPRESSION = new JavaCompositeElementType("LITERAL_EXPRESSION", PsiLiteralExpressionImpl.class); IElementType IMPORT_STATIC_REFERENCE = new JavaCompositeElementType("IMPORT_STATIC_REFERENCE", PsiImportStaticReferenceElementImpl.class); IElementType TYPE = new JavaCompositeElementType("TYPE", PsiTypeElementImpl.class); @@ -86,7 +89,6 @@ public interface JavaElementType { 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); @@ -131,8 +133,6 @@ public interface JavaElementType { IElementType LABELED_STATEMENT = new JavaCompositeElementType("LABELED_STATEMENT", PsiLabeledStatementImpl.class); IElementType ASSERT_STATEMENT = new JavaCompositeElementType("ASSERT_STATEMENT", PsiAssertStatementImpl.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); class ICodeBlockElementType extends IErrorCounterReparseableElementType implements ICompositeElementType, ILightLazyParseableElementType { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParameterListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/AnnotationParamListElement.java similarity index 95% rename from java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParameterListImpl.java rename to java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/AnnotationParamListElement.java index 7d8225059711..4953bd2d3804 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParameterListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/AnnotationParamListElement.java @@ -28,11 +28,11 @@ import org.jetbrains.annotations.NotNull; /** * @author ven */ -public class PsiAnnotationParameterListImpl extends PsiCommaSeparatedListImpl implements PsiAnnotationParameterList { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiAnnotationParameterListImpl"); +public class AnnotationParamListElement extends PsiCommaSeparatedListImpl implements PsiAnnotationParameterList { + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.AnnotationParamListElement"); private volatile PsiNameValuePair[] myCachedMembers = null; - public PsiAnnotationParameterListImpl() { + public AnnotationParamListElement() { super(ANNOTATION_PARAMETER_LIST, NAME_VALUE_PAIR_BIT_SET); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/NameValuePairElement.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/NameValuePairElement.java new file mode 100644 index 000000000000..3f3788f98930 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/NameValuePairElement.java @@ -0,0 +1,87 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.source.tree.java; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.impl.source.tree.*; +import com.intellij.psi.tree.ChildRoleBase; +import com.intellij.util.CharTable; +import org.jetbrains.annotations.NotNull; + +/** + * @author ven + */ + +//Retrieves method reference from this pair, do NOT reuse!!! +public class NameValuePairElement extends CompositeElement { + + public NameValuePairElement() { + super(JavaElementType.NAME_VALUE_PAIR); + } + + @Override + public int getChildRole(ASTNode child) { + if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getElementType())) { + return ChildRole.ANNOTATION_VALUE; + } + if (child.getElementType() == JavaTokenType.IDENTIFIER) { + return ChildRole.NAME; + } + if (child.getElementType() == JavaTokenType.EQ) { + return ChildRole.OPERATION_SIGN; + } + + return ChildRoleBase.NONE; + } + + @Override + public ASTNode findChildByRole(int role) { + if (role == ChildRole.NAME) { + return findChildByType(JavaTokenType.IDENTIFIER); + } + if (role == ChildRole.ANNOTATION_VALUE) { + return findChildByType(ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET); + } + if (role == ChildRole.OPERATION_SIGN) { + return findChildByType(JavaTokenType.EQ); + } + + return null; + } + + @Override + public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) { + final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this); + final TreeElement treeElement = super.addInternal(first, last, anchor, before); + if (first == last && first.getElementType() == JavaTokenType.IDENTIFIER) { + LeafElement eq = Factory.createSingleLeafElement(JavaTokenType.EQ, "=", 0, 1, treeCharTab, getManager()); + super.addInternal(eq, eq, first, Boolean.FALSE); + } + return treeElement; + } + + @Override + public void deleteChildInternal(@NotNull ASTNode child) { + super.deleteChildInternal(child); + if (child.getElementType() == JavaTokenType.IDENTIFIER) { + final ASTNode sign = findChildByRole(ChildRole.OPERATION_SIGN); + if (sign != null) { + super.deleteChildInternal(sign); + } + } + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java index 047e0182facf..72b4a95b2782 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationImpl.java @@ -91,12 +91,7 @@ public class PsiAnnotationImpl extends JavaStubPsiElement imp @Override @NotNull public PsiAnnotationParameterList getParameterList() { - final PsiAnnotationStub stub = getStub(); - if (stub != null) { - return (PsiAnnotationParameterList)stub.getTreeElement().findChildByRoleAsPsiElement(ChildRole.PARAMETER_LIST); - } - - return PsiTreeUtil.getRequiredChildOfType(this, PsiAnnotationParameterList.class); + return getRequiredStubOrPsiChild(JavaStubElementTypes.ANNOTATION_PARAMETER_LIST); } @Override @@ -183,7 +178,6 @@ public class PsiAnnotationImpl extends JavaStubPsiElement imp if (attributes.length == 0) { return !strict; } - PsiAnnotationMemberValue value = attributes[0].getValue(); LOG.assertTrue(elementTypeFields.length > 0); PsiClass elementTypeClass = @@ -194,11 +188,15 @@ public class PsiAnnotationImpl extends JavaStubPsiElement imp //return !ArrayUtil.contains("TYPE_USE", elementTypeFields); } + PsiAnnotationMemberValue value = null; for (String fieldName : elementTypeFields) { PsiField field = elementTypeClass.findFieldByName(fieldName, false); if (field == null) { continue; } + if (value == null) { + value = attributes[0].getValue(); + } if (value instanceof PsiArrayInitializerMemberValue) { PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)value).getInitializers(); for (PsiAnnotationMemberValue initializer : initializers) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParamListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParamListImpl.java new file mode 100644 index 000000000000..5a3ccb23e420 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiAnnotationParamListImpl.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-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 com.intellij.psi.impl.source.tree.java; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiAnnotationParameterList; +import com.intellij.psi.PsiNameValuePair; +import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; +import com.intellij.psi.impl.java.stubs.PsiAnnotationParameterListStub; +import com.intellij.psi.impl.source.JavaStubPsiElement; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dmitry Avdeev + * Date: 7/27/12 + */ +public class PsiAnnotationParamListImpl extends JavaStubPsiElement implements + PsiAnnotationParameterList { + public PsiAnnotationParamListImpl(@NotNull PsiAnnotationParameterListStub stub) { + super(stub, JavaStubElementTypes.ANNOTATION_PARAMETER_LIST); + } + + public PsiAnnotationParamListImpl(@NotNull ASTNode node) { + super(node); + } + + @NotNull + @Override + public PsiNameValuePair[] getAttributes() { + return getStubOrPsiChildren(JavaStubElementTypes.NAME_VALUE_PAIR, PsiNameValuePair.ARRAY_FACTORY); + } + + @NonNls + public String toString(){ + return "PsiAnnotationParameterList:" + getText(); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCommaSeparatedListImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCommaSeparatedListImpl.java index 272931438e58..475542fdc868 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCommaSeparatedListImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCommaSeparatedListImpl.java @@ -33,13 +33,11 @@ import org.jetbrains.annotations.NotNull; public abstract class PsiCommaSeparatedListImpl extends CompositePsiElement implements Constants { private final TokenSet myTypesOfElements; - protected PsiCommaSeparatedListImpl(IElementType type, final TokenSet typeOfElements) { super(type); myTypesOfElements = typeOfElements; } - @Override public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) { if (myTypesOfElements.contains(first.getElementType()) && myTypesOfElements.contains(last.getElementType())) { @@ -68,7 +66,6 @@ public abstract class PsiCommaSeparatedListImpl extends CompositePsiElement impl return super.addInternal(first, last, anchor, before); } - @Override public void deleteChildInternal(@NotNull ASTNode child) { if (myTypesOfElements.contains(child.getElementType())) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java index c13aa8815de2..7bb0bbf781a7 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-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. @@ -20,115 +20,76 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.impl.java.stubs.JavaStubElementTypes; +import com.intellij.psi.impl.java.stubs.PsiNameValuePairStub; +import com.intellij.psi.impl.source.JavaStubPsiElement; import com.intellij.psi.impl.source.SourceTreeToPsiMap; -import com.intellij.psi.impl.source.tree.*; -import com.intellij.psi.tree.ChildRoleBase; +import com.intellij.psi.impl.source.tree.ChildRole; +import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.util.MethodSignature; import com.intellij.psi.util.MethodSignatureUtil; import com.intellij.util.ArrayUtil; -import com.intellij.util.CharTable; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * @author ven + * @author Dmitry Avdeev + * Date: 7/27/12 */ +public class PsiNameValuePairImpl extends JavaStubPsiElement implements PsiNameValuePair { -//Retrieves method reference from this pair, do NOT reuse!!! -public class PsiNameValuePairImpl extends CompositePsiElement implements PsiNameValuePair { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl"); - private volatile String myCachedName = null; - private volatile PsiIdentifier myCachedNameIdentifier = null; - private volatile PsiAnnotationMemberValue myCachedValue = null; - private volatile boolean myNameCached = false; - - @Override - public void clearCaches() { - myNameCached = false; - myCachedName = null; - myCachedNameIdentifier = null; - myCachedValue = null; - super.clearCaches(); + public PsiNameValuePairImpl(@NotNull PsiNameValuePairStub stub) { + super(stub, JavaStubElementTypes.NAME_VALUE_PAIR); } - public PsiNameValuePairImpl() { - super(JavaElementType.NAME_VALUE_PAIR); + public PsiNameValuePairImpl(@NotNull ASTNode node) { + super(node); } + @NotNull @Override - public PsiIdentifier getNameIdentifier() { - PsiIdentifier cachedNameIdentifier = myCachedNameIdentifier; - if (!myNameCached) { - myCachedNameIdentifier = cachedNameIdentifier = (PsiIdentifier)findChildByRoleAsPsiElement(ChildRole.NAME); - myCachedName = cachedNameIdentifier == null ? null : cachedNameIdentifier.getText(); - myNameCached = true; - } - return cachedNameIdentifier; + public NameValuePairElement getNode() { + return (NameValuePairElement)super.getNode(); } @Override public String getName() { - String cachedName = myCachedName; - if (!myNameCached) { - PsiIdentifier identifier; - myCachedNameIdentifier = identifier = (PsiIdentifier)findChildByRoleAsPsiElement(ChildRole.NAME); - myCachedName = cachedName = identifier == null ? null : identifier.getText(); - myNameCached = true; + PsiNameValuePairStub stub = getStub(); + if (stub == null) { + PsiIdentifier nameIdentifier = getNameIdentifier(); + return nameIdentifier == null ? null : nameIdentifier.getText(); } - return cachedName; + else { + return stub.getName(); + } + } + + @Override + public String getLiteralValue() { + PsiNameValuePairStub stub = getStub(); + return stub == null ? null : stub.getValue(); + } + + @Override + public PsiIdentifier getNameIdentifier() { + ASTNode node = getNode().findChildByRole(ChildRole.NAME); + return node == null ? null : (PsiIdentifier)node.getPsi(); } @Override public PsiAnnotationMemberValue getValue() { - PsiAnnotationMemberValue cachedValue = myCachedValue; - if (cachedValue == null) { - myCachedValue = cachedValue = (PsiAnnotationMemberValue)findChildByRoleAsPsiElement(ChildRole.ANNOTATION_VALUE); - } - - return cachedValue; + ASTNode node = getNode().findChildByRole(ChildRole.ANNOTATION_VALUE); + return node == null ? null : (PsiAnnotationMemberValue)node.getPsi(); } - @Override @NotNull + @Override public PsiAnnotationMemberValue setValue(@NotNull PsiAnnotationMemberValue newValue) { getValue().replace(newValue); return getValue(); } - @Override - public int getChildRole(ASTNode child) { - if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getElementType())) { - return ChildRole.ANNOTATION_VALUE; - } - if (child.getElementType() == JavaTokenType.IDENTIFIER) { - return ChildRole.NAME; - } - if (child.getElementType() == JavaTokenType.EQ) { - return ChildRole.OPERATION_SIGN; - } - - return ChildRoleBase.NONE; - } - - @Override - public ASTNode findChildByRole(int role) { - if (role == ChildRole.NAME) { - return findChildByType(JavaTokenType.IDENTIFIER); - } - if (role == ChildRole.ANNOTATION_VALUE) { - return findChildByType(ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET); - } - if (role == ChildRole.OPERATION_SIGN) { - return findChildByType(JavaTokenType.EQ); - } - - return null; - } - - public String toString() { - return "PsiNameValuePair"; - } @Override public PsiReference getReference() { @@ -167,7 +128,8 @@ public class PsiNameValuePairImpl extends CompositePsiElement implements PsiName if (refClass == null) return null; String name = getName(); if (name == null) name = PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME; - MethodSignature signature = MethodSignatureUtil.createMethodSignature(name, PsiType.EMPTY_ARRAY, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); + MethodSignature signature = MethodSignatureUtil + .createMethodSignature(name, PsiType.EMPTY_ARRAY, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY); return MethodSignatureUtil.findMethodBySignature(refClass, signature, false); } @@ -184,10 +146,10 @@ public class PsiNameValuePairImpl extends CompositePsiElement implements PsiName if (nameIdentifier != null) { PsiImplUtil.setName(nameIdentifier, newElementName); } - else if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(getFirstChildNode().getElementType())) { + else if (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(getNode().getFirstChildNode().getElementType())) { PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); nameIdentifier = factory.createIdentifier(newElementName); - addBefore(nameIdentifier, SourceTreeToPsiMap.treeElementToPsi(getFirstChildNode())); + addBefore(nameIdentifier, SourceTreeToPsiMap.treeElementToPsi(getNode().getFirstChildNode())); } return PsiNameValuePairImpl.this; @@ -227,24 +189,10 @@ public class PsiNameValuePairImpl extends CompositePsiElement implements PsiName } @Override - public TreeElement addInternal(TreeElement first, ASTNode last, ASTNode anchor, Boolean before) { - final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this); - final TreeElement treeElement = super.addInternal(first, last, anchor, before); - if (first == last && first.getElementType() == JavaTokenType.IDENTIFIER) { - LeafElement eq = Factory.createSingleLeafElement(JavaTokenType.EQ, "=", 0, 1, treeCharTab, getManager()); - super.addInternal(eq, eq, first, Boolean.FALSE); - } - return treeElement; + public String toString() { + return "PsiNameValuePair"; } - @Override - public void deleteChildInternal(@NotNull ASTNode child) { - super.deleteChildInternal(child); - if (child.getElementType() == JavaTokenType.IDENTIFIER) { - final ASTNode sign = findChildByRole(ChildRole.OPERATION_SIGN); - if (sign != null) { - super.deleteChildInternal(sign); - } - } - } + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl"); + } diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java index 7d2a9cdd696f..f43e66c6b38f 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java @@ -92,6 +92,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { " CLASS:PsiClassStub[interface deprecatedA name=I fqn=p.I]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=5120]\n" + " ANNOTATION:PsiAnnotationStub[@java.lang.Deprecated]\n" + + " ANNOTATION_PARAMETER_LIST:PsiAnnotationParameterListStubImpl\n" + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + " EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" + " IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n" + @@ -308,6 +309,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { " METHOD:PsiMethodStub[close:void]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=1]\n" + " ANNOTATION:PsiAnnotationStub[@Override]\n" + + " ANNOTATION_PARAMETER_LIST:PsiAnnotationParameterListStubImpl\n" + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + " PARAMETER_LIST:PsiParameterListStub\n" + " THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n"); @@ -339,11 +341,45 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { " METHOD:PsiMethodStub[iterator:Iterator]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=1]\n" + " ANNOTATION:PsiAnnotationStub[@Override]\n" + + " ANNOTATION_PARAMETER_LIST:PsiAnnotationParameterListStubImpl\n" + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + " PARAMETER_LIST:PsiParameterListStub\n" + " THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n"); } + public void testAnnotationParameters() throws Exception { + doTest("@Deprecated(\"bar\")\n" + + "class Foo {\n" + + "}", + + "PsiJavaFileStub []\n" + + " IMPORT_LIST:PsiImportListStub\n" + + " CLASS:PsiClassStub[deprecatedA name=Foo fqn=Foo]\n" + + " MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" + + " ANNOTATION:PsiAnnotationStub[@Deprecated(\"bar\")]\n" + + " ANNOTATION_PARAMETER_LIST:PsiAnnotationParameterListStubImpl\n" + + " NAME_VALUE_PAIR:PsiNameValuePairStubImpl\n" + + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + + " EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" + + " IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n"); + } + + public void testAnnotation() throws Exception { + doTest("@Deprecated\n" + + "class Foo {\n" + + "}", + + "PsiJavaFileStub []\n" + + " IMPORT_LIST:PsiImportListStub\n" + + " CLASS:PsiClassStub[deprecatedA name=Foo fqn=Foo]\n" + + " MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" + + " ANNOTATION:PsiAnnotationStub[@Deprecated]\n" + + " ANNOTATION_PARAMETER_LIST:PsiAnnotationParameterListStubImpl\n" + + " TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" + + " EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" + + " IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n"); + } + public void testSOEProof() { final StringBuilder sb = new StringBuilder(); final SecureRandom random = new SecureRandom(); diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubBase.java b/platform/core-api/src/com/intellij/psi/stubs/StubBase.java index 52bc118cdc5e..cb267ead41b3 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/StubBase.java +++ b/platform/core-api/src/com/intellij/psi/stubs/StubBase.java @@ -226,4 +226,9 @@ public abstract class StubBase extends UserDataHolderBase ((StubBase)child).printTree(builder, nestingLevel + 1); } } + + @Override + public String toString() { + return getClass().getSimpleName(); + } } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 0ea3a70f9dba..1c2d3f4cf6fb 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -362,7 +362,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { void renameElement(PsiElement element, String newName); - void allowTreeAccessForFile(@NotNull VirtualFile file); + void allowTreeAccessForFile(VirtualFile file); void allowTreeAccessForAllFiles(); diff --git a/plugins/devkit/src/dom/impl/ExtensionDomExtender.java b/plugins/devkit/src/dom/impl/ExtensionDomExtender.java index 13e25dc51ab2..44b53afa1b31 100644 --- a/plugins/devkit/src/dom/impl/ExtensionDomExtender.java +++ b/plugins/devkit/src/dom/impl/ExtensionDomExtender.java @@ -236,6 +236,8 @@ public class ExtensionDomExtender extends DomExtender { private static String getStringAttribute(final PsiAnnotation annotation, final String name, final PsiConstantEvaluationHelper evalHelper) { + String value = getAttributeValue(annotation, name); + if (value != null) return value; final Object o = evalHelper.computeConstantExpression(annotation.findAttributeValue(name), false); return o instanceof String && StringUtil.isNotEmpty((String)o)? (String)o : null; } @@ -243,8 +245,20 @@ public class ExtensionDomExtender extends DomExtender { private static boolean getBooleanAttribute(final PsiAnnotation annotation, final String name, final PsiConstantEvaluationHelper evalHelper) { + String value = getAttributeValue(annotation, name); + if (value != null) return Boolean.parseBoolean(value); final Object o = evalHelper.computeConstantExpression(annotation.findAttributeValue(name), false); - return o instanceof Boolean? ((Boolean)o).booleanValue() : false; + return o instanceof Boolean && ((Boolean)o).booleanValue(); + } + + @Nullable + private static String getAttributeValue(PsiAnnotation annotation, String name) { + for (PsiNameValuePair attribute : annotation.getParameterList().getAttributes()) { + if (name.equals(attribute.getName())) { + return attribute.getLiteralValue(); + } + } + return null; } @Nullable diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java index 68676a66fc91..bf084a6baf78 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java @@ -56,6 +56,11 @@ public class GrAnnotationNameValuePairImpl extends GroovyPsiElementImpl implemen return nameId != null ? nameId.getText() : null; } + @Override + public String getLiteralValue() { + return null; + } + @Nullable public PsiElement getNameIdentifierGroovy() { return findChildByType(GroovyTokenTypes.mIDENT);