Index for top level objects
This commit is contained in:
@@ -75,6 +75,15 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectSt
|
||||
return JetPsiUtil.getFQName(this);
|
||||
}
|
||||
|
||||
public boolean isTopLevel() {
|
||||
PsiJetObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isTopLevel();
|
||||
}
|
||||
|
||||
return getParent() instanceof JetFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
|
||||
@@ -27,4 +27,5 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
public interface PsiJetObjectStub extends NamedStub<JetObjectDeclaration> {
|
||||
@Nullable
|
||||
FqName getFQName();
|
||||
boolean isTopLevel();
|
||||
}
|
||||
|
||||
+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 = 17;
|
||||
public static final int STUB_VERSION = 18;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
+4
-2
@@ -69,7 +69,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
||||
assert name != null;
|
||||
|
||||
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
|
||||
@@ -77,6 +77,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
||||
dataStream.writeName(stub.getName());
|
||||
FqName fqName = stub.getFQName();
|
||||
dataStream.writeName(fqName != null ? fqName.toString() : null);
|
||||
dataStream.writeBoolean(stub.isTopLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,8 +85,9 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
||||
StringRef name = dataStream.readName();
|
||||
StringRef fqNameStr = dataStream.readName();
|
||||
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
|
||||
|
||||
+17
-4
@@ -32,24 +32,28 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
|
||||
private final StringRef name;
|
||||
private final FqName fqName;
|
||||
private final boolean isTopLevel;
|
||||
|
||||
public PsiJetObjectStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@NotNull String name,
|
||||
@Nullable FqName fqName) {
|
||||
this(elementType, parent, StringRef.fromString(name), fqName);
|
||||
@Nullable FqName fqName,
|
||||
boolean isTopLevel) {
|
||||
this(elementType, parent, StringRef.fromString(name), fqName, isTopLevel);
|
||||
}
|
||||
|
||||
public PsiJetObjectStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@NotNull StringRef name,
|
||||
@Nullable FqName fqName) {
|
||||
@Nullable FqName fqName,
|
||||
boolean isTopLevel) {
|
||||
super(parent, elementType);
|
||||
|
||||
this.name = name;
|
||||
this.fqName = fqName;
|
||||
this.isTopLevel = isTopLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,13 +67,22 @@ public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> impleme
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTopLevel() {
|
||||
return isTopLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
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("]");
|
||||
|
||||
|
||||
@@ -204,6 +204,7 @@
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex" />
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex" />
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAnnotationsIndex" />
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelShortObjectNameIndex" />
|
||||
|
||||
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
|
||||
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
package org.jetbrains.jet.plugin.stubindex;
|
||||
|
||||
import com.intellij.psi.stubs.StubIndexKey;
|
||||
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
@@ -30,6 +27,9 @@ public interface JetIndexKeys {
|
||||
StubIndexKey<String, JetClassOrObject> SUPERCLASS_NAME_KEY = StubIndexKey.createIndexKey("jet.class.superClassName");
|
||||
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.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);
|
||||
|
||||
if (stub.isTopLevel()) {
|
||||
sink.occurrence(JetIndexKeys.TOP_LEVEL_OBJECT_SHORT_NAME_KEY, name);
|
||||
}
|
||||
|
||||
FqName fqName = stub.getFQName();
|
||||
if (fqName != null) {
|
||||
sink.occurrence(JetIndexKeys.FQN_KEY, fqName.toString());
|
||||
|
||||
@@ -161,7 +161,7 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testNamedObject() {
|
||||
doBuildTest("object Test {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" OBJECT_DECLARATION:PsiJetObjectStubImpl[name=Test fqName=Test]\n");
|
||||
" OBJECT_DECLARATION:PsiJetObjectStubImpl[top name=Test fqName=Test]\n");
|
||||
}
|
||||
|
||||
public void testAnnotationOnClass() {
|
||||
|
||||
Reference in New Issue
Block a user