本文整理汇总了Java中com.intellij.refactoring.extractMethod.ExtractMethodProcessor类的典型用法代码示例。如果您正苦于以下问题:Java ExtractMethodProcessor类的具体用法?Java ExtractMethodProcessor怎么用?Java ExtractMethodProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExtractMethodProcessor类属于com.intellij.refactoring.extractMethod包,在下文中一共展示了ExtractMethodProcessor类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor; //导入依赖的package包/类
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());
}
}
示例2: performExtractMethod
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor; //导入依赖的package包/类
public static boolean performExtractMethod(boolean doRefactor,
boolean replaceAllDuplicates,
Editor editor,
PsiFile file,
Project project,
final boolean extractChainedConstructor,
PsiType returnType,
boolean makeStatic,
String newNameOfFirstParam,
int... disabledParams)
throws PrepareFailedException, IncorrectOperationException {
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);
}
if (elements.length == 0) {
final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
if (expression != null) {
elements = new PsiElement[]{expression};
}
}
assertTrue(elements.length > 0);
final ExtractMethodProcessor processor =
new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
processor.setShowErrorDialogs(false);
processor.setChainedConstructor(extractChainedConstructor);
if (!processor.prepare()) {
return false;
}
if (doRefactor) {
processor.testPrepare(returnType, makeStatic);
processor.testNullness();
if (disabledParams != null) {
for (int param : disabledParams) {
processor.doNotPassParameter(param);
}
}
if (newNameOfFirstParam != null) {
processor.changeParamName(0, newNameOfFirstParam);
}
ExtractMethodHandler.run(project, editor, processor);
}
if (replaceAllDuplicates) {
final Boolean hasDuplicates = processor.hasDuplicates();
if (hasDuplicates == null || hasDuplicates.booleanValue()) {
final List<Match> duplicates = processor.getDuplicates();
for (final Match match : duplicates) {
if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid()) continue;
PsiDocumentManager.getInstance(project).commitAllDocuments();
processor.processMatch(match);
}
}
}
return true;
}
示例3: performExtractMethod
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor; //导入依赖的package包/类
public static boolean performExtractMethod(boolean doRefactor,
boolean replaceAllDuplicates,
Editor editor,
PsiFile file,
Project project,
final boolean extractChainedConstructor,
int... disabledParams)
throws PrepareFailedException, IncorrectOperationException {
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);
}
if (elements.length == 0) {
final PsiExpression expression = IntroduceVariableBase.getSelectedExpression(project, file, startOffset, endOffset);
if (expression != null) {
elements = new PsiElement[]{expression};
}
}
assertTrue(elements.length > 0);
final ExtractMethodProcessor processor =
new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
processor.setShowErrorDialogs(false);
processor.setChainedConstructor(extractChainedConstructor);
if (!processor.prepare()) {
return false;
}
if (doRefactor) {
processor.testPrepare();
if (disabledParams != null) {
for (int param : disabledParams) {
processor.doNotPassParameter(param);
}
}
ExtractMethodHandler.run(project, editor, processor);
}
if (replaceAllDuplicates) {
final List<Match> duplicates = processor.getDuplicates();
for (final Match match : duplicates) {
if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid()) continue;
PsiDocumentManager.getInstance(project).commitAllDocuments();
processor.processMatch(match);
}
}
return true;
}