diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 4d3ba4cbd6b..7199d23c45c 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -204,6 +204,7 @@
+
diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllPackagesIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllPackagesIndex.java
new file mode 100644
index 00000000000..7573fe110bb
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllPackagesIndex.java
@@ -0,0 +1,55 @@
+/*
+ * 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.JetFile;
+
+import java.util.Collection;
+
+/**
+ * Contains all packages, i.e. if a file declares
+ * package a.b.c
+ *
+ * Three packages "a", "a.b" and "a.b.c" will be registered in this index
+ */
+public class JetAllPackagesIndex extends StringStubIndexExtension {
+ private static final StubIndexKey KEY = KotlinIndexUtil.createIndexKey(JetAllPackagesIndex.class);
+
+ private static final JetAllPackagesIndex ourInstance = new JetAllPackagesIndex();
+
+ public static JetAllPackagesIndex getInstance() {
+ return ourInstance;
+ }
+
+ private JetAllPackagesIndex() {}
+
+ @NotNull
+ @Override
+ public StubIndexKey getKey() {
+ return KEY;
+ }
+
+ @Override
+ public Collection get(final String fqName, final Project project, @NotNull final GlobalSearchScope scope) {
+ return super.get(fqName, project, new JetSourceFilterScope(scope));
+ }
+}
diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetPackageDeclarationIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetPackageDeclarationIndex.java
index 13f889bda4d..62c6ff4ac2c 100644
--- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetPackageDeclarationIndex.java
+++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetPackageDeclarationIndex.java
@@ -25,6 +25,12 @@ import org.jetbrains.jet.lang.psi.JetFile;
import java.util.Collection;
+/**
+ * Explicitly declared packages, i.e. if a file declares
+ * package a.b.c
+ *
+ * Only "a.b.c" will be registered, not "a" nor "a.b"
+ */
public class JetPackageDeclarationIndex extends StringStubIndexExtension {
private static final StubIndexKey KEY = KotlinIndexUtil.createIndexKey(JetPackageDeclarationIndex.class);
diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
index 7daadf3613b..54044618857 100644
--- a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
+++ b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
@@ -27,7 +27,17 @@ public class StubIndexServiceImpl implements StubIndexService {
@Override
public void indexFile(PsiJetFileStub stub, IndexSink sink) {
String packageName = stub.getPackageName();
- sink.occurrence(JetPackageDeclarationIndex.getInstance().getKey(), packageName == null ? "" : packageName);
+ FqName fqName = new FqName(packageName == null ? "" : packageName);
+
+ sink.occurrence(JetPackageDeclarationIndex.getInstance().getKey(), fqName.getFqName());
+
+ while (true) {
+ sink.occurrence(JetAllPackagesIndex.getInstance().getKey(), fqName.getFqName());
+ if (fqName.isRoot()) {
+ return;
+ }
+ fqName = fqName.parent();
+ }
}
@Override