use of com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl in project intellij-community by JetBrains.
the class JavaStubIndexer method indexFile.
@Nullable
@Override
public Unit indexFile(@NotNull FileContent content) {
Stub stubTree = StubTreeBuilder.buildStubTree(content);
if (!(stubTree instanceof PsiJavaFileStub))
return null;
PsiJavaFileStub javaFileStub = (PsiJavaFileStub) stubTree;
new StubTree(javaFileStub, false);
List<ClassDecl> classList = new ArrayList<>();
Set<String> usedNames = new HashSet<>();
for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
if (el instanceof PsiClassStubImpl) {
classList.add(processClassDecl((PsiClassStubImpl<?>) el, usedNames));
}
}
List<IndexTree.Import> importList = new ArrayList<>();
for (StubElement<?> el : javaFileStub.getChildrenStubs()) {
if (el instanceof PsiImportListStub) {
processImport((PsiImportListStub) el, importList, usedNames);
}
}
ClassDecl[] classes = classList.isEmpty() ? ClassDecl.EMPTY_ARRAY : classList.toArray(new ClassDecl[classList.size()]);
IndexTree.Import[] imports = importList.isEmpty() ? IndexTree.Import.EMPTY_ARRAY : importList.toArray(new IndexTree.Import[importList.size()]);
byte type = javaFileStub.isCompiled() ? IndexTree.BYTECODE : IndexTree.JAVA;
return new Unit(javaFileStub.getPackageName(), type, imports, classes);
}
use of com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl in project intellij-community by JetBrains.
the class JavaClassElementType method deserialize.
@NotNull
@Override
public PsiClassStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
byte flags = dataStream.readByte();
boolean isAnonymous = PsiClassStubImpl.isAnonymous(flags);
boolean isEnumConst = PsiClassStubImpl.isEnumConstInitializer(flags);
JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
if (!isAnonymous) {
StringRef name = dataStream.readName();
StringRef qname = dataStream.readName();
StringRef sourceFileName = dataStream.readName();
PsiClassStubImpl classStub = new PsiClassStubImpl(type, parentStub, StringRef.toString(qname), StringRef.toString(name), null, flags);
classStub.setSourceFileName(StringRef.toString(sourceFileName));
return classStub;
} else {
StringRef baseRef = dataStream.readName();
return new PsiClassStubImpl(type, parentStub, null, null, StringRef.toString(baseRef), flags);
}
}
use of com.intellij.psi.impl.java.stubs.impl.PsiClassStubImpl in project intellij-community by JetBrains.
the class JavaClassElementType method createStub.
@Override
public PsiClassStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
boolean isDeprecatedByComment = false;
boolean isInterface = false;
boolean isEnum = false;
boolean isEnumConst = false;
boolean isAnonymous = false;
boolean isAnnotation = false;
boolean isInQualifiedNew = false;
boolean hasDeprecatedAnnotation = false;
String qualifiedName = null;
String name = null;
String baseRef = null;
if (node.getTokenType() == JavaElementType.ANONYMOUS_CLASS) {
isAnonymous = true;
} else if (node.getTokenType() == JavaElementType.ENUM_CONSTANT_INITIALIZER) {
isAnonymous = isEnumConst = true;
baseRef = ((PsiClassStub) parentStub.getParentStub()).getName();
}
for (final LighterASTNode child : tree.getChildren(node)) {
final IElementType type = child.getTokenType();
if (type == JavaDocElementType.DOC_COMMENT) {
isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
} else if (type == JavaElementType.MODIFIER_LIST) {
hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
} else if (type == JavaTokenType.AT) {
isAnnotation = true;
} else if (type == JavaTokenType.INTERFACE_KEYWORD) {
isInterface = true;
} else if (type == JavaTokenType.ENUM_KEYWORD) {
isEnum = 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);
}
}
final byte flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation, isInQualifiedNew, hasDeprecatedAnnotation);
final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
return new PsiClassStubImpl(type, parentStub, qualifiedName, name, baseRef, flags);
}
Aggregations