mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no staticness distinction in stub hierarchy
This commit is contained in:
@@ -19,11 +19,9 @@ import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiNameHelper;
|
||||
import com.intellij.psi.PsiReferenceList;
|
||||
import com.intellij.psi.compiled.ClassFileDecompilers;
|
||||
import com.intellij.psi.impl.cache.ModifierFlags;
|
||||
import com.intellij.psi.impl.java.stubs.*;
|
||||
import com.intellij.psi.impl.java.stubs.hierarchy.IndexTree;
|
||||
import com.intellij.psi.impl.java.stubs.hierarchy.IndexTree.*;
|
||||
@@ -35,6 +33,7 @@ import com.intellij.psi.stubs.StubTree;
|
||||
import com.intellij.psi.stubs.StubTreeBuilder;
|
||||
import com.intellij.psi.stubsHierarchy.StubHierarchyIndexer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.indexing.FileContent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -154,18 +153,8 @@ public class JavaStubIndexer extends StubHierarchyIndexer {
|
||||
|
||||
private static int translateFlags(PsiClassStubImpl<?> classStub, int accessModifiers) {
|
||||
int flags = 0;
|
||||
if (classStub.isInterface()) {
|
||||
flags |= IndexTree.INTERFACE;
|
||||
}
|
||||
if (classStub.isEnum()) {
|
||||
flags |= IndexTree.ENUM;
|
||||
}
|
||||
if (classStub.isAnnotationType()) {
|
||||
flags |= IndexTree.ANNOTATION;
|
||||
}
|
||||
if (ModifierFlags.hasModifierProperty(PsiModifier.STATIC, accessModifiers)) {
|
||||
flags |= IndexTree.STATIC;
|
||||
}
|
||||
flags = BitUtil.set(flags, IndexTree.ENUM, classStub.isEnum());
|
||||
flags = BitUtil.set(flags, IndexTree.ANNOTATION, classStub.isAnnotationType());
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,11 +101,6 @@ public class StubEnter {
|
||||
|
||||
private static int checkFlags(long flags, Symbol owner, boolean compiled) {
|
||||
int mask = 0;
|
||||
if (owner.isClass() && (owner.myOwner.isPackage() || owner.isStatic())) {
|
||||
if ((flags & (IndexTree.INTERFACE | IndexTree.ENUM | IndexTree.STATIC)) != 0) {
|
||||
mask |= IndexTree.STATIC;
|
||||
}
|
||||
}
|
||||
if ((flags & IndexTree.SUPERS_UNRESOLVED) != 0) {
|
||||
mask |= IndexTree.SUPERS_UNRESOLVED;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class StubHierarchyIndex extends FileBasedIndexExtension<Integer, Seriali
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return IndexTree.STUB_HIERARCHY_ENABLED ? 6 + Arrays.stream(ourIndexers).mapToInt(StubHierarchyIndexer::getVersion).sum() : 0;
|
||||
return IndexTree.STUB_HIERARCHY_ENABLED ? 7 + Arrays.stream(ourIndexers).mapToInt(StubHierarchyIndexer::getVersion).sum() : 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -100,18 +100,17 @@ public class StubResolver {
|
||||
|
||||
private void findMemberType(Symbol s, @ShortName int name, Set<Symbol> symbols) throws IncompleteHierarchyException {
|
||||
if (s.isClass()) {
|
||||
processInheritedMembers((Symbol.ClassSymbol)s, name, false, symbols, null);
|
||||
processInheritedMembers((Symbol.ClassSymbol)s, name, symbols, null);
|
||||
} else {
|
||||
processMembers(s.getMembers(), name, symbols, false);
|
||||
processMembers(s.getMembers(), name, symbols);
|
||||
}
|
||||
}
|
||||
|
||||
private void processInheritedMembers(Symbol.ClassSymbol s,
|
||||
@ShortName int name,
|
||||
boolean requireStatic,
|
||||
Set<Symbol> symbols,
|
||||
@Nullable Set<Symbol> processed) throws IncompleteHierarchyException {
|
||||
processMembers(s.getMembers(), name, symbols, requireStatic);
|
||||
processMembers(s.getMembers(), name, symbols);
|
||||
|
||||
@CompactArray(Symbol.ClassSymbol.class) Object supers = s.getSuperClasses(myConnector);
|
||||
if (supers == null) return;
|
||||
@@ -120,10 +119,10 @@ public class StubResolver {
|
||||
if (!processed.add(s)) return;
|
||||
|
||||
if (supers instanceof Symbol.ClassSymbol) {
|
||||
processInheritedMembers((Symbol.ClassSymbol)supers, name, requireStatic, symbols, processed);
|
||||
processInheritedMembers((Symbol.ClassSymbol)supers, name, symbols, processed);
|
||||
} else if (supers instanceof Symbol.ClassSymbol[]) {
|
||||
for (Symbol.ClassSymbol st : (Symbol.ClassSymbol[])supers) {
|
||||
processInheritedMembers(st, name, requireStatic, symbols, processed);
|
||||
processInheritedMembers(st, name, symbols, processed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,34 +179,25 @@ public class StubResolver {
|
||||
|
||||
// handling of import static `tsym.name` as
|
||||
private void importNamedStatic(final Symbol.ClassSymbol tsym, @ShortName final int name, final Set<Symbol> symbols) throws IncompleteHierarchyException {
|
||||
processInheritedMembers(tsym, name, true, symbols, null);
|
||||
processInheritedMembers(tsym, name, symbols, null);
|
||||
}
|
||||
|
||||
private static void processMembers(Symbol.ClassSymbol[] members, @ShortName int name, Set<Symbol> symbols, boolean requireStatic) {
|
||||
private static void processMembers(Symbol.ClassSymbol[] members, @ShortName int name, Set<Symbol> symbols) {
|
||||
int index = getIndex(name, members);
|
||||
if (index < 0) return;
|
||||
|
||||
// elem
|
||||
Symbol.ClassSymbol member = members[index];
|
||||
if (!requireStatic || member.isStatic()) {
|
||||
symbols.add(member);
|
||||
}
|
||||
symbols.add(members[index]);
|
||||
// on the left
|
||||
int i = index - 1;
|
||||
while (i >= 0 && members[i].myShortName == name) {
|
||||
member = members[i];
|
||||
if (!requireStatic || member.isStatic()) {
|
||||
symbols.add(member);
|
||||
}
|
||||
symbols.add(members[i]);
|
||||
i--;
|
||||
}
|
||||
// on the right
|
||||
i = index + 1;
|
||||
while (i < members.length && members[i].myShortName == name) {
|
||||
member = members[i];
|
||||
if (!requireStatic || member.isStatic()) {
|
||||
symbols.add(member);
|
||||
}
|
||||
symbols.add(members[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.*;
|
||||
* Java symbols needed for hierarchy building. Mostly classes ({@link ClassSymbol}) or packages ({@link PackageSymbol}),
|
||||
* but other {@link MemberSymbol}s are also sometimes needed for working with anonymous or local classes.
|
||||
*/
|
||||
public abstract class Symbol {
|
||||
abstract class Symbol {
|
||||
public int myFlags;
|
||||
public int myShortName;
|
||||
public final Symbol myOwner;
|
||||
@@ -47,10 +47,6 @@ public abstract class Symbol {
|
||||
return ClassSymbol.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return BitUtil.isSet(myFlags, IndexTree.STATIC);
|
||||
}
|
||||
|
||||
public boolean isPackage() {
|
||||
return BitUtil.isSet(myFlags, IndexTree.PACKAGE);
|
||||
}
|
||||
|
||||
@@ -29,11 +29,8 @@ import java.util.List;
|
||||
public class IndexTree {
|
||||
public static final boolean STUB_HIERARCHY_ENABLED = Registry.is("java.hierarchy.service");
|
||||
|
||||
@SuppressWarnings("PointlessBitwiseExpression")
|
||||
public final static int PACKAGE = 1 << 0;
|
||||
public final static int PACKAGE = 1;
|
||||
public final static int CLASS = 1 << 1;
|
||||
public static final int STATIC = 1 << 3;
|
||||
public static final int INTERFACE = 1 << 4;
|
||||
public static final int ANNOTATION = 1 << 5;
|
||||
public static final int ENUM = 1 << 6;
|
||||
public static final int COMPILED = 1 << 7;
|
||||
@@ -45,14 +42,14 @@ public class IndexTree {
|
||||
public static final byte GROOVY = 2;
|
||||
|
||||
public static int hashIdentifier(@Nullable String s) {
|
||||
if (s == null) return 0;
|
||||
if (StringUtil.isEmpty(s)) return 0;
|
||||
|
||||
// not using String.hashCode because this way there's less collisions for short package names like 'com'
|
||||
int hash = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
hash = hash * 239 + s.charAt(i);
|
||||
}
|
||||
return hash;
|
||||
return hash == 0 ? 1 : hash;
|
||||
}
|
||||
|
||||
public static int[] hashQualifiedName(@NotNull String qName) {
|
||||
|
||||
+7
-13
@@ -26,6 +26,7 @@ import com.intellij.psi.stubs.StubTree;
|
||||
import com.intellij.psi.stubs.StubTreeBuilder;
|
||||
import com.intellij.psi.stubsHierarchy.StubHierarchyIndexer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.FileContent;
|
||||
import com.intellij.util.indexing.FileContentImpl;
|
||||
@@ -38,7 +39,10 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrStubFileElementType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class GrStubIndexer extends StubHierarchyIndexer {
|
||||
@Override
|
||||
@@ -152,18 +156,8 @@ public class GrStubIndexer extends StubHierarchyIndexer {
|
||||
|
||||
private static int translateFlags(GrTypeDefinitionStub classStub) {
|
||||
int flags = 0;
|
||||
if (classStub.isInterface()) {
|
||||
flags |= IndexTree.INTERFACE;
|
||||
}
|
||||
if (classStub.isEnum()) {
|
||||
flags |= IndexTree.ENUM;
|
||||
}
|
||||
if (classStub.isAnnotationType()) {
|
||||
flags |= IndexTree.ANNOTATION;
|
||||
}
|
||||
if (GrStubUtils.isGroovyStaticMemberStub(classStub)) {
|
||||
flags |= IndexTree.STATIC;
|
||||
}
|
||||
flags = BitUtil.set(flags, IndexTree.ENUM, classStub.isEnum());
|
||||
flags = BitUtil.set(flags, IndexTree.ANNOTATION, classStub.isAnnotationType());
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user