mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Initial version of extract method for python
This commit is contained in:
@@ -576,7 +576,8 @@ public class PsiTreeUtil {
|
||||
return filteredElements.toArray(new PsiElement[filteredElements.size()]);
|
||||
}
|
||||
|
||||
public static boolean treeWalkUp(@NotNull final PsiScopeProcessor processor, @NotNull final PsiElement entrance,
|
||||
public static boolean treeWalkUp(@NotNull final PsiScopeProcessor processor,
|
||||
@NotNull final PsiElement entrance,
|
||||
@Nullable final PsiElement maxScope,
|
||||
@NotNull final ResolveState state) {
|
||||
PsiElement prevParent = entrance;
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
/**
|
||||
* @author oleg
|
||||
*/
|
||||
public interface ExtractMethodDecorator {
|
||||
String createMethodPreview(String methodName, VariableData[] variableDatas);
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
import com.intellij.codeInsight.codeFragment.CodeFragment;
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExtractMethodDialog extends DialogWrapper implements ExtractMethodSettings {
|
||||
private JPanel myContentPane;
|
||||
private ParameterTablePanel myParametersPanel;
|
||||
private JTextField myMethodNameTextField;
|
||||
private JTextArea mySignaturePreviewTextArea;
|
||||
private JTextArea myOutputVariablesTextArea;
|
||||
private final String myDefaultName;
|
||||
private final ExtractMethodValidator myValidator;
|
||||
private final ExtractMethodDecorator myDecorator;
|
||||
|
||||
private VariableData[] myVariableData;
|
||||
private Map<String, VariableData> myVariablesMap;
|
||||
|
||||
private final List<String> myArguments;
|
||||
private final ArrayList<String> myOutputVariables;
|
||||
|
||||
public ExtractMethodDialog(final Project project,
|
||||
final String defaultName,
|
||||
final CodeFragment fragment,
|
||||
final ExtractMethodValidator validator,
|
||||
final ExtractMethodDecorator decorator) {
|
||||
super(project, true);
|
||||
myDefaultName = defaultName;
|
||||
CodeFragment fragment1 = fragment;
|
||||
myValidator = validator;
|
||||
myDecorator = decorator;
|
||||
myArguments = new ArrayList<String>(fragment1.getInputVariables());
|
||||
Collections.sort(myArguments);
|
||||
myOutputVariables = new ArrayList<String>(fragment1.getOutputVariables());
|
||||
Collections.sort(myOutputVariables);
|
||||
setModal(true);
|
||||
setTitle(RefactoringBundle.message("extract.method.title"));
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
// Set default name and select it
|
||||
myMethodNameTextField.setText(myDefaultName);
|
||||
myMethodNameTextField.setSelectionStart(0);
|
||||
myMethodNameTextField.setSelectionStart(myDefaultName.length());
|
||||
myMethodNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
updateOutputVariables();
|
||||
updateSignature();
|
||||
updateOkStatus();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
myVariableData = createVariableData(myArguments);
|
||||
myVariablesMap = createVariableMap(myVariableData);
|
||||
myParametersPanel.setVariableData(myVariableData);
|
||||
myParametersPanel.init();
|
||||
|
||||
updateOutputVariables();
|
||||
updateSignature();
|
||||
updateOkStatus();
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myMethodNameTextField;
|
||||
}
|
||||
|
||||
public static VariableData[] createVariableData(final List<String> args) {
|
||||
final VariableData[] datas = new VariableData[args.size()];
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
final VariableData data = new VariableData();
|
||||
final String name = args.get(i);
|
||||
data.originalName = name;
|
||||
data.name = name;
|
||||
data.passAsParameter = true;
|
||||
datas[i] = data;
|
||||
}
|
||||
return datas;
|
||||
}
|
||||
|
||||
public static Map<String, VariableData> createVariableMap(final VariableData[] data) {
|
||||
final HashMap<String, VariableData> map = new HashMap<String, VariableData>();
|
||||
for (VariableData variableData : data) {
|
||||
map.put(variableData.getOriginalName(), variableData);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Action[] createActions() {
|
||||
return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
final String error = myValidator.check(getMethodName());
|
||||
if (error!=null){
|
||||
Messages.showInfoMessage(error, RefactoringBundle.message("error.title"));
|
||||
return;
|
||||
}
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHelpAction() {
|
||||
HelpManager.getInstance().invokeHelp("refactoring.extractMethod");
|
||||
}
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
return myContentPane;
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
myParametersPanel = new ParameterTablePanel(myValidator){
|
||||
protected void doCancelAction() {
|
||||
ExtractMethodDialog.this.doCancelAction();
|
||||
}
|
||||
|
||||
protected void doEnterAction() {
|
||||
doOKAction();
|
||||
}
|
||||
|
||||
protected void updateSignature() {
|
||||
updateOutputVariables();
|
||||
ExtractMethodDialog.this.updateSignature();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateOutputVariables() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String variable : myOutputVariables) {
|
||||
if (myVariablesMap!=null){
|
||||
final VariableData data = myVariablesMap.get(variable);
|
||||
final String outputName = data != null ? data.getName() : variable;
|
||||
if (first){
|
||||
first = false;
|
||||
} else {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(outputName);
|
||||
}
|
||||
}
|
||||
myOutputVariablesTextArea.setText(builder.length() > 0 ? builder.toString() : RefactoringBundle.message("Empty output variables"));
|
||||
}
|
||||
|
||||
private void updateSignature() {
|
||||
//final StringBuilder builder = new StringBuilder();
|
||||
//builder.append(PyTokenTypes.DEF_KEYWORD.toString()).append(' ').append(getMethodName());
|
||||
//builder.append("(");
|
||||
//if (myVariableData!=null){
|
||||
// boolean first = true;
|
||||
// for (VariableData variableData : myVariableData) {
|
||||
// if (variableData.passAsParameter){
|
||||
// if (first){
|
||||
// first = false;
|
||||
// } else {
|
||||
// builder.append(", ");
|
||||
// }
|
||||
// builder.append(variableData.name);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//builder.append(")\nend");
|
||||
//mySignaturePreviewTextArea.setText(builder.toString());
|
||||
mySignaturePreviewTextArea.setText(myDecorator.createMethodPreview(getMethodName(), myVariableData));
|
||||
}
|
||||
|
||||
private void updateOkStatus() {
|
||||
setOKActionEnabled(myValidator.isValidName(getMethodName()));
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return myMethodNameTextField.getText().trim();
|
||||
}
|
||||
|
||||
public VariableData[] getVariableData() {
|
||||
return myVariableData;
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
/**
|
||||
* @author oleg
|
||||
*/
|
||||
public interface ExtractMethodSettings {
|
||||
String getMethodName();
|
||||
VariableData[] getVariableData();
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author oleg
|
||||
* This validator should check if name will clash with existing methods
|
||||
*/
|
||||
public interface ExtractMethodValidator {
|
||||
@Nullable
|
||||
String check(String name);
|
||||
|
||||
boolean isValidName(String name);
|
||||
}
|
||||
+318
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.TableUtil;
|
||||
import com.intellij.ui.UIBundle;
|
||||
import com.intellij.util.ui.Table;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* @author oleg
|
||||
* It`s a modified copy of com.intellij.refactoring.util.ParameterTablePanel
|
||||
*/
|
||||
public abstract class ParameterTablePanel extends JPanel {
|
||||
private VariableData[] myVariableData;
|
||||
|
||||
private Table myTable;
|
||||
private MyTableModel myTableModel;
|
||||
private JButton myUpButton;
|
||||
private JButton myDownButton;
|
||||
private final ExtractMethodValidator myValidator;
|
||||
|
||||
protected abstract void updateSignature();
|
||||
|
||||
protected abstract void doEnterAction();
|
||||
|
||||
protected abstract void doCancelAction();
|
||||
|
||||
public void setVariableData(VariableData[] variableData) {
|
||||
myVariableData = variableData;
|
||||
}
|
||||
|
||||
public ParameterTablePanel(final ExtractMethodValidator validator) {
|
||||
super(new BorderLayout());
|
||||
myValidator = validator;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
myTableModel = new MyTableModel();
|
||||
myTable = new Table(myTableModel);
|
||||
DefaultCellEditor defaultEditor = (DefaultCellEditor)myTable.getDefaultEditor(Object.class);
|
||||
defaultEditor.setClickCountToStart(1);
|
||||
|
||||
myTable.setTableHeader(null);
|
||||
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
myTable.getColumnModel().getColumn(MyTableModel.CHECKMARK_COLUMN).setMaxWidth(new JCheckBox().getPreferredSize().width);
|
||||
myTable.getColumnModel().getColumn(MyTableModel.PARAMETER_NAME_COLUMN).setCellRenderer(new DefaultTableCellRenderer() {
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
VariableData data = myVariableData[row];
|
||||
setText(data.name);
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
myTable.setPreferredScrollableViewportSize(new Dimension(250, myTable.getRowHeight() * 5));
|
||||
myTable.setShowGrid(false);
|
||||
myTable.setIntercellSpacing(new Dimension(0, 0));
|
||||
@NonNls final InputMap inputMap = myTable.getInputMap();
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
|
||||
@NonNls final ActionMap actionMap = myTable.getActionMap();
|
||||
actionMap.put("enable_disable", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (myTable.isEditing()) return;
|
||||
int[] rows = myTable.getSelectedRows();
|
||||
if (rows.length > 0) {
|
||||
boolean valueToBeSet = false;
|
||||
for (int row : rows) {
|
||||
if (!myVariableData[row].passAsParameter) {
|
||||
valueToBeSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int row : rows) {
|
||||
myVariableData[row].passAsParameter = valueToBeSet;
|
||||
}
|
||||
myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]);
|
||||
TableUtil.selectRows(myTable, rows);
|
||||
}
|
||||
}
|
||||
});
|
||||
// F2 should edit the name
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "edit_parameter_name");
|
||||
actionMap.put("edit_parameter_name", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (!myTable.isEditing()) {
|
||||
int row = myTable.getSelectedRow();
|
||||
if (row >= 0 && row < myTableModel.getRowCount()) {
|
||||
TableUtil.editCellAt(myTable, row, MyTableModel.PARAMETER_NAME_COLUMN);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make ENTER work when the table has focus
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl");
|
||||
actionMap.put("invokeImpl", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
TableCellEditor editor = myTable.getCellEditor();
|
||||
if (editor != null) {
|
||||
editor.stopCellEditing();
|
||||
}
|
||||
else {
|
||||
doEnterAction();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make ESCAPE work when the table has focus
|
||||
actionMap.put("doCancel", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
TableCellEditor editor = myTable.getCellEditor();
|
||||
if (editor != null) {
|
||||
editor.stopCellEditing();
|
||||
}
|
||||
else {
|
||||
doCancelAction();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JPanel listPanel = new JPanel(new BorderLayout());
|
||||
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
|
||||
listPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
listPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
|
||||
add(listPanel, BorderLayout.CENTER);
|
||||
|
||||
JPanel buttonsPanel = new JPanel();
|
||||
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
|
||||
add(buttonsPanel, BorderLayout.EAST);
|
||||
|
||||
buttonsPanel.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
||||
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbConstraints.insets = new Insets(2, 4, 2, 4);
|
||||
|
||||
myUpButton = new JButton();
|
||||
myUpButton.setText(UIBundle.message("row.move.up"));
|
||||
myUpButton.setDefaultCapable(false);
|
||||
buttonsPanel.add(myUpButton, gbConstraints);
|
||||
|
||||
myDownButton = new JButton();
|
||||
myDownButton.setText(UIBundle.message("row.move.down"));
|
||||
myDownButton.setDefaultCapable(false);
|
||||
buttonsPanel.add(myDownButton, gbConstraints);
|
||||
|
||||
gbConstraints.weighty = 1;
|
||||
buttonsPanel.add(new JPanel(), gbConstraints);
|
||||
|
||||
myUpButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (myTable.isEditing()) {
|
||||
final boolean isStopped = myTable.getCellEditor().stopCellEditing();
|
||||
if (!isStopped) return;
|
||||
}
|
||||
moveSelectedItem(-1);
|
||||
updateSignature();
|
||||
myTable.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
myDownButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (myTable.isEditing()) {
|
||||
final boolean isStopped = myTable.getCellEditor().stopCellEditing();
|
||||
if (!isStopped) return;
|
||||
}
|
||||
moveSelectedItem(+1);
|
||||
updateSignature();
|
||||
myTable.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
updateMoveButtons();
|
||||
}
|
||||
});
|
||||
if (myVariableData.length <= 1) {
|
||||
myUpButton.setEnabled(false);
|
||||
myDownButton.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
myTable.getSelectionModel().setSelectionInterval(0, 0);
|
||||
}
|
||||
updateMoveButtons();
|
||||
}
|
||||
|
||||
private void updateMoveButtons() {
|
||||
int row = myTable.getSelectedRow();
|
||||
if (0 <= row && row < myVariableData.length) {
|
||||
myUpButton.setEnabled(row > 0);
|
||||
myDownButton.setEnabled(row < myVariableData.length - 1);
|
||||
}
|
||||
else {
|
||||
myUpButton.setEnabled(false);
|
||||
myDownButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void moveSelectedItem(int moveIncrement) {
|
||||
int row = myTable.getSelectedRow();
|
||||
if (row < 0 || row >= myVariableData.length) return;
|
||||
int targetRow = row + moveIncrement;
|
||||
if (targetRow < 0 || targetRow >= myVariableData.length) return;
|
||||
|
||||
VariableData currentItem = myVariableData[row];
|
||||
myVariableData[row] = myVariableData[targetRow];
|
||||
myVariableData[targetRow] = currentItem;
|
||||
|
||||
myTableModel.fireTableRowsUpdated(Math.min(targetRow, row), Math.max(targetRow, row));
|
||||
myTable.getSelectionModel().setSelectionInterval(targetRow, targetRow);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
myTable.setEnabled(enabled);
|
||||
if (!enabled) {
|
||||
myUpButton.setEnabled(false);
|
||||
myDownButton.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
updateMoveButtons();
|
||||
}
|
||||
super.setEnabled(enabled);
|
||||
}
|
||||
|
||||
private class MyTableModel extends AbstractTableModel {
|
||||
public static final int CHECKMARK_COLUMN = 0;
|
||||
public static final int PARAMETER_NAME_COLUMN = 1;
|
||||
|
||||
public int getRowCount() {
|
||||
return myVariableData.length;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case CHECKMARK_COLUMN: {
|
||||
return myVariableData[rowIndex].passAsParameter ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
case PARAMETER_NAME_COLUMN: {
|
||||
return myVariableData[rowIndex].name;
|
||||
}
|
||||
}
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case CHECKMARK_COLUMN: {
|
||||
myVariableData[rowIndex].passAsParameter = ((Boolean)aValue).booleanValue();
|
||||
fireTableRowsUpdated(rowIndex, rowIndex);
|
||||
myTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex);
|
||||
updateSignature();
|
||||
break;
|
||||
}
|
||||
case PARAMETER_NAME_COLUMN: {
|
||||
VariableData data = myVariableData[rowIndex];
|
||||
String name = (String)aValue;
|
||||
if (myValidator.isValidName(name)) {
|
||||
data.name = name;
|
||||
}
|
||||
updateSignature();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case CHECKMARK_COLUMN:
|
||||
return isEnabled();
|
||||
case PARAMETER_NAME_COLUMN:
|
||||
return isEnabled() && myVariableData[rowIndex].passAsParameter;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
if (columnIndex == CHECKMARK_COLUMN) {
|
||||
return Boolean.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.refactoring.extractmethod.ExtractMethodDialog">
|
||||
<grid id="cbd77" binding="myContentPane" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="297"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="462a8" class="javax.swing.JTextField" binding="myMethodNameTextField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<columns value="10"/>
|
||||
<horizontalAlignment value="2"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e8f16" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="org/jetbrains/plugins/ruby/RBundle" key="refactoring.extract.method.dialog.method.name"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="865ab" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="etched" title-resource-bundle="org/jetbrains/plugins/ruby/RBundle" title-key="refactoring.extract.method.dialog.parameters"/>
|
||||
<children>
|
||||
<component id="d4ee9" class="com.intellij.refactoring.extractmethod.ParameterTablePanel" binding="myParametersPanel" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<scrollpane id="b0a7b">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6b27f" class="javax.swing.JTextArea" binding="mySignaturePreviewTextArea">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<columns value="10"/>
|
||||
<editable value="false"/>
|
||||
<enabled value="true"/>
|
||||
<rows value="0"/>
|
||||
<text value="def foo()"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="d94f6" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="org/jetbrains/plugins/ruby/RBundle" key="refactoring.extract.method.dialog.signature.preview"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="ca3f5">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="ccc83" class="javax.swing.JTextArea" binding="myOutputVariablesTextArea">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="4bbe1" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="org/jetbrains/plugins/ruby/RBundle" key="refactoring.extract.method.dialog.output.variables"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 com.intellij.refactoring.extractmethod;
|
||||
|
||||
/**
|
||||
* @author oleg
|
||||
*/
|
||||
public class VariableData {
|
||||
public String originalName;
|
||||
public String name;
|
||||
public boolean passAsParameter;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getOriginalName() {
|
||||
return originalName;
|
||||
}
|
||||
|
||||
public boolean isPassAsParameter() {
|
||||
return passAsParameter;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user