Add a deserializeNullableString utility method to the base stub class

This commit is contained in:
Ben Gruver 2015-02-16 13:03:08 -08:00
parent 9423a7d7d0
commit eb1d98f063
6 changed files with 21 additions and 31 deletions

View File

@ -36,7 +36,6 @@ 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 org.jf.smalidea.psi.impl.SmaliClass;
import org.jf.smalidea.psi.index.SmaliClassNameIndex;
@ -74,12 +73,7 @@ public class SmaliClassElementType extends SmaliStubElementType<SmaliClassStub,
@NotNull @Override
public SmaliClassStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef nameRef = dataStream.readName();
String name = null;
if (nameRef != null) {
name = nameRef.getString();
}
return new SmaliClassStub(parentStub, name);
return new SmaliClassStub(parentStub, deserializeNullableString(dataStream));
}
@Override public void indexStub(@NotNull SmaliClassStub stub, @NotNull IndexSink sink) {

View File

@ -36,7 +36,6 @@ 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 org.jf.smalidea.psi.impl.SmaliField;
import org.jf.smalidea.psi.stub.SmaliFieldStub;
@ -74,13 +73,8 @@ public class SmaliFieldElementType extends SmaliStubElementType<SmaliFieldStub,
@NotNull @Override
public SmaliFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef nameRef = dataStream.readName();
String name = null;
if (nameRef != null) {
name = nameRef.getString();
}
return new SmaliFieldStub(parentStub, name, dataStream.readName().getString());
return new SmaliFieldStub(parentStub, deserializeNullableString(dataStream),
dataStream.readName().getString());
}
@Override public void indexStub(@NotNull SmaliFieldStub stub, @NotNull IndexSink sink) {

View File

@ -36,7 +36,6 @@ 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 org.jf.smalidea.psi.impl.SmaliMethod;
import org.jf.smalidea.psi.stub.SmaliMethodStub;
@ -73,8 +72,7 @@ public class SmaliMethodElementType extends SmaliStubElementType<SmaliMethodStub
@NotNull @Override
public SmaliMethodStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef methodNameRef = dataStream.readName();
return new SmaliMethodStub(parentStub, methodNameRef.getString());
return new SmaliMethodStub(parentStub, dataStream.readName().getString());
}
@Override public void indexStub(@NotNull SmaliMethodStub stub, @NotNull IndexSink sink) {

View File

@ -36,7 +36,6 @@ 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 org.jf.smalidea.psi.impl.SmaliMethodParameter;
import org.jf.smalidea.psi.stub.SmaliMethodParameterStub;
@ -77,11 +76,8 @@ public class SmaliMethodParameterElementType
@NotNull @Override
public SmaliMethodParameterStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub)
throws IOException {
String type = dataStream.readName().getString();
StringRef nameRef = dataStream.readName();
String name = nameRef==null ? null : nameRef.getString();
return new SmaliMethodParameterStub(parentStub, type, name);
return new SmaliMethodParameterStub(parentStub, dataStream.readName().getString(),
deserializeNullableString(dataStream));
}
@Override public void indexStub(@NotNull SmaliMethodParameterStub stub, @NotNull IndexSink sink) {

View File

@ -37,7 +37,6 @@ 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 org.jf.smalidea.psi.impl.SmaliMethodPrototype;
import org.jf.smalidea.psi.stub.SmaliMethodPrototypeStub;
@ -83,12 +82,7 @@ public class SmaliMethodPrototypeElementType
@NotNull @Override
public SmaliMethodPrototypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub)
throws IOException {
StringRef returnTypeRef = dataStream.readName();
String returnType = null;
if (returnTypeRef != null) {
returnType = returnTypeRef.getString();
}
return new SmaliMethodPrototypeStub(parentStub, returnType);
return new SmaliMethodPrototypeStub(parentStub, deserializeNullableString(dataStream));
}
@Override public void indexStub(@NotNull SmaliMethodPrototypeStub stub, @NotNull IndexSink sink) {

View File

@ -35,10 +35,15 @@ import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jf.smalidea.SmaliLanguage;
import java.io.IOException;
public abstract class SmaliStubElementType<StubT extends StubElement, PsiT extends PsiElement>
extends IStubElementType<StubT, PsiT> {
protected SmaliStubElementType(@NotNull @NonNls String debugName) {
@ -46,4 +51,13 @@ public abstract class SmaliStubElementType<StubT extends StubElement, PsiT exten
}
public abstract PsiT createPsi(@NotNull ASTNode node);
@Nullable
protected String deserializeNullableString(@NotNull StubInputStream dataStream) throws IOException {
StringRef stringRef = dataStream.readName();
if (stringRef == null) {
return null;
}
return stringRef.getString();
}
}