index occurrences of superclass names for Kotlin classes
This commit is contained in:
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
* @author max
|
||||
*/
|
||||
public class JetClass extends JetTypeParameterListOwner
|
||||
implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub<?>> {
|
||||
implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub> {
|
||||
|
||||
private PsiJetClassStub stub;
|
||||
|
||||
@@ -158,7 +158,7 @@ public class JetClass extends JetTypeParameterListOwner
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetClassStub<?> getStub() {
|
||||
public PsiJetClassStub getStub() {
|
||||
// TODO (stubs)
|
||||
return null;
|
||||
}
|
||||
@@ -198,4 +198,48 @@ public class JetClass extends JetTypeParameterListOwner
|
||||
Collections.reverse(parts);
|
||||
return StringUtil.join(parts, ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
|
||||
* via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
|
||||
*
|
||||
* @return the list of possible superclass names
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getSuperNames() {
|
||||
final JetDelegationSpecifierList delegationSpecifierList = getDelegationSpecifierList();
|
||||
if (delegationSpecifierList == null) return Collections.emptyList();
|
||||
final List<JetDelegationSpecifier> specifiers = delegationSpecifierList.getDelegationSpecifiers();
|
||||
if (specifiers.size() == 0) return Collections.emptyList();
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (JetDelegationSpecifier specifier : specifiers) {
|
||||
final JetTypeReference typeReference = specifier.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
final JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
if (typeElement instanceof JetUserType) {
|
||||
final String referencedName = ((JetUserType) typeElement).getReferencedName();
|
||||
if (referencedName != null) {
|
||||
addSuperName(result, referencedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addSuperName(List<String> result, String referencedName) {
|
||||
result.add(referencedName);
|
||||
if (getContainingFile() instanceof JetFile) {
|
||||
final JetImportDirective directive = ((JetFile) getContainingFile()).findImportByAlias(referencedName);
|
||||
if (directive != null) {
|
||||
JetExpression reference = directive.getImportedReference();
|
||||
while (reference instanceof JetDotQualifiedExpression) {
|
||||
reference = ((JetDotQualifiedExpression) reference).getSelectorExpression();
|
||||
}
|
||||
if (reference instanceof JetSimpleNameExpression) {
|
||||
result.add(((JetSimpleNameExpression) reference).getReferencedName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,16 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer {
|
||||
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetImportDirective findImportByAlias(@NotNull String name) {
|
||||
for (JetImportDirective directive : getImportDirectives()) {
|
||||
if (name.equals(directive.getAliasName())) {
|
||||
return directive;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// scripts has no namespace header
|
||||
@Nullable
|
||||
public JetNamespaceHeader getNamespaceHeader() {
|
||||
|
||||
@@ -18,13 +18,16 @@ package org.jetbrains.jet.lang.psi.stubs;
|
||||
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
|
||||
public interface PsiJetClassStub extends StubElement<JetClass> {
|
||||
@NonNls
|
||||
@Nullable
|
||||
String getQualifiedName();
|
||||
@@ -32,6 +35,9 @@ public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
|
||||
@Nullable
|
||||
String getName();
|
||||
|
||||
@NotNull
|
||||
List<String> getSuperNames();
|
||||
|
||||
boolean isDeprecated();
|
||||
boolean hasDeprecatedAnnotation();
|
||||
}
|
||||
|
||||
+9
-3
@@ -62,7 +62,8 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
||||
@Override
|
||||
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
||||
FqName fqName = JetPsiUtil.getFQName(psi);
|
||||
return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName());
|
||||
return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName(),
|
||||
psi.getSuperNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,9 +76,14 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
||||
public PsiJetClassStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
final StringRef name = dataStream.readName();
|
||||
final StringRef qualifiedName = dataStream.readName();
|
||||
|
||||
final int superCount = dataStream.readVarInt();
|
||||
final StringRef[] superNames = StringRef.createArray(superCount);
|
||||
for (int i = 0; i < superCount; i++) {
|
||||
superNames[i] = dataStream.readName();
|
||||
}
|
||||
|
||||
final JetClassElementType type = JetStubElementTypes.CLASS;
|
||||
final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name);
|
||||
final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name, superNames);
|
||||
|
||||
return classStub;
|
||||
}
|
||||
|
||||
+2
-7
@@ -16,12 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageParserDefinitions;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.PsiBuilderFactory;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.StubBuilder;
|
||||
@@ -43,7 +38,7 @@ import java.io.IOException;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
public static final int STUB_VERSION = 3;
|
||||
public static final int STUB_VERSION = 4;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
+30
-4
@@ -19,37 +19,53 @@ package org.jetbrains.jet.lang.psi.stubs.impl;
|
||||
import com.intellij.psi.stubs.StubBase;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub<JetClass> {
|
||||
public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub {
|
||||
|
||||
private final StringRef qualifiedName;
|
||||
private final StringRef name;
|
||||
private final StringRef[] superNames;
|
||||
|
||||
public PsiJetClassStubImpl(
|
||||
JetClassElementType type,
|
||||
final StubElement parent,
|
||||
@Nullable final String qualifiedName,
|
||||
final String name) {
|
||||
final String name,
|
||||
final List<String> superNames) {
|
||||
|
||||
this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
|
||||
this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames));
|
||||
}
|
||||
|
||||
private static StringRef[] wrapStrings(List<String> names) {
|
||||
StringRef[] refs = new StringRef[names.size()];
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
refs[i] = StringRef.fromString(names.get(i));
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
public PsiJetClassStubImpl(
|
||||
JetClassElementType type,
|
||||
final StubElement parent,
|
||||
final StringRef qualifiedName,
|
||||
final StringRef name) {
|
||||
final StringRef name,
|
||||
final StringRef[] superNames) {
|
||||
|
||||
super(parent, type);
|
||||
this.qualifiedName = qualifiedName;
|
||||
this.name = name;
|
||||
this.superNames = superNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,4 +87,14 @@ public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetCla
|
||||
public String getName() {
|
||||
return StringRef.toString(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getSuperNames() {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (StringRef ref : superNames) {
|
||||
result.add(ref.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user