Stub for annotations: write shortName instead getText

This commit is contained in:
Natalia.Ukhorskaya
2012-10-04 13:57:44 +04:00
parent 8e89cf40b7
commit a5b43cbbae
6 changed files with 45 additions and 15 deletions
@@ -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();
}
@@ -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
@@ -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();
}