@Override public PsiNameValuePairStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { String name = null; String value = null; List<LighterASTNode> children = tree.getChildren(node); for (LighterASTNode child : children) { if (child.getTokenType() == JavaTokenType.IDENTIFIER) { name = RecordUtil.intern(tree.getCharTable(), child); } else if (child.getTokenType() == JavaElementType.LITERAL_EXPRESSION) { value = RecordUtil.intern(tree.getCharTable(), tree.getChildren(child).get(0)); value = StringUtil.unquoteString(value); } } return new PsiNameValuePairStubImpl(parentStub, StringRef.fromString(name), StringRef.fromString(value)); }
@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); } }
public PsiClassStubImpl(final JavaClassElementType type, final StubElement parent, final StringRef qualifiedName, final StringRef name, final StringRef baseRefText, final byte flags) { super(parent, type); myQualifiedName = qualifiedName; myName = name; myBaseRefText = baseRefText; myFlags = flags; if (StubBasedPsiElementBase.ourTraceStubAstBinding) { String creationTrace = "Stub creation thread: " + Thread.currentThread() + "\n" + DebugUtil.currentStackTrace(); putUserData(StubBasedPsiElementBase.CREATION_TRACE, creationTrace); } }
@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 @Override protected StubElement createStubForFile(@NotNull PsiFile file, @NotNull LighterAST tree) { if (!(file instanceof PsiJavaFile)) { return super.createStubForFile(file, tree); } String refText = ""; LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT); if (pkg != null) { LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE); if (ref != null) { refText = JavaSourceUtil.getReferenceText(tree, ref); } } return new PsiJavaFileStubImpl((PsiJavaFile)file, StringRef.fromString(refText), false); }
@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 ModuleStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { StringRef moduleName = dataStream.readName(); int moduleQNLength = dataStream.readInt(); String[] moduleQN = new String[moduleQNLength]; for (int i = 0; i < moduleQNLength; i++) { moduleQN[i] = dataStream.readUTFFast(); } ModulePath modulePath = new ModulePath(moduleQN); return new ModuleStub(parentStub, this, moduleName, modulePath); }
@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 createStub(@NotNull LuaCompoundIdentifier psi, StubElement parentStub) { final LuaType luaType = psi.getLuaType(); final byte[] bytes = luaType instanceof LuaPrimitiveType ? null : SerializationUtils.serialize(luaType); final boolean declaration = psi.isCompoundDeclaration() && psi.getScopeIdentifier() instanceof LuaGlobal; return new LuaCompoundIdentifierStubImpl(parentStub, StringRef.fromNullableString(psi.getName()), declaration, bytes, luaType); }
@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 createStub(@NotNull LuaModuleExpression psi, StubElement parentStub) { log.debug(psi.getText()); final String moduleName = psi.getModuleName(); return new LuaModuleDeclarationStubImpl(parentStub, StringRef.fromNullableString(psi.getName()), StringRef.fromNullableString(moduleName), SerializationUtils.serialize(psi.getLuaType())); }
@Override public LuaFileStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); // System.out.println("deserialized file " + name.getString() + " module " + (module!=null?module.getString():"null")); return new LuaFileStub(name); }
public LuaGlobalDeclarationStubImpl(@Nullable StubElement parent, IStubElementType elementType, @Nullable StringRef name, @Nullable StringRef module, byte[] type, LuaType luaType) { super(parent, elementType, name); myModule = module; myType = type; this.luaType = luaType; }
public String getNameAsString(StringRef name) { if (name != null) { return name.getString(); } return null; }
@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); }
public PsiFieldStubImpl(StubElement parent, StringRef name, @NotNull TypeInfo type, @Nullable StringRef initializer, byte flags) { super(parent, isEnumConst(flags) ? JavaStubElementTypes.ENUM_CONSTANT : JavaStubElementTypes.FIELD); myName = name; myType = type; myInitializer = initializer; myFlags = flags; }
public PsiClassStubImpl(final JavaClassElementType type, final StubElement parent, final String qualifiedName, final String name, @Nullable final String baseRefText, final byte flags) { this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), StringRef.fromString(baseRefText), flags); }
public PsiClassReferenceListStubImpl(final JavaClassReferenceListElementType type, final StubElement parent, final String[] names, final PsiReferenceList.Role role) { super(parent, type); myNames = StringRef.createArray(names.length); for (int i = 0; i < names.length; i++) { myNames[i] = StringRef.fromString(names[i]); } myRole = role; }
@Override public String[] getReferencedNames() { String[] names = ArrayUtil.newStringArray(myNames.length); for (int i = 0; i < names.length; i++) { names[i] = StringRef.toString(myNames[i]); } return names; }
@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); }
private static PsiTypeParameterStub parseTypeParameter(CharacterIterator iterator, PsiTypeParameterListStub parent) throws ClsFormatException { StringBuilder name = new StringBuilder(); while (iterator.current() != ':' && iterator.current() != CharacterIterator.DONE) { name.append(iterator.current()); iterator.next(); } if (iterator.current() == CharacterIterator.DONE) { throw new ClsFormatException(); } //todo parse annotations on type param PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString())); // postpone list allocation till a second bound is seen; ignore sole Object bound List<String> bounds = null; boolean jlo = false; while (iterator.current() == ':') { iterator.next(); String bound = parseTopLevelClassRefSignature(iterator); if (bound == null) continue; if (bounds == null) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(bound)) { jlo = true; continue; } bounds = ContainerUtil.newSmartList(); if (jlo) { bounds.add(CommonClassNames.JAVA_LANG_OBJECT); } } bounds.add(bound); } StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds)); return parameterStub; }
@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 PsiJavaFileStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { boolean compiled = dataStream.readBoolean(); StringRef packName = dataStream.readName(); return new PsiJavaFileStubImpl(null, packName, compiled); }
@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); }
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 PyClassStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { String name = StringRef.toString(dataStream.readName()); int superClassCount = dataStream.readByte(); QualifiedName[] superClasses = new QualifiedName[superClassCount]; for (int i = 0; i < superClassCount; i++) { superClasses[i] = QualifiedName.deserialize(dataStream); } final QualifiedName metaClass = QualifiedName.deserialize(dataStream); List<String> slots = PyFileElementType.readNullableList(dataStream); final String docString = dataStream.readUTFFast(); return new PyClassStubImpl(name, parentStub, superClasses, metaClass, slots, docString.length() > 0 ? docString : null, getStubElementType()); }
@NotNull @Override public SchemaNamespaceDeclStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef fqnStr = dataStream.readName(); Qn fqn = fqnStr == null ? null : Qn.fromDotSeparated(fqnStr.getString()); return new SchemaNamespaceDeclStubImpl(parentStub, fqn); }
@NotNull public PyFunctionStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { String name = StringRef.toString(dataStream.readName()); String docString = dataStream.readUTFFast(); StringRef deprecationMessage = dataStream.readName(); final boolean isAsync = dataStream.readBoolean(); return new PyFunctionStubImpl(name, docString.length() > 0 ? docString : null, deprecationMessage, isAsync, parentStub, getStubElementType()); }
public PyFunctionStubImpl(final String name, final String docString, @Nullable final StringRef deprecationMessage, boolean isAsync, final StubElement parent, IStubElementType stubElementType) { super(parent, stubElementType); myName = name; myDocString = docString; myDeprecationMessage = deprecationMessage; myAsync = isAsync; }
public PyFileStubImpl(final PyFile file) { super(file); final PyFileImpl fileImpl = (PyFileImpl)file; myFutureFeatures = new BitSet(FUTURE_FEATURE_SET_SIZE); myDunderAll = fileImpl.calculateDunderAll(); for (FutureFeature fuf : FutureFeature.ALL) { myFutureFeatures.set(fuf.ordinal(), fileImpl.calculateImportFromFuture(fuf)); } String message = fileImpl.extractDeprecationMessage(); myDeprecationMessage = message == null ? null : StringRef.fromString(message); }
public FileStub(StringRef tagName, StringRef tagNamespace, StringRef publicId, StringRef systemId) { super(null, tagName, tagNamespace, 0, false, null, ""); myHeader = new XmlFileHeader(tagName.getString(), tagNamespace == null ? null : tagNamespace.getString(), publicId == null ? null : publicId.getString(), systemId == null ? null : systemId.getString()); }
public ElementStub(@Nullable ElementStub parent, @NotNull StringRef name, @Nullable StringRef namespace, int index, boolean custom, @Nullable StringRef elementClass, @NotNull String value) { super(parent, name, namespace); myIndex = index; myCustom = custom; myElementClass = elementClass; myValue = value; }