當前位置: 首頁>>代碼示例>>Java>>正文


Java ExtractMethodProcessor類代碼示例

本文整理匯總了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());
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:42,代碼來源:SuggestedReturnTypesTest.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:68,代碼來源:ExtractMethodTest.java

示例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;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:58,代碼來源:ExtractMethodTest.java


注:本文中的com.intellij.refactoring.extractMethod.ExtractMethodProcessor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。