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


Java ExtractMethodProcessor.testPrepare方法代碼示例

本文整理匯總了Java中com.intellij.refactoring.extractMethod.ExtractMethodProcessor.testPrepare方法的典型用法代碼示例。如果您正苦於以下問題:Java ExtractMethodProcessor.testPrepare方法的具體用法?Java ExtractMethodProcessor.testPrepare怎麽用?Java ExtractMethodProcessor.testPrepare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.refactoring.extractMethod.ExtractMethodProcessor的用法示例。


在下文中一共展示了ExtractMethodProcessor.testPrepare方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例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,
                                           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.testPrepare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。