@NotNull @Override public PsiClassStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { byte flags = dataStream.readByte(); boolean isAnonymous = PsiClassStubImpl.isAnonymous(flags); boolean isEnumConst = PsiClassStubImpl.isEnumConstInitializer(flags); JavaClassElementType type = typeForClass(isAnonymous, isEnumConst); if (!isAnonymous) { StringRef name = dataStream.readName(); StringRef qname = dataStream.readName(); int languageLevelId = dataStream.readByte(); StringRef sourceFileName = dataStream.readName(); PsiClassStubImpl classStub = new PsiClassStubImpl(type, parentStub, qname, name, null, flags); classStub.setLanguageLevel(LanguageLevel.values()[languageLevelId]); classStub.setSourceFileName(sourceFileName); return classStub; } else { StringRef baseRef = dataStream.readName(); return new PsiClassStubImpl(type, parentStub, null, null, baseRef, flags); } }
@Nullable public static QualifiedName deserialize(StubInputStream dataStream) throws IOException { QualifiedName qName; int size = dataStream.readVarInt(); if (size == 0) { qName = null; } else { qName = new QualifiedName(size); for (int i = 0; i < size; i++) { final StringRef name = dataStream.readName(); qName.myComponents.add(name == null ? null : name.getString()); } } return qName; }
@NotNull public PyTargetExpressionStub deserialize(@NotNull final StubInputStream stream, final StubElement parentStub) throws IOException { String name = StringRef.toString(stream.readName()); String docString = stream.readUTFFast(); if (docString.isEmpty()) { docString = null; } PyTargetExpressionStub.InitializerType initializerType = PyTargetExpressionStub.InitializerType.fromIndex(stream.readVarInt()); if (initializerType == PyTargetExpressionStub.InitializerType.Custom) { final String typeName = stream.readName().getString(); for(CustomTargetExpressionStubType type: getCustomStubTypes()) { if (type.getClass().getCanonicalName().equals(typeName)) { CustomTargetExpressionStub stub = type.deserializeStub(stream); return new PyTargetExpressionStubImpl(name, docString, stub, parentStub); } } throw new IOException("Unknown custom stub type " + typeName); } QualifiedName initializer = QualifiedName.deserialize(stream); boolean isQualified = stream.readBoolean(); return new PyTargetExpressionStubImpl(name, docString, initializerType, initializer, isQualified, parentStub); }
@NotNull public static SerializedFqnTypeRef deserialize(@NotNull StubInputStream stream) throws IOException { String shortNameStr = StringRef.toString(stream.readName()); Qn shortName = null; List<Qn> namespacesToSearch = null; if (shortNameStr != null) { shortName = Qn.fromDotSeparated(shortNameStr); namespacesToSearch = StubSerializerUtil.deserializeList(s -> { StringRef namespaceRef = s.readName(); String namespace = StringRef.toString(namespaceRef); return namespace == null ? null : Qn.fromDotSeparated(namespace); }, stream, true); } return new SerializedFqnTypeRef(shortName, namespacesToSearch); }
@NotNull public static <T> Set<T> deserializeSet(@NotNull Deserializer<T> itemDeserializer, @NotNull StubInputStream stream, boolean skipNulls) throws IOException { short numItems = stream.readShort(); // can't do this, we may want to add more elements to it later on // if (numItems == 0) return Collections.emptySet(); Set<T> result = ContainerUtil.newTroveSet(); for (int i = 0; i < numItems; i++) { T item = itemDeserializer.deserialize(stream); if (item != null || skipNulls) result.add(item); } return result; }
@NotNull public static <T> List<T> deserializeList(@NotNull Deserializer<T> itemDeserializer, @NotNull StubInputStream stream, boolean skipNulls) throws IOException { short numItems = stream.readShort(); // can't do this, we may want to add more elements to it later on // if (numItems == 0) return Collections.emptyList(); List<T> result = ContainerUtil.newSmartList(); // our lists often contain only one element for (int i = 0; i < numItems; i++) { T item = itemDeserializer.deserialize(stream); if (item != null || skipNulls) result.add(item); } return result; }
@Override @Nullable public LuaTableStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { boolean hasType = dataStream.readBoolean(); byte[] typedata = null; if (hasType) { int len = dataStream.readVarInt(); if (len < 0) ((SerializationManagerEx) SerializationManagerEx.getInstance()).repairNameStorage(); if (len <= 0) { return new LuaTableStubImpl(parentStub); } typedata = new byte[len]; dataStream.read(typedata, 0, len); } return new LuaTableStubImpl(parentStub, typedata); }
@NotNull @Override public PsiClassStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { byte flags = dataStream.readByte(); boolean isAnonymous = PsiClassStubImpl.isAnonymous(flags); if(!isAnonymous) { StringRef name = dataStream.readName(); StringRef qname = dataStream.readName(); StringRef sourceFileName = dataStream.readName(); PsiClassStubImpl classStub = new PsiClassStubImpl(this, parentStub, StringRef.toString(qname), StringRef.toString(name), null, flags); classStub.setSourceFileName(StringRef.toString(sourceFileName)); return classStub; } else { StringRef baseRef = dataStream.readName(); return new PsiClassStubImpl(this, parentStub, null, null, StringRef.toString(baseRef), flags); } }
@NotNull public static TypeInfo readTYPE(@NotNull StubInputStream record) throws IOException { int flags = 0xFF & record.readByte(); if(flags == FREQUENT_INDEX_MASK) { return NULL; } int frequentIndex = FREQUENT_INDEX_MASK & flags; byte arrayCount = isSet(flags, HAS_ARRAY_COUNT) ? record.readByte() : 0; boolean hasEllipsis = isSet(flags, HAS_ELLIPSIS); String text = frequentIndex == 0 ? StringRef.toString(record.readName()) : ourIndexFrequentType[frequentIndex]; return new TypeInfo(text, arrayCount, hasEllipsis, PsiAnnotationStub.EMPTY_ARRAY); }
@NotNull @Override public TemplateDefinitionStub deserialize( @NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { final StringRef ref = dataStream.readName(); return new TemplateDefinitionStub(parentStub, ref.getString()); }
@NotNull @Override public NamespaceDeclarationStub deserialize( @NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { final StringRef ref = dataStream.readName(); return new NamespaceDeclarationStub(parentStub, ref.getString()); }
@NotNull @Override public AtParamStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { final StringRef ref = dataStream.readName(); final StringRef ref2 = dataStream.readName(); return new AtParamStub( parentStub, ref.getString(), ref2.getString(), dataStream.readBoolean()); }
@Override public LuaCompoundIdentifierStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef ref = dataStream.readName(); final Pair<LuaType, byte[]> pair = LuaStubUtils.readSubstitutableType(dataStream); byte[] typedata = pair.getSecond(); LuaType type = pair.first; boolean isDeclaration = dataStream.readBoolean(); return new LuaCompoundIdentifierStubImpl(parentStub, ref, isDeclaration, typedata, type); }
@Override public LuaModuleDeclarationStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef ref = dataStream.readName(); StringRef mref = dataStream.readName(); int len = dataStream.readVarInt(); byte[] typedata = new byte[len]; int readLen = dataStream.read(typedata, 0, len); assert readLen == len; return new LuaModuleDeclarationStubImpl(parentStub, ref, mref, typedata); }
public static Pair<LuaType, byte[]> readSubstitutableType(StubInputStream dataStream) throws IOException { final boolean primitive = dataStream.readBoolean(); LuaType type = null; byte[] bytes = null; if (primitive) type = LuaPrimitiveType.PRIMITIVE_TYPES[dataStream.readByte()]; else { bytes = new byte[dataStream.readVarInt()]; int len = dataStream.read(bytes, 0, bytes.length); assert len == bytes.length : "read wrong length"; } return new Pair<LuaType, byte[]>(type, bytes); }
@NotNull @Override public S deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { return createStub(parentStub, dataStream.readName().getString(), dataStream.readName().getString()); }
@NotNull @Override public PsiMethodStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); final TypeInfo type = TypeInfo.readTYPE(dataStream); byte flags = dataStream.readByte(); final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null; return new PsiMethodStubImpl(parentStub, StringRef.toString(name), type, flags, StringRef.toString(defaultMethodValue)); }
@NotNull @Override public PsiFieldStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { final StringRef name = dataStream.readName(); final TypeInfo type = TypeInfo.readTYPE(dataStream); final StringRef initializerText = dataStream.readName(); final byte flags = dataStream.readByte(); return new PsiFieldStubImpl(parentStub, name, type, initializerText, flags); }
@NotNull @Override public PsiClassReferenceListStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { byte role = dataStream.readByte(); int len = dataStream.readVarInt(); StringRef[] names = StringRef.createArray(len); for (int i = 0; i < names.length; i++) { names[i] = dataStream.readName(); } PsiReferenceList.Role decodedRole = decodeRole(role); return new PsiClassReferenceListStubImpl(roleToElementType(decodedRole), parentStub, names, decodedRole); }
@NotNull @Override public PsiImportStatementStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { final byte flags = dataStream.readByte(); final StringRef refText = dataStream.readName(); return new PsiImportStatementStubImpl(parentStub, refText, flags); }
@NotNull @Override public PsiParameterStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); TypeInfo type = TypeInfo.readTYPE(dataStream); boolean isEllipsis = dataStream.readBoolean(); return new PsiParameterStubImpl(parentStub, name, type, isEllipsis); }
@NotNull public static TypeInfo readTYPE(@NotNull StubInputStream record) throws IOException { int flags = 0xFF & record.readByte(); if (flags == FREQUENT_INDEX_MASK) { return NULL; } int frequentIndex = FREQUENT_INDEX_MASK & flags; byte arrayCount = isSet(flags, HAS_ARRAY_COUNT) ? record.readByte() : 0; boolean hasEllipsis = isSet(flags, HAS_ELLIPSIS); String text = frequentIndex == 0 ? StringRef.toString(record.readName()) : ourIndexFrequentType[frequentIndex]; return new TypeInfo(text, arrayCount, hasEllipsis, PsiAnnotationStub.EMPTY_ARRAY); }
@NotNull @Override public PyFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { List<String> all = readNullableList(dataStream); BitSet future_features = readBitSet(dataStream); StringRef deprecationMessage = dataStream.readName(); return new PyFileStubImpl(all, future_features, deprecationMessage); }
private static BitSet readBitSet(StubInputStream dataStream) throws IOException { // NOTE: here we assume that bitset has no more than 32 bits so that the value fits into an int. BitSet ret = new BitSet(32); // see PyFileStubImpl: we assume that all bits fit into an int int bits = dataStream.readInt(); for (int i = 0; i < 32; i += 1) { boolean bit = (bits & (1 << i)) != 0; ret.set(i, bit); } return ret; }
@Nullable public static List<String> readNullableList(StubInputStream dataStream) throws IOException { boolean hasNames = dataStream.readBoolean(); List<String> names = null; if (hasNames) { int size = dataStream.readVarInt(); names = new ArrayList<String>(size); for (int i = 0; i < size; i++) { names.add(dataStream.readName().getString()); } } return names; }
public static PropertyStubStorage deserialize(StubInputStream stream) throws IOException { PropertyStubStorage me = new PropertyStubStorage(); me.myGetter = readOne(stream); me.mySetter = readOne(stream); me.myDeleter = readOne(stream); // StringRef ref = stream.readName(); me.myDoc = ref != null? ref.getString() : null; return me; }
@Nullable private static Maybe<String> readOne(StubInputStream stream) throws IOException { StringRef ref = stream.readName(); if (ref == null) return none; else { String s = ref.getString(); if (IMPOSSIBLE_NAME.equals(s)) return unknown; else return new Maybe<String>(s); } }
@NotNull public PyNamedParameterStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { String name = StringRef.toString(dataStream.readName()); byte flags = dataStream.readByte(); return new PyNamedParameterStubImpl(name, (flags & POSITIONAL_CONTAINER) != 0, (flags & KEYWORD_CONTAINER) != 0, (flags & HAS_DEFAULT_VALUE) != 0, parentStub, getStubElementType()); }
@NotNull public PyFromImportStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { QualifiedName qName = QualifiedName.deserialize(dataStream); boolean isStarImport = dataStream.readBoolean(); int relativeLevel = dataStream.readVarInt(); return new PyFromImportStatementStubImpl(qName, isStarImport, relativeLevel, parentStub, getStubElementType()); }
@Override @NotNull public GrMethodStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef ref = dataStream.readName(); final String[] annNames = GrStubUtils.readStringArray(dataStream); String[] namedParameters = GrStubUtils.readStringArray(dataStream); String typeText = GrStubUtils.readNullableString(dataStream); final byte flags = dataStream.readByte(); return new GrMethodStub(parentStub, ref, annNames, namedParameters, this, typeText, flags); }
@NotNull @Override public GrImportStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { String referenceText = GrStubUtils.readNullableString(dataStream); String aliasName = GrStubUtils.readNullableString(dataStream); byte flags = dataStream.readByte(); return new GrImportStatementStub(parentStub, this, referenceText, aliasName, flags); }
static GrFieldStub deserializeFieldStub(StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef ref = dataStream.readName(); final String[] annNames = GrStubUtils.readStringArray(dataStream); final String[] namedParameters = GrStubUtils.readStringArray(dataStream); byte flags = dataStream.readByte(); final String typeText = GrStubUtils.readNullableString(dataStream); return new GrFieldStub(parentStub, ref, annNames, namedParameters, GrFieldStub.isEnumConstant(flags) ? GroovyElementTypes.ENUM_CONSTANT : GroovyElementTypes.FIELD, flags, typeText); }
@Override @NotNull public GrTypeDefinitionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { String name = StringRef.toString(dataStream.readName()); String qname = StringRef.toString(dataStream.readName()); byte flags = dataStream.readByte(); String[] superClasses = readStringArray(dataStream); String[] annos = readStringArray(dataStream); return new GrTypeDefinitionStub(parentStub, name, superClasses, this, qname, annos, flags); }
private static String[] readStringArray(StubInputStream dataStream) throws IOException { byte supersNumber = dataStream.readByte(); String[] superClasses = new String[supersNumber]; for (int i = 0; i < supersNumber; i++) { superClasses[i] = StringRef.toString(dataStream.readName()); } return superClasses; }
public static String[] readStringArray(StubInputStream dataStream) throws IOException { int length = dataStream.readByte(); if (length == TOO_LONG) { length = dataStream.readInt(); } final String[] annNames = new String[length]; for (int i = 0; i < length; i++) { annNames[i] = dataStream.readName().toString(); } return annNames; }
@NotNull @Override protected SchemaListTypeDefStub deserialize( @NotNull StubInputStream dataStream, StubElement parentStub, String name, String namespace, @Nullable final List<SerializedFqnTypeRef> extendsTypeRefs) throws IOException { return new SchemaListTypeDefStubImpl(parentStub, name, namespace, extendsTypeRefs); }
@NotNull @Override protected SchemaEntityTypeDefStub deserialize( @NotNull StubInputStream dataStream, StubElement parentStub, String name, String namespace, @Nullable final List<SerializedFqnTypeRef> extendsTypeRefs) throws IOException { List<SerializedFqnTypeRef> supplementedRefs = StubSerializerUtil.deserializeList(SerializedFqnTypeRef::deserialize, dataStream, true); return new SchemaEntityTypeDefStubImpl(parentStub, name, namespace, extendsTypeRefs, supplementedRefs); }
@NotNull @Override protected SchemaRecordTypeDefStub deserialize( @NotNull StubInputStream dataStream, StubElement parentStub, String name, String namespace, @Nullable final List<SerializedFqnTypeRef> extendsTypeRefs) throws IOException { List<SerializedFqnTypeRef> supplementedRefs = StubSerializerUtil.deserializeList(SerializedFqnTypeRef::deserialize, dataStream, true); return new SchemaRecordTypeDefStubImpl(parentStub, name, namespace, extendsTypeRefs, supplementedRefs); }