KT-1103 Public outer function from different package and source file is not visible in completion:
- Stubs elements are enabled - Changed method for selecting indexing policy for plugin and compiler - Quick fix for import unresolved top-level function added
This commit is contained in:
@@ -16,27 +16,14 @@ import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeType;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetFakeStubElementFactory;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementFactory;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementType;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||
import org.jetbrains.jet.lexer.JetLexer;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class JetParserDefinition implements ParserDefinition {
|
||||
|
||||
// TODO (stubs):
|
||||
private static JetStubElementFactory stubElementFactory = new JetFakeStubElementFactory();
|
||||
|
||||
public static void setStubFactory(JetStubElementFactory factory) {
|
||||
stubElementFactory = factory;
|
||||
}
|
||||
|
||||
public static JetStubElementFactory getStubElementTypeFactory() {
|
||||
return stubElementFactory;
|
||||
}
|
||||
|
||||
public JetParserDefinition() {
|
||||
if (!ApplicationManager.getApplication().isCommandLine()) {
|
||||
}
|
||||
@@ -52,9 +39,7 @@ public class JetParserDefinition implements ParserDefinition {
|
||||
}
|
||||
|
||||
public IFileElementType getFileNodeType() {
|
||||
// TODO (stubs)
|
||||
return JetNodeTypes.JET_FILE;
|
||||
// return JetStubElementTypes.FILE;
|
||||
return JetStubElementTypes.FILE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.intellij.extapi.psi.PsiFileBase;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.stubs.StubTree;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
@@ -58,4 +60,19 @@ public class JetFile extends PsiFileBase {
|
||||
visitor.visitFile(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StubElement getStub() {
|
||||
return super.getStub(); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public StubTree calcStubTree() {
|
||||
return super.calcStubTree(); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public StubTree getStubTree() {
|
||||
return super.getStubTree(); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -66,11 +67,37 @@ public class JetNamedFunction extends JetFunction implements StubBasedPsiElement
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full qualified name for function "package_fqn.function_name"
|
||||
* Not null for top level functions.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public String getQualifiedName() {
|
||||
final PsiJetFunctionStub stub = getStub();
|
||||
if (stub != null) {
|
||||
// TODO (stubs): return stub.getQualifiedName();
|
||||
}
|
||||
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof JetFile) {
|
||||
JetFile jetFile = (JetFile) parent;
|
||||
final String fileFQN = JetPsiUtil.getFQName(jetFile);
|
||||
if (!fileFQN.isEmpty()) {
|
||||
return fileFQN + "." + getName();
|
||||
}
|
||||
|
||||
return getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStubElementType getElementType() {
|
||||
return JetStubElementTypes.FUNCTION;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub<?> getStub() {
|
||||
// TODO (stubs)
|
||||
|
||||
@@ -12,11 +12,17 @@ public interface PsiJetFunctionStub <T extends JetFunction> extends StubElement<
|
||||
@Nullable
|
||||
String getName();
|
||||
|
||||
boolean isDeclaration();
|
||||
/**
|
||||
* Is function defined in directly in package.
|
||||
* @return
|
||||
*/
|
||||
boolean isTopLevel();
|
||||
|
||||
/**
|
||||
* Does function extends some type.
|
||||
*/
|
||||
boolean isExtension();
|
||||
|
||||
@NotNull
|
||||
String[] getAnnotations();
|
||||
|
||||
@NotNull
|
||||
String getReturnTypeText();
|
||||
}
|
||||
|
||||
+6
-6
@@ -13,17 +13,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassStubImpl;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public abstract class JetClassElementType extends JetStubElementType<PsiJetClassStub, JetClass> {
|
||||
public class JetClassElementType extends JetStubElementType<PsiJetClassStub, JetClass> {
|
||||
|
||||
public JetClassElementType(@NotNull @NonNls String debugName) {
|
||||
super(debugName, JetLanguage.INSTANCE);
|
||||
super(debugName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +32,6 @@ public abstract class JetClassElementType extends JetStubElementType<PsiJetClass
|
||||
|
||||
@Override
|
||||
public JetClass createPsi(@NotNull PsiJetClassStub stub) {
|
||||
// TODO: Don't work for kotlin classes
|
||||
// return getPsiFactory(stub).createClass(stub);
|
||||
return null;
|
||||
}
|
||||
@@ -45,7 +43,7 @@ public abstract class JetClassElementType extends JetStubElementType<PsiJetClass
|
||||
|
||||
@Override
|
||||
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, psi.getName(), psi.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,5 +64,7 @@ public abstract class JetClassElementType extends JetStubElementType<PsiJetClass
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void indexStub(PsiJetClassStub stub, IndexSink sink);
|
||||
public void indexStub(PsiJetClassStub stub, IndexSink sink) {
|
||||
StubIndexServiceFactory.getInstance().indexClass(stub, sink);
|
||||
}
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFakeStubElementFactory implements JetStubElementFactory {
|
||||
@Override
|
||||
public JetClassElementType getClassElementType() {
|
||||
return new JetClassElementType("CLASS") {
|
||||
@Override
|
||||
public void indexStub(PsiJetClassStub stub, IndexSink sink) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetFunctionElementType getFunctionElementType() {
|
||||
return new JetFunctionElementType("FUN") {
|
||||
@Override
|
||||
public void indexStub(PsiJetFunctionStub stub, IndexSink sink) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
-17
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.StubBuilder;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
@@ -35,21 +33,6 @@ public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
return STUB_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBuildStubFor(final VirtualFile file) {
|
||||
// TODO:
|
||||
return true;
|
||||
|
||||
// final VirtualFile dir = file.getParent();
|
||||
// return dir == null || dir.getUserData(LanguageLevel.KEY) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTNode createNode(final CharSequence text) {
|
||||
// TODO (stub):
|
||||
return super.createNode(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExternalId() {
|
||||
return "jet.FILE";
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class JetFileStubBuilder extends DefaultStubBuilder {
|
||||
if (!(file instanceof JetFile)) return super.createStubForFile(file);
|
||||
|
||||
JetFile jetFile = (JetFile) file;
|
||||
|
||||
|
||||
// TODO (stubs):
|
||||
String packageName = "default";
|
||||
|
||||
|
||||
+28
-10
@@ -3,29 +3,31 @@ package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LighterAST;
|
||||
import com.intellij.lang.LighterASTNode;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.stubs.StubInputStream;
|
||||
import com.intellij.psi.stubs.StubOutputStream;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
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.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFunctionStubImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public abstract class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStub, JetFunction> {
|
||||
public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStub, JetNamedFunction> {
|
||||
|
||||
public JetFunctionElementType(@NotNull @NonNls String debugName) {
|
||||
super(debugName, JetLanguage.INSTANCE);
|
||||
super(debugName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetFunction createPsiFromAst(@NotNull ASTNode node) {
|
||||
public JetNamedFunction createPsiFromAst(@NotNull ASTNode node) {
|
||||
return new JetNamedFunction(node);
|
||||
}
|
||||
|
||||
@@ -35,22 +37,38 @@ public abstract class JetFunctionElementType extends JetStubElementType<PsiJetFu
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetFunction createPsi(@NotNull PsiJetFunctionStub stub) {
|
||||
public JetNamedFunction createPsi(@NotNull PsiJetFunctionStub stub) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub createStub(@NotNull JetFunction psi, StubElement parentStub) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, StubElement parentStub) {
|
||||
final boolean isTopLevel = parentStub instanceof PsiJetFileStub;
|
||||
final boolean isExtension = psi.getReceiverTypeRef() != null;
|
||||
|
||||
return new PsiJetFunctionStubImpl(
|
||||
JetStubElementTypes.FUNCTION, parentStub, psi.getName(),
|
||||
isTopLevel, isExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PsiJetFunctionStub stub, StubOutputStream dataStream) throws IOException {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeBoolean(stub.isTopLevel());
|
||||
dataStream.writeBoolean(stub.isExtension());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
final StringRef name = dataStream.readName();
|
||||
final boolean isTopLevel = dataStream.readBoolean();
|
||||
final boolean isExtension = dataStream.readBoolean();
|
||||
|
||||
return new PsiJetFunctionStubImpl(JetStubElementTypes.FUNCTION, parentStub, name, isTopLevel, isExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexStub(PsiJetFunctionStub stub, IndexSink sink) {
|
||||
StubIndexServiceFactory.getInstance().indexFunction(stub, sink);
|
||||
}
|
||||
}
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface JetStubElementFactory {
|
||||
JetClassElementType getClassElementType();
|
||||
JetFunctionElementType getFunctionElementType();
|
||||
}
|
||||
+3
-6
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
|
||||
import com.intellij.psi.impl.java.stubs.StubPsiFactory;
|
||||
@@ -10,7 +9,7 @@ import com.intellij.psi.stubs.PsiFileStub;
|
||||
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.plugin.JetLanguage;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
@@ -18,12 +17,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class JetStubElementType<StubT extends StubElement, PsiT extends PsiElement>
|
||||
extends ILightStubElementType<StubT, PsiT> {
|
||||
|
||||
public JetStubElementType(@NotNull @NonNls String debugName, @Nullable Language language) {
|
||||
super(debugName, language);
|
||||
public JetStubElementType(@NotNull @NonNls String debugName) {
|
||||
super(debugName, JetLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public abstract PsiT createPsiFromAst(@NotNull ASTNode node);
|
||||
|
||||
protected StubPsiFactory getPsiFactory(StubT stub) {
|
||||
|
||||
+2
-4
@@ -1,13 +1,11 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface JetStubElementTypes {
|
||||
JetFileElementType FILE = new JetFileElementType();
|
||||
|
||||
JetClassElementType CLASS = JetParserDefinition.getStubElementTypeFactory().getClassElementType();
|
||||
JetFunctionElementType FUNCTION = JetParserDefinition.getStubElementTypeFactory().getFunctionElementType();
|
||||
JetClassElementType CLASS = new JetClassElementType("CLASS");
|
||||
JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface StubIndexService {
|
||||
|
||||
/**
|
||||
* Default implementation with no indexing.
|
||||
*/
|
||||
StubIndexService NO_INDEX_SERVICE = new StubIndexService() {
|
||||
@Override
|
||||
public void indexClass(PsiJetClassStub stub, IndexSink sink) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexFunction(PsiJetFunctionStub stub, IndexSink sink) {
|
||||
}
|
||||
};
|
||||
|
||||
void indexClass(PsiJetClassStub stub, IndexSink sink);
|
||||
void indexFunction(PsiJetFunctionStub stub, IndexSink sink);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
final class StubIndexServiceFactory {
|
||||
|
||||
private StubIndexServiceFactory() {
|
||||
}
|
||||
|
||||
public static StubIndexService getInstance() {
|
||||
// If executed in plugin service will be registered
|
||||
final StubIndexService registeredService = ServiceManager.getService(StubIndexService.class);
|
||||
return registeredService != null ? registeredService : StubIndexService.NO_INDEX_SERVICE;
|
||||
}
|
||||
}
|
||||
+28
-31
@@ -3,7 +3,9 @@ package org.jetbrains.jet.lang.psi.stubs.impl;
|
||||
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.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
|
||||
@@ -11,49 +13,44 @@ import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class PsiJetFunctionStubImpl extends StubBase<JetFunction> implements PsiJetFunctionStub<JetFunction> {
|
||||
protected PsiJetFunctionStubImpl(StubElement parent, IStubElementType elementType) {
|
||||
super(parent, elementType);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// public PsiJetFunctionStubImpl(
|
||||
// Jet type,
|
||||
// final StubElement parent,
|
||||
// final String qualifiedName,
|
||||
// final String name) {
|
||||
//
|
||||
// this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
|
||||
// }
|
||||
//
|
||||
// public PsiJetFunctionStubImpl(
|
||||
// JetClassElementType type,
|
||||
// final StubElement parent,
|
||||
// final StringRef qualifiedName,
|
||||
// final StringRef name) {
|
||||
//
|
||||
// super(parent, type);
|
||||
// this.qualifiedName = qualifiedName;
|
||||
// this.name = name;
|
||||
// }
|
||||
public PsiJetFunctionStubImpl(@NotNull IStubElementType elementType, @NotNull StubElement parent,
|
||||
@Nullable StringRef nameRef, boolean isTopLevel, boolean isExtension) {
|
||||
super(parent, elementType);
|
||||
|
||||
this.nameRef = nameRef;
|
||||
this.isTopLevel = isTopLevel;
|
||||
this.isExtension = isExtension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return StringRef.toString(nameRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeclaration() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
public boolean isTopLevel() {
|
||||
return isTopLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtension() {
|
||||
return isExtension;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getAnnotations() {
|
||||
return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getReturnTypeText() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
// TODO (stubs)
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user