Translate JetFindUsagesProvider to Kotlin

This commit is contained in:
Alexey Sedunov
2013-10-18 17:53:48 +04:00
parent d491f0337e
commit 8ca3f6a1ad
3 changed files with 57 additions and 107 deletions
@@ -1,76 +0,0 @@
/*
* Copyright 2010-2013 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.findUsages;
import com.intellij.lang.cacheBuilder.WordsScanner;
import com.intellij.lang.findUsages.FindUsagesProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
public class JetFindUsagesProvider implements FindUsagesProvider {
@Override
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
return psiElement instanceof JetNamedDeclaration;
}
@Override
public WordsScanner getWordsScanner() {
return new JetWordsScanner();
}
@Override
public String getHelpId(@NotNull PsiElement psiElement) {
return null;
}
@NotNull
@Override
public String getType(@NotNull PsiElement psiElement) {
if (psiElement instanceof JetNamedFunction) {
return "function";
}
if (psiElement instanceof JetClass) {
return "class";
}
if (psiElement instanceof JetParameter) {
return "parameter";
}
if (psiElement instanceof JetProperty) {
return "property";
}
return "";
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement psiElement) {
if (psiElement instanceof PsiNamedElement) {
String name = ((PsiNamedElement)psiElement).getName();
return name == null ? "<unnamed>" : name;
}
return "";
}
@NotNull
@Override
public String getNodeText(@NotNull PsiElement psiElement, boolean useFullName) {
return getDescriptiveName(psiElement);
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2013 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.findUsages
import com.intellij.lang.cacheBuilder.WordsScanner
import com.intellij.lang.findUsages.FindUsagesProvider
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNamedElement
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lexer.JetLexer
import com.intellij.lang.cacheBuilder.DefaultWordsScanner
import org.jetbrains.jet.lexer.JetTokens
import com.intellij.psi.tree.TokenSet
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo
public class JetFindUsagesProvider : FindUsagesProvider {
class JetWordsScanner : DefaultWordsScanner(JetLexer(), TokenSet.create(JetTokens.IDENTIFIER), JetTokens.COMMENTS, JetTokens.STRINGS)
public override fun canFindUsagesFor(psiElement: PsiElement): Boolean =
psiElement is JetNamedDeclaration
public override fun getWordsScanner(): WordsScanner =
JetWordsScanner()
public override fun getHelpId(psiElement: PsiElement): String? = null
public override fun getType(element: PsiElement): String {
return when(element) {
is JetNamedFunction -> "function"
is JetClass -> "class"
is JetParameter -> "parameter"
is JetProperty -> "property"
else -> ""
}
}
public override fun getDescriptiveName(element: PsiElement): String {
return if (element is PsiNamedElement) element.getName() ?: "<unnamed>" else ""
}
public override fun getNodeText(element: PsiElement, useFullName: Boolean): String =
getDescriptiveName(element)
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2013 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.findUsages;
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.jet.lexer.JetLexer;
import org.jetbrains.jet.lexer.JetTokens;
public class JetWordsScanner extends DefaultWordsScanner {
public JetWordsScanner() {
super(new JetLexer(),
TokenSet.create(JetTokens.IDENTIFIER),
JetTokens.COMMENTS,
JetTokens.STRINGS);
}
}