Skip to content

Commit

Permalink
simpler implementation of java/kotlin mirror processing in rename and…
Browse files Browse the repository at this point in the history
… find usages (KT-2078)

#KT-2078 fixed
  • Loading branch information
yole committed May 24, 2012
1 parent f67aaa4 commit cc0a532
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 56 deletions.
2 changes: 2 additions & 0 deletions idea/src/META-INF/plugin.xml
Expand Up @@ -184,6 +184,8 @@

<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>

<referencesSearch implementation="org.jetbrains.jet.plugin.references.KotlinReferencesSearcher"/>

<toolWindow id="Kotlin"
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
anchor="right"
Expand Down
Expand Up @@ -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
Expand All @@ -29,10 +27,4 @@ public class KotlinFindClassUsagesHandler extends FindUsagesHandler {
public KotlinFindClassUsagesHandler(@NotNull PsiElement psiElement) {
super(psiElement);
}

@NotNull
@Override
public PsiElement[] getSecondaryElements() {
return new PsiElement[] {JetLightClass.wrapDelegate((JetClass) getPsiElement()) };
}
}
Expand Up @@ -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
Expand All @@ -31,17 +27,4 @@ public class KotlinFindFunctionUsagesHandler extends FindUsagesHandler {
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;
}
}
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down
Expand Up @@ -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);
}
}
@@ -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.references;

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));
}
}

}
}
}

0 comments on commit cc0a532

Please sign in to comment.