Add local class/object declarations to super name index

This commit is contained in:
Alexey Sedunov
2013-11-08 18:01:21 +04:00
parent 72c7399df1
commit 594c966c44
9 changed files with 128 additions and 50 deletions
@@ -1008,8 +1008,10 @@ public class JetPsiUtil {
}
//noinspection unchecked
JetElement container =
PsiTreeUtil.getParentOfType(declaration, JetBlockExpression.class, JetClassInitializer.class);
JetElement container = PsiTreeUtil.getParentOfType(
declaration,
JetBlockExpression.class, JetClassInitializer.class, JetProperty.class, JetFunction.class
);
if (container == null) return null;
return (container instanceof JetClassInitializer) ? ((JetClassInitializer) container).getBody() : container;
@@ -22,6 +22,8 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject;
import java.util.List;
public interface PsiJetClassOrObjectStub<T extends JetClassOrObject> extends PsiJetStubWithFqName<T> {
boolean isLocal();
@NotNull
List<String> getSuperNames();
}
@@ -50,13 +50,29 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
return node.getElementType() != JetStubElementTypes.ENUM_ENTRY ? new JetClass(node) : new JetEnumEntry(node);
}
@Override
public boolean shouldCreateStub(ASTNode node) {
return true;
}
@Override
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
FqName fqName = JetPsiUtil.getFQName(psi);
boolean isEnumEntry = psi instanceof JetEnumEntry;
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
return new PsiJetClassStubImpl(getStubType(isEnumEntry), parentStub, fqName != null ? fqName.asString() : null, psi.getName(),
superNames, psi.isTrait(), psi.isEnum(), isEnumEntry, psi.isAnnotation(), psi.isInner());
return new PsiJetClassStubImpl(
getStubType(isEnumEntry),
parentStub,
fqName != null ? fqName.asString() : null,
psi.getName(),
superNames,
psi.isTrait(),
psi.isEnum(),
isEnumEntry,
psi.isAnnotation(),
psi.isInner(),
JetPsiUtil.isLocal(psi)
);
}
@Override
@@ -69,6 +85,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
dataStream.writeBoolean(stub.isEnumEntry());
dataStream.writeBoolean(stub.isAnnotation());
dataStream.writeBoolean(stub.isInner());
dataStream.writeBoolean(stub.isLocal());
List<String> superNames = stub.getSuperNames();
dataStream.writeVarInt(superNames.size());
@@ -87,6 +104,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
boolean isEnumEntry = dataStream.readBoolean();
boolean isAnnotation = dataStream.readBoolean();
boolean isInner = dataStream.readBoolean();
boolean isLocal = dataStream.readBoolean();
int superCount = dataStream.readVarInt();
StringRef[] superNames = StringRef.createArray(superCount);
@@ -95,7 +113,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
}
return new PsiJetClassStubImpl(getStubType(isEnumEntry), parentStub, qualifiedName, name, superNames,
isTrait, isEnumClass, isEnumEntry, isAnnotation, isInner);
isTrait, isEnumClass, isEnumEntry, isAnnotation, isInner, isLocal);
}
@Override
@@ -36,7 +36,7 @@ import org.jetbrains.jet.plugin.JetLanguage;
import java.io.IOException;
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
public static final int STUB_VERSION = 25;
public static final int STUB_VERSION = 26;
public JetFileElementType() {
super("jet.FILE", JetLanguage.INSTANCE);
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.psi.stubs.elements;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
@@ -27,6 +26,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetClassObject;
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetObjectStubImpl;
@@ -52,15 +52,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
@Override
public boolean shouldCreateStub(ASTNode node) {
if (super.shouldCreateStub(node)) {
PsiElement psiElement = node.getPsi();
if (psiElement instanceof JetObjectDeclaration) {
JetObjectDeclaration objectDeclaration = (JetObjectDeclaration) psiElement;
return objectDeclaration.getName() != null || isClassObject(objectDeclaration);
}
}
return false;
return true;
}
@Override
@@ -69,7 +61,14 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
FqName fqName = psi.getFqName();
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
return new PsiJetObjectStubImpl(
JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName, superNames, psi.isTopLevel(), isClassObject(psi)
JetStubElementTypes.OBJECT_DECLARATION,
parentStub,
name,
fqName,
superNames,
psi.isTopLevel(),
isClassObject(psi),
JetPsiUtil.isLocal(psi)
);
}
@@ -82,6 +81,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
dataStream.writeBoolean(stub.isTopLevel());
dataStream.writeBoolean(stub.isClassObject());
dataStream.writeBoolean(stub.isLocal());
List<String> superNames = stub.getSuperNames();
dataStream.writeVarInt(superNames.size());
@@ -99,6 +99,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
boolean isTopLevel = dataStream.readBoolean();
boolean isClassObject = dataStream.readBoolean();
boolean isLocal = dataStream.readBoolean();
int superCount = dataStream.readVarInt();
StringRef[] superNames = StringRef.createArray(superCount);
@@ -106,7 +107,9 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
superNames[i] = dataStream.readName();
}
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName, superNames, isTopLevel, isClassObject);
return new PsiJetObjectStubImpl(
JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName, superNames, isTopLevel, isClassObject, isLocal
);
}
@Override
@@ -40,6 +40,7 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
private final boolean isEnumEntry;
private final boolean isAnnotation;
private final boolean isInner;
private final boolean isLocal;
public PsiJetClassStubImpl(
JetClassElementType type,
@@ -47,9 +48,9 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
@Nullable String qualifiedName,
String name,
List<String> superNames,
boolean isTrait, boolean isEnumClass, boolean isEnumEntry, boolean isAnnotation, boolean isInner) {
boolean isTrait, boolean isEnumClass, boolean isEnumEntry, boolean isAnnotation, boolean isInner, boolean isLocal) {
this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames),
isTrait, isEnumClass, isEnumEntry, isAnnotation, isInner);
isTrait, isEnumClass, isEnumEntry, isAnnotation, isInner, isLocal);
}
public PsiJetClassStubImpl(
@@ -62,7 +63,8 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
boolean isEnumClass,
boolean isEnumEntry,
boolean isAnnotation,
boolean isInner) {
boolean isInner,
boolean isLocal) {
super(parent, type);
this.qualifiedName = qualifiedName;
this.name = name;
@@ -72,6 +74,7 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
this.isEnumEntry = isEnumEntry;
this.isAnnotation = isAnnotation;
this.isInner = isInner;
this.isLocal = isLocal;
}
private static StringRef[] wrapStrings(List<String> names) {
@@ -116,6 +119,11 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
return isInner;
}
@Override
public boolean isLocal() {
return isLocal;
}
@Override
public String getName() {
return StringRef.toString(name);
@@ -156,6 +164,10 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
builder.append("inner ");
}
if (isLocal()) {
builder.append("local ");
}
builder.append("name=").append(getName());
builder.append(" fqn=").append(getFqName());
builder.append(" superNames=").append("[").append(StringUtil.join(ArrayUtil.toStringArray(getSuperNames()))).append("]");
@@ -37,6 +37,7 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
private final StringRef[] superNames;
private final boolean isTopLevel;
private final boolean isClassObject;
private final boolean isLocal;
public PsiJetObjectStubImpl(
@NotNull IStubElementType elementType,
@@ -45,9 +46,10 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
@Nullable FqName fqName,
@NotNull List<String> superNames,
boolean isTopLevel,
boolean isClassObject
boolean isClassObject,
boolean isLocal
) {
this(elementType, parent, StringRef.fromString(name), fqName, Utils.instance$.wrapStrings(superNames), isTopLevel, isClassObject);
this(elementType, parent, StringRef.fromString(name), fqName, Utils.instance$.wrapStrings(superNames), isTopLevel, isClassObject, isLocal);
}
public PsiJetObjectStubImpl(
@@ -57,7 +59,8 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
@Nullable FqName fqName,
@NotNull StringRef[] superNames,
boolean isTopLevel,
boolean isClassObject) {
boolean isClassObject,
boolean isLocal) {
super(parent, elementType);
this.name = name;
@@ -65,6 +68,7 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
this.superNames = superNames;
this.isTopLevel = isTopLevel;
this.isClassObject = isClassObject;
this.isLocal = isLocal;
}
@Override
@@ -98,6 +102,11 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
return isClassObject;
}
@Override
public boolean isLocal() {
return isLocal;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@@ -112,6 +121,10 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
builder.append("top ");
}
if (isLocal()) {
builder.append("local ");
}
builder.append("name=").append(getName());
builder.append(" fqName=").append(fqName != null ? fqName.toString() : "null");
builder.append(" superNames=").append("[").append(StringUtil.join(ArrayUtil.toStringArray(getSuperNames()))).append("]");