当前位置: 首页>>代码示例>>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;未经允许,请勿转载。