Index package-level properties

This commit is contained in:
Nikolay Krasko
2012-07-02 15:13:23 +04:00
parent 3a196d6718
commit de4e302578
19 changed files with 209 additions and 52 deletions
@@ -74,15 +74,19 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
}
public boolean isLocal() {
PsiJetPropertyStub stub = getStub();
if (stub != null) {
return stub.isLocal();
}
PsiElement parent = getParent();
return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody);
}
public boolean isTopLevel() {
PsiJetPropertyStub stub = getStub();
if (stub != null) {
return stub.isTopLevel();
}
return getParent() instanceof JetFile;
}
@NotNull
@Override
public SearchScope getUseScope() {
@@ -165,8 +165,8 @@ public class JetPsiUtil {
return getFQName(objectDeclaration);
}
Name functionName = namedDeclaration.getNameAsName();
if (functionName == null) {
Name name = namedDeclaration.getNameAsName();
if (name == null) {
return null;
}
@@ -180,7 +180,7 @@ public class JetPsiUtil {
if (parent instanceof JetFile) {
firstPart = getFQName((JetFile) parent);
}
else if (parent instanceof JetNamedDeclaration) {
else if (parent instanceof JetNamedFunction || parent instanceof JetClass || parent instanceof JetObjectDeclaration) {
firstPart = getFQName((JetNamedDeclaration) parent);
}
@@ -188,7 +188,7 @@ public class JetPsiUtil {
return null;
}
return firstPart.child(functionName);
return firstPart.child(name);
}
@Nullable @IfNotParsed
@@ -17,14 +17,21 @@
package org.jetbrains.jet.lang.psi.stubs;
import com.intellij.psi.stubs.NamedStub;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.resolve.name.FqName;
/**
* @author Nikolay Krasko
*/
public interface PsiJetPropertyStub extends NamedStub<JetProperty> {
boolean isVar();
boolean isLocal();
boolean isTopLevel();
@Nullable
FqName getTopFQName();
String getTypeText();
String getInferenceBodyText();
}
@@ -38,7 +38,7 @@ import java.io.IOException;
* @author Nikolay Krasko
*/
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
public static final int STUB_VERSION = 16;
public static final int STUB_VERSION = 17;
public JetFileElementType() {
super("jet.FILE", JetLanguage.INSTANCE);
@@ -17,6 +17,7 @@
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;
@@ -26,9 +27,11 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.psi.JetTypeReference;
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.io.IOException;
@@ -50,13 +53,28 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
return new JetProperty(stub, JetStubElementTypes.PROPERTY);
}
@Override
public boolean shouldCreateStub(ASTNode node) {
if (super.shouldCreateStub(node)) {
PsiElement psi = node.getPsi();
if (psi instanceof JetProperty) {
JetProperty property = (JetProperty) psi;
return property.getName() != null;
}
}
return false;
}
@Override
public PsiJetPropertyStub createStub(@NotNull JetProperty psi, StubElement parentStub) {
JetTypeReference typeRef = psi.getPropertyTypeRef();
JetExpression expression = psi.getInitializer();
assert !psi.isLocal() : "Should not store local property";
return new PsiJetPropertyStubImpl(JetStubElementTypes.PROPERTY, parentStub,
psi.getName(), psi.isVar(), psi.isLocal(),
psi.getName(), psi.isVar(), psi.isTopLevel(), JetPsiUtil.getFQName(psi),
typeRef != null ? typeRef.getText() : null,
expression != null ? expression.getText() : null);
}
@@ -65,7 +83,11 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
public void serialize(PsiJetPropertyStub stub, StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
dataStream.writeBoolean(stub.isVar());
dataStream.writeBoolean(stub.isLocal());
dataStream.writeBoolean(stub.isTopLevel());
FqName topFQName = stub.getTopFQName();
dataStream.writeName(topFQName != null ? topFQName.toString() : null);
dataStream.writeName(stub.getTypeText());
dataStream.writeName(stub.getInferenceBodyText());
}
@@ -74,16 +96,20 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
public PsiJetPropertyStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef name = dataStream.readName();
boolean isVar = dataStream.readBoolean();
boolean isLocal = dataStream.readBoolean();
boolean isTopLevel = dataStream.readBoolean();
StringRef topFQNameStr = dataStream.readName();
FqName fqName = topFQNameStr != null ? new FqName(topFQNameStr.toString()) : null;
StringRef typeText = dataStream.readName();
StringRef inferenceBodyText = dataStream.readName();
return new PsiJetPropertyStubImpl(JetStubElementTypes.PROPERTY, parentStub,
name, isVar, isLocal, typeText, inferenceBodyText);
name, isVar, isTopLevel, fqName, typeText, inferenceBodyText);
}
@Override
public void indexStub(PsiJetPropertyStub stub, IndexSink sink) {
// No index
StubIndexServiceFactory.getInstance().indexProperty(stub, sink);
}
}
@@ -23,7 +23,10 @@ import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetBlockExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunctionLiteral;
import org.jetbrains.jet.lang.psi.JetWithExpressionInitializer;
import org.jetbrains.jet.plugin.JetLanguage;
/**
@@ -53,10 +56,7 @@ public abstract class JetStubElementType<StubT extends StubElement, PsiT extends
// Don't create stubs if declaration is inside function or property accessor with block
JetBlockExpression blockExpression = PsiTreeUtil.getParentOfType(psi, JetBlockExpression.class);
@SuppressWarnings("unchecked") JetDeclarationWithBody stubStopElement =
PsiTreeUtil.getParentOfType(blockExpression, JetFunction.class, JetPropertyAccessor.class);
if (stubStopElement != null) {
if (blockExpression != null) {
return false;
}
@@ -20,6 +20,7 @@ import com.intellij.psi.stubs.IndexSink;
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
/**
* @author Nikolay Krasko
@@ -41,9 +42,14 @@ public interface StubIndexService {
@Override
public void indexObject(PsiJetObjectStub stub, IndexSink sink) {
}
@Override
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
}
};
void indexClass(PsiJetClassStub stub, IndexSink sink);
void indexFunction(PsiJetFunctionStub stub, IndexSink sink);
void indexObject(PsiJetObjectStub stub, IndexSink sink);
void indexProperty(PsiJetPropertyStub stub, IndexSink sink);
}
@@ -20,8 +20,10 @@ import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
import org.jetbrains.jet.lang.resolve.name.FqName;
/**
* @author Nikolay Krasko
@@ -29,26 +31,33 @@ import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
public class PsiJetPropertyStubImpl extends StubBase<JetProperty> implements PsiJetPropertyStub {
private final StringRef name;
private final boolean isVar;
private final boolean isLocal;
private final boolean isTopLevel;
private final FqName topFQName;
private final StringRef typeText;
private final StringRef inferenceBodyText;
public PsiJetPropertyStubImpl(IStubElementType elementType, StubElement parent, StringRef name,
boolean isVar, boolean isLocal, StringRef typeText, StringRef inferenceBodyText) {
boolean isVar, boolean isTopLevel, @Nullable FqName topFQName, StringRef typeText, StringRef inferenceBodyText) {
super(parent, elementType);
if (isTopLevel && topFQName == null) {
throw new IllegalArgumentException("topFQName shouldn't be null for top level properties");
}
this.name = name;
this.isVar = isVar;
this.isLocal = isLocal;
this.isTopLevel = isTopLevel;
this.topFQName = topFQName;
this.typeText = typeText;
this.inferenceBodyText = inferenceBodyText;
}
public PsiJetPropertyStubImpl(IStubElementType elementType, StubElement parent, String name,
boolean isVal, boolean isLocal,
boolean isVal, boolean isTopLevel, @Nullable FqName topFQName,
String typeText, String inferenceBodyText
) {
this(elementType, parent, StringRef.fromString(name),
isVal, isLocal, StringRef.fromString(typeText), StringRef.fromString(inferenceBodyText));
isVal, isTopLevel, topFQName, StringRef.fromString(typeText), StringRef.fromString(inferenceBodyText));
}
@Override
@@ -57,8 +66,14 @@ public class PsiJetPropertyStubImpl extends StubBase<JetProperty> implements Psi
}
@Override
public boolean isLocal() {
return isLocal;
public boolean isTopLevel() {
return isTopLevel;
}
@Nullable
@Override
public FqName getTopFQName() {
return topFQName;
}
@Override
@@ -84,8 +99,9 @@ public class PsiJetPropertyStubImpl extends StubBase<JetProperty> implements Psi
builder.append(isVar() ? "var " : "val ");
if (isLocal()) {
builder.append("local ");
if (isTopLevel()) {
assert topFQName != null;
builder.append("top ").append("topFQName=").append(topFQName.toString()).append(" ");
}
builder.append("name=").append(getName());
@@ -133,7 +133,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
Set<VariableDescriptor> result = Sets.newLinkedHashSet();
List<JetProperty> declarations = declarationProvider.getPropertyDeclarations(name);
Collection<JetProperty> declarations = declarationProvider.getPropertyDeclarations(name);
for (JetProperty propertyDeclaration : declarations) {
JetScope resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration);
result.add(resolveSession.getInjector().getDescriptorResolver().resolvePropertyDescriptor(thisDescriptor, resolutionScope,
@@ -37,7 +37,7 @@ public interface DeclarationProvider {
Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name);
@NotNull
List<JetProperty> getPropertyDeclarations(@NotNull Name name);
Collection<JetProperty> getPropertyDeclarations(@NotNull Name name);
@Nullable
JetClassOrObject getClassOrObjectDeclaration(@NotNull Name name);