use of com.intellij.refactoring.ui.TypeSelectorManager in project intellij-community by JetBrains.
the class SuggestedParamTypesTest method doTest.
private void doTest(String... types) throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final Editor editor = getEditor();
final PsiFile file = getFile();
final Project project = getProject();
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
PsiElement[] elements;
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
if (expr != null) {
elements = new PsiElement[] { expr };
} else {
elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
}
assertTrue(elements.length > 0);
final ExtractMethodProcessor processor = new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
processor.prepare();
for (final VariableData data : processor.getInputVariables().getInputVariables()) {
final PsiExpression[] occurrences = ParameterTablePanel.findVariableOccurrences(elements, data.variable);
final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, data.type, occurrences, true) {
@Override
protected boolean isUsedAfter() {
return processor.isOutputVariable(data.variable);
}
};
final JComponent component = manager.getTypeSelector().getComponent();
if (types.length > 1) {
assertTrue("One type suggested", component instanceof JComboBox);
final DefaultComboBoxModel model = (DefaultComboBoxModel) ((JComboBox) component).getModel();
assertEquals(types.length, model.getSize());
for (int i = 0, typesLength = types.length; i < typesLength; i++) {
String type = types[i];
assertEquals(type, model.getElementAt(i).toString());
}
} else if (types.length == 1) {
assertTrue("Multiple types suggested", component instanceof JLabel);
assertEquals(types[0], ((JLabel) component).getText());
}
}
}
use of com.intellij.refactoring.ui.TypeSelectorManager in project intellij-community by JetBrains.
the class ParameterTablePanel method createSelector.
protected TypeSelector createSelector(final Project project, final VariableData data, PsiElement[] scopeElements) {
final PsiVariable variable = data.variable;
final PsiExpression[] occurrences = findVariableOccurrences(scopeElements, variable);
final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, data.type, occurrences, areTypesDirected()) {
@Override
protected boolean isUsedAfter() {
return ParameterTablePanel.this.isUsedAfter(variable);
}
};
return manager.getTypeSelector();
}
use of com.intellij.refactoring.ui.TypeSelectorManager in project intellij-community by JetBrains.
the class SuggestedReturnTypesTest method doTest.
private void doTest(String... types) throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final Editor editor = getEditor();
final PsiFile file = getFile();
final Project project = getProject();
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
PsiElement[] elements;
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
if (expr != null) {
elements = new PsiElement[] { expr };
} else {
elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
}
assertTrue(elements.length > 0);
final ExtractMethodProcessor processor = new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
processor.prepare();
final PsiExpression[] occurrences = processor.findOccurrences();
final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, processor.getReturnType(), occurrences, true);
final JComponent component = manager.getTypeSelector().getComponent();
if (types.length > 1) {
assertTrue("One type suggested", component instanceof JComboBox);
final DefaultComboBoxModel model = (DefaultComboBoxModel) ((JComboBox) component).getModel();
assertEquals(types.length, model.getSize());
for (int i = 0, typesLength = types.length; i < typesLength; i++) {
String type = types[i];
assertEquals(type, model.getElementAt(i).toString());
}
} else if (types.length == 1) {
assertTrue("Multiple types suggested", component instanceof JLabel);
assertEquals(types[0], ((JLabel) component).getText());
}
}
Aggregations