Index for top level objects
This commit is contained in:
@@ -75,6 +75,15 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectSt
|
|||||||
return JetPsiUtil.getFQName(this);
|
return JetPsiUtil.getFQName(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTopLevel() {
|
||||||
|
PsiJetObjectStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
return stub.isTopLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getParent() instanceof JetFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNameIdentifier() {
|
public PsiElement getNameIdentifier() {
|
||||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||||
|
|||||||
@@ -27,4 +27,5 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
public interface PsiJetObjectStub extends NamedStub<JetObjectDeclaration> {
|
public interface PsiJetObjectStub extends NamedStub<JetObjectDeclaration> {
|
||||||
@Nullable
|
@Nullable
|
||||||
FqName getFQName();
|
FqName getFQName();
|
||||||
|
boolean isTopLevel();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ import java.io.IOException;
|
|||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
*/
|
*/
|
||||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||||
public static final int STUB_VERSION = 17;
|
public static final int STUB_VERSION = 18;
|
||||||
|
|
||||||
public JetFileElementType() {
|
public JetFileElementType() {
|
||||||
super("jet.FILE", JetLanguage.INSTANCE);
|
super("jet.FILE", JetLanguage.INSTANCE);
|
||||||
|
|||||||
+4
-2
@@ -69,7 +69,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
|||||||
assert name != null;
|
assert name != null;
|
||||||
|
|
||||||
FqName fqName = psi.getFqName();
|
FqName fqName = psi.getFqName();
|
||||||
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName);
|
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName, psi.isTopLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,6 +77,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
|||||||
dataStream.writeName(stub.getName());
|
dataStream.writeName(stub.getName());
|
||||||
FqName fqName = stub.getFQName();
|
FqName fqName = stub.getFQName();
|
||||||
dataStream.writeName(fqName != null ? fqName.toString() : null);
|
dataStream.writeName(fqName != null ? fqName.toString() : null);
|
||||||
|
dataStream.writeBoolean(stub.isTopLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,8 +85,9 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
|||||||
StringRef name = dataStream.readName();
|
StringRef name = dataStream.readName();
|
||||||
StringRef fqNameStr = dataStream.readName();
|
StringRef fqNameStr = dataStream.readName();
|
||||||
FqName fqName = fqNameStr != null ? new FqName(fqNameStr.toString()) : null;
|
FqName fqName = fqNameStr != null ? new FqName(fqNameStr.toString()) : null;
|
||||||
|
boolean isTopLevel = dataStream.readBoolean();
|
||||||
|
|
||||||
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName);
|
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName, isTopLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+17
-4
@@ -32,24 +32,28 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
|
public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
|
||||||
private final StringRef name;
|
private final StringRef name;
|
||||||
private final FqName fqName;
|
private final FqName fqName;
|
||||||
|
private final boolean isTopLevel;
|
||||||
|
|
||||||
public PsiJetObjectStubImpl(
|
public PsiJetObjectStubImpl(
|
||||||
@NotNull IStubElementType elementType,
|
@NotNull IStubElementType elementType,
|
||||||
@NotNull StubElement parent,
|
@NotNull StubElement parent,
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@Nullable FqName fqName) {
|
@Nullable FqName fqName,
|
||||||
this(elementType, parent, StringRef.fromString(name), fqName);
|
boolean isTopLevel) {
|
||||||
|
this(elementType, parent, StringRef.fromString(name), fqName, isTopLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PsiJetObjectStubImpl(
|
public PsiJetObjectStubImpl(
|
||||||
@NotNull IStubElementType elementType,
|
@NotNull IStubElementType elementType,
|
||||||
@NotNull StubElement parent,
|
@NotNull StubElement parent,
|
||||||
@NotNull StringRef name,
|
@NotNull StringRef name,
|
||||||
@Nullable FqName fqName) {
|
@Nullable FqName fqName,
|
||||||
|
boolean isTopLevel) {
|
||||||
super(parent, elementType);
|
super(parent, elementType);
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.fqName = fqName;
|
this.fqName = fqName;
|
||||||
|
this.isTopLevel = isTopLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,13 +67,22 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
|
|||||||
return fqName;
|
return fqName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTopLevel() {
|
||||||
|
return isTopLevel;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("PsiJetObjectStubImpl[");
|
builder.append("PsiJetObjectStubImpl[");
|
||||||
builder.append("name=").append(getName());
|
|
||||||
|
|
||||||
|
if (isTopLevel) {
|
||||||
|
builder.append("top ");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("name=").append(getName());
|
||||||
builder.append(" fqName=").append(fqName != null ? fqName.toString() : "null");
|
builder.append(" fqName=").append(fqName != null ? fqName.toString() : "null");
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,7 @@
|
|||||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex" />
|
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex" />
|
||||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex" />
|
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex" />
|
||||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAnnotationsIndex" />
|
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAnnotationsIndex" />
|
||||||
|
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelShortObjectNameIndex" />
|
||||||
|
|
||||||
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
|
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
|
||||||
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
|
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
package org.jetbrains.jet.plugin.stubindex;
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
import com.intellij.psi.stubs.StubIndexKey;
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
@@ -30,6 +27,9 @@ public interface JetIndexKeys {
|
|||||||
StubIndexKey<String, JetClassOrObject> SUPERCLASS_NAME_KEY = StubIndexKey.createIndexKey("jet.class.superClassName");
|
StubIndexKey<String, JetClassOrObject> SUPERCLASS_NAME_KEY = StubIndexKey.createIndexKey("jet.class.superClassName");
|
||||||
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
|
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
|
||||||
|
|
||||||
|
StubIndexKey<String, JetObjectDeclaration> TOP_LEVEL_OBJECT_SHORT_NAME_KEY =
|
||||||
|
StubIndexKey.createIndexKey("jet.top.level.object.short.name");
|
||||||
|
|
||||||
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY =
|
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY =
|
||||||
StubIndexKey.createIndexKey("jet.top.level.function.short.name");
|
StubIndexKey.createIndexKey("jet.top.level.function.short.name");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class JetTopLevelShortObjectNameIndex extends StringStubIndexExtension<JetObjectDeclaration> {
|
||||||
|
private static final JetTopLevelShortObjectNameIndex ourInstance = new JetTopLevelShortObjectNameIndex();
|
||||||
|
|
||||||
|
public static JetTopLevelShortObjectNameIndex getInstance() {
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public StubIndexKey<String, JetObjectDeclaration> getKey() {
|
||||||
|
return JetIndexKeys.TOP_LEVEL_OBJECT_SHORT_NAME_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<JetObjectDeclaration> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||||
|
return super.get(s, project, new JetSourceFilterScope(scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,10 @@ public class StubIndexServiceImpl implements StubIndexService {
|
|||||||
|
|
||||||
sink.occurrence(JetIndexKeys.SHORT_NAME_KEY, name);
|
sink.occurrence(JetIndexKeys.SHORT_NAME_KEY, name);
|
||||||
|
|
||||||
|
if (stub.isTopLevel()) {
|
||||||
|
sink.occurrence(JetIndexKeys.TOP_LEVEL_OBJECT_SHORT_NAME_KEY, name);
|
||||||
|
}
|
||||||
|
|
||||||
FqName fqName = stub.getFQName();
|
FqName fqName = stub.getFQName();
|
||||||
if (fqName != null) {
|
if (fqName != null) {
|
||||||
sink.occurrence(JetIndexKeys.FQN_KEY, fqName.toString());
|
sink.occurrence(JetIndexKeys.FQN_KEY, fqName.toString());
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
|||||||
public void testNamedObject() {
|
public void testNamedObject() {
|
||||||
doBuildTest("object Test {}",
|
doBuildTest("object Test {}",
|
||||||
"PsiJetFileStubImpl[package=]\n" +
|
"PsiJetFileStubImpl[package=]\n" +
|
||||||
" OBJECT_DECLARATION:PsiJetObjectStubImpl[name=Test fqName=Test]\n");
|
" OBJECT_DECLARATION:PsiJetObjectStubImpl[top name=Test fqName=Test]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnnotationOnClass() {
|
public void testAnnotationOnClass() {
|
||||||
|
|||||||
Reference in New Issue
Block a user