Stub for annotations: write shortName instead getText
This commit is contained in:
@@ -20,5 +20,5 @@ import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
||||
|
||||
public interface PsiJetAnnotationStub extends StubElement<JetAnnotationEntry> {
|
||||
String getText();
|
||||
String getShortName();
|
||||
}
|
||||
|
||||
+14
-3
@@ -24,7 +24,7 @@ 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.*;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetAnnotationStubImpl;
|
||||
|
||||
@@ -48,12 +48,23 @@ public class JetAnnotationElementType extends JetStubElementType<PsiJetAnnotatio
|
||||
|
||||
@Override
|
||||
public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) {
|
||||
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, psi.getText());
|
||||
JetTypeReference typeReference = psi.getTypeReference();
|
||||
assert typeReference != null : "Annotation entry hasn't typeReference " + psi.getText();
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
String shortName = null;
|
||||
if (typeElement instanceof JetUserType) {
|
||||
JetUserType userType = (JetUserType) typeElement;
|
||||
shortName = userType.getReferencedName();
|
||||
}
|
||||
if (shortName == null) {
|
||||
shortName = psi.getText();
|
||||
}
|
||||
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, shortName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PsiJetAnnotationStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getText());
|
||||
dataStream.writeName(stub.getShortName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-8
@@ -20,31 +20,32 @@ 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.annotations.NotNull;
|
||||
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;
|
||||
private final StringRef shortName;
|
||||
|
||||
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, String text) {
|
||||
this(parent, elementType, StringRef.fromString(text));
|
||||
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, @NotNull String shortName) {
|
||||
this(parent, elementType, StringRef.fromString(shortName));
|
||||
}
|
||||
|
||||
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, StringRef text) {
|
||||
public PsiJetAnnotationStubImpl(StubElement parent, IStubElementType elementType, StringRef shortName) {
|
||||
super(parent, elementType);
|
||||
this.text = text;
|
||||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return text.getString();
|
||||
public String getShortName() {
|
||||
return shortName.getString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("PsiJetAnnotationStubImpl[");
|
||||
builder.append("text=").append(getText());
|
||||
builder.append("shortName=").append(getShortName());
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ public class KotlinAnnotatedElementsSearcher extends AnnotatedElementsSearcher {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Return all elements annotated with given annotation name. Aliases don't work now. */
|
||||
private static Collection<? extends PsiElement> getJetAnnotationCandidates(final PsiClass annClass, final SearchScope useScope) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends PsiElement>>() {
|
||||
@Override
|
||||
|
||||
@@ -91,6 +91,6 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
|
||||
@Override
|
||||
public void indexAnnotation(PsiJetAnnotationStub stub, IndexSink sink) {
|
||||
sink.occurrence(JetIndexKeys.ANNOTATIONS_KEY, stub.getText());
|
||||
sink.occurrence(JetIndexKeys.ANNOTATIONS_KEY, stub.getShortName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
doBuildTest("Deprecated class Test {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" CLASS:PsiJetClassStubImpl[name=Test fqn=Test superNames=[]]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[text=Deprecated]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
@@ -176,7 +176,24 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
doBuildTest("Deprecated fun foo() {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=foo name=foo]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[text=Deprecated]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
public void testQualifiedAnnotationOnFunction() {
|
||||
doBuildTest("java.lang.Deprecated fun foo() {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=foo name=foo]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
public void testManyAnnotationsOnFunction() {
|
||||
doBuildTest("[Deprecated Override] fun foo() {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=foo name=foo]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n" +
|
||||
" ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Override]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user