encapsulate ObjectStubBase.id

This commit is contained in:
peter
2018-03-02 11:41:53 +01:00
parent 0e1d64ce77
commit 17d63eb321
6 changed files with 22 additions and 5 deletions
@@ -139,7 +139,7 @@ public class JavaStubIndexer extends StubHierarchyIndexer {
}
String[] supers = superList.isEmpty() ? ArrayUtil.EMPTY_STRING_ARRAY : ArrayUtil.toStringArray(superList);
Decl[] inners = innerList.isEmpty() ? Decl.EMPTY_ARRAY : innerList.toArray(Decl.EMPTY_ARRAY);
return new ClassDecl(classStub.id, flags, classStub.getName(), supers, inners);
return new ClassDecl(classStub.getStubId(), flags, classStub.getName(), supers, inners);
}
private static int translateFlags(PsiClassStubImpl<?> classStub) {
@@ -27,7 +27,7 @@ public abstract class ObjectStubBase<T extends Stub> extends UserDataHolderBase
private static final Key<Boolean> DANGLING_STUB = Key.create("DIRECT_PARENT_IS_STUBBED");
protected final T myParent;
public int id;
int id;
public ObjectStubBase(T parent) {
myParent = parent;
@@ -52,4 +52,11 @@ public abstract class ObjectStubBase<T extends Stub> extends UserDataHolderBase
public void markDangling() {
putUserData(DANGLING_STUB, true);
}
/**
* @return the index of this stub in {@code ObjectStubTree#getPlainList}.
*/
public int getStubId() {
return id;
}
}
@@ -227,4 +227,14 @@ public abstract class StubBase<T extends PsiElement> extends ObjectStubBase<Stub
public String toString() {
return getClass().getSimpleName();
}
/**
* @return comparison result (as in {@link Comparable}) of this stub with {@code another},
* where "a<b" means that "a" occurs before "b" in the deep-first traversal of the stub tree,
* and the same holds for their AST equivalents.
*/
public int compareByOrderWith(ObjectStubBase<?> another) {
return Integer.compare(getStubId(), another.getStubId());
}
}
@@ -160,7 +160,7 @@ public abstract class PsiAnchor {
StubElement liveStub = psi instanceof StubBasedPsiElementBase ? ((StubBasedPsiElementBase)psi).getGreenStub() : psi.getStub();
if (liveStub != null) {
return ((StubBase)liveStub).id;
return ((StubBase)liveStub).getStubId();
}
return ((PsiFileImpl)psi.getContainingFile()).calcTreeElement().getStubbedSpine().getStubIndex(psi);
@@ -151,7 +151,7 @@ public class GrStubIndexer extends StubHierarchyIndexer {
}
String[] supers = superList.isEmpty() ? ArrayUtil.EMPTY_STRING_ARRAY : ArrayUtil.toStringArray(superList);
Decl[] inners = innerList.isEmpty() ? Decl.EMPTY_ARRAY : innerList.toArray(Decl.EMPTY_ARRAY);
return new ClassDecl(classStub.id, flags, classStub.getName(), supers, inners);
return new ClassDecl(classStub.getStubId(), flags, classStub.getName(), supers, inners);
}
private static int translateFlags(GrTypeDefinitionStub classStub) {
@@ -115,7 +115,7 @@ public class CollectionElementInvocationHandler extends DomInvocationHandler<Abs
public int hashCode() {
ElementStub stub = getStub();
if (stub != null) {
return stub.getName().hashCode() + stub.id;
return stub.getName().hashCode() + stub.getStubId();
}
final XmlElement element = getXmlElement();
return element == null ? super.hashCode() : element.hashCode();