Converted to Kotlin

This commit is contained in:
Valentin Kipyatkov
2015-11-10 14:01:09 +03:00
parent 774b3269d6
commit 6006969ab9
10 changed files with 181 additions and 221 deletions
@@ -1,64 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation;
import com.intellij.navigation.ColoredItemPresentation;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.Iconable;
import org.jetbrains.kotlin.idea.KotlinIconProvider;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtNamedDeclaration;
import org.jetbrains.kotlin.psi.KtPsiUtil;
import javax.swing.*;
public class KotlinDefaultNamedDeclarationPresentation implements ColoredItemPresentation {
private final KtNamedDeclaration declaration;
KotlinDefaultNamedDeclarationPresentation(KtNamedDeclaration declaration) {
this.declaration = declaration;
}
@Override
public TextAttributesKey getTextAttributesKey() {
if (KtPsiUtil.isDeprecated(declaration)) {
return CodeInsightColors.DEPRECATED_ATTRIBUTES;
}
return null;
}
@Override
public String getPresentableText() {
return declaration.getName();
}
@Override
public String getLocationString() {
FqName name = declaration.getFqName();
if (name != null) {
return "(" + name.parent().toString() + ")";
}
return null;
}
@Override
public Icon getIcon(boolean unused) {
return KotlinIconProvider.INSTANCE.getIcon(declaration, Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
}
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation
import com.intellij.navigation.ColoredItemPresentation
import com.intellij.openapi.editor.colors.CodeInsightColors
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.util.Iconable
import org.jetbrains.kotlin.idea.KotlinIconProvider
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtPsiUtil
open class KotlinDefaultNamedDeclarationPresentation(private val declaration: KtNamedDeclaration) : ColoredItemPresentation {
override fun getTextAttributesKey(): TextAttributesKey? {
if (KtPsiUtil.isDeprecated(declaration)) {
return CodeInsightColors.DEPRECATED_ATTRIBUTES
}
return null
}
override fun getPresentableText() = declaration.name
override fun getLocationString(): String? {
val name = declaration.fqName ?: return null
return "(" + name.parent().asString() + ")"
}
override fun getIcon(unused: Boolean)
= KotlinIconProvider.INSTANCE.getIcon(declaration, Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS)
}
@@ -14,15 +14,11 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.presentation;
package org.jetbrains.kotlin.idea.presentation
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.jetbrains.kotlin.psi.KtObjectDeclaration;
import com.intellij.navigation.ItemPresentationProvider
import org.jetbrains.kotlin.psi.KtClass
public class KtObjectPresenter implements ItemPresentationProvider<KtObjectDeclaration> {
@Override
public ItemPresentation getPresentation(KtObjectDeclaration item) {
return new KotlinDefaultNamedDeclarationPresentation(item);
}
class KtClassPresenter : ItemPresentationProvider<KtClass> {
override fun getPresentation(item: KtClass) = KotlinDefaultNamedDeclarationPresentation(item)
}
@@ -1,79 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.*;
import java.util.Collection;
public class KtFunctionPresenter implements ItemPresentationProvider<KtFunction> {
@Override
public ItemPresentation getPresentation(@NotNull final KtFunction function) {
if (function instanceof KtFunctionLiteral) return null;
return new KotlinDefaultNamedDeclarationPresentation(function) {
@Override
public String getPresentableText() {
StringBuilder presentation = new StringBuilder(function.getName() != null ? function.getName() : "");
Collection<String> paramsStrings = Collections2.transform(function.getValueParameters(), new Function<KtParameter, String>() {
@Override
public String apply(KtParameter parameter) {
if (parameter != null) {
KtTypeReference reference = parameter.getTypeReference();
if (reference != null) {
String text = reference.getText();
if (text != null) {
return text;
}
}
}
return "?";
}
});
presentation.append("(").append(StringUtils.join(paramsStrings, ",")).append(")");
return presentation.toString();
}
@Override
public String getLocationString() {
if (function instanceof KtConstructor) {
FqName name = ((KtConstructor) function).getContainingClassOrObject().getFqName();
return name != null ? String.format("(in %s)", name) : "";
}
FqName name = function.getFqName();
if (name != null) {
KtTypeReference receiverTypeRef = function.getReceiverTypeReference();
String extensionLocation = receiverTypeRef != null ? "for " + receiverTypeRef.getText() + " " : "";
return String.format("(%sin %s)", extensionLocation, name.parent());
}
return "";
}
};
}
}
@@ -0,0 +1,68 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation
import com.google.common.base.Function
import com.google.common.collect.Collections2
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProvider
import org.apache.commons.lang.StringUtils
import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtFunctionLiteral
class KtFunctionPresenter : ItemPresentationProvider<KtFunction> {
override fun getPresentation(function: KtFunction): ItemPresentation? {
if (function is KtFunctionLiteral) return null
return object : KotlinDefaultNamedDeclarationPresentation(function) {
override fun getPresentableText(): String {
return buildString {
function.name?.let { append(it) }
val paramsStrings = Collections2.transform(function.valueParameters, Function<org.jetbrains.kotlin.psi.KtParameter, kotlin.String> { parameter ->
if (parameter != null) {
val reference = parameter.typeReference
if (reference != null) {
val text = reference.text
if (text != null) {
return@Function text
}
}
}
"?"
})
append("(").append(StringUtils.join(paramsStrings, ",")).append(")")
}
}
override fun getLocationString(): String {
if (function is KtConstructor<*>) {
val name = function.getContainingClassOrObject().fqName ?: return ""
return "(in $name)"
}
val name = function.fqName ?: return ""
val receiverTypeRef = function.receiverTypeReference
val extensionLocation = if (receiverTypeRef != null) "for " + receiverTypeRef.text + " " else ""
return "(%sin %s)".format(extensionLocation, name.parent())
}
}
}
}
@@ -1,45 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation;
import com.intellij.ide.util.PsiElementListCellRenderer;
import com.intellij.psi.presentation.java.ClassPresentationUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.asJava.KtLightClass;
public class KtLightClassListCellRenderer extends PsiElementListCellRenderer<KtLightClass> {
@Override
public String getElementText(@NotNull KtLightClass element) {
return ClassPresentationUtil.getNameForClass(element, false);
}
@Override
protected String getContainerText(KtLightClass element, String name) {
return getContainerTextStatic(element);
}
@Nullable
public static String getContainerTextStatic(KtLightClass element) {
return "(" + element.getFqName().parent() + ")";
}
@Override
protected int getIconFlags() {
return 0;
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2015 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.kotlin.idea.presentation
import com.intellij.ide.util.PsiElementListCellRenderer
import com.intellij.psi.presentation.java.ClassPresentationUtil
import org.jetbrains.kotlin.asJava.KtLightClass
class KtLightClassListCellRenderer : PsiElementListCellRenderer<KtLightClass>() {
override fun getElementText(element: KtLightClass): String {
return ClassPresentationUtil.getNameForClass(element, false)
}
override fun getContainerText(element: KtLightClass, name: String): String? {
return getContainerTextStatic(element)
}
override fun getIconFlags(): Int {
return 0
}
companion object {
fun getContainerTextStatic(element: KtLightClass): String? {
return "(" + element.getFqName().parent() + ")"
}
}
}
@@ -14,15 +14,14 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.presentation;
package org.jetbrains.kotlin.idea.presentation
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.jetbrains.kotlin.psi.KtProperty;
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProvider
import org.jetbrains.kotlin.psi.KtObjectDeclaration
public class KtPropertyPresenter implements ItemPresentationProvider<KtProperty> {
@Override
public ItemPresentation getPresentation(KtProperty item) {
return new KotlinDefaultNamedDeclarationPresentation(item);
class KtObjectPresenter : ItemPresentationProvider<KtObjectDeclaration> {
override fun getPresentation(item: KtObjectDeclaration): ItemPresentation {
return KotlinDefaultNamedDeclarationPresentation(item)
}
}
@@ -14,15 +14,14 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.presentation;
package org.jetbrains.kotlin.idea.presentation
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.jetbrains.kotlin.psi.KtClass;
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProvider
import org.jetbrains.kotlin.psi.KtParameter
public class KtClassPresenter implements ItemPresentationProvider<KtClass> {
@Override
public ItemPresentation getPresentation(KtClass item) {
return new KotlinDefaultNamedDeclarationPresentation(item);
class KtParameterPresenter : ItemPresentationProvider<KtParameter> {
override fun getPresentation(item: KtParameter): ItemPresentation {
return KotlinDefaultNamedDeclarationPresentation(item)
}
}
@@ -14,15 +14,14 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.presentation;
package org.jetbrains.kotlin.idea.presentation
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.jetbrains.kotlin.psi.KtParameter;
import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProvider
import org.jetbrains.kotlin.psi.KtProperty
public class KtParameterPresenter implements ItemPresentationProvider<KtParameter> {
@Override
public ItemPresentation getPresentation(KtParameter item) {
return new KotlinDefaultNamedDeclarationPresentation(item);
class KtPropertyPresenter : ItemPresentationProvider<KtProperty> {
override fun getPresentation(item: KtProperty): ItemPresentation {
return KotlinDefaultNamedDeclarationPresentation(item)
}
}