Stub for annotations

This commit is contained in:
Natalia.Ukhorskaya
2012-10-03 12:21:59 +04:00
parent 3cdc2363fa
commit ae6aa1b160
12 changed files with 244 additions and 10 deletions
@@ -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);
@@ -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<PsiJetAnnotationStub> 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);
@@ -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<JetAnnotationEntry> {
String getText();
}
@@ -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<PsiJetAnnotationStub, JetAnnotationEntry> {
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);
}
}
@@ -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");
}
@@ -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);
}
@@ -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<JetAnnotationEntry> 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();
}
}
+1
View File
@@ -203,6 +203,7 @@
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex" />
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex" />
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAnnotationsIndex" />
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
@@ -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<JetAnnotationEntry> {
private static final JetAnnotationsIndex ourInstance = new JetAnnotationsIndex();
public static JetAnnotationsIndex getInstance() {
return ourInstance;
}
@NotNull
@Override
public StubIndexKey<String, JetAnnotationEntry> getKey() {
return JetIndexKeys.ANNOTATIONS_KEY;
}
@Override
public Collection<JetAnnotationEntry> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(s, project, new JetSourceFilterScope(scope));
}
}
@@ -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<String, JetNamedFunction> FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name");
StubIndexKey<String, JetAnnotationEntry> ANNOTATIONS_KEY = StubIndexKey.createIndexKey("jet.annotations");
}
@@ -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());
}
}
@@ -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();