Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: JetBrains/kotlin
base: f67aaa49b7
...
head fork: JetBrains/kotlin
compare: 05054bfa49
  • 6 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
Showing with 457 additions and 83 deletions.
  1. +41 −2 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
  2. +12 −0 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java
  3. +2 −10 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java
  4. +10 −0 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
  5. +7 −1 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
  6. +15 −3 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
  7. +2 −7 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
  8. +30 −4 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
  9. +5 −0 idea/src/META-INF/plugin.xml
  10. +0 −8 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindClassUsagesHandler.java
  11. +0 −17 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindFunctionUsagesHandler.java
  12. +60 −0 idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java
  13. +0 −19 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java
  14. +0 −12 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinFunctionProcessor.java
  15. +46 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinDefinitionsSearcher.java
  16. +67 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinDirectInheritorsSearcher.java
  17. +58 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinReferencesSearcher.java
  18. +1 −0  idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
  19. +47 −0 idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
  20. +4 −0 idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
  21. +50 −0 idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
43 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
View
@@ -39,7 +39,7 @@
* @author max
*/
public class JetClass extends JetTypeParameterListOwner
- implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub<?>> {
+ implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub> {
private PsiJetClassStub stub;
@@ -158,7 +158,7 @@ public IStubElementType getElementType() {
}
@Override
- public PsiJetClassStub<?> getStub() {
+ public PsiJetClassStub getStub() {
// TODO (stubs)
return null;
}
@@ -198,4 +198,43 @@ private String getQualifiedName() {
Collections.reverse(parts);
return StringUtil.join(parts, ".");
}
+
+ /**
+ * Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
+ * via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
+ *
+ * @return the list of possible superclass names
+ */
+ @NotNull
+ public List<String> getSuperNames() {
+ final List<JetDelegationSpecifier> specifiers = getDelegationSpecifiers();
+ if (specifiers.size() == 0) return Collections.emptyList();
+ List<String> result = new ArrayList<String>();
+ for (JetDelegationSpecifier specifier : specifiers) {
+ final JetUserType superType = specifier.getTypeAsUserType();
+ if (superType != null) {
+ final String referencedName = superType.getReferencedName();
+ if (referencedName != null) {
+ addSuperName(result, referencedName);
+ }
+ }
+ }
+ return result;
+ }
+
+ private void addSuperName(List<String> result, String referencedName) {
+ result.add(referencedName);
+ if (getContainingFile() instanceof JetFile) {
+ final JetImportDirective directive = ((JetFile) getContainingFile()).findImportByAlias(referencedName);
+ if (directive != null) {
+ JetExpression reference = directive.getImportedReference();
+ while (reference instanceof JetDotQualifiedExpression) {
+ reference = ((JetDotQualifiedExpression) reference).getSelectorExpression();
+ }
+ if (reference instanceof JetSimpleNameExpression) {
+ result.add(((JetSimpleNameExpression) reference).getReferencedName());
+ }
+ }
+ }
+ }
}
12 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java
View
@@ -43,4 +43,16 @@ public void accept(@NotNull JetVisitorVoid visitor) {
public JetTypeReference getTypeReference() {
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
}
+
+ @Nullable
+ public JetUserType getTypeAsUserType() {
+ final JetTypeReference reference = getTypeReference();
+ if (reference != null) {
+ final JetTypeElement element = reference.getTypeElement();
+ if (element instanceof JetUserType) {
+ return ((JetUserType) element);
+ }
+ }
+ return null;
+ }
}
12 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java
View
@@ -82,16 +82,8 @@ public JetTypeReference getTypeReference() {
@Override
public JetTypeArgumentList getTypeArgumentList() {
- JetTypeReference typeReference = getTypeReference();
- if (typeReference == null) {
- return null;
- }
- JetTypeElement typeElement = typeReference.getTypeElement();
- if (typeElement instanceof JetUserType) {
- JetUserType userType = (JetUserType) typeElement;
- return userType.getTypeArgumentList();
- }
- return null;
+ final JetUserType userType = getTypeAsUserType();
+ return userType != null ? userType.getTypeArgumentList() : null;
}
}
10 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
View
@@ -61,6 +61,16 @@ public String toString() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
}
+ @Nullable
+ public JetImportDirective findImportByAlias(@NotNull String name) {
+ for (JetImportDirective directive : getImportDirectives()) {
+ if (name.equals(directive.getAliasName())) {
+ return directive;
+ }
+ }
+ return null;
+ }
+
// scripts has no namespace header
@Nullable
public JetNamespaceHeader getNamespaceHeader() {
8 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
View
@@ -18,13 +18,16 @@
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.lang.psi.JetClass;
+import java.util.List;
+
/**
* @author Nikolay Krasko
*/
-public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
+public interface PsiJetClassStub extends StubElement<JetClass> {
@NonNls
@Nullable
String getQualifiedName();
@@ -32,6 +35,9 @@
@Nullable
String getName();
+ @NotNull
+ List<String> getSuperNames();
+
boolean isDeprecated();
boolean hasDeprecatedAnnotation();
}
18 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
View
@@ -33,6 +33,7 @@
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.io.IOException;
+import java.util.List;
/**
* @author Nikolay Krasko
@@ -62,22 +63,33 @@ public JetClass createPsiFromAst(@NotNull ASTNode node) {
@Override
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
FqName fqName = JetPsiUtil.getFQName(psi);
- return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName());
+ return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName(),
+ psi.getSuperNames());
}
@Override
public void serialize(PsiJetClassStub stub, StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
dataStream.writeName(stub.getQualifiedName());
+ final List<String> superNames = stub.getSuperNames();
+ dataStream.writeVarInt(superNames.size());
+ for (String name : superNames) {
+ dataStream.writeName(name);
+ }
}
@Override
public PsiJetClassStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
final StringRef name = dataStream.readName();
final StringRef qualifiedName = dataStream.readName();
-
+ final int superCount = dataStream.readVarInt();
+ final StringRef[] superNames = StringRef.createArray(superCount);
+ for (int i = 0; i < superCount; i++) {
+ superNames[i] = dataStream.readName();
+ }
+
final JetClassElementType type = JetStubElementTypes.CLASS;
- final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name);
+ final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name, superNames);
return classStub;
}
9 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
View
@@ -16,12 +16,7 @@
package org.jetbrains.jet.lang.psi.stubs.elements;
-import com.intellij.lang.ASTNode;
-import com.intellij.lang.Language;
-import com.intellij.lang.LanguageParserDefinitions;
-import com.intellij.lang.PsiBuilder;
-import com.intellij.lang.PsiBuilderFactory;
-import com.intellij.lang.PsiParser;
+import com.intellij.lang.*;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.StubBuilder;
@@ -43,7 +38,7 @@
* @author Nikolay Krasko
*/
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
- public static final int STUB_VERSION = 3;
+ public static final int STUB_VERSION = 4;
public JetFileElementType() {
super("jet.FILE", JetLanguage.INSTANCE);
34 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
View
@@ -19,37 +19,53 @@
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.JetClass;
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author Nikolay Krasko
*/
-public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub<JetClass> {
+public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub {
private final StringRef qualifiedName;
private final StringRef name;
+ private final StringRef[] superNames;
public PsiJetClassStubImpl(
JetClassElementType type,
final StubElement parent,
@Nullable final String qualifiedName,
- final String name) {
+ final String name,
+ final List<String> superNames) {
+
+ this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames));
+ }
- this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
+ private static StringRef[] wrapStrings(List<String> names) {
+ StringRef[] refs = new StringRef[names.size()];
+ for (int i = 0; i < names.size(); i++) {
+ refs[i] = StringRef.fromString(names.get(i));
+ }
+ return refs;
}
public PsiJetClassStubImpl(
JetClassElementType type,
final StubElement parent,
final StringRef qualifiedName,
- final StringRef name) {
+ final StringRef name,
+ final StringRef[] superNames) {
super(parent, type);
this.qualifiedName = qualifiedName;
this.name = name;
+ this.superNames = superNames;
}
@Override
@@ -71,4 +87,14 @@ public boolean hasDeprecatedAnnotation() {
public String getName() {
return StringRef.toString(name);
}
+
+ @NotNull
+ @Override
+ public List<String> getSuperNames() {
+ List<String> result = new ArrayList<String>();
+ for (StringRef ref : superNames) {
+ result.add(ref.toString());
+ }
+ return result;
+ }
}
5 idea/src/META-INF/plugin.xml
View
@@ -175,6 +175,7 @@
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExtensionFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllShortFunctionNameIndex"/>
+ <stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex"/>
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
@@ -184,6 +185,10 @@
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>
+ <referencesSearch implementation="org.jetbrains.jet.plugin.search.KotlinReferencesSearcher"/>
+ <directClassInheritorsSearch implementation="org.jetbrains.jet.plugin.search.KotlinDirectInheritorsSearcher"/>
+ <definitionsSearch implementation="org.jetbrains.jet.plugin.search.KotlinDefinitionsSearcher"/>
+
<toolWindow id="Kotlin"
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
anchor="right"
8 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindClassUsagesHandler.java
View
@@ -19,8 +19,6 @@
import com.intellij.find.findUsages.FindUsagesHandler;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClass;
/**
* @author yole
@@ -29,10 +27,4 @@
public KotlinFindClassUsagesHandler(@NotNull PsiElement psiElement) {
super(psiElement);
}
-
- @NotNull
- @Override
- public PsiElement[] getSecondaryElements() {
- return new PsiElement[] {JetLightClass.wrapDelegate((JetClass) getPsiElement()) };
- }
}
17 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindFunctionUsagesHandler.java
View
@@ -18,11 +18,7 @@
import com.intellij.find.findUsages.FindUsagesHandler;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClassBody;
-import org.jetbrains.jet.lang.psi.JetFunction;
/**
* @author yole
@@ -31,17 +27,4 @@
protected KotlinFindFunctionUsagesHandler(@NotNull PsiElement psiElement) {
super(psiElement);
}
-
- @NotNull
- @Override
- public PsiElement[] getSecondaryElements() {
- JetFunction function = (JetFunction) getPsiElement();
- if (function.getParent() instanceof JetClassBody) {
- final PsiMethod method = JetLightClass.wrapMethod(function);
- if (method != null) {
- return new PsiElement[] { method };
- }
- }
- return PsiElement.EMPTY_ARRAY;
- }
}
60 idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java
View
@@ -21,24 +21,31 @@
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
+import com.intellij.codeInsight.daemon.impl.MarkerType;
import com.intellij.codeInsight.hint.HintUtil;
import com.intellij.codeInsight.navigation.NavigationUtil;
+import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.IconLoader;
+import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.Function;
import com.intellij.util.PsiNavigateUtil;
+import org.jetbrains.jet.asJava.JetLightClass;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.Modality;
+import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
+import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.codeInsight.JetFunctionPsiElementCellRenderer;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import org.jetbrains.jet.resolve.DescriptorRenderer;
@@ -55,6 +62,38 @@
public class JetLineMarkerProvider implements LineMarkerProvider {
public static final Icon OVERRIDING_MARK = IconLoader.getIcon("/gutter/overridingMethod.png");
public static final Icon IMPLEMENTING_MARK = IconLoader.getIcon("/gutter/implementingMethod.png");
+ protected static final Icon OVERRIDDEN_MARK = IconLoader.getIcon("/gutter/overridenMethod.png");
+
+ private static final Function<PsiElement, String> SUBCLASSED_CLASS_TOOLTIP_ADAPTER = new Function<PsiElement, String>() {
+ @Override
+ public String fun(PsiElement element) {
+ PsiElement child = getPsiClassFirstChild(element);
+ // Java puts its marker on a child of the PsiClass, so we must find a child of our own class too
+ return child != null ? MarkerType.SUBCLASSED_CLASS.getTooltip().fun(child) : null;
+ }
+ };
+
+ private static PsiElement getPsiClassFirstChild(PsiElement element) {
+ if (!(element instanceof JetClass)) {
+ element = element.getParent();
+ if (!(element instanceof JetClass)) {
+ return null;
+ }
+ }
+ final PsiClass lightClass = JetLightClass.wrapDelegate((JetClass) element).getDelegate();
+ final PsiElement[] children = lightClass.getChildren();
+ return children.length > 0 ? children[0] : null;
+ }
+
+ private static final GutterIconNavigationHandler<PsiElement> SUBCLASSED_CLASS_NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiElement>() {
+ @Override
+ public void navigate(MouseEvent e, PsiElement elt) {
+ PsiElement child = getPsiClassFirstChild(elt);
+ if (child != null) {
+ MarkerType.SUBCLASSED_CLASS.getNavigationHandler().navigate(e, child);
+ }
+ }
+ };
@Override
public LineMarkerInfo getLineMarkerInfo(final PsiElement element) {
@@ -141,5 +180,26 @@ public void navigate(MouseEvent event, PsiElement elt) {
@Override
public void collectSlowLineMarkers(List<PsiElement> elements, Collection<LineMarkerInfo> result) {
+ if (elements.isEmpty() || DumbService.getInstance(elements.get(0).getProject()).isDumb()) {
+ return;
+ }
+ for (PsiElement element : elements) {
+ if (element instanceof JetClass) {
+ collectInheritingClasses((JetClass)element, result);
+ }
+ }
+ }
+
+ private static void collectInheritingClasses(JetClass element, Collection<LineMarkerInfo> result) {
+ if (!element.hasModifier(JetTokens.OPEN_KEYWORD)) {
+ return;
+ }
+ PsiClass inheritor = ClassInheritorsSearch.search(JetLightClass.wrapDelegate(element), false).findFirst();
+ if (inheritor != null) {
+ final PsiElement nameIdentifier = element.getNameIdentifier();
+ PsiElement anchor = nameIdentifier != null ? nameIdentifier : element;
+ result.add(new LineMarkerInfo<PsiElement>(anchor, anchor.getTextOffset(), OVERRIDDEN_MARK, Pass.UPDATE_OVERRIDEN_MARKERS,
+ SUBCLASSED_CLASS_TOOLTIP_ADAPTER, SUBCLASSED_CLASS_NAVIGATION_HANDLER));
+ }
}
}
19 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java
View
@@ -18,18 +18,11 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiReference;
-import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.refactoring.rename.RenamePsiElementProcessor;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetFile;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
import java.util.Map;
/**
@@ -42,18 +35,6 @@ public boolean canProcessElement(@NotNull PsiElement element) {
return element instanceof JetClassOrObject;
}
- @NotNull
- @Override
- public Collection<PsiReference> findReferences(PsiElement element) {
- if (element instanceof JetClass) {
- List<PsiReference> references = new ArrayList<PsiReference>();
- references.addAll(ReferencesSearch.search(element).findAll());
- references.addAll(ReferencesSearch.search(JetLightClass.wrapDelegate((JetClass) element)).findAll());
- return references;
- }
- return super.findReferences(element);
- }
-
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
JetClassOrObject clazz = (JetClassOrObject) element;
12 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinFunctionProcessor.java
View
@@ -52,16 +52,4 @@ public PsiElement substituteElementToRename(PsiElement element, @Nullable Editor
}
return super.substituteElementToRename(element, editor);
}
-
- @NotNull
- @Override
- public Collection<PsiReference> findReferences(PsiElement element) {
- if (element instanceof JetFunction) {
- List<PsiReference> references = new ArrayList<PsiReference>();
- references.addAll(ReferencesSearch.search(element).findAll());
- references.addAll(ReferencesSearch.search(JetLightClass.wrapMethod((JetFunction) element)).findAll());
- return references;
- }
- return super.findReferences(element);
- }
}
46 idea/src/org/jetbrains/jet/plugin/search/KotlinDefinitionsSearcher.java
View
@@ -0,0 +1,46 @@
+/*
+ * 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.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.search.searches.ClassInheritorsSearch;
+import com.intellij.util.Processor;
+import com.intellij.util.Query;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.JetClass;
+
+/**
+ * @author yole
+ */
+public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, PsiElement> {
+ @Override
+ public void processQuery(@NotNull PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
+ if (queryParameters instanceof JetClass) {
+ final JetLightClass psiClass = JetLightClass.wrapDelegate((JetClass) queryParameters);
+ final Query<PsiClass> query = ClassInheritorsSearch.search(psiClass, true);
+ query.forEach(new Processor<PsiClass>() {
+ @Override
+ public boolean process(final PsiClass pyClass) {
+ return consumer.process(pyClass);
+ }
+ });
+ }
+ }
+}
67 idea/src/org/jetbrains/jet/plugin/search/KotlinDirectInheritorsSearcher.java
View
@@ -0,0 +1,67 @@
+/*
+ * 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.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.search.searches.DirectClassInheritorsSearch;
+import com.intellij.util.Processor;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.*;
+import org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author yole
+ */
+public class KotlinDirectInheritorsSearcher extends QueryExecutorBase<PsiClass, DirectClassInheritorsSearch.SearchParameters> {
+ public KotlinDirectInheritorsSearcher() {
+ super(true);
+ }
+
+ @Override
+ public void processQuery(@NotNull DirectClassInheritorsSearch.SearchParameters queryParameters, @NotNull Processor<PsiClass> consumer) {
+ final PsiClass clazz = queryParameters.getClassToProcess();
+ final String name = clazz.getName();
+ if (name == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) return;
+ GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
+ final Collection<JetClassOrObject> candidates = JetSuperClassIndex.getInstance().get(name, clazz.getProject(), scope);
+ for (JetClassOrObject candidate : candidates) {
+ if (!(candidate instanceof JetClass)) continue;
+ final List<JetDelegationSpecifier> specifiers = candidate.getDelegationSpecifiers();
+ for (JetDelegationSpecifier specifier : specifiers) {
+ final JetUserType type = specifier.getTypeAsUserType();
+ if (type != null) {
+ final JetSimpleNameExpression referenceExpression = type.getReferenceExpression();
+ if (referenceExpression != null) {
+ final PsiReference reference = referenceExpression.getReference();
+ final PsiElement resolved = reference != null ? reference.resolve() : null;
+ if ((resolved instanceof PsiClass || resolved instanceof JetClass) && resolved.isEquivalentTo(clazz)) {
+ consumer.process(JetLightClass.wrapDelegate((JetClass) candidate));
+ }
+ }
+ }
+ }
+ }
+ }
+}
58 idea/src/org/jetbrains/jet/plugin/search/KotlinReferencesSearcher.java
View
@@ -0,0 +1,58 @@
+/*
+ * 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.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.search.searches.ReferencesSearch;
+import com.intellij.util.Processor;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetClassBody;
+import org.jetbrains.jet.lang.psi.JetFunction;
+
+/**
+ * @author yole
+ */
+public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
+ @Override
+ public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
+ PsiElement element = queryParameters.getElementToSearch();
+ if (element instanceof JetClass) {
+ String className = ((JetClass) element).getName();
+ if (className != null) {
+ queryParameters.getOptimizer().searchWord(className, queryParameters.getScope(),
+ true, JetLightClass.wrapDelegate((JetClass) element));
+ }
+ }
+ else if (element instanceof JetFunction) {
+ final JetFunction function = (JetFunction) element;
+ final String name = function.getName();
+ if (function.getParent() instanceof JetClassBody && name != null) {
+ final PsiMethod method = JetLightClass.wrapMethod(function);
+ if (method != null) {
+ queryParameters.getOptimizer().searchWord(name, queryParameters.getScope(),
+ true, JetLightClass.wrapMethod((JetFunction) element));
+ }
+ }
+
+ }
+ }
+}
1  idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
View
@@ -25,6 +25,7 @@
*/
public interface JetIndexKeys {
StubIndexKey<String, JetClassOrObject> SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.class.shortName");
+ StubIndexKey<String, JetClassOrObject> SUPERCLASS_NAME_KEY = StubIndexKey.createIndexKey("jet.class.superClassName");
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.function.short.name");
47 idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
View
@@ -0,0 +1,47 @@
+/*
+ * 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.JetClassOrObject;
+
+import java.util.Collection;
+
+/**
+ * @author yole
+ */
+public class JetSuperClassIndex extends StringStubIndexExtension<JetClassOrObject> {
+ private static final JetSuperClassIndex ourInstance = new JetSuperClassIndex();
+ public static JetSuperClassIndex getInstance() {
+ return ourInstance;
+ }
+
+ @NotNull
+ @Override
+ public StubIndexKey<String, JetClassOrObject> getKey() {
+ return JetIndexKeys.SUPERCLASS_NAME_KEY;
+ }
+
+ @Override
+ public Collection<JetClassOrObject> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
+ return super.get(s, project, new JetSourceFilterScope(scope));
+ }
+}
4 idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
View
@@ -37,6 +37,10 @@ public void indexClass(PsiJetClassStub stub, IndexSink sink) {
if (fqn != null) {
sink.occurrence(JetIndexKeys.FQN_KEY, fqn);
}
+
+ for (String superName : stub.getSuperNames()) {
+ sink.occurrence(JetIndexKeys.SUPERCLASS_NAME_KEY, superName);
+ }
}
@Override
50 idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
View
@@ -0,0 +1,50 @@
+/*
+ * 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.stubs;
+
+import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.LightProjectDescriptor;
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetDeclaration;
+import org.jetbrains.jet.lang.psi.JetFile;
+import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
+import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
+import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
+
+import java.util.List;
+
+/**
+ * @author yole
+ */
+public class JetStubsTest extends LightCodeInsightFixtureTestCase {
+ @NotNull
+ @Override
+ protected LightProjectDescriptor getProjectDescriptor() {
+ return JetLightProjectDescriptor.INSTANCE;
+ }
+
+ public void testSuperclassNames() {
+ final PsiFile psiFile = myFixture.configureByText("foo.kt", "import java.util.ArrayList as alist\nclass C(): alist() { }");
+ final List<JetDeclaration> declarations = ((JetFile) psiFile).getDeclarations();
+ final JetClass jetClass = (JetClass) declarations.get(0);
+ final PsiJetClassStub stub = JetStubElementTypes.CLASS.createStub(jetClass, null);
+ final List<String> names = stub.getSuperNames();
+ assertSameElements(names, "ArrayList", "alist");
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.