当前位置: 首页>>代码示例>>Java>>正文


Java CommonRefactoringUtil.RefactoringErrorHintException方法代码示例

本文整理汇总了Java中com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException方法的典型用法代码示例。如果您正苦于以下问题:Java CommonRefactoringUtil.RefactoringErrorHintException方法的具体用法?Java CommonRefactoringUtil.RefactoringErrorHintException怎么用?Java CommonRefactoringUtil.RefactoringErrorHintException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.refactoring.util.CommonRefactoringUtil的用法示例。


在下文中一共展示了CommonRefactoringUtil.RefactoringErrorHintException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext, @Nullable Editor editor) {
  if (element != null && !canRename(project, editor, element)) {
    return;
  }

  VirtualFile contextFile = PsiUtilCore.getVirtualFile(nameSuggestionContext);

  if (nameSuggestionContext != null &&
      nameSuggestionContext.isPhysical() &&
      (contextFile == null || contextFile.getFileType() != ScratchFileType.INSTANCE) &&
      !PsiManager.getInstance(project).isInProject(nameSuggestionContext)) {
    final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
    if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
    if (Messages.showYesNoDialog(project, message,
                                 RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != Messages.YES) {
      return;
    }
  }

  FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");

  rename(element, project, nameSuggestionContext, editor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PsiElementRenameHandler.java

示例2: test20

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void test20() {
  final boolean thisOnly = false;
  final String testName = getTestName(true);
  final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + testName + "_styles.xml", "res/values/styles.xml");
  final String layoutPath = BASE_PATH + testName + ".xml";
  myFixture.copyFileToProject(layoutPath, "res/layout/test.xml");
  myFixture.configureFromExistingVirtualFile(f);
  try {
    doCommonInlineAction(thisOnly);
    fail();
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
  }
  myFixture.checkResultByFile(BASE_PATH + testName + "_styles_after.xml", true);
  myFixture.checkResultByFile("res/layout/test.xml", layoutPath, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidInlineStyleTest.java

示例3: testNotAvailableForArrayLength

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testNotAvailableForArrayLength() throws Exception {
  try {
    doTest("val");
    fail("Should be impossible to rename");
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Cannot perform refactoring.\n" +
                 "This element cannot be renamed", e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:RenameCollisionsTest.java

示例4: testRejectIntroduceFieldFromExprInThisCall

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testRejectIntroduceFieldFromExprInThisCall() throws Exception {
  configureByFile("/refactoring/introduceField/beforeRejectIntroduceFieldFromExprInThisCall.java");
  try {
    performRefactoring(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, false);
    fail("Should not proceed");
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Cannot perform refactoring.\n" +
                 "Invalid expression context.", e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:IntroduceFieldInSameClassTest.java

示例5: testParameterWithWriteAccess

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testParameterWithWriteAccess() throws Exception {
  try {
    doTest(false);
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Inline parameter which has write usages is not supported", e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:InlineParameterTest.java

示例6: doTestCannotFindInitializer

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
private void doTestCannotFindInitializer() throws Exception {
  try {
    doTest(false);
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Cannot find constant initializer for parameter", e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:InlineParameterTest.java

示例7: testCantInlineRecursive

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testCantInlineRecursive() throws Exception {
  try {
    doTest(false);
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Cannot find constant initializer for parameter", e.getMessage());
    return;
  }
  fail("Initializer shoul not be found");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:InlineParameterTest.java

示例8: testParameterDefWithWriteAccess

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testParameterDefWithWriteAccess()  throws Exception {
  try {
    doTest(false);
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals("Method has no usages", e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:InlineParameterTest.java

示例9: canRename

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
static boolean canRename(Project project, Editor editor, PsiElement element) throws CommonRefactoringUtil.RefactoringErrorHintException {
  String message = renameabilityStatus(project, element);
  if (StringUtil.isNotEmpty(message)) {
    showErrorMessage(project, editor, message);
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PsiElementRenameHandler.java

示例10: doTestCannotPerform

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
private void doTestCannotPerform(String expected) {
  try {
    doTest();
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    assertEquals(expected, e.getMessage());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PyIntroduceParameterTest.java

示例11: doTestCannotPerform

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
private void doTestCannotPerform() {
  boolean thrownExpectedException = false;
  try {
    doTest();
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    if (e.getMessage().equals("Cannot perform refactoring using selected element(s)")) {
      thrownExpectedException = true;
    }
  }
  assertTrue(thrownExpectedException);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PyIntroduceVariableTest.java

示例12: testInlineResourceField

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void testInlineResourceField() throws Exception {
  copyFileToProject("value_resources.xml", "res/values/value_resources.xml");
  final VirtualFile virtualFile = copyFileToProject(getTestName(false) + ".java", "src/p1/p2/" + getTestName(false) + ".java");
  myFixture.configureFromExistingVirtualFile(virtualFile);
  try {
    myFixture.testAction(new InlineAction());
    fail();
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
  }
  myFixture.checkResultByFile(testFolder + '/' + getTestName(false) + ".java", true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:AndroidValueResourcesTest.java

示例13: test18

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
public void test18() {
  final String testName = getTestName(true);
  final String stylesPath = BASE_PATH + testName + "_styles.xml";
  myFixture.copyFileToProject(stylesPath, "res/values/styles.xml");
  final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + testName + ".xml", "res/layout/test.xml");
  myFixture.configureFromExistingVirtualFile(f);
  try {
    doCommonInlineAction(false);
    fail();
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
  }
  myFixture.checkResultByFile(BASE_PATH + testName + "_after.xml");
  myFixture.checkResultByFile("res/values/styles.xml", stylesPath, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AndroidInlineStyleTest.java

示例14: assertCannotRename

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
protected void assertCannotRename() throws Exception {
  MapDataContext context = createRenameDataContext(myProjectPom, "new name");
  RenameHandler handler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
  if (handler == null) return;
  try {
    invokeRename(context, handler);
  }
  catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
    if (!e.getMessage().startsWith("Cannot perform refactoring.")) {
      throw e;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:MavenDomTestCase.java

示例15: getNameAndVariableData

import com.intellij.refactoring.util.CommonRefactoringUtil; //导入方法依赖的package包/类
@NotNull
private static Pair<String, AbstractVariableData[]> getNameAndVariableData(@NotNull final Project project,
                                                                           @NotNull final CodeFragment fragment,
                                                                           @NotNull final PsiElement element,
                                                                           final boolean isClassMethod,
                                                                           final boolean isStaticMethod) {
  final ExtractMethodValidator validator = new PyExtractMethodValidator(element, project);
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    String name = System.getProperty(NAME);
    if (name == null) {
      name = "foo";
    }
    final String error = validator.check(name);
    if (error != null) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        throw new CommonRefactoringUtil.RefactoringErrorHintException(error);
      }
      if (Messages.showOkCancelDialog(error + ". " + RefactoringBundle.message("do.you.wish.to.continue"),
                                      RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) != Messages.OK) {
        throw new CommonRefactoringUtil.RefactoringErrorHintException(error);
      }
    }
    final List<AbstractVariableData> data = new ArrayList<AbstractVariableData>();
    for (String in : fragment.getInputVariables()) {
      final AbstractVariableData d = new AbstractVariableData();
      d.name = in + "_new";
      d.originalName = in;
      d.passAsParameter = true;
      data.add(d);
    }
    return Pair.create(name, data.toArray(new AbstractVariableData[data.size()]));
  }

  final boolean isMethod = PyPsiUtils.isMethodContext(element);
  final ExtractMethodDecorator decorator = new ExtractMethodDecorator() {
    @NotNull
    public String createMethodPreview(final String methodName, @NotNull final AbstractVariableData[] variableDatas) {
      final StringBuilder builder = new StringBuilder();
      if (isClassMethod) {
        builder.append("cls");
      }
      else if (isMethod && !isStaticMethod) {
        builder.append("self");
      }
      for (AbstractVariableData variableData : variableDatas) {
        if (variableData.passAsParameter) {
          if (builder.length() != 0) {
            builder.append(", ");
          }
          builder.append(variableData.name);
        }
      }
      builder.insert(0, "(");
      builder.insert(0, methodName);
      builder.insert(0, "def ");
      builder.append(")");
      return builder.toString();
    }
  };

  final AbstractExtractMethodDialog dialog = new AbstractExtractMethodDialog(project, "method_name", fragment, validator, decorator,
                                                                             PythonFileType.INSTANCE) {
    @Override
    protected String getHelpId() {
      return "python.reference.extractMethod";
    }
  };
  dialog.show();

  //return if don`t want to extract method
  if (!dialog.isOK()) {
    return Pair.empty();
  }

  return Pair.create(dialog.getMethodName(), dialog.getVariableData());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:77,代码来源:PyExtractMethodUtil.java


注:本文中的com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。