IDEA-365317 decouple java psi and stubs using stub registry api

GitOrigin-RevId: 98da6acabfedf1e2bb0c023fb7c5580404c2b06a
This commit is contained in:
Max Medvedev
2025-03-19 03:45:34 +00:00
committed by intellij-monorepo-bot
parent d07a54ad0e
commit 9cba241999
143 changed files with 3176 additions and 1786 deletions
@@ -0,0 +1,53 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterASTNode;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.java.parser.JavaParserUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.impl.source.JavaFileElementType;
import com.intellij.psi.impl.source.JavaLightStubBuilder;
import com.intellij.psi.stubs.LanguageStubDefinition;
import com.intellij.psi.stubs.LightLanguageStubDefinition;
import com.intellij.psi.stubs.LightStubBuilder;
import com.intellij.util.diff.FlyweightCapableTreeStructure;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ApiStatus.Internal
public class JavaStubDefinition implements LightLanguageStubDefinition, LanguageStubDefinition {
private static volatile int TEST_STUB_VERSION_MODIFIER = 0;
@Override
public @NotNull LightStubBuilder getBuilder() {
return new JavaLightStubBuilder();
}
@Override
public int getStubVersion() {
return JavaFileElementType.STUB_VERSION + (ApplicationManager.getApplication().isUnitTestMode() ? TEST_STUB_VERSION_MODIFIER : 0);
}
@Override
public boolean shouldBuildStubFor(@NotNull VirtualFile file) {
return shouldBuildStubForFile(file);
}
public static boolean shouldBuildStubForFile(VirtualFile file) {
return JavaFileElementType.isInSourceContent(file);
}
@Override
public @NotNull FlyweightCapableTreeStructure<LighterASTNode> parseContentsLight(@NotNull ASTNode chameleon) {
PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
JavaFileElementType.doParse(builder);
return builder.getLightTree();
}
@ApiStatus.Internal
public static void setTestStubVersionModifier(int modifier) {
TEST_STUB_VERSION_MODIFIER = modifier;
}
}
@@ -232,7 +232,7 @@ public final class PsiTypesUtil {
}
else {
PsiElement parent = call.getContext();
while (parent != null && condition.value(parent instanceof StubBasedPsiElement ? ((StubBasedPsiElement<?>)parent).getElementType()
while (parent != null && condition.value(parent instanceof StubBasedPsiElement ? ((StubBasedPsiElement<?>)parent).getIElementType()
: parent.getNode().getElementType())) {
parent = parent.getContext();
}
@@ -102,6 +102,9 @@
serviceImplementation="com.intellij.psi.impl.JavaPsiFacadeImpl"/>
<psi.treeChangePreprocessor implementation="com.intellij.psi.impl.PsiJavaModuleTreeChangePreprocessor"/>
<languageStubDefinition language="JAVA" implementationClass="com.intellij.psi.impl.java.stubs.JavaStubDefinition"/>
<stubElementRegistryExtension implementation="com.intellij.psi.impl.java.stubs.JavaStubRegistryExtension"/>
<metaLanguage implementation="com.intellij.lang.jvm.JvmMetaLanguage"/>
<java.elementFinder implementation="com.intellij.psi.impl.PsiElementFinderImpl" id="java" order="first"/>
<treeGenerator implementation="com.intellij.psi.impl.source.tree.JavaTreeGenerator"/>
@@ -28,12 +28,14 @@ import com.intellij.psi.impl.PsiSubstitutorFactoryImpl;
import com.intellij.psi.impl.compiled.ClassFileStubBuilder;
import com.intellij.psi.impl.compiled.ClsDecompilerImpl;
import com.intellij.psi.impl.file.PsiPackageImplementationHelper;
import com.intellij.psi.impl.java.stubs.JavaStubRegistryExtension;
import com.intellij.psi.impl.search.MethodSuperSearcher;
import com.intellij.psi.impl.source.tree.JavaASTFactory;
import com.intellij.psi.impl.source.tree.PlainTextASTFactory;
import com.intellij.psi.presentation.java.*;
import com.intellij.psi.search.searches.SuperMethodsSearch;
import com.intellij.psi.stubs.BinaryFileStubBuilders;
import com.intellij.psi.stubs.StubElementRegistryServiceImplKt;
import com.intellij.util.QueryExecutor;
import org.jetbrains.annotations.NotNull;
@@ -53,6 +55,7 @@ public class JavaCoreApplicationEnvironment extends CoreApplicationEnvironment {
addExplicitExtension(LanguageASTFactory.INSTANCE, PlainTextLanguage.INSTANCE, new PlainTextASTFactory());
registerParserDefinition(new PlainTextParserDefinition());
addExtension(StubElementRegistryServiceImplKt.STUB_REGISTRY_EP, new JavaStubRegistryExtension());
addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory());
addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder());
@@ -13,20 +13,19 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.JavaNonCompositeElementType;
import com.intellij.psi.impl.source.JavaFileElementType;
import com.intellij.psi.impl.source.PsiJavaFileImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaParserDefinition implements ParserDefinition {
public static final IStubFileElementType JAVA_FILE = new JavaFileElementType();
public static final IFileElementType JAVA_FILE = new JavaFileElementType();
@Override
public @NotNull Lexer createLexer(@Nullable Project project) {
@@ -70,8 +69,8 @@ public class JavaParserDefinition implements ParserDefinition {
@Override
public @NotNull PsiElement createElement(ASTNode node) {
IElementType type = node.getElementType();
if (type instanceof JavaStubElementType) {
return ((JavaStubElementType<?, ?>)type).createPsi(node);
if (type instanceof JavaNonCompositeElementType) {
return ((JavaNonCompositeElementType)type).createPsi(node);
}
// This exception is caught in com.intellij.psi.impl.source.tree.injected.InjectionRegistrarImpl.findNewInjectionHost
@@ -81,7 +81,7 @@ public final class RecordUtil {
}
public static boolean isStaticNonPrivateMember(@NotNull StubElement<?> stub) {
PsiModifierListStub type = stub.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
PsiModifierListStub type = (PsiModifierListStub)stub.findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST);
if (type == null) {
return false;
}
@@ -96,7 +96,7 @@ public final class RecordUtil {
}
return stub instanceof PsiFieldStub &&
stub.getStubType() == JavaElementType.ENUM_CONSTANT ||
stub.getElementType() == JavaElementType.ENUM_CONSTANT ||
stub.getParentStub() instanceof PsiClassStub && ((PsiClassStub<?>)stub.getParentStub()).isInterface();
}
}
@@ -61,7 +61,7 @@ public class ClsClassImpl extends ClsMemberImpl<PsiClassStub<?>> implements PsiE
@Override
public @NotNull PsiTypeParameterList getTypeParameterList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST)).getPsi();
return (PsiTypeParameterList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.TYPE_PARAMETER_LIST)).getPsi();
}
@Override
@@ -89,7 +89,7 @@ public class ClsClassImpl extends ClsMemberImpl<PsiClassStub<?>> implements PsiE
}
private PsiModifierList getModifierListInternal() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
return (PsiModifierList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
}
@Override
@@ -99,18 +99,18 @@ public class ClsClassImpl extends ClsMemberImpl<PsiClassStub<?>> implements PsiE
@Override
public @NotNull PsiReferenceList getExtendsList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.EXTENDS_LIST)).getPsi();
return (PsiReferenceList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.EXTENDS_LIST)).getPsi();
}
@Override
public @Nullable PsiReferenceList getPermitsList() {
PsiClassReferenceListStub type = getStub().findChildStubByType(JavaStubElementTypes.PERMITS_LIST);
PsiClassReferenceListStub type = (PsiClassReferenceListStub)getStub().findChildStubByElementType(JavaStubElementTypes.PERMITS_LIST);
return type == null ? null : type.getPsi();
}
@Override
public @NotNull PsiReferenceList getImplementsList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.IMPLEMENTS_LIST)).getPsi();
return (PsiReferenceList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.IMPLEMENTS_LIST)).getPsi();
}
@Override
@@ -220,7 +220,7 @@ public class ClsClassImpl extends ClsMemberImpl<PsiClassStub<?>> implements PsiE
@Override
public @Nullable PsiRecordHeader getRecordHeader() {
PsiRecordHeaderStub headerStub = getStub().findChildStubByType(JavaStubElementTypes.RECORD_HEADER);
PsiRecordHeaderStub headerStub = (PsiRecordHeaderStub)getStub().findChildStubByElementType(JavaStubElementTypes.RECORD_HEADER);
return headerStub == null ? null : headerStub.getPsi();
}
@@ -63,7 +63,7 @@ public class ClsFieldImpl extends ClsMemberImpl<PsiFieldStub> implements PsiFiel
@Override
public PsiModifierList getModifierList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
return (PsiModifierList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
}
@Override
@@ -144,7 +144,7 @@ public class ClsFileImpl extends PsiBinaryFileImpl
if (statement == null) {
statement = ClsPackageStatementImpl.NULL_PACKAGE;
PsiClassHolderFileStub<?> stub = getStub();
if (!(stub instanceof PsiJavaFileStub) || stub.findChildStubByType(JavaStubElementTypes.MODULE) == null) {
if (!(stub instanceof PsiJavaFileStub) || stub.findChildStubByElementType(JavaStubElementTypes.MODULE) == null) {
String packageName = findPackageName(stub);
if (packageName != null) {
statement = new ClsPackageStatementImpl(this, packageName);
@@ -15,6 +15,7 @@ import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.JBIterable;
import org.jetbrains.annotations.NotNull;
@@ -137,9 +138,10 @@ public class ClsJavaModuleImpl extends ClsRepositoryPsiElement<PsiJavaModuleStub
throw cannotModifyException(this);
}
@SuppressWarnings("unchecked")
@Override
public PsiModifierList getModifierList() {
StubElement<PsiModifierList> childStub = getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
StubElement<PsiModifierList> childStub = ObjectUtils.tryCast(getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST), StubElement.class);
return childStub != null ? childStub.getPsi() : null;
}
@@ -109,7 +109,7 @@ public final class ClsMethodImpl extends ClsMemberImpl<PsiMethodStub> implements
@Override
public @NotNull PsiModifierList getModifierList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
return (PsiModifierList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST)).getPsi();
}
@Override
@@ -119,17 +119,17 @@ public final class ClsMethodImpl extends ClsMemberImpl<PsiMethodStub> implements
@Override
public @NotNull PsiParameterList getParameterList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.PARAMETER_LIST)).getPsi();
return (PsiParameterList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.PARAMETER_LIST)).getPsi();
}
@Override
public @NotNull PsiReferenceList getThrowsList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.THROWS_LIST)).getPsi();
return (PsiReferenceList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.THROWS_LIST)).getPsi();
}
@Override
public PsiTypeParameterList getTypeParameterList() {
return Objects.requireNonNull(getStub().findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST)).getPsi();
return (PsiTypeParameterList)Objects.requireNonNull(getStub().findChildStubByElementType(JavaStubElementTypes.TYPE_PARAMETER_LIST)).getPsi();
}
@Override
@@ -42,7 +42,7 @@ public final class ClsPackageAccessibilityStatementImpl extends ClsRepositoryPsi
@Override
public @NotNull Role getRole() {
return JavaPackageAccessibilityStatementElementType.typeToRole(getStub().getStubType());
return JavaPackageAccessibilityStatementElementType.typeToRole(getStub().getElementType());
}
@Override
@@ -82,7 +82,7 @@ public final class ClsPackageAccessibilityStatementImpl extends ClsRepositoryPsi
@Override
protected void setMirror(@NotNull TreeElement element) throws InvalidMirrorException {
setMirrorCheckingType(element, getStub().getStubType());
setMirrorCheckingType(element, getStub().getElementType());
}
@Override
@@ -93,7 +93,8 @@ public final class ClsParameterImpl extends ClsRepositoryPsiElement<PsiParameter
@Override
public @NotNull PsiModifierList getModifierList() {
final StubElement<PsiModifierList> child = getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
final StubElement<PsiModifierList> child =
(StubElement<PsiModifierList>)getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST);
assert child != null;
return child.getPsi();
}
@@ -43,7 +43,7 @@ public class ClsParameterListImpl extends ClsRepositoryPsiElement<PsiParameterLi
}
int count = 0;
for (StubElement<?> child : getStub().getChildrenStubs()) {
if (child.getStubType() == JavaStubElementTypes.PARAMETER) {
if (child.getElementType() == JavaStubElementTypes.PARAMETER) {
if (count == index) return (PsiParameter)child.getPsi();
count++;
}
@@ -42,7 +42,8 @@ public class ClsProvidesStatementImpl extends ClsRepositoryPsiElement<PsiProvide
@Override
public PsiReferenceList getImplementationList() {
StubElement<PsiReferenceList> stub = getStub().findChildStubByType(JavaStubElementTypes.PROVIDES_WITH_LIST);
StubElement<PsiReferenceList> stub =
(StubElement<PsiReferenceList>)getStub().findChildStubByElementType(JavaStubElementTypes.PROVIDES_WITH_LIST);
return stub != null ? stub.getPsi() : null;
}
@@ -51,7 +51,8 @@ public final class ClsRecordComponentImpl extends ClsRepositoryPsiElement<PsiRec
@Override
public @NotNull PsiModifierList getModifierList() {
final StubElement<PsiModifierList> child = getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
final StubElement<PsiModifierList> child =
(StubElement<PsiModifierList>)getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST);
assert child != null;
return child.getPsi();
}
@@ -19,6 +19,7 @@ import com.intellij.psi.*;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.PsiFileStub;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
@@ -36,6 +37,11 @@ public abstract class ClsRepositoryPsiElement<T extends StubElement<?>> extends
return myStub.getStubType();
}
@Override
public IElementType getIElementType() {
return myStub.getElementType();
}
@Override
public PsiElement getParent() {
return myStub.getParentStub().getPsi();
@@ -61,7 +61,8 @@ public final class ClsRequiresStatementImpl extends ClsRepositoryPsiElement<PsiR
@Override
public PsiModifierList getModifierList() {
StubElement<PsiModifierList> childStub = getStub().findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
StubElement<PsiModifierList> childStub =
(StubElement<PsiModifierList>)getStub().findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST);
return childStub != null ? childStub.getPsi() : null;
}
@@ -167,7 +167,7 @@ public class ClsTypeParameterImpl extends ClsRepositoryPsiElement<PsiTypeParamet
@Override
public @NotNull PsiReferenceList getExtendsList() {
return getStub().findChildStubByType(JavaStubElementTypes.EXTENDS_BOUND_LIST).getPsi();
return (PsiReferenceList)getStub().findChildStubByElementType(JavaStubElementTypes.EXTENDS_BOUND_LIST).getPsi();
}
@Override
@@ -5,7 +5,7 @@ import com.intellij.psi.impl.cache.ModifierFlags;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.java.stubs.PsiJavaModuleStub;
import com.intellij.psi.impl.java.stubs.impl.*;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.Function;
import org.jetbrains.org.objectweb.asm.*;
@@ -84,11 +84,6 @@ public class ModuleStubBuildingVisitor extends ClassVisitor {
super.visitAttribute(attribute);
}
@Override
public void visitEnd() {
super.visitEnd();
}
private static boolean isGenerated(int access) {
return isSet(access, Opcodes.ACC_SYNTHETIC) || isSet(access, Opcodes.ACC_MANDATED);
}
@@ -138,7 +133,7 @@ public class ModuleStubBuildingVisitor extends ClassVisitor {
myRequires.add(new Requires(module, flags));
}
void addPackageAccessibility(IStubElementType type, String packageName, String[] modules) {
void addPackageAccessibility(IJavaElementType type, String packageName, String[] modules) {
myPackageAccessibilities.add(new PackageAccessibility(type, packageName, modules));
}
@@ -213,11 +208,11 @@ public class ModuleStubBuildingVisitor extends ClassVisitor {
}
private static class PackageAccessibility {
final IStubElementType myType;
final IJavaElementType myType;
final String myPackageName;
final List<String> myModules;
PackageAccessibility(IStubElementType type, String packageName, String[] modules) {
PackageAccessibility(IJavaElementType type, String packageName, String[] modules) {
myType = type;
myPackageName = packageName;
myModules = modules == null ? null : Arrays.asList(modules);
@@ -12,6 +12,7 @@ import com.intellij.psi.impl.java.stubs.impl.PsiClassReferenceListStubImpl;
import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterStubImpl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.Function;
import com.intellij.util.ObjectUtils;
import com.intellij.util.SmartList;
import com.intellij.util.cls.ClsFormatException;
import org.jetbrains.annotations.NotNull;
@@ -121,7 +122,7 @@ public final class SignatureParsing {
void fillInTypeParameterList(StubElement<?> parent) {
List<TypeParameterDeclaration> declarations = this.myDeclarations;
if (declarations.isEmpty()) return;
PsiTypeParameterListStub listStub = parent.findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST);
PsiTypeParameterListStub listStub = ObjectUtils.tryCast(parent.findChildStubByElementType(JavaStubElementTypes.TYPE_PARAMETER_LIST), PsiTypeParameterListStub.class);
if (listStub == null) return;
for (TypeParameterDeclaration parameter : declarations) {
parameter.createTypeParameter(listStub);
@@ -452,7 +452,8 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
private boolean isGroovyClosure(String canonicalMethodName) {
if (canonicalMethodName != null && canonicalMethodName.startsWith("_closure")) {
PsiClassReferenceListStub extendsList = myResult.findChildStubByType(JavaStubElementTypes.EXTENDS_LIST);
PsiClassReferenceListStub extendsList =
(PsiClassReferenceListStub)myResult.findChildStubByElementType(JavaStubElementTypes.EXTENDS_LIST);
if (extendsList != null) {
String[] names = extendsList.getReferencedNames();
return names.length == 1 && "groovy.lang.Closure".equals(names[0]);
@@ -1,41 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiFunctionalExpression;
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.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public abstract class FunctionalExpressionElementType<T extends PsiFunctionalExpression> extends JavaStubElementType<FunctionalExpressionStub<T>,T> {
public FunctionalExpressionElementType(@NotNull String debugName, @NotNull IElementType parentElementType) {
super(debugName, parentElementType);
}
@Override
public void serialize(@NotNull FunctionalExpressionStub<T> stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getPresentableText());
}
@Override
public @NotNull FunctionalExpressionStub<T> deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new FunctionalExpressionStub<>(parentStub, this, dataStream.readNameString());
}
@Override
public void indexStub(@NotNull FunctionalExpressionStub<T> stub, @NotNull IndexSink sink) {
}
@Override
public @NotNull FunctionalExpressionStub<T> createStub(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr, @NotNull StubElement<?> parentStub) {
return new FunctionalExpressionStub<>(parentStub, this, getPresentableText(tree, funExpr));
}
protected abstract @NotNull String getPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr);
}
@@ -16,14 +16,14 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.psi.PsiFunctionalExpression;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.java.IJavaElementType;
public class FunctionalExpressionStub<T extends PsiFunctionalExpression> extends StubBase<T> {
private final String myPresentableText;
protected FunctionalExpressionStub(StubElement parent, IStubElementType elementType, String presentableTextRef) {
public FunctionalExpressionStub(StubElement parent, IJavaElementType elementType, String presentableTextRef) {
super(parent, elementType);
myPresentableText = presentableTextRef;
}
@@ -2,25 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.AnnotationElement;
import com.intellij.psi.impl.source.tree.java.PsiAnnotationImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaAnnotationElementType extends JavaStubElementType<PsiAnnotationStub, PsiAnnotation> {
public class JavaAnnotationElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaAnnotationElementType() {
super("ANNOTATION", BasicJavaElementType.BASIC_ANNOTATION);
super("ANNOTATION");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_ANNOTATION);
}
@Override
@@ -28,48 +29,8 @@ public class JavaAnnotationElementType extends JavaStubElementType<PsiAnnotation
return new AnnotationElement();
}
@Override
public PsiAnnotation createPsi(@NotNull PsiAnnotationStub stub) {
return getPsiFactory(stub).createAnnotation(stub);
}
@Override
public PsiAnnotation createPsi(@NotNull ASTNode node) {
return new PsiAnnotationImpl(node);
}
@Override
public @NotNull PsiAnnotationStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
String text = LightTreeUtil.toFilteredString(tree, node, null);
return new PsiAnnotationStubImpl(parentStub, text);
}
@Override
public void serialize(@NotNull PsiAnnotationStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeUTFFast(stub.getText());
}
@Override
public @NotNull PsiAnnotationStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiAnnotationStubImpl(parentStub, dataStream.readUTFFast());
}
@Override
public void indexStub(@NotNull PsiAnnotationStub stub, @NotNull IndexSink sink) {
String shortName = getReferenceShortName(stub.getText());
if (!StringUtil.isEmptyOrSpaces(shortName)) {
sink.occurrence(JavaStubIndexKeys.ANNOTATIONS, shortName);
}
}
private static String getReferenceShortName(String annotationText) {
int index = annotationText.indexOf('(');
if (index >= 0) annotationText = annotationText.substring(0, index);
return PsiNameHelper.getShortClassName(annotationText);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
}
}
@@ -2,26 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiAnnotationParameterList;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationParameterListStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.java.AnnotationParamListElement;
import com.intellij.psi.impl.source.tree.java.PsiAnnotationParamListImpl;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
/**
* @author Dmitry Avdeev
*/
public class JavaAnnotationParameterListType extends JavaStubElementType<PsiAnnotationParameterListStub, PsiAnnotationParameterList>
implements EmptyStubSerializer<PsiAnnotationParameterListStub> {
import java.util.Collections;
import java.util.Set;
protected JavaAnnotationParameterListType() {
super("ANNOTATION_PARAMETER_LIST", true, BasicJavaElementType.BASIC_ANNOTATION_PARAMETER_LIST);
public class JavaAnnotationParameterListType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaAnnotationParameterListType() {
super("ANNOTATION_PARAMETER_LIST", true);
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_ANNOTATION_PARAMETER_LIST);
}
@Override
@@ -33,23 +33,4 @@ public class JavaAnnotationParameterListType extends JavaStubElementType<PsiAnno
public @NotNull ASTNode createCompositeNode() {
return new AnnotationParamListElement();
}
@Override
public @NotNull PsiAnnotationParameterListStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiAnnotationParameterListStubImpl(parentStub);
}
@Override
public PsiAnnotationParameterList createPsi(@NotNull PsiAnnotationParameterListStub stub) {
return getPsiFactory(stub).createAnnotationParameterList(stub);
}
@Override
public @NotNull PsiAnnotationParameterListStub instantiate(StubElement<?> parentStub) {
return new PsiAnnotationParameterListStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiAnnotationParameterListStub stub, @NotNull IndexSink sink) {
}
}
}
@@ -2,42 +2,33 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.PsiAnonymousClassImpl;
import com.intellij.psi.impl.source.PsiClassImpl;
import com.intellij.psi.impl.source.PsiEnumConstantInitializerImpl;
import com.intellij.psi.impl.source.PsiImplicitClassImpl;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.AnonymousClassElement;
import com.intellij.psi.impl.source.tree.java.EnumConstantInitializerElement;
import com.intellij.psi.impl.source.tree.java.ImplicitClassElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public abstract class JavaClassElementType extends JavaStubElementType<PsiClassStub<PsiClass>, PsiClass> {
JavaClassElementType(@NotNull String id, @NotNull IElementType parentElementType) {
super(id, parentElementType);
public abstract class JavaClassElementType extends JavaStubElementType implements ParentProviderElementType, ICompositeElementType, JavaNonCompositeElementType {
private final IElementType myParentElementType;
public JavaClassElementType(@NotNull String id, @NotNull IElementType type) {
super(id);
myParentElementType = type;
}
@Override
public PsiClass createPsi(final @NotNull PsiClassStub<PsiClass> stub) {
return getPsiFactory(stub).createClass(stub);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(myParentElementType);
}
@Override
@@ -54,166 +45,4 @@ public abstract class JavaClassElementType extends JavaStubElementType<PsiClassS
return new PsiClassImpl(node);
}
@Override
public @NotNull PsiClassStub<PsiClass> createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
boolean isDeprecatedByComment = false;
boolean isInterface = false;
boolean isEnum = false;
boolean isRecord = false;
boolean isValueClass = 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);
isValueClass = RecordUtil.hasValueModifier(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 isImplicit = node.getTokenType() == JavaElementType.IMPLICIT_CLASS;
final short flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation,
isInQualifiedNew, hasDeprecatedAnnotation, false, false, hasDocComment, isRecord,
isImplicit, isValueClass);
final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst, isImplicit);
return new PsiClassStubImpl<>(type, parentStub, qualifiedName, name, baseRef, flags);
}
private static @NotNull JavaClassElementType typeForClass(final boolean anonymous, final boolean enumConst, final boolean implicitClass) {
return enumConst
? JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER
: implicitClass ? JavaStubElementTypes.IMPLICIT_CLASS
: anonymous ? JavaStubElementTypes.ANONYMOUS_CLASS : JavaStubElementTypes.CLASS;
}
@Override
public void serialize(@NotNull PsiClassStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeShort(((PsiClassStubImpl<?>)stub).getFlags());
if (!stub.isAnonymous()) {
String name = stub.getName();
TypeInfo info = ((PsiClassStubImpl<?>)stub).getQualifiedNameTypeInfo();
dataStream.writeName(info.getShortTypeText().equals(name) ? null : name);
TypeInfo.writeTYPE(dataStream, info);
dataStream.writeName(stub.getSourceFileName());
}
else {
dataStream.writeName(stub.getBaseClassReferenceText());
}
}
@Override
public @NotNull PsiClassStub<PsiClass> deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
short flags = dataStream.readShort();
boolean isAnonymous = PsiClassStubImpl.isAnonymous(flags);
boolean isEnumConst = PsiClassStubImpl.isEnumConstInitializer(flags);
boolean isImplicit = PsiClassStubImpl.isImplicit(flags);
JavaClassElementType type = typeForClass(isAnonymous, isEnumConst, isImplicit);
if (!isAnonymous) {
String name = dataStream.readNameString();
TypeInfo typeInfo = TypeInfo.readTYPE(dataStream);
if (name == null) {
name = typeInfo.getShortTypeText();
}
String sourceFileName = dataStream.readNameString();
PsiClassStubImpl<PsiClass> classStub = new PsiClassStubImpl<>(type, parentStub, typeInfo, name, null, flags);
classStub.setSourceFileName(sourceFileName);
return classStub;
}
else {
String baseRef = dataStream.readNameString();
return new PsiClassStubImpl<>(type, parentStub, TypeInfo.SimpleTypeInfo.NULL, null, baseRef, flags);
}
}
@Override
public void indexStub(@NotNull PsiClassStub stub, @NotNull IndexSink sink) {
boolean isAnonymous = stub.isAnonymous();
if (isAnonymous) {
String baseRef = stub.getBaseClassReferenceText();
if (baseRef != null) {
sink.occurrence(JavaStubIndexKeys.ANONYMOUS_BASEREF, PsiNameHelper.getShortClassName(baseRef));
}
}
else {
final String shortName = stub.getName();
if (shortName != null && (!(stub instanceof PsiClassStubImpl) || !((PsiClassStubImpl<?>)stub).isAnonymousInner())) {
sink.occurrence(JavaStubIndexKeys.CLASS_SHORT_NAMES, shortName);
}
final String fqn = stub.getQualifiedName();
if (fqn != null) {
sink.occurrence(JavaStubIndexKeys.CLASS_FQN, fqn);
}
}
}
}
@@ -2,22 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiClassInitializer;
import com.intellij.psi.impl.java.stubs.impl.PsiClassInitializerStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiClassInitializerImpl;
import com.intellij.psi.impl.source.tree.java.ClassInitializerElement;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public class JavaClassInitializerElementType extends JavaStubElementType<PsiClassInitializerStub, PsiClassInitializer>
implements EmptyStubSerializer<PsiClassInitializerStub> {
import java.util.Collections;
import java.util.Set;
public class JavaClassInitializerElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaClassInitializerElementType() {
super("CLASS_INITIALIZER", BasicJavaElementType.BASIC_CLASS_INITIALIZER);
super("CLASS_INITIALIZER");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_CLASS_INITIALIZER);
}
@Override
@@ -25,29 +29,8 @@ public class JavaClassInitializerElementType extends JavaStubElementType<PsiClas
return new ClassInitializerElement();
}
@Override
public PsiClassInitializer createPsi(final @NotNull PsiClassInitializerStub stub) {
return getPsiFactory(stub).createClassInitializer(stub);
}
@Override
public PsiClassInitializer createPsi(final @NotNull ASTNode node) {
return new PsiClassInitializerImpl(node);
}
@Override
public @NotNull PsiClassInitializerStub createStub(final @NotNull LighterAST tree,
final @NotNull LighterASTNode node,
final @NotNull StubElement<?> parentStub) {
return new PsiClassInitializerStubImpl(parentStub);
}
@Override
public @NotNull PsiClassInitializerStub instantiate(StubElement<?> parentStub) {
return new PsiClassInitializerStubImpl(parentStub);
}
@Override
public void indexStub(final @NotNull PsiClassInitializerStub stub, final @NotNull IndexSink sink) {
}
}
}
@@ -2,102 +2,24 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiReferenceList;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiClassReferenceListStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.PsiReferenceListImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.ArrayUtil;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.List;
import java.util.Collections;
import java.util.Set;
public abstract class JavaClassReferenceListElementType extends JavaStubElementType implements ICompositeElementType,
ParentProviderElementType,
JavaNonCompositeElementType {
@NotNull private final IElementType myParentElementType;
public abstract class JavaClassReferenceListElementType extends JavaStubElementType<PsiClassReferenceListStub, PsiReferenceList> {
public JavaClassReferenceListElementType(@NotNull String id, @NotNull IElementType parentElementType) {
super(id, true, parentElementType);
}
@Override
public PsiReferenceList createPsi(@NotNull PsiClassReferenceListStub stub) {
return getPsiFactory(stub).createClassReferenceList(stub);
}
@Override
public PsiReferenceList createPsi(@NotNull ASTNode node) {
return new PsiReferenceListImpl(node);
}
@Override
public @NotNull PsiClassReferenceListStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
JavaClassReferenceListElementType type = (JavaClassReferenceListElementType)node.getTokenType();
return new PsiClassReferenceListStubImpl(type, parentStub, getTexts(tree, node));
}
private static String @NotNull [] getTexts(@NotNull LighterAST tree, @NotNull LighterASTNode node) {
List<LighterASTNode> refs = LightTreeUtil.getChildrenOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String[] texts = ArrayUtil.newStringArray(refs.size());
for (int i = 0; i < refs.size(); i++) {
texts[i] = LightTreeUtil.toFilteredString(tree, refs.get(i), null);
}
return texts;
}
@Override
public void serialize(@NotNull PsiClassReferenceListStub stub, @NotNull StubOutputStream dataStream) throws IOException {
TypeInfo[] types = stub.getTypes();
dataStream.writeVarInt(types.length);
for (TypeInfo info : types) {
TypeInfo.writeTYPE(dataStream, info);
}
}
@Override
public @NotNull PsiClassReferenceListStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
int len = dataStream.readVarInt();
TypeInfo[] infos = len == 0 ? TypeInfo.EMPTY_ARRAY : new TypeInfo[len];
for (int i = 0; i < infos.length; i++) {
infos[i] = TypeInfo.readTYPE(dataStream);
}
return new PsiClassReferenceListStubImpl(this, parentStub, infos);
}
@Override
public void indexStub(@NotNull PsiClassReferenceListStub stub, @NotNull IndexSink sink) {
PsiReferenceList.Role role = stub.getRole();
if (role == PsiReferenceList.Role.EXTENDS_LIST || role == PsiReferenceList.Role.IMPLEMENTS_LIST) {
String[] names = stub.getReferencedNames();
for (String name : names) {
String shortName = PsiNameHelper.getShortClassName(name);
if (!StringUtil.isEmptyOrSpaces(shortName)) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, shortName);
}
}
if (role == PsiReferenceList.Role.EXTENDS_LIST) {
StubElement<?> parentStub = stub.getParentStub();
if (parentStub instanceof PsiClassStub) {
PsiClassStub<?> psiClassStub = (PsiClassStub<?>)parentStub;
if (psiClassStub.isEnum()) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, "Enum");
}
if (psiClassStub.isAnnotationType()) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, "Annotation");
}
}
}
}
super(id, true);
myParentElementType = parentElementType;
}
public static @NotNull PsiReferenceList.Role elementTypeToRole(@NotNull IElementType type) {
@@ -109,4 +31,14 @@ public abstract class JavaClassReferenceListElementType extends JavaStubElementT
if (type == JavaStubElementTypes.PERMITS_LIST) return PsiReferenceList.Role.PERMITS_LIST;
throw new RuntimeException("Unknown element type: " + type);
}
@Override
public PsiReferenceList createPsi(@NotNull ASTNode node) {
return new PsiReferenceListImpl(node);
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(myParentElementType);
}
}
@@ -2,40 +2,29 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiField;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiFieldStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.PsiEnumConstantImpl;
import com.intellij.psi.impl.source.PsiFieldImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.EnumConstantElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public abstract class JavaFieldStubElementType extends JavaStubElementType<PsiFieldStub, PsiField> {
private static final int INITIALIZER_LENGTH_LIMIT = 1000;
public abstract class JavaFieldStubElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
@NotNull private final IElementType myParentElementType;
public JavaFieldStubElementType(@NotNull String id, @NotNull IElementType parentElementType) {
super(id, parentElementType);
super(id);
myParentElementType = parentElementType;
}
@Override
public PsiField createPsi(final @NotNull PsiFieldStub stub) {
return getPsiFactory(stub).createField(stub);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(myParentElementType);
}
@Override
@@ -47,85 +36,4 @@ public abstract class JavaFieldStubElementType extends JavaStubElementType<PsiFi
return new PsiFieldImpl(node);
}
}
@Override
public @NotNull PsiFieldStub createStub(final @NotNull LighterAST tree, final @NotNull LighterASTNode node, final @NotNull StubElement<?> parentStub) {
final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String name = null;
String initializer = null;
boolean expectingInit = false;
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.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
}
else if (type == JavaTokenType.EQ) {
expectingInit = true;
}
else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
initializer = encodeInitializer(tree, child);
break;
}
}
final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT;
final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags);
}
private static String encodeInitializer(final LighterAST tree, final LighterASTNode initializer) {
final IElementType type = initializer.getTokenType();
if (type == JavaElementType.NEW_EXPRESSION || type == JavaElementType.METHOD_CALL_EXPRESSION) {
return PsiFieldStub.INITIALIZER_NOT_STORED;
}
if (initializer.getEndOffset() - initializer.getStartOffset() > INITIALIZER_LENGTH_LIMIT) {
return PsiFieldStub.INITIALIZER_TOO_LONG;
}
return LightTreeUtil.toFilteredString(tree, initializer, null);
}
@Override
public void serialize(@NotNull PsiFieldStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getType());
dataStream.writeName(stub.getInitializerText());
dataStream.writeByte(((PsiFieldStubImpl)stub).getFlags());
}
@Override
public @NotNull PsiFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
TypeInfo type = TypeInfo.readTYPE(dataStream);
String initializerText = dataStream.readNameString();
byte flags = dataStream.readByte();
return new PsiFieldStubImpl(parentStub, name, type, initializerText, flags);
}
@Override
public void indexStub(@NotNull PsiFieldStub stub, @NotNull IndexSink sink) {
String name = stub.getName();
if (name != null) {
sink.occurrence(JavaStubIndexKeys.FIELDS, name);
if (RecordUtil.isStaticNonPrivateMember(stub)) {
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getType().getShortTypeText());
}
}
}
}
@@ -0,0 +1,36 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl;
import com.intellij.psi.stubs.*;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaFileSerializer implements ObjectStubSerializer<PsiJavaFileStub, StubElement> {
@Override
public @NotNull String getExternalId() {
return "java.FILE";
}
@Override
public void serialize(@NotNull PsiJavaFileStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeBoolean(stub.isCompiled());
LanguageLevel level = stub.getLanguageLevel();
dataStream.writeByte(level != null ? level.ordinal() : -1);
dataStream.writeName(stub.getPackageName());
}
@Override
public @NotNull PsiJavaFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
boolean compiled = dataStream.readBoolean();
int level = dataStream.readByte();
String packageName = dataStream.readNameString();
return new PsiJavaFileStubImpl(null, packageName, level >= 0 ? LanguageLevel.values()[level] : null, compiled);
}
@Override
public void indexStub(@NotNull PsiJavaFileStub stub, @NotNull IndexSink sink) { }
}
@@ -2,22 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiImportList;
import com.intellij.psi.impl.java.stubs.impl.PsiImportListStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiImportListImpl;
import com.intellij.psi.impl.source.tree.java.ImportListElement;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public final class JavaImportListElementType extends JavaStubElementType<PsiImportListStub, PsiImportList>
implements EmptyStubSerializer<PsiImportListStub> {
import java.util.Collections;
import java.util.Set;
public final class JavaImportListElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaImportListElementType() {
super("IMPORT_LIST", BasicJavaElementType.BASIC_IMPORT_LIST);
super("IMPORT_LIST");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_IMPORT_LIST);
}
@Override
@@ -25,27 +29,8 @@ public final class JavaImportListElementType extends JavaStubElementType<PsiImpo
return new ImportListElement();
}
@Override
public PsiImportList createPsi(final @NotNull PsiImportListStub stub) {
return getPsiFactory(stub).createImportList(stub);
}
@Override
public PsiImportList createPsi(final @NotNull ASTNode node) {
return new PsiImportListImpl(node);
}
@Override
public @NotNull PsiImportListStub createStub(final @NotNull LighterAST tree, final @NotNull LighterASTNode node, final @NotNull StubElement<?> parentStub) {
return new PsiImportListStubImpl(parentStub);
}
@Override
public @NotNull PsiImportListStub instantiate(final StubElement parentStub) {
return new PsiImportListStubImpl(parentStub);
}
@Override
public void indexStub(final @NotNull PsiImportListStub stub, final @NotNull IndexSink sink) {
}
}
}
@@ -2,36 +2,32 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiImportStatementBase;
import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
import com.intellij.psi.impl.source.PsiImportModuleStatementImpl;
import com.intellij.psi.impl.source.PsiImportStatementImpl;
import com.intellij.psi.impl.source.PsiImportStaticStatementImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.java.ImportModuleStatementElement;
import com.intellij.psi.impl.source.tree.java.ImportStaticStatementElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public abstract class JavaImportStatementElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
@NotNull private final IElementType myParentElementType;
public abstract class JavaImportStatementElementType extends JavaStubElementType<PsiImportStatementStub, PsiImportStatementBase> {
public JavaImportStatementElementType(final @NonNls @NotNull String id, @NotNull IElementType parentElementType) {
super(id, parentElementType);
super(id);
myParentElementType = parentElementType;
}
@Override
public PsiImportStatementBase createPsi(final @NotNull PsiImportStatementStub stub) {
return getPsiFactory(stub).createImportStatement(stub);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(myParentElementType);
}
@Override
@@ -46,42 +42,4 @@ public abstract class JavaImportStatementElementType extends JavaStubElementType
return new PsiImportStatementImpl(node);
}
}
@Override
public @NotNull PsiImportStatementStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
boolean isOnDemand = false;
String refText = null;
for (LighterASTNode child : tree.getChildren(node)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.JAVA_CODE_REFERENCE ||
type == JavaElementType.IMPORT_STATIC_REFERENCE ||
type == JavaElementType.MODULE_REFERENCE) {
refText = JavaSourceUtil.getReferenceText(tree, child);
}
else if (type == JavaTokenType.DOT || type == JavaTokenType.MODULE_KEYWORD) {
isOnDemand = true;
}
}
byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT,
node.getTokenType() == JavaElementType.IMPORT_MODULE_STATEMENT);
return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
@Override
public void serialize(final @NotNull PsiImportStatementStub stub, final @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeByte(((PsiImportStatementStubImpl)stub).getFlags());
dataStream.writeName(stub.getImportReferenceText());
}
@Override
public @NotNull PsiImportStatementStub deserialize(final @NotNull StubInputStream dataStream, final StubElement parentStub) throws IOException {
byte flags = dataStream.readByte();
String refText = dataStream.readNameString();
return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
@Override
public void indexStub(final @NotNull PsiImportStatementStub stub, final @NotNull IndexSink sink) {
}
}
@@ -2,68 +2,28 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.impl.PsiLiteralStub;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
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.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaLiteralExpressionElementType extends JavaStubElementType<PsiLiteralStub, PsiLiteralExpression> {
public class JavaLiteralExpressionElementType extends JavaStubElementType implements JavaNonCompositeElementType, ParentProviderElementType {
public JavaLiteralExpressionElementType() {
super("LITERAL_EXPRESSION", BasicJavaElementType.BASIC_LITERAL_EXPRESSION);
super("LITERAL_EXPRESSION");
}
@Override
public PsiLiteralExpression createPsi(@NotNull ASTNode node) {
public PsiElement createPsi(@NotNull ASTNode node) {
return new PsiLiteralExpressionImpl(node);
}
@Override
public @NotNull PsiLiteralStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiLiteralStub(parentStub, RecordUtil.intern(tree.getCharTable(), tree.getChildren(node).get(0)));
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_LITERAL_EXPRESSION);
}
@Override
public PsiLiteralExpression createPsi(@NotNull PsiLiteralStub stub) {
return new PsiLiteralExpressionImpl(stub);
}
@Override
public void serialize(@NotNull PsiLiteralStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeUTFFast(stub.getLiteralText());
}
@Override
public @NotNull PsiLiteralStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiLiteralStub(parentStub, dataStream.readUTFFast());
}
@Override
public void indexStub(@NotNull PsiLiteralStub stub, @NotNull IndexSink sink) { }
@Override
public @NotNull ASTNode createCompositeNode() {
return new CompositeElement(this);
}
@Override
public boolean shouldCreateStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement parentStub) {
LighterASTNode parent = tree.getParent(node);
return parent != null && parent.getTokenType() == JavaStubElementTypes.NAME_VALUE_PAIR;
}
@Override
public boolean shouldCreateStub(ASTNode node) {
return node.getTreeParent().getElementType() == JavaStubElementTypes.NAME_VALUE_PAIR;
}
}
}
@@ -2,47 +2,32 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.*;
import com.intellij.psi.impl.cache.ModifierFlags;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.impl.source.PsiAnnotationMethodImpl;
import com.intellij.psi.impl.source.PsiMethodImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.AnnotationMethodElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.BitUtil;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ApiStatus.Internal
public abstract class JavaMethodElementType extends JavaStubElementType<PsiMethodStub, PsiMethod> {
public abstract class JavaMethodElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
@NotNull private final IElementType myParentElementType;
JavaMethodElementType(final @NonNls String name, @NotNull IElementType parentElementType) {
super(name, parentElementType);
super(name);
myParentElementType = parentElementType;
}
@Override
public PsiMethod createPsi(final @NotNull PsiMethodStub stub) {
return getPsiFactory(stub).createMethod(stub);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(myParentElementType);
}
@Override
@@ -52,145 +37,4 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
}
return new PsiMethodImpl(node);
}
@Override
public @NotNull PsiMethodStub createStub(final @NotNull LighterAST tree, final @NotNull LighterASTNode node, final @NotNull StubElement<?> parentStub) {
String name = null;
boolean isConstructor = true;
boolean isVarArgs = false;
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String defValueText = null;
boolean expectingDef = false;
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 == JavaElementType.TYPE) {
isConstructor = false;
}
else if (type == JavaTokenType.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
}
else if (type == JavaElementType.PARAMETER_LIST) {
final List<LighterASTNode> params = LightTreeUtil.getChildrenOfType(tree, child, JavaElementType.PARAMETER);
if (!params.isEmpty()) {
final LighterASTNode pType = LightTreeUtil.firstChildOfType(tree, params.get(params.size() - 1), JavaElementType.TYPE);
if (pType != null) {
isVarArgs = LightTreeUtil.firstChildOfType(tree, pType, JavaTokenType.ELLIPSIS) != null;
}
}
}
else if (type == JavaTokenType.DEFAULT_KEYWORD) {
expectingDef = true;
}
else if (expectingDef && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) &&
type != JavaTokenType.SEMICOLON && type != JavaElementType.CODE_BLOCK) {
defValueText = LightTreeUtil.toFilteredString(tree, child, null);
break;
}
}
TypeInfo typeInfo = isConstructor ? TypeInfo.createConstructorType() : TypeInfo.create(tree, node, parentStub);
boolean isAnno = node.getTokenType() == JavaElementType.ANNOTATION_METHOD;
byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
return new PsiMethodStubImpl(parentStub, name, typeInfo, flags, defValueText);
}
@Override
public void serialize(final @NotNull PsiMethodStub stub, final @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getReturnTypeText());
dataStream.writeByte(((PsiMethodStubImpl)stub).getFlags());
if (stub.isAnnotationMethod()) {
dataStream.writeName(stub.getDefaultValueText());
}
}
@Override
public @NotNull PsiMethodStub deserialize(final @NotNull StubInputStream dataStream, final StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
final TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
String defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readNameString() : null;
return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue);
}
@Override
public void indexStub(final @NotNull PsiMethodStub stub, final @NotNull IndexSink sink) {
final String name = stub.getName();
if (name != null) {
sink.occurrence(JavaStubIndexKeys.METHODS, name);
if (RecordUtil.isStaticNonPrivateMember(stub)) {
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getReturnTypeText().getShortTypeText());
}
}
Set<String> methodTypeParams = getVisibleTypeParameters(stub);
for (StubElement<?> stubElement : stub.getChildrenStubs()) {
if (stubElement instanceof PsiParameterListStub) {
for (StubElement<?> paramStub : stubElement.getChildrenStubs()) {
if (paramStub instanceof PsiParameterStub) {
TypeInfo type = ((PsiParameterStub)paramStub).getType();
String typeName = PsiNameHelper.getShortClassName(type.text());
if (TypeConversionUtil.isPrimitive(typeName) || TypeConversionUtil.isPrimitiveWrapper(typeName)) continue;
if (!methodTypeParams.contains(typeName)) {
sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, typeName);
}
}
}
break;
}
}
}
private static @NotNull Set<String> getVisibleTypeParameters(@NotNull StubElement<?> stub) {
Set<String> result = null;
while (stub != null) {
Set<String> names = getOwnTypeParameterNames(stub);
if (!names.isEmpty()) {
if (result == null) result = new HashSet<>();
result.addAll(names);
}
if (isStatic(stub)) break;
stub = stub.getParentStub();
}
return result == null ? Collections.emptySet() : result;
}
private static boolean isStatic(@NotNull StubElement<?> stub) {
if (stub instanceof PsiMemberStub) {
PsiModifierListStub modList = stub.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
if (modList != null) {
return BitUtil.isSet(modList.getModifiersMask(),
ModifierFlags.NAME_TO_MODIFIER_FLAG_MAP.getInt(PsiModifier.STATIC));
}
}
return false;
}
private static Set<String> getOwnTypeParameterNames(StubElement<?> stubElement) {
StubElement<PsiTypeParameterList> typeParamList = stubElement.findChildStubByType(JavaStubElementTypes.TYPE_PARAMETER_LIST);
if (typeParamList == null) return Collections.emptySet();
Set<String> methodTypeParams = null;
for (Object tStub : typeParamList.getChildrenStubs()) {
if (tStub instanceof PsiTypeParameterStub) {
if (methodTypeParams == null) methodTypeParams = new HashSet<>();
methodTypeParams.add(((PsiTypeParameterStub)tStub).getName());
}
}
return methodTypeParams == null ? Collections.emptySet() : methodTypeParams;
}
}
@@ -1,24 +1,27 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.impl.PsiModifierListStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiModifierListImpl;
import com.intellij.psi.impl.source.tree.java.ModifierListElement;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
class JavaModifierListElementType extends JavaStubElementType<PsiModifierListStub, PsiModifierList> {
JavaModifierListElementType() {
super("MODIFIER_LIST", BasicJavaElementType.BASIC_MODIFIER_LIST);
public class JavaModifierListElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaModifierListElementType() {
super("MODIFIER_LIST");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_MODIFIER_LIST);
}
@Override
@@ -26,48 +29,8 @@ class JavaModifierListElementType extends JavaStubElementType<PsiModifierListStu
return new ModifierListElement();
}
@Override
public PsiModifierList createPsi(@NotNull PsiModifierListStub stub) {
return getPsiFactory(stub).createModifierList(stub);
}
@Override
public PsiModifierList createPsi(@NotNull ASTNode node) {
return new PsiModifierListImpl(node);
}
@Override
public @NotNull PsiModifierListStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiModifierListStubImpl(parentStub, RecordUtil.packModifierList(tree, node));
}
@Override
public void serialize(@NotNull PsiModifierListStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeVarInt(stub.getModifiersMask());
}
@Override
public boolean shouldCreateStub(ASTNode node) {
IElementType parentType = node.getTreeParent().getElementType();
return shouldCreateStub(parentType);
}
@Override
public boolean shouldCreateStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement parentStub) {
LighterASTNode parent = tree.getParent(node);
IElementType parentType = parent != null ? parent.getTokenType() : null;
return shouldCreateStub(parentType);
}
private static boolean shouldCreateStub(IElementType parentType) {
return parentType instanceof IStubElementType;
}
@Override
public @NotNull PsiModifierListStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiModifierListStubImpl(parentStub, dataStream.readVarInt());
}
@Override
public void indexStub(@NotNull PsiModifierListStub stub, @NotNull IndexSink sink) { }
}
}
@@ -2,28 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiJavaModule;
import com.intellij.psi.impl.java.stubs.impl.PsiJavaModuleStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiJavaModuleImpl;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaModuleElementType extends JavaStubElementType<PsiJavaModuleStub, PsiJavaModule> {
public class JavaModuleElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaModuleElementType() {
super("MODULE", BasicJavaElementType.BASIC_MODULE);
super("MODULE");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_MODULE);
}
@Override
@@ -31,35 +29,8 @@ public class JavaModuleElementType extends JavaStubElementType<PsiJavaModuleStub
return new CompositeElement(this);
}
@Override
public PsiJavaModule createPsi(@NotNull PsiJavaModuleStub stub) {
return getPsiFactory(stub).createModule(stub);
}
@Override
public PsiJavaModule createPsi(@NotNull ASTNode node) {
return new PsiJavaModuleImpl(node);
}
@Override
public @NotNull PsiJavaModuleStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.requiredChildOfType(tree, node, JavaElementType.MODULE_REFERENCE);
return new PsiJavaModuleStubImpl(parentStub, JavaSourceUtil.getReferenceText(tree, ref), 0);
}
@Override
public void serialize(@NotNull PsiJavaModuleStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
dataStream.writeVarInt(stub.getResolution());
}
@Override
public @NotNull PsiJavaModuleStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiJavaModuleStubImpl(parentStub, dataStream.readNameString(), dataStream.readVarInt());
}
@Override
public void indexStub(@NotNull PsiJavaModuleStub stub, @NotNull IndexSink sink) {
sink.occurrence(JavaStubIndexKeys.MODULE_NAMES, stub.getName());
}
}
@@ -2,32 +2,23 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiNameValuePair;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.impl.PsiNameValuePairStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.NameValuePairElement;
import com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.List;
import java.util.Collections;
import java.util.Set;
/**
* @author Dmitry Avdeev
*/
public final class JavaNameValuePairType extends JavaStubElementType<PsiNameValuePairStub, PsiNameValuePair> {
JavaNameValuePairType() {
super("NAME_VALUE_PAIR", true, BasicJavaElementType.BASIC_NAME_VALUE_PAIR);
public final class JavaNameValuePairType extends JavaStubElementType implements ICompositeElementType,
ParentProviderElementType,
JavaNonCompositeElementType {
public JavaNameValuePairType() {
super("NAME_VALUE_PAIR", true);
}
@Override
@@ -35,52 +26,13 @@ public final class JavaNameValuePairType extends JavaStubElementType<PsiNameValu
return new PsiNameValuePairImpl(node);
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_NAME_VALUE_PAIR);
}
@Override
public @NotNull ASTNode createCompositeNode() {
return new NameValuePairElement();
}
@Override
public @NotNull PsiNameValuePairStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull 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 (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getTokenType())) {
value = LightTreeUtil.toFilteredString(tree, child, null);
}
}
return new PsiNameValuePairStubImpl(parentStub, name, value);
}
@Override
public PsiNameValuePair createPsi(@NotNull PsiNameValuePairStub stub) {
return getPsiFactory(stub).createNameValuePair(stub);
}
@Override
public void serialize(@NotNull PsiNameValuePairStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
String value = stub.getValue();
boolean hasValue = value != null;
dataStream.writeBoolean(hasValue);
if (hasValue) {
dataStream.writeUTFFast(value);
}
}
@Override
public @NotNull PsiNameValuePairStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
boolean hasValue = dataStream.readBoolean();
return new PsiNameValuePairStubImpl(parentStub, name, hasValue ? dataStream.readUTFFast() : null);
}
@Override
public void indexStub(@NotNull PsiNameValuePairStub stub, @NotNull IndexSink sink) {
}
}
}
@@ -0,0 +1,10 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
public interface JavaNonCompositeElementType {
PsiElement createPsi(@NotNull ASTNode node);
}
@@ -2,34 +2,27 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiPackageAccessibilityStatement;
import com.intellij.psi.impl.java.stubs.impl.PsiPackageAccessibilityStatementStubImpl;
import com.intellij.psi.impl.source.PackageAccessibilityStatementElement;
import com.intellij.psi.impl.source.PsiPackageAccessibilityStatementImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.SmartList;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.List;
import java.util.Collections;
import java.util.Set;
public class JavaPackageAccessibilityStatementElementType extends JavaStubElementType implements ICompositeElementType,
ParentProviderElementType,
JavaNonCompositeElementType {
private final IElementType myParentElementType;
public class JavaPackageAccessibilityStatementElementType extends JavaStubElementType<PsiPackageAccessibilityStatementStub, PsiPackageAccessibilityStatement> {
public JavaPackageAccessibilityStatementElementType(@NotNull String debugName, @NotNull IElementType parentElementType) {
super(debugName, parentElementType);
}
@Override
public PsiPackageAccessibilityStatement createPsi(@NotNull PsiPackageAccessibilityStatementStub stub) {
return getPsiFactory(stub).createPackageAccessibilityStatement(stub);
super(debugName);
myParentElementType = parentElementType;
}
@Override
@@ -43,35 +36,10 @@ public class JavaPackageAccessibilityStatementElementType extends JavaStubElemen
}
@Override
public @NotNull PsiPackageAccessibilityStatementStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
String refText = null;
List<String> to = new SmartList<>();
for (LighterASTNode child : tree.getChildren(node)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.JAVA_CODE_REFERENCE) refText = JavaSourceUtil.getReferenceText(tree, child);
else if (type == JavaElementType.MODULE_REFERENCE) to.add(JavaSourceUtil.getReferenceText(tree, child));
}
return new PsiPackageAccessibilityStatementStubImpl(parentStub, this, refText, to);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton( myParentElementType);
}
@Override
public void serialize(@NotNull PsiPackageAccessibilityStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getPackageName());
dataStream.writeUTFFast(StringUtil.join(stub.getTargets(), "/"));
}
@Override
public @NotNull PsiPackageAccessibilityStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String packageName = dataStream.readNameString();
List<String> targets = StringUtil.split(dataStream.readUTFFast(), "/");
return new PsiPackageAccessibilityStatementStubImpl(parentStub, this, packageName, targets);
}
@Override
public void indexStub(@NotNull PsiPackageAccessibilityStatementStub stub, @NotNull IndexSink sink) { }
public static @NotNull PsiPackageAccessibilityStatement.Role typeToRole(@NotNull IElementType type) {
if (type == JavaElementType.EXPORTS_STATEMENT) return PsiPackageAccessibilityStatement.Role.EXPORTS;
if (type == JavaElementType.OPENS_STATEMENT) return PsiPackageAccessibilityStatement.Role.OPENS;
@@ -2,29 +2,27 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiParameterImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.ParameterElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaParameterElementType extends JavaStubElementType<PsiParameterStub, PsiParameter> {
public class JavaParameterElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaParameterElementType() {
super("PARAMETER", BasicJavaElementType.BASIC_PARAMETER);
super("PARAMETER");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_PARAMETER);
}
@Override
@@ -32,40 +30,8 @@ public class JavaParameterElementType extends JavaStubElementType<PsiParameterSt
return new ParameterElement(JavaElementType.PARAMETER);
}
@Override
public PsiParameter createPsi(@NotNull PsiParameterStub stub) {
return getPsiFactory(stub).createParameter(stub);
}
@Override
public PsiParameter createPsi(@NotNull ASTNode node) {
return new PsiParameterImpl(node);
}
@Override
public @NotNull PsiParameterStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
String name = RecordUtil.intern(tree.getCharTable(), id);
return new PsiParameterStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis(), false);
}
@Override
public void serialize(@NotNull PsiParameterStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getType());
dataStream.writeByte(((PsiParameterStubImpl)stub).getFlags());
}
@Override
public @NotNull PsiParameterStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
if (name == null) throw new IOException("corrupted indices");
TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
return new PsiParameterStubImpl(parentStub, name, type, flags);
}
@Override
public void indexStub(@NotNull PsiParameterStub stub, @NotNull IndexSink sink) { }
}
@@ -2,22 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiParameterList;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterListStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiParameterListImpl;
import com.intellij.psi.impl.source.tree.java.ParameterListElement;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public class JavaParameterListElementType extends JavaStubElementType<PsiParameterListStub, PsiParameterList>
implements EmptyStubSerializer<PsiParameterListStub> {
import java.util.Collections;
import java.util.Set;
public class JavaParameterListElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaParameterListElementType() {
super("PARAMETER_LIST", BasicJavaElementType.BASIC_PARAMETER_LIST);
super("PARAMETER_LIST");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_PARAMETER_LIST);
}
@Override
@@ -25,27 +29,8 @@ public class JavaParameterListElementType extends JavaStubElementType<PsiParamet
return new ParameterListElement();
}
@Override
public PsiParameterList createPsi(final @NotNull PsiParameterListStub stub) {
return getPsiFactory(stub).createParameterList(stub);
}
@Override
public PsiParameterList createPsi(final @NotNull ASTNode node) {
return new PsiParameterListImpl(node);
}
@Override
public @NotNull PsiParameterListStub createStub(final @NotNull LighterAST tree, final @NotNull LighterASTNode node, final @NotNull StubElement<?> parentStub) {
return new PsiParameterListStubImpl(parentStub);
}
@Override
public @NotNull PsiParameterListStub instantiate(final StubElement parentStub) {
return new PsiParameterListStubImpl(parentStub);
}
@Override
public void indexStub(final @NotNull PsiParameterListStub stub, final @NotNull IndexSink sink) {
}
}
}
@@ -2,27 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiProvidesStatement;
import com.intellij.psi.impl.java.stubs.impl.PsiProvidesStatementStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiProvidesStatementImpl;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaProvidesStatementElementType extends JavaStubElementType<PsiProvidesStatementStub, PsiProvidesStatement> {
public class JavaProvidesStatementElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaProvidesStatementElementType() {
super("PROVIDES_STATEMENT", BasicJavaElementType.BASIC_PROVIDES_STATEMENT);
super("PROVIDES_STATEMENT");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_PROVIDES_STATEMENT);
}
@Override
@@ -30,33 +29,8 @@ public class JavaProvidesStatementElementType extends JavaStubElementType<PsiPro
return new CompositeElement(this);
}
@Override
public PsiProvidesStatement createPsi(@NotNull PsiProvidesStatementStub stub) {
return getPsiFactory(stub).createProvidesStatement(stub);
}
@Override
public PsiProvidesStatement createPsi(@NotNull ASTNode node) {
return new PsiProvidesStatementImpl(node);
}
@Override
public @NotNull PsiProvidesStatementStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiProvidesStatementStubImpl(parentStub, refText);
}
@Override
public void serialize(@NotNull PsiProvidesStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getInterface());
}
@Override
public @NotNull PsiProvidesStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiProvidesStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
public void indexStub(@NotNull PsiProvidesStatementStub stub, @NotNull IndexSink sink) { }
}
@@ -2,30 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiRecordComponent;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiRecordComponentStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiRecordComponentImpl;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaRecordComponentElementType extends JavaStubElementType<PsiRecordComponentStub, PsiRecordComponent> {
public class JavaRecordComponentElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaRecordComponentElementType() {
super("RECORD_COMPONENT", BasicJavaElementType.BASIC_RECORD_COMPONENT);
super("RECORD_COMPONENT");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_RECORD_COMPONENT);
}
@Override
@@ -33,45 +29,8 @@ public class JavaRecordComponentElementType extends JavaStubElementType<PsiRecor
return new CompositeElement(this);
}
@Override
public void serialize(@NotNull PsiRecordComponentStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getType());
dataStream.writeByte(((PsiRecordComponentStubImpl)stub).getFlags());
}
@Override
public @NotNull PsiRecordComponentStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
return new PsiRecordComponentStubImpl(parentStub, name, type, flags);
}
@Override
public void indexStub(@NotNull PsiRecordComponentStub stub, @NotNull IndexSink sink) {
String name = stub.getName();
sink.occurrence(JavaStubIndexKeys.RECORD_COMPONENTS, name);
}
@Override
public PsiRecordComponent createPsi(@NotNull PsiRecordComponentStub stub) {
return getPsiFactory(stub).createRecordComponent(stub);
}
@Override
public PsiRecordComponent createPsi(@NotNull ASTNode node) {
return new PsiRecordComponentImpl(node);
}
@Override
public @NotNull PsiRecordComponentStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
String name = RecordUtil.intern(tree.getCharTable(), id);
LighterASTNode modifierList = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.MODIFIER_LIST);
boolean hasDeprecatedAnnotation = modifierList != null && RecordUtil.isDeprecatedByAnnotation(tree, modifierList);
return new PsiRecordComponentStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis(), hasDeprecatedAnnotation);
}
}
@@ -2,22 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiRecordHeader;
import com.intellij.psi.impl.java.stubs.impl.PsiRecordHeaderStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiRecordHeaderImpl;
import com.intellij.psi.impl.source.tree.java.RecordHeaderElement;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public class JavaRecordHeaderElementType extends JavaStubElementType<PsiRecordHeaderStub, PsiRecordHeader>
implements EmptyStubSerializer<PsiRecordHeaderStub> {
import java.util.Collections;
import java.util.Set;
public class JavaRecordHeaderElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaRecordHeaderElementType() {
super("RECORD_HEADER", BasicJavaElementType.BASIC_RECORD_HEADER);
super("RECORD_HEADER");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_RECORD_HEADER);
}
@Override
@@ -25,29 +29,8 @@ public class JavaRecordHeaderElementType extends JavaStubElementType<PsiRecordHe
return new RecordHeaderElement();
}
@Override
public @NotNull PsiRecordHeaderStub instantiate(StubElement parentStub) {
return new PsiRecordHeaderStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiRecordHeaderStub stub, @NotNull IndexSink sink) {
}
@Override
public PsiRecordHeader createPsi(@NotNull PsiRecordHeaderStub stub) {
return getPsiFactory(stub).createRecordHeader(stub);
}
@Override
public PsiRecordHeader createPsi(@NotNull ASTNode node) {
return new PsiRecordHeaderImpl(node);
}
@Override
public @NotNull PsiRecordHeaderStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiRecordHeaderStubImpl(parentStub);
}
}
@@ -2,27 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiRequiresStatement;
import com.intellij.psi.impl.java.stubs.impl.PsiRequiresStatementStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiRequiresStatementImpl;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaRequiresStatementElementType extends JavaStubElementType<PsiRequiresStatementStub, PsiRequiresStatement> {
public class JavaRequiresStatementElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaRequiresStatementElementType() {
super("REQUIRES_STATEMENT", BasicJavaElementType.BASIC_REQUIRES_STATEMENT);
super("REQUIRES_STATEMENT");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_REQUIRES_STATEMENT);
}
@Override
@@ -30,33 +29,8 @@ public class JavaRequiresStatementElementType extends JavaStubElementType<PsiReq
return new CompositeElement(this);
}
@Override
public PsiRequiresStatement createPsi(@NotNull PsiRequiresStatementStub stub) {
return getPsiFactory(stub).createRequiresStatement(stub);
}
@Override
public PsiRequiresStatement createPsi(@NotNull ASTNode node) {
return new PsiRequiresStatementImpl(node);
}
@Override
public @NotNull PsiRequiresStatementStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.MODULE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiRequiresStatementStubImpl(parentStub, refText);
}
@Override
public void serialize(@NotNull PsiRequiresStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getModuleName());
}
@Override
public @NotNull PsiRequiresStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiRequiresStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
public void indexStub(@NotNull PsiRequiresStatementStub stub, @NotNull IndexSink sink) { }
}
@@ -2,54 +2,35 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.ILightStubElementType;
import com.intellij.psi.stubs.PsiFileStub;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NonNls;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Set;
public abstract class JavaStubElementType<StubT extends StubElement<?>, PsiT extends PsiElement>
extends ILightStubElementType<StubT, PsiT> implements ICompositeElementType, ParentProviderElementType {
private final boolean myLeftBound;
private final Set<IElementType> myParentElementTypes;
protected JavaStubElementType(final @NotNull @NonNls String debugName, @NotNull IElementType parentElementType) {
this(debugName, false, parentElementType);
/**
* keeping for backward compatibility
*/
@ApiStatus.Obsolete
public abstract class JavaStubElementType extends IJavaElementType {
@ApiStatus.Internal
protected JavaStubElementType(String debugName) {
super(debugName);
}
protected JavaStubElementType(final @NotNull @NonNls String debugName, final boolean leftBound, @NotNull IElementType parentElementType) {
super(debugName, JavaLanguage.INSTANCE);
myLeftBound = leftBound;
myParentElementTypes = Collections.singleton(parentElementType);
@ApiStatus.Internal
protected JavaStubElementType(String debugName, boolean leftBound) {
super(debugName, leftBound);
}
@Override
public @NotNull Set<IElementType> getParents() {
return myParentElementTypes;
}
@Override
public @NotNull String getExternalId() {
return "java." + toString();
}
protected StubPsiFactory getPsiFactory(StubT stub) {
return getFileStub(stub).getPsiFactory();
}
public boolean isCompiled(StubT stub) {
@ApiStatus.Internal
public static boolean isCompiled(StubElement<?> stub) {
return getFileStub(stub).isCompiled();
}
private PsiJavaFileStub getFileStub(StubT stub) {
@ApiStatus.Internal
public static PsiJavaFileStub getFileStub(StubElement<?> stub) {
StubElement<?> parent = stub;
while (!(parent instanceof PsiFileStub)) {
parent = parent.getParentStub();
@@ -58,16 +39,8 @@ public abstract class JavaStubElementType<StubT extends StubElement<?>, PsiT ext
return (PsiJavaFileStub)parent;
}
public abstract PsiT createPsi(@NotNull ASTNode node);
@Override
public final @NotNull StubT createStub(@NotNull PsiT psi, StubElement<? extends PsiElement> parentStub) {
final String message = "Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
@Override
public boolean isLeftBound() {
return myLeftBound;
public PsiElement createPsi(@NotNull ASTNode node) {
// backward compatibility with manifold.ij plugin
return node.getPsi();
}
}
@@ -5,14 +5,9 @@ import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiKeyword;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.java.*;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.psi.util.JavaImplicitClassUtil;
import com.intellij.psi.tree.IFileElementType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -54,14 +49,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new ImplicitClassElement();
}
@Override
public void indexStub(@NotNull PsiClassStub stub, @NotNull IndexSink sink) {
StubElement parent = stub.getParentStub();
if (parent instanceof PsiJavaFileStub) {
sink.occurrence(JavaStubIndexKeys.IMPLICIT_CLASSES, JavaImplicitClassUtil.getJvmName(((PsiJavaFileStub)parent).getPsi().getName()));
}
}
};
JavaClassElementType ANONYMOUS_CLASS = new JavaClassElementType("ANONYMOUS_CLASS", BasicJavaElementType.BASIC_ANONYMOUS_CLASS) {
@@ -110,11 +97,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new ReferenceListElement(this, JavaTokenType.EXTENDS_KEYWORD, PsiKeyword.EXTENDS);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
};
JavaClassReferenceListElementType PERMITS_LIST =
@@ -123,11 +105,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new ReferenceListElement(this, JavaTokenType.PERMITS_KEYWORD, PsiKeyword.PERMITS);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
};
JavaClassReferenceListElementType IMPLEMENTS_LIST =
new JavaClassReferenceListElementType("IMPLEMENTS_LIST", BasicJavaElementType.BASIC_IMPLEMENTS_LIST) {
@@ -135,11 +112,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new ReferenceListElement(this, JavaTokenType.IMPLEMENTS_KEYWORD, PsiKeyword.IMPLEMENTS);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
};
JavaClassReferenceListElementType THROWS_LIST =
new JavaClassReferenceListElementType("THROWS_LIST", BasicJavaElementType.BASIC_THROWS_LIST) {
@@ -147,11 +119,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new ReferenceListElement(this, JavaTokenType.THROWS_KEYWORD, PsiKeyword.THROWS);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
};
JavaClassReferenceListElementType EXTENDS_BOUND_LIST =
new JavaClassReferenceListElementType("EXTENDS_BOUND_LIST", BasicJavaElementType.BASIC_EXTENDS_BOUND_LIST) {
@@ -159,11 +126,6 @@ public interface JavaStubElementTypes {
public @NotNull ASTNode createCompositeNode() {
return new TypeParameterExtendsBoundsListElement();
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
};
JavaClassReferenceListElementType PROVIDES_WITH_LIST =
new JavaClassReferenceListElementType("PROVIDES_WITH_LIST", BasicJavaElementType.BASIC_PROVIDES_WITH_LIST) {
@@ -199,5 +161,5 @@ public interface JavaStubElementTypes {
* @deprecated use {@link JavaParserDefinition#JAVA_FILE}
*/
@Deprecated @ApiStatus.ScheduledForRemoval
IStubFileElementType<?> JAVA_FILE = JavaParserDefinition.JAVA_FILE;
IFileElementType JAVA_FILE = JavaParserDefinition.JAVA_FILE;
}
@@ -0,0 +1,130 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.psi.impl.java.stubs.factories.*;
import com.intellij.psi.impl.java.stubs.serializers.*;
import com.intellij.psi.stubs.StubRegistry;
import com.intellij.psi.stubs.StubRegistryExtension;
import org.jetbrains.annotations.NotNull;
public class JavaStubRegistryExtension implements StubRegistryExtension {
@Override
public void register(@NotNull StubRegistry registry) {
registry.registerStubSerializer(JavaParserDefinition.JAVA_FILE, new JavaFileSerializer());
registry.registerStubSerializer(JavaStubElementTypes.LITERAL_EXPRESSION, new JavaLiteralExpressionStubSerializer(JavaStubElementTypes.LITERAL_EXPRESSION));
registry.registerLightStubFactory(JavaStubElementTypes.LITERAL_EXPRESSION, new JavaLiteralExpressionStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.MODIFIER_LIST, new JavaModifierListSerializer(JavaStubElementTypes.MODIFIER_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.MODIFIER_LIST, new JavaModifierListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ANNOTATION, new JavaAnnotationStubSerializer(JavaStubElementTypes.ANNOTATION));
registry.registerLightStubFactory(JavaStubElementTypes.ANNOTATION, new JavaAnnotationStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ANNOTATION_PARAMETER_LIST, new JavaAnnotationParameterListStubSerializer(JavaStubElementTypes.ANNOTATION_PARAMETER_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.ANNOTATION_PARAMETER_LIST, new JavaAnnotationParameterListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.NAME_VALUE_PAIR, new JavaNameValuePairStubSerializer(JavaStubElementTypes.NAME_VALUE_PAIR));
registry.registerLightStubFactory(JavaStubElementTypes.NAME_VALUE_PAIR, new JavaNameValuePairStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.LAMBDA_EXPRESSION, new LambdaExpressionStubSerializer(JavaStubElementTypes.LAMBDA_EXPRESSION));
registry.registerLightStubFactory(JavaStubElementTypes.LAMBDA_EXPRESSION, new LambdaExpressionStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.METHOD_REF_EXPRESSION, new MethodReferenceStubSerializer(JavaStubElementTypes.METHOD_REF_EXPRESSION));
registry.registerLightStubFactory(JavaStubElementTypes.METHOD_REF_EXPRESSION, new MethodReferenceStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.PARAMETER_LIST, new JavaParameterListStubSerializer(JavaStubElementTypes.PARAMETER_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.PARAMETER_LIST, new JavaParameterListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.PARAMETER, new JavaParameterStubSerializer(JavaStubElementTypes.PARAMETER));
registry.registerLightStubFactory(JavaStubElementTypes.PARAMETER, new JavaParameterStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.TYPE_PARAMETER, new JavaTypeParameterStubSerializer(JavaStubElementTypes.TYPE_PARAMETER));
registry.registerLightStubFactory(JavaStubElementTypes.TYPE_PARAMETER, new JavaTypeParameterStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.TYPE_PARAMETER_LIST, new JavaTypeParameterListStubSerializer(JavaStubElementTypes.TYPE_PARAMETER_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.TYPE_PARAMETER_LIST, new JavaTypeParameterListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.CLASS_INITIALIZER, new JavaClassInitializerStubSerializer(JavaStubElementTypes.CLASS_INITIALIZER));
registry.registerLightStubFactory(JavaStubElementTypes.CLASS_INITIALIZER, new JavaClassInitializerStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPORT_LIST, new JavaImportListStubSerializer(JavaStubElementTypes.IMPORT_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.IMPORT_LIST, new JavaImportListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.MODULE, new JavaModuleStubSerializer(JavaStubElementTypes.MODULE));
registry.registerLightStubFactory(JavaStubElementTypes.MODULE, new JavaModuleStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.REQUIRES_STATEMENT, new JavaRequiresStatementStubSerializer(JavaStubElementTypes.REQUIRES_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.REQUIRES_STATEMENT, new JavaRequiresStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.USES_STATEMENT, new JavaUsesStatementStubSerializer(JavaStubElementTypes.USES_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.USES_STATEMENT, new JavaUsesStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.PROVIDES_STATEMENT, new JavaProvidesStatementStubSerializer(JavaStubElementTypes.PROVIDES_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.PROVIDES_STATEMENT, new JavaProvidesStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.RECORD_COMPONENT, new JavaRecordComponentStubSerializer(JavaStubElementTypes.RECORD_COMPONENT));
registry.registerLightStubFactory(JavaStubElementTypes.RECORD_COMPONENT, new JavaRecordComponentStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.RECORD_HEADER, new JavaRecordHeaderStubSerializer(JavaStubElementTypes.RECORD_HEADER));
registry.registerLightStubFactory(JavaStubElementTypes.RECORD_HEADER, new JavaRecordHeaderStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.EXPORTS_STATEMENT, new JavaPackageAccessibilityStatementStubSerializer(JavaStubElementTypes.EXPORTS_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.EXPORTS_STATEMENT, new JavaPackageAccessibilityStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.OPENS_STATEMENT, new JavaPackageAccessibilityStatementStubSerializer(JavaStubElementTypes.OPENS_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.OPENS_STATEMENT, new JavaPackageAccessibilityStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.CLASS, new JavaClassStubSerializer(JavaStubElementTypes.CLASS));
registry.registerLightStubFactory(JavaStubElementTypes.CLASS, new JavaClassStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPLICIT_CLASS, new JavaClassStubSerializer(JavaStubElementTypes.IMPLICIT_CLASS));
registry.registerLightStubFactory(JavaStubElementTypes.IMPLICIT_CLASS, new JavaClassStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ANONYMOUS_CLASS, new JavaClassStubSerializer(JavaStubElementTypes.ANONYMOUS_CLASS));
registry.registerLightStubFactory(JavaStubElementTypes.ANONYMOUS_CLASS, new JavaClassStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER, new JavaClassStubSerializer(JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER));
registry.registerLightStubFactory(JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER, new JavaClassStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.METHOD, new JavaMethodStubSerializer(JavaStubElementTypes.METHOD));
registry.registerLightStubFactory(JavaStubElementTypes.METHOD, new JavaMethodStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ANNOTATION_METHOD, new JavaMethodStubSerializer(JavaStubElementTypes.ANNOTATION_METHOD));
registry.registerLightStubFactory(JavaStubElementTypes.ANNOTATION_METHOD, new JavaMethodStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.FIELD, new JavaFieldStubSerializer(JavaStubElementTypes.FIELD));
registry.registerLightStubFactory(JavaStubElementTypes.FIELD, new JavaFieldStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.ENUM_CONSTANT, new JavaFieldStubSerializer(JavaStubElementTypes.ENUM_CONSTANT));
registry.registerLightStubFactory(JavaStubElementTypes.ENUM_CONSTANT, new JavaFieldStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.EXTENDS_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.EXTENDS_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.EXTENDS_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.PERMITS_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.PERMITS_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.PERMITS_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPLEMENTS_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.IMPLEMENTS_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.IMPLEMENTS_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.THROWS_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.THROWS_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.THROWS_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.EXTENDS_BOUND_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.EXTENDS_BOUND_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.EXTENDS_BOUND_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.PROVIDES_WITH_LIST, new JavaClassReferenceListStubSerializer(JavaStubElementTypes.PROVIDES_WITH_LIST));
registry.registerLightStubFactory(JavaStubElementTypes.PROVIDES_WITH_LIST, new JavaClassReferenceListStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPORT_STATEMENT, new JavaImportStatementStubSerializer(JavaStubElementTypes.IMPORT_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.IMPORT_STATEMENT, new JavaImportStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPORT_STATIC_STATEMENT, new JavaImportStatementStubSerializer(JavaStubElementTypes.IMPORT_STATIC_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.IMPORT_STATIC_STATEMENT, new JavaImportStatementStubFactory());
registry.registerStubSerializer(JavaStubElementTypes.IMPORT_MODULE_STATEMENT, new JavaImportStatementStubSerializer(JavaStubElementTypes.IMPORT_MODULE_STATEMENT));
registry.registerLightStubFactory(JavaStubElementTypes.IMPORT_MODULE_STATEMENT, new JavaImportStatementStubFactory());
}
}
@@ -2,27 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl;
import com.intellij.psi.impl.source.tree.java.TypeParameterElement;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaTypeParameterElementType extends JavaStubElementType<PsiTypeParameterStub, PsiTypeParameter> {
public class JavaTypeParameterElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaTypeParameterElementType() {
super("TYPE_PARAMETER", BasicJavaElementType.BASIC_TYPE_PARAMETER);
super("TYPE_PARAMETER");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_TYPE_PARAMETER);
}
@Override
@@ -30,35 +29,8 @@ public class JavaTypeParameterElementType extends JavaStubElementType<PsiTypePar
return new TypeParameterElement();
}
@Override
public PsiTypeParameter createPsi(final @NotNull PsiTypeParameterStub stub) {
return getPsiFactory(stub).createTypeParameter(stub);
}
@Override
public PsiTypeParameter createPsi(final @NotNull ASTNode node) {
return new PsiTypeParameterImpl(node);
}
@Override
public @NotNull PsiTypeParameterStub createStub(final @NotNull LighterAST tree, final @NotNull LighterASTNode node, final @NotNull StubElement<?> parentStub) {
final LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
final String name = RecordUtil.intern(tree.getCharTable(), id);
return new PsiTypeParameterStubImpl(parentStub, name);
}
@Override
public void serialize(final @NotNull PsiTypeParameterStub stub, final @NotNull StubOutputStream dataStream) throws IOException {
String name = stub.getName();
dataStream.writeName(name);
}
@Override
public @NotNull PsiTypeParameterStub deserialize(final @NotNull StubInputStream dataStream, final StubElement parentStub) throws IOException {
return new PsiTypeParameterStubImpl(parentStub, dataStream.readNameString());
}
@Override
public void indexStub(final @NotNull PsiTypeParameterStub stub, final @NotNull IndexSink sink) {
}
}
}
@@ -2,22 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiTypeParameterList;
import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterListStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.java.PsiTypeParameterListImpl;
import com.intellij.psi.impl.source.tree.java.TypeParameterListElement;
import com.intellij.psi.stubs.EmptyStubSerializer;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public class JavaTypeParameterListElementType extends JavaStubElementType<PsiTypeParameterListStub, PsiTypeParameterList>
implements EmptyStubSerializer<PsiTypeParameterListStub> {
import java.util.Collections;
import java.util.Set;
public class JavaTypeParameterListElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaTypeParameterListElementType() {
super("TYPE_PARAMETER_LIST", true, BasicJavaElementType.BASIC_TYPE_PARAMETER_LIST);
super("TYPE_PARAMETER_LIST", true);
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_TYPE_PARAMETER_LIST);
}
@Override
@@ -25,29 +29,8 @@ public class JavaTypeParameterListElementType extends JavaStubElementType<PsiTyp
return new TypeParameterListElement();
}
@Override
public PsiTypeParameterList createPsi(final @NotNull PsiTypeParameterListStub stub) {
return getPsiFactory(stub).createTypeParameterList(stub);
}
@Override
public PsiTypeParameterList createPsi(final @NotNull ASTNode node) {
return new PsiTypeParameterListImpl(node);
}
@Override
public @NotNull PsiTypeParameterListStub createStub(final @NotNull LighterAST tree,
final @NotNull LighterASTNode node,
final @NotNull StubElement<?> parentStub) {
return new PsiTypeParameterListStubImpl(parentStub);
}
@Override
public @NotNull PsiTypeParameterListStub instantiate(final StubElement parentStub) {
return new PsiTypeParameterListStubImpl(parentStub);
}
@Override
public void indexStub(final @NotNull PsiTypeParameterListStub stub, final @NotNull IndexSink sink) {
}
}
}
@@ -2,27 +2,26 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiUsesStatement;
import com.intellij.psi.impl.java.stubs.impl.PsiUsesStatementStubImpl;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.PsiUsesStatementImpl;
import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
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.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
public class JavaUsesStatementElementType extends JavaStubElementType<PsiUsesStatementStub, PsiUsesStatement> {
public class JavaUsesStatementElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public JavaUsesStatementElementType() {
super("USES_STATEMENT", BasicJavaElementType.BASIC_USES_STATEMENT);
super("USES_STATEMENT");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_USES_STATEMENT);
}
@Override
@@ -30,33 +29,8 @@ public class JavaUsesStatementElementType extends JavaStubElementType<PsiUsesSta
return new CompositeElement(this);
}
@Override
public PsiUsesStatement createPsi(@NotNull PsiUsesStatementStub stub) {
return getPsiFactory(stub).createUsesStatement(stub);
}
@Override
public PsiUsesStatement createPsi(@NotNull ASTNode node) {
return new PsiUsesStatementImpl(node);
}
@Override
public @NotNull PsiUsesStatementStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiUsesStatementStubImpl(parentStub, refText);
}
@Override
public void serialize(@NotNull PsiUsesStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getClassName());
}
@Override
public @NotNull PsiUsesStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiUsesStatementStubImpl(parentStub, dataStream.readNameString());
}
@Override
public void indexStub(@NotNull PsiUsesStatementStub stub, @NotNull IndexSink sink) { }
}
@@ -2,23 +2,22 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiLambdaExpression;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.impl.source.tree.java.PsiLambdaExpressionImpl;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Objects;
import java.util.Collections;
import java.util.Set;
public class LambdaExpressionElementType extends FunctionalExpressionElementType<PsiLambdaExpression> {
public class LambdaExpressionElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public LambdaExpressionElementType() {
super("LAMBDA_EXPRESSION", BasicJavaElementType.BASIC_LAMBDA_EXPRESSION);
super("LAMBDA_EXPRESSION");
}
@Override
@@ -26,9 +25,10 @@ public class LambdaExpressionElementType extends FunctionalExpressionElementType
return new PsiLambdaExpressionImpl(node);
}
@Override
public PsiLambdaExpression createPsi(@NotNull FunctionalExpressionStub<PsiLambdaExpression> stub) {
return new PsiLambdaExpressionImpl(stub);
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_LAMBDA_EXPRESSION);
}
@Override
@@ -49,111 +49,4 @@ public class LambdaExpressionElementType extends FunctionalExpressionElementType
}
};
}
@Override
protected @NotNull String getPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr) {
LighterASTNode parameterList =
Objects.requireNonNull(LightTreeUtil.firstChildOfType(tree, funExpr, JavaStubElementTypes.PARAMETER_LIST));
return getLambdaPresentableText(tree, parameterList);
}
private static String getLambdaPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode parameterList) {
StringBuilder buf = new StringBuilder(parameterList.getEndOffset() - parameterList.getStartOffset());
formatParameterList(tree, parameterList, buf);
buf.append(" -> {...}");
return buf.toString();
}
private static void formatParameterList(@NotNull LighterAST tree, @NotNull LighterASTNode parameterList, StringBuilder buf) {
final List<LighterASTNode> children = tree.getChildren(parameterList);
boolean isFirstParameter = true;
boolean appendCloseBracket = false;
for (final LighterASTNode node : children) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaTokenType.LPARENTH) {
buf.append('(');
appendCloseBracket = true;
}
else if (tokenType == JavaStubElementTypes.PARAMETER) {
if (!isFirstParameter) {
buf.append(", ");
}
formatParameter(tree, node, buf);
if (isFirstParameter) {
isFirstParameter = false;
}
}
}
if (appendCloseBracket) buf.append(')');
}
private static void formatParameter(@NotNull LighterAST tree, @NotNull LighterASTNode parameter, StringBuilder buf) {
final List<LighterASTNode> children = tree.getChildren(parameter);
for (LighterASTNode node : children) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaElementType.TYPE) {
formatType(tree, node, buf);
buf.append(' ');
}
else if (tokenType == JavaTokenType.IDENTIFIER) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
}
}
}
private static void formatType(LighterAST tree, LighterASTNode typeElement, StringBuilder buf) {
for (LighterASTNode node : tree.getChildren(typeElement)) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaElementType.JAVA_CODE_REFERENCE) {
formatCodeReference(tree, node, buf);
}
else if (tokenType == JavaElementType.TYPE) {
formatType(tree, node, buf);
}
else if (tokenType == JavaTokenType.QUEST) {
buf.append("? ");
}
else if (ElementType.KEYWORD_BIT_SET.contains(tokenType)) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
if (!ElementType.PRIMITIVE_TYPE_BIT_SET.contains(tokenType)) {
buf.append(" ");
}
}
else if (tokenType == JavaTokenType.ELLIPSIS) {
buf.append("...");
}
else if (tokenType == JavaTokenType.RBRACKET) {
buf.append("]");
}
else if (tokenType == JavaTokenType.LBRACKET) {
buf.append("[");
}
}
}
private static void formatCodeReference(LighterAST tree, LighterASTNode codeRef, StringBuilder buf) {
for (LighterASTNode node : tree.getChildren(codeRef)) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaTokenType.IDENTIFIER) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
}
else if (tokenType == JavaElementType.REFERENCE_PARAMETER_LIST) {
formatTypeParameters(tree, node, buf);
}
}
}
private static void formatTypeParameters(LighterAST tree, LighterASTNode typeParameters, StringBuilder buf) {
final List<LighterASTNode> children = LightTreeUtil.getChildrenOfType(tree, typeParameters, JavaElementType.TYPE);
if (children.isEmpty()) return;
buf.append('<');
for (int i = 0; i < children.size(); i++) {
LighterASTNode child = children.get(i);
formatType(tree, child, buf);
if (i != children.size() - 1) {
buf.append(", ");
}
}
buf.append('>');
}
}
@@ -2,26 +2,27 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiMethodReferenceExpression;
import com.intellij.psi.impl.source.BasicJavaElementType;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.impl.source.tree.java.PsiMethodReferenceExpressionImpl;
import com.intellij.psi.tree.ICompositeElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.tree.ParentProviderElementType;
import org.jetbrains.annotations.NotNull;
public class MethodReferenceElementType extends FunctionalExpressionElementType<PsiMethodReferenceExpression> {
//prevents cyclic static variables initialization
private static final NotNullLazyValue<TokenSet> EXCLUDE_FROM_PRESENTABLE_TEXT = NotNullLazyValue.lazy(() -> {
return TokenSet.orSet(ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.REFERENCE_PARAMETER_LIST));
});
import java.util.Collections;
import java.util.Set;
public class MethodReferenceElementType extends JavaStubElementType implements ICompositeElementType, ParentProviderElementType, JavaNonCompositeElementType {
public MethodReferenceElementType() {
super("METHOD_REF_EXPRESSION", BasicJavaElementType.BASIC_METHOD_REF_EXPRESSION);
super("METHOD_REF_EXPRESSION");
}
@Override
public @NotNull Set<IElementType> getParents() {
return Collections.singleton(BasicJavaElementType.BASIC_METHOD_REF_EXPRESSION);
}
@Override
@@ -29,11 +30,6 @@ public class MethodReferenceElementType extends FunctionalExpressionElementType<
return new PsiMethodReferenceExpressionImpl(node);
}
@Override
public PsiMethodReferenceExpression createPsi(@NotNull FunctionalExpressionStub<PsiMethodReferenceExpression> stub) {
return new PsiMethodReferenceExpressionImpl(stub);
}
@Override
public @NotNull ASTNode createCompositeNode() {
return new CompositeElement(this) {
@@ -52,9 +48,4 @@ public class MethodReferenceElementType extends FunctionalExpressionElementType<
}
};
}
@Override
protected @NotNull String getPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr) {
return LightTreeUtil.toFilteredString(tree, funExpr, EXCLUDE_FROM_PRESENTABLE_TEXT.getValue());
}
}
@@ -0,0 +1,31 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiAnnotationParameterList;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationParameterListStubImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaAnnotationParameterListStubFactory implements LightStubElementFactory<PsiAnnotationParameterListStubImpl, PsiAnnotationParameterList> {
@Override
public @NotNull PsiAnnotationParameterListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiAnnotationParameterListStubImpl(parentStub);
}
@Override
public PsiAnnotationParameterList createPsi(@NotNull PsiAnnotationParameterListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createAnnotationParameterList(stub);
}
@Override
public @NotNull PsiAnnotationParameterListStubImpl createStub(@NotNull PsiAnnotationParameterList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,34 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaAnnotationStubFactory implements LightStubElementFactory<PsiAnnotationStubImpl, PsiAnnotation> {
@Override
public @NotNull PsiAnnotationStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
String text = LightTreeUtil.toFilteredString(tree, node, null);
return new PsiAnnotationStubImpl(parentStub, text);
}
@Override
public PsiAnnotation createPsi(@NotNull PsiAnnotationStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createAnnotation(stub);
}
@Override
public @NotNull PsiAnnotationStubImpl createStub(@NotNull PsiAnnotation psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,31 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiClassInitializer;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiClassInitializerStubImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaClassInitializerStubFactory implements LightStubElementFactory<PsiClassInitializerStubImpl, PsiClassInitializer> {
@Override
public @NotNull PsiClassInitializerStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiClassInitializerStubImpl(parentStub);
}
@Override
public PsiClassInitializer createPsi(@NotNull PsiClassInitializerStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createClassInitializer(stub);
}
@Override
public @NotNull PsiClassInitializerStubImpl createStub(@NotNull PsiClassInitializer psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,47 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiReferenceList;
import com.intellij.psi.impl.java.stubs.JavaClassReferenceListElementType;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiClassReferenceListStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JavaClassReferenceListStubFactory implements LightStubElementFactory<PsiClassReferenceListStubImpl, PsiReferenceList> {
@Override
public @NotNull PsiClassReferenceListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
JavaClassReferenceListElementType type = (JavaClassReferenceListElementType)node.getTokenType();
return new PsiClassReferenceListStubImpl(type, parentStub, getTexts(tree, node));
}
@Override
public PsiReferenceList createPsi(@NotNull PsiClassReferenceListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createClassReferenceList(stub);
}
@Override
public @NotNull PsiClassReferenceListStubImpl createStub(@NotNull PsiReferenceList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
private static String @NotNull [] getTexts(@NotNull LighterAST tree, @NotNull LighterASTNode node) {
List<LighterASTNode> refs = LightTreeUtil.getChildrenOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String[] texts = ArrayUtil.newStringArray(refs.size());
for (int i = 0; i < refs.size(); i++) {
texts[i] = LightTreeUtil.toFilteredString(tree, refs.get(i), null);
}
return texts;
}
}
@@ -0,0 +1,128 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiClass;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.JavaClassElementType;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.PsiClassStub;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl;
import com.intellij.psi.impl.java.stubs.serializers.JavaClassStubSerializer;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaClassStubFactory implements LightStubElementFactory<PsiClassStubImpl<PsiClass>, PsiClass> {
@Override
public @NotNull PsiClassStubImpl<PsiClass> createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
boolean isDeprecatedByComment = false;
boolean isInterface = false;
boolean isEnum = false;
boolean isRecord = false;
boolean isValueClass = 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);
isValueClass = RecordUtil.hasValueModifier(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 isImplicit = node.getTokenType() == JavaElementType.IMPLICIT_CLASS;
final short flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation,
isInQualifiedNew, hasDeprecatedAnnotation, false, false, hasDocComment, isRecord,
isImplicit, isValueClass);
final JavaClassElementType type = JavaClassStubSerializer.typeForClass(isAnonymous, isEnumConst, isImplicit);
return new PsiClassStubImpl<>(type, parentStub, qualifiedName, name, baseRef, flags);
}
@Override
public PsiClass createPsi(@NotNull PsiClassStubImpl<PsiClass> stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createClass(stub);
}
@Override
public @NotNull PsiClassStubImpl<PsiClass> createStub(@NotNull PsiClass psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,88 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiField;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.PsiFieldStub;
import com.intellij.psi.impl.java.stubs.impl.PsiFieldStubImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaFieldStubFactory implements LightStubElementFactory<PsiFieldStubImpl, PsiField> {
private static final int INITIALIZER_LENGTH_LIMIT = 1000;
@Override
public @NotNull PsiFieldStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String name = null;
String initializer = null;
boolean expectingInit = false;
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.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
}
else if (type == JavaTokenType.EQ) {
expectingInit = true;
}
else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
initializer = encodeInitializer(tree, child);
break;
}
}
final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT;
final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags);
}
@Override
public PsiField createPsi(@NotNull PsiFieldStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createField(stub);
}
@Override
public @NotNull PsiFieldStubImpl createStub(@NotNull PsiField psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
private static String encodeInitializer(final LighterAST tree, final LighterASTNode initializer) {
final IElementType type = initializer.getTokenType();
if (type == JavaElementType.NEW_EXPRESSION || type == JavaElementType.METHOD_CALL_EXPRESSION) {
return PsiFieldStub.INITIALIZER_NOT_STORED;
}
if (initializer.getEndOffset() - initializer.getStartOffset() > INITIALIZER_LENGTH_LIMIT) {
return PsiFieldStub.INITIALIZER_TOO_LONG;
}
return LightTreeUtil.toFilteredString(tree, initializer, null);
}
}
@@ -0,0 +1,31 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiImportList;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiImportListStubImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaImportListStubFactory implements LightStubElementFactory<PsiImportListStubImpl, PsiImportList> {
@Override
public @NotNull PsiImportListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiImportListStubImpl(parentStub);
}
@Override
public PsiImportList createPsi(@NotNull PsiImportListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createImportList(stub);
}
@Override
public @NotNull PsiImportListStubImpl createStub(@NotNull PsiImportList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,51 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiImportStatementBase;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaImportStatementStubFactory implements LightStubElementFactory<PsiImportStatementStubImpl, PsiImportStatementBase> {
@Override
public @NotNull PsiImportStatementStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
boolean isOnDemand = false;
String refText = null;
for (LighterASTNode child : tree.getChildren(node)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.JAVA_CODE_REFERENCE ||
type == JavaElementType.IMPORT_STATIC_REFERENCE ||
type == JavaElementType.MODULE_REFERENCE) {
refText = JavaSourceUtil.getReferenceText(tree, child);
}
else if (type == JavaTokenType.DOT || type == JavaTokenType.MODULE_KEYWORD) {
isOnDemand = true;
}
}
byte flags = PsiImportStatementStubImpl.packFlags(isOnDemand, node.getTokenType() == JavaElementType.IMPORT_STATIC_STATEMENT,
node.getTokenType() == JavaElementType.IMPORT_MODULE_STATEMENT);
return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
@Override
public PsiImportStatementBase createPsi(@NotNull PsiImportStatementStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createImportStatement(stub);
}
@Override
public @NotNull PsiImportStatementStubImpl createStub(@NotNull PsiImportStatementBase psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,46 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
import com.intellij.psi.impl.java.stubs.impl.PsiLiteralStub;
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaLiteralExpressionStubFactory implements LightStubElementFactory<PsiLiteralStub, PsiLiteralExpression> {
@Override
public @NotNull PsiLiteralStub createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiLiteralStub(parentStub, RecordUtil.intern(tree.getCharTable(), tree.getChildren(node).get(0)));
}
@Override
public PsiLiteralExpression createPsi(@NotNull PsiLiteralStub stub) {
return new PsiLiteralExpressionImpl(stub);
}
@Override
public boolean shouldCreateStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement parentStub) {
LighterASTNode parent = tree.getParent(node);
return parent != null && parent.getTokenType() == JavaStubElementTypes.NAME_VALUE_PAIR;
}
@Override
public boolean shouldCreateStub(ASTNode node) {
return node.getTreeParent().getElementType() == JavaStubElementTypes.NAME_VALUE_PAIR;
}
@Override
public @NotNull PsiLiteralStub createStub(@NotNull PsiLiteralExpression psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,88 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JavaMethodStubFactory implements LightStubElementFactory<PsiMethodStubImpl, PsiMethod> {
@Override
public @NotNull PsiMethodStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
String name = null;
boolean isConstructor = true;
boolean isVarArgs = false;
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String defValueText = null;
boolean expectingDef = false;
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 == JavaElementType.TYPE) {
isConstructor = false;
}
else if (type == JavaTokenType.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
}
else if (type == JavaElementType.PARAMETER_LIST) {
final List<LighterASTNode> params = LightTreeUtil.getChildrenOfType(tree, child, JavaElementType.PARAMETER);
if (!params.isEmpty()) {
final LighterASTNode pType = LightTreeUtil.firstChildOfType(tree, params.get(params.size() - 1), JavaElementType.TYPE);
if (pType != null) {
isVarArgs = LightTreeUtil.firstChildOfType(tree, pType, JavaTokenType.ELLIPSIS) != null;
}
}
}
else if (type == JavaTokenType.DEFAULT_KEYWORD) {
expectingDef = true;
}
else if (expectingDef && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) &&
type != JavaTokenType.SEMICOLON && type != JavaElementType.CODE_BLOCK) {
defValueText = LightTreeUtil.toFilteredString(tree, child, null);
break;
}
}
TypeInfo typeInfo = isConstructor ? TypeInfo.createConstructorType() : TypeInfo.create(tree, node, parentStub);
boolean isAnno = node.getTokenType() == JavaElementType.ANNOTATION_METHOD;
byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
return new PsiMethodStubImpl(parentStub, name, typeInfo, flags, defValueText);
}
@Override
public PsiMethod createPsi(@NotNull PsiMethodStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createMethod(stub);
}
@Override
public @NotNull PsiMethodStubImpl createStub(@NotNull PsiMethod psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,54 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiModifierListStubImpl;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubElementRegistryService;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaModifierListStubFactory implements LightStubElementFactory<PsiModifierListStubImpl, PsiModifierList> {
@Override
public @NotNull PsiModifierListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiModifierListStubImpl(parentStub, RecordUtil.packModifierList(tree, node));
}
@Override
public PsiModifierList createPsi(@NotNull PsiModifierListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createModifierList(stub);
}
@Override
public @NotNull PsiModifierListStubImpl createStub(@NotNull PsiModifierList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
@Override
public boolean shouldCreateStub(ASTNode node) {
IElementType parentType = node.getTreeParent().getElementType();
return shouldCreateStub(parentType);
}
@Override
public boolean shouldCreateStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement parentStub) {
LighterASTNode parent = tree.getParent(node);
IElementType parentType = parent != null ? parent.getTokenType() : null;
return shouldCreateStub(parentType);
}
private static boolean shouldCreateStub(IElementType parentType) {
return StubElementRegistryService.getInstance().getStubSerializer(parentType) != null;
}
}
@@ -0,0 +1,35 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiJavaModule;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiJavaModuleStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaModuleStubFactory implements LightStubElementFactory<PsiJavaModuleStubImpl, PsiJavaModule> {
@Override
public @NotNull PsiJavaModuleStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.requiredChildOfType(tree, node, JavaElementType.MODULE_REFERENCE);
return new PsiJavaModuleStubImpl(parentStub, JavaSourceUtil.getReferenceText(tree, ref), 0);
}
@Override
public PsiJavaModule createPsi(@NotNull PsiJavaModuleStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createModule(stub);
}
@Override
public @NotNull PsiJavaModuleStubImpl createStub(@NotNull PsiJavaModule psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,48 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiNameValuePair;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiNameValuePairStubImpl;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JavaNameValuePairStubFactory implements LightStubElementFactory<PsiNameValuePairStubImpl, PsiNameValuePair> {
@Override
public @NotNull PsiNameValuePairStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull 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 (ElementType.ANNOTATION_MEMBER_VALUE_BIT_SET.contains(child.getTokenType())) {
value = LightTreeUtil.toFilteredString(tree, child, null);
}
}
return new PsiNameValuePairStubImpl(parentStub, name, value);
}
@Override
public PsiNameValuePair createPsi(@NotNull PsiNameValuePairStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createNameValuePair(stub);
}
@Override
public @NotNull PsiNameValuePairStubImpl createStub(@NotNull PsiNameValuePair psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,47 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiPackageAccessibilityStatement;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiPackageAccessibilityStatementStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JavaPackageAccessibilityStatementStubFactory implements LightStubElementFactory<PsiPackageAccessibilityStatementStubImpl, PsiPackageAccessibilityStatement> {
@Override
public @NotNull PsiPackageAccessibilityStatementStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
String refText = null;
List<String> to = new SmartList<>();
for (LighterASTNode child : tree.getChildren(node)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.JAVA_CODE_REFERENCE) refText = JavaSourceUtil.getReferenceText(tree, child);
else if (type == JavaElementType.MODULE_REFERENCE) to.add(JavaSourceUtil.getReferenceText(tree, child));
}
return new PsiPackageAccessibilityStatementStubImpl(parentStub, (IJavaElementType)node.getTokenType(), refText, to);
}
@Override
public PsiPackageAccessibilityStatement createPsi(@NotNull PsiPackageAccessibilityStatementStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createPackageAccessibilityStatement(stub);
}
@Override
public @NotNull PsiPackageAccessibilityStatementStubImpl createStub(@NotNull PsiPackageAccessibilityStatement psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,31 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiParameterList;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterListStubImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaParameterListStubFactory implements LightStubElementFactory<PsiParameterListStubImpl, PsiParameterList> {
@Override
public @NotNull PsiParameterListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiParameterListStubImpl(parentStub);
}
@Override
public PsiParameterList createPsi(@NotNull PsiParameterListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createParameterList(stub);
}
@Override
public @NotNull PsiParameterListStubImpl createStub(@NotNull PsiParameterList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,38 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaParameterStubFactory implements LightStubElementFactory<PsiParameterStubImpl, PsiParameter> {
@Override
public @NotNull PsiParameterStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
String name = RecordUtil.intern(tree.getCharTable(), id);
return new PsiParameterStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis(), false);
}
@Override
public PsiParameter createPsi(@NotNull PsiParameterStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createParameter(stub);
}
@Override
public @NotNull PsiParameterStubImpl createStub(@NotNull PsiParameter psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,36 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiProvidesStatement;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiProvidesStatementStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaProvidesStatementStubFactory implements LightStubElementFactory<PsiProvidesStatementStubImpl, PsiProvidesStatement> {
@Override
public @NotNull PsiProvidesStatementStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiProvidesStatementStubImpl(parentStub, refText);
}
@Override
public PsiProvidesStatement createPsi(@NotNull PsiProvidesStatementStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createProvidesStatement(stub);
}
@Override
public @NotNull PsiProvidesStatementStubImpl createStub(@NotNull PsiProvidesStatement psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,42 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiRecordComponent;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiRecordComponentStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaRecordComponentStubFactory implements LightStubElementFactory<PsiRecordComponentStubImpl, PsiRecordComponent> {
@Override
public @NotNull PsiRecordComponentStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
String name = RecordUtil.intern(tree.getCharTable(), id);
LighterASTNode modifierList = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.MODIFIER_LIST);
boolean hasDeprecatedAnnotation = modifierList != null && RecordUtil.isDeprecatedByAnnotation(tree, modifierList);
return new PsiRecordComponentStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis(), hasDeprecatedAnnotation);
}
@Override
public PsiRecordComponent createPsi(@NotNull PsiRecordComponentStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createRecordComponent(stub);
}
@Override
public @NotNull PsiRecordComponentStubImpl createStub(@NotNull PsiRecordComponent psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,31 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiRecordHeader;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiRecordHeaderStubImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaRecordHeaderStubFactory implements LightStubElementFactory<PsiRecordHeaderStubImpl, PsiRecordHeader> {
@Override
public @NotNull PsiRecordHeaderStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiRecordHeaderStubImpl(parentStub);
}
@Override
public PsiRecordHeader createPsi(@NotNull PsiRecordHeaderStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createRecordHeader(stub);
}
@Override
public @NotNull PsiRecordHeaderStubImpl createStub(@NotNull PsiRecordHeader psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,36 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiRequiresStatement;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiRequiresStatementStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaRequiresStatementStubFactory implements LightStubElementFactory<PsiRequiresStatementStubImpl, PsiRequiresStatement> {
@Override
public @NotNull PsiRequiresStatementStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.MODULE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiRequiresStatementStubImpl(parentStub, refText);
}
@Override
public PsiRequiresStatement createPsi(@NotNull PsiRequiresStatementStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createRequiresStatement(stub);
}
@Override
public @NotNull PsiRequiresStatementStubImpl createStub(@NotNull PsiRequiresStatement psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,32 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiTypeParameterList;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterListStubImpl;
import com.intellij.psi.impl.source.tree.java.PsiTypeParameterListImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaTypeParameterListStubFactory implements LightStubElementFactory<PsiTypeParameterListStubImpl, PsiTypeParameterList> {
@Override
public @NotNull PsiTypeParameterListStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new PsiTypeParameterListStubImpl(parentStub);
}
@Override
public PsiTypeParameterList createPsi(@NotNull PsiTypeParameterListStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createTypeParameterList(stub);
}
@Override
public @NotNull PsiTypeParameterListStubImpl createStub(@NotNull PsiTypeParameterList psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,37 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiTypeParameter;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiTypeParameterStubImpl;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaTypeParameterStubFactory implements LightStubElementFactory<PsiTypeParameterStubImpl, PsiTypeParameter> {
@Override
public @NotNull PsiTypeParameterStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
final LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER);
final String name = RecordUtil.intern(tree.getCharTable(), id);
return new PsiTypeParameterStubImpl(parentStub, name);
}
@Override
public PsiTypeParameter createPsi(@NotNull PsiTypeParameterStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createTypeParameter(stub);
}
@Override
public @NotNull PsiTypeParameterStubImpl createStub(@NotNull PsiTypeParameter psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,36 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.PsiUsesStatement;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.impl.PsiUsesStatementStubImpl;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.JavaSourceUtil;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JavaUsesStatementStubFactory implements LightStubElementFactory<PsiUsesStatementStubImpl, PsiUsesStatement> {
@Override
public @NotNull PsiUsesStatementStubImpl createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, node, JavaElementType.JAVA_CODE_REFERENCE);
String refText = ref != null ? JavaSourceUtil.getReferenceText(tree, ref) : null;
return new PsiUsesStatementStubImpl(parentStub, refText);
}
@Override
public PsiUsesStatement createPsi(@NotNull PsiUsesStatementStubImpl stub) {
return JavaStubElementType.getFileStub(stub).getPsiFactory().createUsesStatement(stub);
}
@Override
public @NotNull PsiUsesStatementStubImpl createStub(@NotNull PsiUsesStatement psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
}
@@ -0,0 +1,147 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiLambdaExpression;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.java.stubs.FunctionalExpressionStub;
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.PsiLambdaExpressionImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public class LambdaExpressionStubFactory implements LightStubElementFactory<FunctionalExpressionStub<PsiLambdaExpression>, PsiLambdaExpression> {
@Override
public @NotNull FunctionalExpressionStub<PsiLambdaExpression> createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new FunctionalExpressionStub<>(parentStub, JavaStubElementTypes.LAMBDA_EXPRESSION, getPresentableText(tree, node));
}
@Override
public PsiLambdaExpression createPsi(@NotNull FunctionalExpressionStub<PsiLambdaExpression> stub) {
return new PsiLambdaExpressionImpl(stub);
}
@Override
public @NotNull FunctionalExpressionStub<PsiLambdaExpression> createStub(@NotNull PsiLambdaExpression psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
private static @NotNull String getPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr) {
LighterASTNode parameterList =
Objects.requireNonNull(LightTreeUtil.firstChildOfType(tree, funExpr, JavaStubElementTypes.PARAMETER_LIST));
return getLambdaPresentableText(tree, parameterList);
}
private static String getLambdaPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode parameterList) {
StringBuilder buf = new StringBuilder(parameterList.getEndOffset() - parameterList.getStartOffset());
formatParameterList(tree, parameterList, buf);
buf.append(" -> {...}");
return buf.toString();
}
private static void formatParameterList(@NotNull LighterAST tree, @NotNull LighterASTNode parameterList, StringBuilder buf) {
final List<LighterASTNode> children = tree.getChildren(parameterList);
boolean isFirstParameter = true;
boolean appendCloseBracket = false;
for (final LighterASTNode node : children) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaTokenType.LPARENTH) {
buf.append('(');
appendCloseBracket = true;
}
else if (tokenType == JavaStubElementTypes.PARAMETER) {
if (!isFirstParameter) {
buf.append(", ");
}
formatParameter(tree, node, buf);
if (isFirstParameter) {
isFirstParameter = false;
}
}
}
if (appendCloseBracket) buf.append(')');
}
private static void formatParameter(@NotNull LighterAST tree, @NotNull LighterASTNode parameter, StringBuilder buf) {
final List<LighterASTNode> children = tree.getChildren(parameter);
for (LighterASTNode node : children) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaElementType.TYPE) {
formatType(tree, node, buf);
buf.append(' ');
}
else if (tokenType == JavaTokenType.IDENTIFIER) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
}
}
}
private static void formatType(LighterAST tree, LighterASTNode typeElement, StringBuilder buf) {
for (LighterASTNode node : tree.getChildren(typeElement)) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaElementType.JAVA_CODE_REFERENCE) {
formatCodeReference(tree, node, buf);
}
else if (tokenType == JavaElementType.TYPE) {
formatType(tree, node, buf);
}
else if (tokenType == JavaTokenType.QUEST) {
buf.append("? ");
}
else if (ElementType.KEYWORD_BIT_SET.contains(tokenType)) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
if (!ElementType.PRIMITIVE_TYPE_BIT_SET.contains(tokenType)) {
buf.append(" ");
}
}
else if (tokenType == JavaTokenType.ELLIPSIS) {
buf.append("...");
}
else if (tokenType == JavaTokenType.RBRACKET) {
buf.append("]");
}
else if (tokenType == JavaTokenType.LBRACKET) {
buf.append("[");
}
}
}
private static void formatCodeReference(LighterAST tree, LighterASTNode codeRef, StringBuilder buf) {
for (LighterASTNode node : tree.getChildren(codeRef)) {
final IElementType tokenType = node.getTokenType();
if (tokenType == JavaTokenType.IDENTIFIER) {
buf.append(RecordUtil.intern(tree.getCharTable(), node));
}
else if (tokenType == JavaElementType.REFERENCE_PARAMETER_LIST) {
formatTypeParameters(tree, node, buf);
}
}
}
private static void formatTypeParameters(LighterAST tree, LighterASTNode typeParameters, StringBuilder buf) {
final List<LighterASTNode> children = LightTreeUtil.getChildrenOfType(tree, typeParameters, JavaElementType.TYPE);
if (children.isEmpty()) return;
buf.append('<');
for (int i = 0; i < children.size(); i++) {
LighterASTNode child = children.get(i);
formatType(tree, child, buf);
if (i != children.size() - 1) {
buf.append(", ");
}
}
buf.append('>');
}
}
@@ -0,0 +1,46 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.factories;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.psi.PsiMethodReferenceExpression;
import com.intellij.psi.impl.java.stubs.FunctionalExpressionStub;
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.impl.source.tree.LightTreeUtil;
import com.intellij.psi.impl.source.tree.java.PsiMethodReferenceExpressionImpl;
import com.intellij.psi.stubs.LightStubElementFactory;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class MethodReferenceStubFactory implements LightStubElementFactory<FunctionalExpressionStub<PsiMethodReferenceExpression>, PsiMethodReferenceExpression> {
//prevents cyclic static variables initialization
private static final NotNullLazyValue<TokenSet> EXCLUDE_FROM_PRESENTABLE_TEXT = NotNullLazyValue.lazy(() -> {
return TokenSet.orSet(ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET, TokenSet.create(JavaElementType.REFERENCE_PARAMETER_LIST));
});
@Override
public @NotNull FunctionalExpressionStub<PsiMethodReferenceExpression> createStub(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull StubElement<?> parentStub) {
return new FunctionalExpressionStub<>(parentStub, JavaStubElementTypes.METHOD_REF_EXPRESSION, getPresentableText(tree, node));
}
@Override
public PsiMethodReferenceExpression createPsi(@NotNull FunctionalExpressionStub<PsiMethodReferenceExpression> stub) {
return new PsiMethodReferenceExpressionImpl(stub);
}
@Override
public @NotNull FunctionalExpressionStub<PsiMethodReferenceExpression> createStub(@NotNull PsiMethodReferenceExpression psi, @Nullable StubElement parentStub) {
final String message =
"Should not be called. Element=" + psi + "; class" + psi.getClass() + "; file=" + (psi.isValid() ? psi.getContainingFile() : "-");
throw new UnsupportedOperationException(message);
}
private static @NotNull String getPresentableText(@NotNull LighterAST tree, @NotNull LighterASTNode funExpr) {
return LightTreeUtil.toFilteredString(tree, funExpr, EXCLUDE_FROM_PRESENTABLE_TEXT.getValue());
}
}
@@ -2,6 +2,7 @@
package com.intellij.psi.impl.java.stubs.impl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiAnnotation;
@@ -6,11 +6,13 @@ import com.intellij.psi.impl.cache.TypeAnnotationContainer;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.compiled.ClsJavaCodeReferenceElementImpl;
import com.intellij.psi.impl.java.stubs.JavaClassReferenceListElementType;
import com.intellij.psi.impl.java.stubs.JavaStubElementType;
import com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
@@ -21,7 +23,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
private final TypeInfo @NotNull [] myInfos;
private volatile PsiClassType [] myTypes;
public PsiClassReferenceListStubImpl(@NotNull JavaClassReferenceListElementType type, StubElement parent, String @NotNull [] names) {
public PsiClassReferenceListStubImpl(@NotNull IJavaElementType type, StubElement parent, String @NotNull [] names) {
this(type, parent, ContainerUtil.map2Array(
ContainerUtil.filter(names, PsiClassReferenceListStubImpl::isCorrectGenericSequence),
TypeInfo.class,
@@ -29,7 +31,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
);
}
public PsiClassReferenceListStubImpl(@NotNull JavaClassReferenceListElementType type, StubElement parent,
public PsiClassReferenceListStubImpl(@NotNull IJavaElementType type, StubElement parent,
TypeInfo @NotNull [] infos) {
super(parent, type);
for (TypeInfo info : infos) {
@@ -49,7 +51,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
}
private boolean shouldSkipSoleObject() {
final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
final boolean compiled = JavaStubElementType.isCompiled(this);
return compiled && myInfos.length == 1 && myInfos[0].getKind() == TypeInfo.TypeKind.JAVA_LANG_OBJECT &&
myInfos[0].getTypeAnnotations() == TypeAnnotationContainer.EMPTY;
}
@@ -57,7 +59,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
private PsiClassType @NotNull [] createTypes() {
PsiClassType[] types = myInfos.length == 0 ? PsiClassType.EMPTY_ARRAY : new PsiClassType[myInfos.length];
final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
final boolean compiled = JavaStubElementType.isCompiled(this);
if (compiled) {
if (shouldSkipSoleObject()) return PsiClassType.EMPTY_ARRAY;
for (int i = 0; i < types.length; i++) {
@@ -122,7 +124,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
@Override
public @NotNull PsiReferenceList.Role getRole() {
return JavaClassReferenceListElementType.elementTypeToRole(getStubType());
return JavaClassReferenceListElementType.elementTypeToRole(getElementType());
}
@Override
@@ -5,10 +5,10 @@ import com.intellij.extapi.psi.StubBasedPsiElementBase;
import com.intellij.psi.PsiClass;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaClassElementType;
import com.intellij.psi.impl.java.stubs.PsiClassStub;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.util.BitUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,7 +36,7 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
private final short myFlags;
private String mySourceFileName;
public PsiClassStubImpl(@NotNull JavaClassElementType type,
public PsiClassStubImpl(@NotNull IJavaElementType type,
StubElement parent,
@Nullable String qualifiedName,
@Nullable String name,
@@ -45,7 +45,7 @@ public class PsiClassStubImpl<T extends PsiClass> extends StubBase<T> implements
this(type, parent, TypeInfo.fromString(qualifiedName), name, baseRefText, flags);
}
public PsiClassStubImpl(@NotNull JavaClassElementType type,
public PsiClassStubImpl(@NotNull IJavaElementType type,
StubElement parent,
@NotNull TypeInfo typeInfo,
@Nullable String name,
@@ -9,7 +9,9 @@ import com.intellij.psi.PsiJavaModule;
import com.intellij.psi.impl.java.stubs.*;
import com.intellij.psi.stubs.PsiFileStubImpl;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
public class PsiJavaFileStubImpl extends PsiFileStubImpl<PsiJavaFile> implements PsiJavaFileStub {
@@ -32,6 +34,16 @@ public class PsiJavaFileStubImpl extends PsiFileStubImpl<PsiJavaFile> implements
@Override
public @NotNull IStubFileElementType<?> getType() {
throw new UnsupportedOperationException();
}
@Override
public IElementType getElementType() {
return JavaParserDefinition.JAVA_FILE;
}
@Override
public @NotNull IElementType getFileElementType() {
return JavaParserDefinition.JAVA_FILE;
}
@@ -42,7 +54,7 @@ public class PsiJavaFileStubImpl extends PsiFileStubImpl<PsiJavaFile> implements
@Override
public PsiJavaModule getModule() {
StubElement<PsiJavaModule> moduleStub = findChildStubByType(JavaStubElementTypes.MODULE);
@SuppressWarnings("SSBasedInspection") StubElement<PsiJavaModule> moduleStub = ObjectUtils.tryCast(findChildStubByElementType(JavaStubElementTypes.MODULE), StubElement.class);
return moduleStub != null ? moduleStub.getPsi() : null;
}
@@ -17,9 +17,9 @@ package com.intellij.psi.impl.java.stubs.impl;
import com.intellij.psi.PsiPackageAccessibilityStatement;
import com.intellij.psi.impl.java.stubs.PsiPackageAccessibilityStatementStub;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.java.IJavaElementType;
import java.util.Collections;
import java.util.List;
@@ -31,7 +31,7 @@ public class PsiPackageAccessibilityStatementStubImpl extends StubBase<PsiPackag
private final String myPackageName;
private final List<String> myTargets;
public PsiPackageAccessibilityStatementStubImpl(StubElement parent, IStubElementType type, String packageName, List<String> targets) {
public PsiPackageAccessibilityStatementStubImpl(StubElement parent, IJavaElementType type, String packageName, List<String> targets) {
super(parent, type);
myPackageName = notNull(packageName, "");
myTargets = targets == null || targets.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(targets);
@@ -50,7 +50,7 @@ public class PsiPackageAccessibilityStatementStubImpl extends StubBase<PsiPackag
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("PsiPackageAccessibilityStatementStub[").append(typeToRole(getStubType())).append("]:").append(myPackageName);
sb.append("PsiPackageAccessibilityStatementStub[").append(typeToRole(getElementType())).append("]:").append(myPackageName);
for (String target : myTargets) sb.append(':').append(target);
return sb.toString();
}
@@ -0,0 +1,35 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationParameterListStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
public class JavaAnnotationParameterListStubSerializer implements StubSerializer<PsiAnnotationParameterListStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaAnnotationParameterListStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiAnnotationParameterListStubImpl stub, @NotNull StubOutputStream dataStream) {
}
@Override
public @NotNull PsiAnnotationParameterListStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new PsiAnnotationParameterListStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiAnnotationParameterListStubImpl stub, @NotNull IndexSink sink) {
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,55 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.java.stubs.impl.PsiAnnotationStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaAnnotationStubSerializer implements StubSerializer<PsiAnnotationStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaAnnotationStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiAnnotationStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeUTFFast(stub.getText());
}
@Override
public @NotNull PsiAnnotationStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiAnnotationStubImpl(parentStub, dataStream.readUTFFast());
}
@Override
public void indexStub(@NotNull PsiAnnotationStubImpl stub, @NotNull IndexSink sink) {
String shortName = getReferenceShortName(stub.getText());
if (!StringUtil.isEmptyOrSpaces(shortName)) {
sink.occurrence(JavaStubIndexKeys.ANNOTATIONS, shortName);
}
}
private static String getReferenceShortName(String annotationText) {
int index = annotationText.indexOf('(');
if (index >= 0) annotationText = annotationText.substring(0, index);
return PsiNameHelper.getShortClassName(annotationText);
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,33 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiClassInitializerStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
public class JavaClassInitializerStubSerializer implements StubSerializer<PsiClassInitializerStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaClassInitializerStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiClassInitializerStubImpl stub, @NotNull StubOutputStream dataStream) {
// Empty stub - nothing to serialize
}
@Override
public @NotNull PsiClassInitializerStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new PsiClassInitializerStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiClassInitializerStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,81 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiReferenceList;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.PsiClassReferenceListStub;
import com.intellij.psi.impl.java.stubs.PsiClassStub;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.java.stubs.impl.PsiClassReferenceListStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaClassReferenceListStubSerializer implements StubSerializer<PsiClassReferenceListStub> {
@NotNull private final IJavaElementType myType;
public JavaClassReferenceListStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiClassReferenceListStub stub, @NotNull StubOutputStream dataStream) throws IOException {
TypeInfo[] types = stub.getTypes();
dataStream.writeVarInt(types.length);
for (TypeInfo info : types) {
TypeInfo.writeTYPE(dataStream, info);
}
}
@Override
public @NotNull PsiClassReferenceListStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
int len = dataStream.readVarInt();
TypeInfo[] infos = len == 0 ? TypeInfo.EMPTY_ARRAY : new TypeInfo[len];
for (int i = 0; i < infos.length; i++) {
infos[i] = TypeInfo.readTYPE(dataStream);
}
return new PsiClassReferenceListStubImpl(myType, parentStub, infos);
}
@Override
public void indexStub(@NotNull PsiClassReferenceListStub stub, @NotNull IndexSink sink) {
PsiReferenceList.Role role = stub.getRole();
if (role == PsiReferenceList.Role.EXTENDS_LIST || role == PsiReferenceList.Role.IMPLEMENTS_LIST) {
String[] names = stub.getReferencedNames();
for (String name : names) {
String shortName = PsiNameHelper.getShortClassName(name);
if (!StringUtil.isEmptyOrSpaces(shortName)) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, shortName);
}
}
if (role == PsiReferenceList.Role.EXTENDS_LIST) {
StubElement<?> parentStub = stub.getParentStub();
if (parentStub instanceof PsiClassStub) {
PsiClassStub<?> psiClassStub = (PsiClassStub<?>)parentStub;
if (psiClassStub.isEnum()) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, "Enum");
}
if (psiClassStub.isAnnotationType()) {
sink.occurrence(JavaStubIndexKeys.SUPER_CLASSES, "Annotation");
}
}
}
}
}
@Override
public boolean isAlwaysLeaf(@NotNull StubBase<?> root) {
return root instanceof PsiJavaFileStub && ((PsiJavaFileStub)root).isCompiled();
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,107 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.JavaClassElementType;
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
import com.intellij.psi.impl.java.stubs.PsiClassStub;
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
import com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.psi.util.JavaImplicitClassUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaClassStubSerializer implements StubSerializer<PsiClassStub<PsiClass>> {
@NotNull private final IJavaElementType myType;
public JavaClassStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiClassStub<PsiClass> stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeShort(((PsiClassStubImpl<?>)stub).getFlags());
if (!stub.isAnonymous()) {
String name = stub.getName();
TypeInfo info = ((PsiClassStubImpl<?>)stub).getQualifiedNameTypeInfo();
dataStream.writeName(info.getShortTypeText().equals(name) ? null : name);
TypeInfo.writeTYPE(dataStream, info);
dataStream.writeName(stub.getSourceFileName());
}
else {
dataStream.writeName(stub.getBaseClassReferenceText());
}
}
@Override
public @NotNull PsiClassStub<PsiClass> deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
short flags = dataStream.readShort();
boolean isAnonymous = PsiClassStubImpl.isAnonymous(flags);
boolean isEnumConst = PsiClassStubImpl.isEnumConstInitializer(flags);
boolean isImplicit = PsiClassStubImpl.isImplicit(flags);
JavaClassElementType type = typeForClass(isAnonymous, isEnumConst, isImplicit);
if (!isAnonymous) {
String name = dataStream.readNameString();
TypeInfo typeInfo = TypeInfo.readTYPE(dataStream);
if (name == null) {
name = typeInfo.getShortTypeText();
}
String sourceFileName = dataStream.readNameString();
PsiClassStubImpl<PsiClass> classStub = new PsiClassStubImpl<>(type, parentStub, typeInfo, name, null, flags);
classStub.setSourceFileName(sourceFileName);
return classStub;
}
else {
String baseRef = dataStream.readNameString();
return new PsiClassStubImpl<>(type, parentStub, TypeInfo.SimpleTypeInfo.NULL, null, baseRef, flags);
}
}
@Override
public void indexStub(@NotNull PsiClassStub<PsiClass> stub, @NotNull IndexSink sink) {
if (stub.isImplicit()) {
StubElement<?> parent = stub.getParentStub();
if (parent instanceof PsiJavaFileStub) {
sink.occurrence(JavaStubIndexKeys.IMPLICIT_CLASSES, JavaImplicitClassUtil.getJvmName(((PsiJavaFileStub)parent).getPsi().getName()));
}
return;
}
boolean isAnonymous = stub.isAnonymous();
if (isAnonymous) {
String baseRef = stub.getBaseClassReferenceText();
if (baseRef != null) {
sink.occurrence(JavaStubIndexKeys.ANONYMOUS_BASEREF, PsiNameHelper.getShortClassName(baseRef));
}
}
else {
final String shortName = stub.getName();
if (shortName != null && (!(stub instanceof PsiClassStubImpl) || !((PsiClassStubImpl<?>)stub).isAnonymousInner())) {
sink.occurrence(JavaStubIndexKeys.CLASS_SHORT_NAMES, shortName);
}
final String fqn = stub.getQualifiedName();
if (fqn != null) {
sink.occurrence(JavaStubIndexKeys.CLASS_FQN, fqn);
}
}
}
public static @NotNull JavaClassElementType typeForClass(final boolean anonymous, final boolean enumConst, final boolean implicitClass) {
return enumConst
? JavaStubElementTypes.ENUM_CONSTANT_INITIALIZER
: implicitClass ? JavaStubElementTypes.IMPLICIT_CLASS
: anonymous ? JavaStubElementTypes.ANONYMOUS_CLASS : JavaStubElementTypes.CLASS;
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,55 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.PsiFieldStub;
import com.intellij.psi.impl.java.stubs.impl.PsiFieldStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaFieldStubSerializer implements StubSerializer<PsiFieldStub> {
@NotNull private final IJavaElementType myType;
public JavaFieldStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiFieldStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getType());
dataStream.writeName(stub.getInitializerText());
dataStream.writeByte(((PsiFieldStubImpl)stub).getFlags());
}
@Override
public @NotNull PsiFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
TypeInfo type = TypeInfo.readTYPE(dataStream);
String initializerText = dataStream.readNameString();
byte flags = dataStream.readByte();
return new PsiFieldStubImpl(parentStub, name, type, initializerText, flags);
}
@Override
public void indexStub(@NotNull PsiFieldStub stub, @NotNull IndexSink sink) {
String name = stub.getName();
if (name != null) {
sink.occurrence(JavaStubIndexKeys.FIELDS, name);
if (RecordUtil.isStaticNonPrivateMember(stub)) {
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getType().getShortTypeText());
}
}
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,32 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiImportListStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
public class JavaImportListStubSerializer implements StubSerializer<PsiImportListStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaImportListStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiImportListStubImpl stub, @NotNull StubOutputStream dataStream) {
}
@Override
public @NotNull PsiImportListStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new PsiImportListStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiImportListStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,40 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.PsiImportStatementStub;
import com.intellij.psi.impl.java.stubs.impl.PsiImportStatementStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaImportStatementStubSerializer implements StubSerializer<PsiImportStatementStub> {
@NotNull private final IJavaElementType myType;
public JavaImportStatementStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiImportStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeByte(((PsiImportStatementStubImpl)stub).getFlags());
dataStream.writeName(stub.getImportReferenceText());
}
@Override
public @NotNull PsiImportStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
byte flags = dataStream.readByte();
String refText = dataStream.readNameString();
return new PsiImportStatementStubImpl(parentStub, refText, flags);
}
@Override
public void indexStub(@NotNull PsiImportStatementStub stub, @NotNull IndexSink sink) {
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,35 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiLiteralStub;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaLiteralExpressionStubSerializer implements StubSerializer<PsiLiteralStub> {
@NotNull private final IJavaElementType myType;
public JavaLiteralExpressionStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiLiteralStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeUTFFast(stub.getLiteralText());
}
@Override
public @NotNull PsiLiteralStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiLiteralStub(parentStub, dataStream.readUTFFast());
}
@Override
public void indexStub(@NotNull PsiLiteralStub stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,129 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiTypeParameterList;
import com.intellij.psi.impl.cache.ModifierFlags;
import com.intellij.psi.impl.cache.RecordUtil;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.*;
import com.intellij.psi.impl.java.stubs.impl.PsiMethodStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.BitUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class JavaMethodStubSerializer implements StubSerializer<PsiMethodStub> {
@NotNull private final IJavaElementType myType;
public JavaMethodStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiMethodStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getReturnTypeText());
dataStream.writeByte(((PsiMethodStubImpl)stub).getFlags());
if (stub.isAnnotationMethod()) {
dataStream.writeName(stub.getDefaultValueText());
}
}
@Override
public @NotNull PsiMethodStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
final TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
String defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readNameString() : null;
return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue);
}
@Override
public void indexStub(@NotNull PsiMethodStub stub, @NotNull IndexSink sink) {
final String name = stub.getName();
if (name != null) {
sink.occurrence(JavaStubIndexKeys.METHODS, name);
if (RecordUtil.isStaticNonPrivateMember(stub)) {
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_NAMES, name);
sink.occurrence(JavaStubIndexKeys.JVM_STATIC_MEMBERS_TYPES, stub.getReturnTypeText().getShortTypeText());
}
}
Set<String> methodTypeParams = getVisibleTypeParameters(stub);
for (StubElement<?> stubElement : stub.getChildrenStubs()) {
if (stubElement instanceof PsiParameterListStub) {
for (StubElement<?> paramStub : stubElement.getChildrenStubs()) {
if (paramStub instanceof PsiParameterStub) {
TypeInfo type = ((PsiParameterStub)paramStub).getType();
String typeName = PsiNameHelper.getShortClassName(type.text());
if (TypeConversionUtil.isPrimitive(typeName) || TypeConversionUtil.isPrimitiveWrapper(typeName)) continue;
if (!methodTypeParams.contains(typeName)) {
sink.occurrence(JavaStubIndexKeys.METHOD_TYPES, typeName);
}
}
}
break;
}
}
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
private static @NotNull Set<String> getVisibleTypeParameters(@NotNull StubElement<?> stub) {
Set<String> result = null;
while (stub != null) {
Set<String> names = getOwnTypeParameterNames(stub);
if (!names.isEmpty()) {
if (result == null) result = new HashSet<>();
result.addAll(names);
}
if (isStatic(stub)) break;
stub = stub.getParentStub();
}
return result == null ? Collections.emptySet() : result;
}
private static boolean isStatic(@NotNull StubElement<?> stub) {
if (stub instanceof PsiMemberStub) {
StubElement<PsiModifierList> modList =
(StubElement<PsiModifierList>)stub.findChildStubByElementType(JavaStubElementTypes.MODIFIER_LIST);
if (modList != null) {
return BitUtil.isSet(((PsiModifierListStub)modList).getModifiersMask(),
ModifierFlags.NAME_TO_MODIFIER_FLAG_MAP.getInt(PsiModifier.STATIC));
}
}
return false;
}
private static Set<String> getOwnTypeParameterNames(StubElement<?> stubElement) {
StubElement<PsiTypeParameterList> typeParamList =
(StubElement<PsiTypeParameterList>)stubElement.findChildStubByElementType(JavaStubElementTypes.TYPE_PARAMETER_LIST);
if (typeParamList == null) return Collections.emptySet();
Set<String> methodTypeParams = null;
List<StubElement<?>> children = typeParamList.getChildrenStubs();
for (StubElement<?> child : children) {
if (child instanceof PsiTypeParameterStub) {
if (methodTypeParams == null) methodTypeParams = new HashSet<>();
methodTypeParams.add(((PsiTypeParameterStub)child).getName());
}
}
return methodTypeParams == null ? Collections.emptySet() : methodTypeParams;
}
}
@@ -0,0 +1,35 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiModifierListStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaModifierListSerializer implements StubSerializer<PsiModifierListStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaModifierListSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiModifierListStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeVarInt(stub.getModifiersMask());
}
@Override
public @NotNull PsiModifierListStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiModifierListStubImpl(parentStub, dataStream.readVarInt());
}
@Override
public void indexStub(@NotNull PsiModifierListStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,39 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiJavaModuleStubImpl;
import com.intellij.psi.impl.java.stubs.index.JavaStubIndexKeys;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaModuleStubSerializer implements StubSerializer<PsiJavaModuleStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaModuleStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiJavaModuleStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
dataStream.writeVarInt(stub.getResolution());
}
@Override
public @NotNull PsiJavaModuleStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new PsiJavaModuleStubImpl(parentStub, dataStream.readNameString(), dataStream.readVarInt());
}
@Override
public void indexStub(@NotNull PsiJavaModuleStubImpl stub, @NotNull IndexSink sink) {
sink.occurrence(JavaStubIndexKeys.MODULE_NAMES, stub.getName());
}
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,44 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiNameValuePairStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaNameValuePairStubSerializer implements StubSerializer<PsiNameValuePairStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaNameValuePairStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiNameValuePairStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
String value = stub.getValue();
boolean hasValue = value != null;
dataStream.writeBoolean(hasValue);
if (hasValue) {
dataStream.writeUTFFast(value);
}
}
@Override
public @NotNull PsiNameValuePairStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
boolean hasValue = dataStream.readBoolean();
return new PsiNameValuePairStubImpl(parentStub, name, hasValue ? dataStream.readUTFFast() : null);
}
@Override
public void indexStub(@NotNull PsiNameValuePairStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,40 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.impl.java.stubs.impl.PsiPackageAccessibilityStatementStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.List;
public class JavaPackageAccessibilityStatementStubSerializer implements StubSerializer<PsiPackageAccessibilityStatementStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaPackageAccessibilityStatementStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiPackageAccessibilityStatementStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getPackageName());
dataStream.writeUTFFast(StringUtil.join(stub.getTargets(), "/"));
}
@Override
public @NotNull PsiPackageAccessibilityStatementStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String packageName = dataStream.readNameString();
List<String> targets = StringUtil.split(dataStream.readUTFFast(), "/");
return new PsiPackageAccessibilityStatementStubImpl(parentStub, myType, packageName, targets);
}
@Override
public void indexStub(@NotNull PsiPackageAccessibilityStatementStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,32 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterListStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
public class JavaParameterListStubSerializer implements StubSerializer<PsiParameterListStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaParameterListStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiParameterListStubImpl stub, @NotNull StubOutputStream dataStream) {
}
@Override
public @NotNull PsiParameterListStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new PsiParameterListStubImpl(parentStub);
}
@Override
public void indexStub(@NotNull PsiParameterListStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}
@@ -0,0 +1,42 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.impl.java.stubs.serializers;
import com.intellij.psi.impl.cache.TypeInfo;
import com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl;
import com.intellij.psi.stubs.*;
import com.intellij.psi.tree.java.IJavaElementType;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class JavaParameterStubSerializer implements StubSerializer<PsiParameterStubImpl> {
@NotNull private final IJavaElementType myType;
public JavaParameterStubSerializer(@NotNull IJavaElementType elementType) {
myType = elementType;
}
@Override
public void serialize(@NotNull PsiParameterStubImpl stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
TypeInfo.writeTYPE(dataStream, stub.getType());
dataStream.writeByte(stub.getFlags());
}
@Override
public @NotNull PsiParameterStubImpl deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
String name = dataStream.readNameString();
if (name == null) throw new IOException("corrupted indices");
TypeInfo type = TypeInfo.readTYPE(dataStream);
byte flags = dataStream.readByte();
return new PsiParameterStubImpl(parentStub, name, type, flags);
}
@Override
public void indexStub(@NotNull PsiParameterStubImpl stub, @NotNull IndexSink sink) { }
@Override
public @NotNull String getExternalId() {
return "java." + myType;
}
}

Some files were not shown because too many files have changed in this diff Show More