PsiClassStub (@NotNull final LighterAST tree, @NotNull final LighterASTNode node, final @NotNull StubElement<?> parentStub) { boolean isDeprecatedByComment = false; boolean isInterface = false; boolean isEnum = false; boolean isRecord = false; boolean isEnumConst = false; boolean isAnonymous = false; boolean isAnnotation = false; boolean isInQualifiedNew = false; boolean classKindFound = false; boolean hasDeprecatedAnnotation = false; boolean hasDocComment = false; String qualifiedName = null; String name = null; String baseRef = null; if (node.getTokenType() == JavaElementType.ANONYMOUS_CLASS) { isAnonymous = true; classKindFound = true; } else if (node.getTokenType() == JavaElementType.ENUM_CONSTANT_INITIALIZER) { isAnonymous = isEnumConst = true; classKindFound = true; baseRef = ((PsiClassStub<?>)parentStub.getParentStub()).getName(); } for (final LighterASTNode child : tree.getChildren(node)) { final IElementType type = child.getTokenType(); if (type == JavaDocElementType.DOC_COMMENT) { hasDocComment = true; isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child); } else if (type == JavaElementType.MODIFIER_LIST) { hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child); } else if (type == JavaTokenType.AT) { isAnnotation = true; } else if (type == JavaTokenType.INTERFACE_KEYWORD && !classKindFound) { isInterface = true; classKindFound = true; } else if (type == JavaTokenType.ENUM_KEYWORD && !classKindFound) { isEnum = true; classKindFound = true; } else if (type == JavaTokenType.RECORD_KEYWORD && !classKindFound) { isRecord = true; classKindFound = true; } else if (type == JavaTokenType.CLASS_KEYWORD) { classKindFound = true; } else if (!isAnonymous && type == JavaTokenType.IDENTIFIER) { name = RecordUtil.intern(tree.getCharTable(), child); } else if (isAnonymous && !isEnumConst && type == JavaElementType.JAVA_CODE_REFERENCE) { baseRef = LightTreeUtil.toFilteredString(tree, child, null); } } if (name != null) { if (parentStub instanceof PsiJavaFileStub) { final String pkg = ((PsiJavaFileStub)parentStub).getPackageName(); if (!pkg.isEmpty()) qualifiedName = pkg + '.' + name; else qualifiedName = name; } else if (parentStub instanceof PsiClassStub) { final String parentFqn = ((PsiClassStub<?>)parentStub).getQualifiedName(); qualifiedName = parentFqn != null ? parentFqn + '.' + name : null; } } if (isAnonymous) { final LighterASTNode parent = tree.getParent(node); if (parent != null && parent.getTokenType() == JavaElementType.NEW_EXPRESSION) { isInQualifiedNew = LightTreeUtil.firstChildOfType(tree, parent, JavaTokenType.DOT) != null; } } boolean isUnnamed = node.getTokenType() == JavaElementType.UNNAMED_CLASS; final short flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation, isInQualifiedNew, hasDeprecatedAnnotation, false, false, hasDocComment, isRecord, isUnnamed); final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst, isUnnamed); return new PsiClassStubImpl<>(type, parentStub, qualifiedName, name, baseRef, flags); }