diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 3d970d9250b..49aaec5165c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -57,7 +57,7 @@ public interface JetNodeTypes { JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class); JetNodeType PRIMARY_CONSTRUCTOR_MODIFIER_LIST = new JetNodeType("PRIMARY_CONSTRUCTOR_MODIFIER_LIST", JetModifierList.class); JetNodeType ANNOTATION = new JetNodeType("ANNOTATION", JetAnnotation.class); - JetNodeType ANNOTATION_ENTRY = new JetNodeType("ANNOTATION_ENTRY", JetAnnotationEntry.class); + IElementType ANNOTATION_ENTRY = JetStubElementTypes.ANNOTATION_ENTRY; JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST", JetTypeArgumentList.class); JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetValueArgumentList.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotationEntry.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotationEntry.java index 38dadbc07aa..044b74e3407 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotationEntry.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotationEntry.java @@ -17,9 +17,12 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; +import com.intellij.psi.stubs.IStubElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import java.util.Collections; import java.util.List; @@ -27,11 +30,21 @@ import java.util.List; /** * @author max */ -public class JetAnnotationEntry extends JetElementImpl implements JetCallElement { +public class JetAnnotationEntry extends JetElementImplStub implements JetCallElement { public JetAnnotationEntry(@NotNull ASTNode node) { super(node); } + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.ANNOTATION_ENTRY; + } + + public JetAnnotationEntry(@NotNull PsiJetAnnotationStub stub) { + super(stub, JetStubElementTypes.ANNOTATION_ENTRY); + } + @Override public void accept(@NotNull JetVisitorVoid visitor) { visitor.visitAnnotationEntry(this); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetAnnotationStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetAnnotationStub.java new file mode 100644 index 00000000000..aafbc4ead5a --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetAnnotationStub.java @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs; + +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.jet.lang.psi.JetAnnotationEntry; + +public interface PsiJetAnnotationStub extends StubElement { + String getText(); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetAnnotationElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetAnnotationElementType.java new file mode 100644 index 00000000000..4542df78241 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetAnnotationElementType.java @@ -0,0 +1,69 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs.elements; + +import com.intellij.lang.ASTNode; +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.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetAnnotationEntry; +import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub; +import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetAnnotationStubImpl; + +import java.io.IOException; + +public class JetAnnotationElementType extends JetStubElementType { + + public JetAnnotationElementType(@NotNull @NonNls String debugName) { + super(debugName); + } + + @Override + public JetAnnotationEntry createPsiFromAst(@NotNull ASTNode node) { + return new JetAnnotationEntry(node); + } + + @Override + public JetAnnotationEntry createPsi(@NotNull PsiJetAnnotationStub stub) { + return new JetAnnotationEntry(stub); + } + + @Override + public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) { + return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, psi.getText()); + } + + @Override + public void serialize(PsiJetAnnotationStub stub, StubOutputStream dataStream) throws IOException { + dataStream.writeName(stub.getText()); + } + + @Override + public PsiJetAnnotationStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + StringRef text = dataStream.readName(); + return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, text); + } + + @Override + public void indexStub(PsiJetAnnotationStub stub, IndexSink sink) { + StubIndexServiceFactory.getInstance().indexAnnotation(stub, sink); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java index 9054129edfe..17e61d12681 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java @@ -33,4 +33,5 @@ public interface JetStubElementTypes { JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER"); JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST"); + JetAnnotationElementType ANNOTATION_ENTRY = new JetAnnotationElementType("ANNOTATION_ENTRY"); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/StubIndexService.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/StubIndexService.java index 0b87b59491b..12524c45b0b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/StubIndexService.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/StubIndexService.java @@ -17,10 +17,7 @@ package org.jetbrains.jet.lang.psi.stubs.elements; import com.intellij.psi.stubs.IndexSink; -import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub; +import org.jetbrains.jet.lang.psi.stubs.*; /** * @author Nikolay Krasko @@ -46,10 +43,15 @@ public interface StubIndexService { @Override public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) { } + + @Override + public void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink) { + } }; void indexClass(PsiJetClassStub stub, IndexSink sink); void indexFunction(PsiJetFunctionStub stub, IndexSink sink); void indexObject(PsiJetObjectStub stub, IndexSink sink); void indexProperty(PsiJetPropertyStub stub, IndexSink sink); + void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetAnnotationStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetAnnotationStubImpl.java new file mode 100644 index 00000000000..052d428e334 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetAnnotationStubImpl.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs.impl; + +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; +import com.intellij.util.io.StringRef; +import org.jetbrains.jet.lang.psi.JetAnnotationEntry; +import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub; + +public class PsiJetAnnotationStubImpl extends StubBase implements PsiJetAnnotationStub { + private final StringRef text; + + public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, String text) { + this(parent, elementType, StringRef.fromString(text)); + } + + public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, StringRef text) { + super(parent, elementType); + this.text = text; + } + + @Override + public String getText() { + return text.getString(); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PsiJetAnnotationStubImpl["); + builder.append("text=").append(getText()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 998dd072756..31fcff13aac 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -203,6 +203,7 @@ + diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetAnnotationsIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAnnotationsIndex.java new file mode 100644 index 00000000000..c4f0b168312 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAnnotationsIndex.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.stubindex; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.stubs.StringStubIndexExtension; +import com.intellij.psi.stubs.StubIndexKey; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetAnnotationEntry; + +import java.util.Collection; + +public class JetAnnotationsIndex extends StringStubIndexExtension { + private static final JetAnnotationsIndex ourInstance = new JetAnnotationsIndex(); + + public static JetAnnotationsIndex getInstance() { + return ourInstance; + } + + @NotNull + @Override + public StubIndexKey getKey() { + return JetIndexKeys.ANNOTATIONS_KEY; + } + + @Override + public Collection get(final String s, final Project project, @NotNull final GlobalSearchScope scope) { + return super.get(s, project, new JetSourceFilterScope(scope)); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java index 70ca0a2f62d..874d714d2b9 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.plugin.stubindex; import com.intellij.psi.stubs.StubIndexKey; +import org.jetbrains.jet.lang.psi.JetAnnotationEntry; import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.psi.JetProperty; @@ -43,5 +44,7 @@ public interface JetIndexKeys { StubIndexKey.createIndexKey("jet.top.level.property.fqn.name"); StubIndexKey FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name"); + + StubIndexKey ANNOTATIONS_KEY = StubIndexKey.createIndexKey("jet.annotations"); } diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java index edaed2468db..a7232793d7c 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java @@ -17,10 +17,7 @@ package org.jetbrains.jet.plugin.stubindex; import com.intellij.psi.stubs.IndexSink; -import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub; -import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub; +import org.jetbrains.jet.lang.psi.stubs.*; import org.jetbrains.jet.lang.psi.stubs.elements.StubIndexService; import org.jetbrains.jet.lang.resolve.name.FqName; @@ -91,4 +88,9 @@ public class StubIndexServiceImpl implements StubIndexService { } } } + + @Override + public void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink) { + sink.occurrence(JetIndexKeys.ANNOTATIONS_KEY, stub.getText()); + } } diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java index d39cadffcde..4d069e8d66f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java @@ -164,6 +164,29 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { " OBJECT_DECLARATION:PsiJetObjectStubImpl[name=Test fqName=Test]\n"); } + public void testAnnotationOnClass() { + doBuildTest("Deprecated class Test {}", + "PsiJetFileStubImpl[package=]\n" + + " CLASS:PsiJetClassStubImpl[name=Test fqn=Test superNames=[]]\n" + + " ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[text=Deprecated]\n" + + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n"); + } + + public void testAnnotationOnFunction() { + doBuildTest("Deprecated fun foo() {}", + "PsiJetFileStubImpl[package=]\n" + + " FUN:PsiJetFunctionStubImpl[top topFQName=foo name=foo]\n" + + " ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[text=Deprecated]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); + } + + public void testAnnotationOnLocalFunction() { + doBuildTest("fun foo() { [Deprecated] fun innerFoo() {} }", + "PsiJetFileStubImpl[package=]\n" + + " FUN:PsiJetFunctionStubImpl[top topFQName=foo name=foo]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); + } + private void doBuildTest(@NonNls final String source, @NonNls @NotNull final String tree) { final JetFile file = (JetFile) createLightFile(JetFileType.INSTANCE, source); final FileASTNode fileNode = file.getNode();