Add qualified name to top level functions stub
This commit is contained in:
@@ -85,15 +85,15 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub<PsiJetFuncti
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full qualified name for function "package_fqn.function_name"
|
||||
* Not null for top level functions.
|
||||
* @return
|
||||
*/
|
||||
* Returns full qualified name for function "package_fqn.function_name"
|
||||
* Not null for top level functions.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public FqName getQualifiedName() {
|
||||
final PsiJetFunctionStub stub = getStub();
|
||||
if (stub != null) {
|
||||
// TODO (stubs): return stub.getQualifiedName();
|
||||
return stub.getTopFQName();
|
||||
}
|
||||
|
||||
PsiElement parent = getParent();
|
||||
|
||||
@@ -18,12 +18,17 @@ package org.jetbrains.jet.lang.psi.stubs;
|
||||
|
||||
import com.intellij.psi.stubs.NamedStub;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface PsiJetFunctionStub extends NamedStub<JetNamedFunction> {
|
||||
@Nullable
|
||||
FqName getTopFQName();
|
||||
|
||||
/**
|
||||
* Is function defined in directly in package.
|
||||
* @return
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import java.io.IOException;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
public static final int STUB_VERSION = 15;
|
||||
public static final int STUB_VERSION = 16;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
+30
-7
@@ -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;
|
||||
@@ -28,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFileStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFunctionStubImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -50,30 +52,51 @@ public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStu
|
||||
return new JetNamedFunction(stub);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateStub(ASTNode node) {
|
||||
if (super.shouldCreateStub(node)) {
|
||||
PsiElement psi = node.getPsi();
|
||||
if (psi instanceof JetNamedFunction) {
|
||||
JetNamedFunction function = (JetNamedFunction) psi;
|
||||
return function.getName() != null;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, @NotNull StubElement parentStub) {
|
||||
final boolean isTopLevel = parentStub instanceof PsiJetFileStub;
|
||||
final boolean isExtension = psi.getReceiverTypeRef() != null;
|
||||
|
||||
return new PsiJetFunctionStubImpl(
|
||||
JetStubElementTypes.FUNCTION, parentStub, psi.getName(),
|
||||
isTopLevel, isExtension);
|
||||
FqName qualifiedName = psi.getQualifiedName();
|
||||
|
||||
return new PsiJetFunctionStubImpl(JetStubElementTypes.FUNCTION, parentStub, psi.getName(), isTopLevel, qualifiedName, isExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PsiJetFunctionStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeBoolean(stub.isTopLevel());
|
||||
|
||||
FqName topFQName = stub.getTopFQName();
|
||||
dataStream.writeName(topFQName != null ? topFQName.toString() : null);
|
||||
|
||||
dataStream.writeBoolean(stub.isExtension());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
final StringRef name = dataStream.readName();
|
||||
final boolean isTopLevel = dataStream.readBoolean();
|
||||
final boolean isExtension = dataStream.readBoolean();
|
||||
StringRef name = dataStream.readName();
|
||||
boolean isTopLevel = dataStream.readBoolean();
|
||||
|
||||
return new PsiJetFunctionStubImpl(JetStubElementTypes.FUNCTION, parentStub, name, isTopLevel, isExtension);
|
||||
StringRef topFQNameStr = dataStream.readName();
|
||||
FqName fqName = topFQNameStr != null ? new FqName(topFQNameStr.toString()) : null;
|
||||
|
||||
boolean isExtension = dataStream.readBoolean();
|
||||
|
||||
return new PsiJetFunctionStubImpl(JetStubElementTypes.FUNCTION, parentStub, name, isTopLevel, fqName, isExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+31
-7
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
@@ -34,17 +35,33 @@ public class PsiJetFunctionStubImpl extends StubBase<JetNamedFunction> implement
|
||||
private final StringRef nameRef;
|
||||
private final boolean isTopLevel;
|
||||
private final boolean isExtension;
|
||||
|
||||
public PsiJetFunctionStubImpl(@NotNull IStubElementType elementType, @NotNull StubElement parent,
|
||||
@Nullable String name, boolean isTopLevel, boolean isExtension) {
|
||||
this(elementType, parent, StringRef.fromString(name), isTopLevel, isExtension);
|
||||
private final FqName topFQName;
|
||||
|
||||
public PsiJetFunctionStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@Nullable String name,
|
||||
boolean isTopLevel,
|
||||
@Nullable FqName topFQName,
|
||||
boolean isExtension) {
|
||||
this(elementType, parent, StringRef.fromString(name), isTopLevel, topFQName, isExtension);
|
||||
}
|
||||
|
||||
public PsiJetFunctionStubImpl(@NotNull IStubElementType elementType, @NotNull StubElement parent,
|
||||
@Nullable StringRef nameRef, boolean isTopLevel, boolean isExtension) {
|
||||
public PsiJetFunctionStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@Nullable StringRef nameRef,
|
||||
boolean isTopLevel,
|
||||
@Nullable FqName topFQName,
|
||||
boolean isExtension) {
|
||||
super(parent, elementType);
|
||||
|
||||
if (isTopLevel && topFQName == null) {
|
||||
throw new IllegalArgumentException("topFQName shouldn't be null for top level functions");
|
||||
}
|
||||
|
||||
this.nameRef = nameRef;
|
||||
this.topFQName = topFQName;
|
||||
this.isTopLevel = isTopLevel;
|
||||
this.isExtension = isExtension;
|
||||
}
|
||||
@@ -54,6 +71,12 @@ public class PsiJetFunctionStubImpl extends StubBase<JetNamedFunction> implement
|
||||
return StringRef.toString(nameRef);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FqName getTopFQName() {
|
||||
return topFQName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTopLevel() {
|
||||
return isTopLevel;
|
||||
@@ -77,7 +100,8 @@ public class PsiJetFunctionStubImpl extends StubBase<JetNamedFunction> implement
|
||||
builder.append("PsiJetFunctionStubImpl[");
|
||||
|
||||
if (isTopLevel()) {
|
||||
builder.append("top ");
|
||||
assert topFQName != null;
|
||||
builder.append("top ").append("topFQName=").append(topFQName.toString()).append(" ");
|
||||
}
|
||||
|
||||
if (isExtension()) {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testFunctionParameters() {
|
||||
doBuildTest("fun some(t: Int, other: String = \"hello\") { }",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top name=some]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=some name=some]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n" +
|
||||
" VALUE_PARAMETER:PsiJetParameterStubImpl[val name=t typeText=Int defaultValue=null]\n" +
|
||||
" VALUE_PARAMETER:PsiJetParameterStubImpl[val name=other typeText=String defaultValue=\"hello\"]\n");
|
||||
@@ -87,14 +87,14 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testNotStoreInFunction() {
|
||||
doBuildTest("fun some() { val test = 12;\n fun fake() {}\n class FakeClass\n }",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top name=some]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=some name=some]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
public void testNotStorePropertyFromInitializer() {
|
||||
doBuildTest("fun DoubleArray.some() = for (element in this) println(element)",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top ext name=some]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top topFQName=some ext name=some]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user