Pull Up: Rewrite some classes to Java to allow compilation against both Java 6 and Java 8

This commit is contained in:
Alexey Sedunov
2015-07-29 13:46:07 +03:00
parent e9d7bbf493
commit d71217eb5c
4 changed files with 99 additions and 28 deletions
@@ -0,0 +1,36 @@
/*
* 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.refactoring.memberInfo;
import com.intellij.openapi.util.Iconable;
import com.intellij.ui.ListCellRendererWrapper;
import org.jetbrains.kotlin.psi.JetClassOrObject;
import javax.swing.*;
public class JetClassOrObjectListCellRenderer extends ListCellRendererWrapper<JetClassOrObject> {
@Override
public void customize(JList list, JetClassOrObject value, int index, boolean selected, boolean hasFocus) {
if (value == null) return;
setText(MemberInfoPackage.qualifiedNameForRendering(value));
Icon icon = value.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
if (icon != null) {
setIcon(icon);
}
}
}
@@ -0,0 +1,62 @@
/*
* 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.refactoring.memberInfo;
import com.intellij.openapi.project.Project;
import com.intellij.refactoring.memberPullUp.PullUpDialogBase;
import com.intellij.refactoring.ui.AbstractMemberSelectionTable;
import org.jetbrains.kotlin.psi.JetClassOrObject;
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
// TODO: This is workaround which allows KotlinPullUpDialog to be compiled against both Java 6 and 8
public abstract class KotlinPullUpDialogBase extends
PullUpDialogBase<KotlinMemberInfoStorage, KotlinMemberInfo, JetNamedDeclaration, JetClassOrObject> {
protected KotlinPullUpDialogBase(
Project project,
JetClassOrObject object,
List<JetClassOrObject> superClasses,
KotlinMemberInfoStorage memberInfoStorage,
String title
) {
super(project, object, superClasses, memberInfoStorage, title);
}
@SuppressWarnings("unchecked")
@Override
protected void initClassCombo(JComboBox classCombo) {
classCombo.setRenderer(new JetClassOrObjectListCellRenderer());
classCombo.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (myMemberSelectionPanel == null) return;
AbstractMemberSelectionTable<JetNamedDeclaration, KotlinMemberInfo> table = myMemberSelectionPanel.getTable();
if (table == null) return;
table.setMemberInfos(myMemberInfos);
table.fireExternalDataChange();
}
}
}
);
}
}
@@ -16,18 +16,6 @@
package org.jetbrains.kotlin.idea.refactoring.memberInfo
import com.intellij.openapi.util.Iconable
import com.intellij.ui.ListCellRendererWrapper
import org.jetbrains.kotlin.psi.JetClassOrObject
import javax.swing.JList
public class JetClassOrObjectCellRenderer: ListCellRendererWrapper<JetClassOrObject>() {
override fun customize(list: JList, value: JetClassOrObject?, index: Int, selected: Boolean, hasFocus: Boolean) {
if (value == null) return
setText(value.qualifiedNameForRendering())
value.getIcon(Iconable.ICON_FLAG_VISIBILITY or Iconable.ICON_FLAG_READ_STATUS)?.let { setIcon(it) }
}
}
public fun JetClassOrObject.qualifiedNameForRendering(): String = getFqName()?.asString() ?: getName() ?: "[Anonymous]"
@@ -21,21 +21,18 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.psi.PsiComment
import com.intellij.refactoring.JavaRefactoringSettings
import com.intellij.refactoring.classMembers.AbstractMemberInfoModel
import com.intellij.refactoring.memberPullUp.PullUpDialogBase
import com.intellij.refactoring.memberPullUp.PullUpProcessor
import com.intellij.refactoring.util.DocCommentPolicy
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.idea.refactoring.memberInfo.*
import org.jetbrains.kotlin.psi.*
import java.awt.event.ItemEvent
import javax.swing.JComboBox
public class KotlinPullUpDialog(
project: Project,
private val classOrObject: JetClassOrObject,
superClasses: List<JetClass>,
memberInfoStorage: KotlinMemberInfoStorage
) : PullUpDialogBase<KotlinMemberInfoStorage, KotlinMemberInfo, JetNamedDeclaration, JetClassOrObject>(
) : KotlinPullUpDialogBase(
project, classOrObject, superClasses, memberInfoStorage, PULL_MEMBERS_UP
) {
init {
@@ -82,18 +79,6 @@ public class KotlinPullUpDialog(
override fun getSuperClass() = super.getSuperClass() as? JetClass
override fun initClassCombo(classCombo: JComboBox) {
classCombo.setRenderer(JetClassOrObjectCellRenderer())
classCombo.addItemListener { event ->
if (event.getStateChange() == ItemEvent.SELECTED) {
myMemberSelectionPanel?.getTable()?.let {
it.setMemberInfos(myMemberInfos)
it.fireExternalDataChange()
}
}
}
}
override fun createMemberInfoModel() = MemberInfoModelImpl()
override fun getPreselection() = mySuperClasses.firstOrNull()