From 6006969ab9ad0844233c815a8bd174ff484b49cb Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 10 Nov 2015 14:01:09 +0300 Subject: [PATCH] Converted to Kotlin --- ...inDefaultNamedDeclarationPresentation.java | 64 --------------- ...tlinDefaultNamedDeclarationPresentation.kt | 45 +++++++++++ ...jectPresenter.java => KtClassPresenter.kt} | 14 ++-- .../presentation/KtFunctionPresenter.java | 79 ------------------- .../idea/presentation/KtFunctionPresenter.kt | 68 ++++++++++++++++ .../KtLightClassListCellRenderer.java | 45 ----------- .../KtLightClassListCellRenderer.kt | 42 ++++++++++ ...rtyPresenter.java => KtObjectPresenter.kt} | 15 ++-- ...Presenter.java => KtParameterPresenter.kt} | 15 ++-- ...rPresenter.java => KtPropertyPresenter.kt} | 15 ++-- 10 files changed, 181 insertions(+), 221 deletions(-) delete mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.java create mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.kt rename idea/src/org/jetbrains/kotlin/idea/presentation/{KtObjectPresenter.java => KtClassPresenter.kt} (57%) delete mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.java create mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.java create mode 100644 idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.kt rename idea/src/org/jetbrains/kotlin/idea/presentation/{KtPropertyPresenter.java => KtObjectPresenter.kt} (58%) rename idea/src/org/jetbrains/kotlin/idea/presentation/{KtClassPresenter.java => KtParameterPresenter.kt} (59%) rename idea/src/org/jetbrains/kotlin/idea/presentation/{KtParameterPresenter.java => KtPropertyPresenter.kt} (58%) diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.java deleted file mode 100644 index cb2ea100469..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.java +++ /dev/null @@ -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); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.kt b/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.kt new file mode 100644 index 00000000000..b689c683410 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KotlinDefaultNamedDeclarationPresentation.kt @@ -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) +} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.kt similarity index 57% rename from idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.java rename to idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.kt index b4e00c9c510..ca6b8521a5d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.java +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.kt @@ -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 { - @Override - public ItemPresentation getPresentation(KtObjectDeclaration item) { - return new KotlinDefaultNamedDeclarationPresentation(item); - } +class KtClassPresenter : ItemPresentationProvider { + override fun getPresentation(item: KtClass) = KotlinDefaultNamedDeclarationPresentation(item) } diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.java deleted file mode 100644 index 45d9f2bc8af..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.java +++ /dev/null @@ -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 { - @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 paramsStrings = Collections2.transform(function.getValueParameters(), new Function() { - @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 ""; - } - }; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.kt b/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.kt new file mode 100644 index 00000000000..65247f3abee --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtFunctionPresenter.kt @@ -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 { + 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 { 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()) + } + } + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.java deleted file mode 100644 index e2198bf6cea..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.java +++ /dev/null @@ -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 { - @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; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.kt new file mode 100644 index 00000000000..84afe08d52f --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtLightClassListCellRenderer.kt @@ -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() { + 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() + ")" + } + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.kt similarity index 58% rename from idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.java rename to idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.kt index 6d9f7fe558e..82576110f27 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.java +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtObjectPresenter.kt @@ -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 { - @Override - public ItemPresentation getPresentation(KtProperty item) { - return new KotlinDefaultNamedDeclarationPresentation(item); +class KtObjectPresenter : ItemPresentationProvider { + override fun getPresentation(item: KtObjectDeclaration): ItemPresentation { + return KotlinDefaultNamedDeclarationPresentation(item) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.kt similarity index 59% rename from idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.java rename to idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.kt index 15ae4ca71b4..8e9d65fd765 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtClassPresenter.java +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.kt @@ -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 { - @Override - public ItemPresentation getPresentation(KtClass item) { - return new KotlinDefaultNamedDeclarationPresentation(item); +class KtParameterPresenter : ItemPresentationProvider { + override fun getPresentation(item: KtParameter): ItemPresentation { + return KotlinDefaultNamedDeclarationPresentation(item) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.java b/idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.kt similarity index 58% rename from idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.java rename to idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.kt index 241f07c93ad..aa0b72279ff 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/KtParameterPresenter.java +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/KtPropertyPresenter.kt @@ -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 { - @Override - public ItemPresentation getPresentation(KtParameter item) { - return new KotlinDefaultNamedDeclarationPresentation(item); +class KtPropertyPresenter : ItemPresentationProvider { + override fun getPresentation(item: KtProperty): ItemPresentation { + return KotlinDefaultNamedDeclarationPresentation(item) } }