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


Java IntroduceParameterHandler类代码示例

本文整理汇总了Java中com.intellij.refactoring.introduceParameter.IntroduceParameterHandler的典型用法代码示例。如果您正苦于以下问题:Java IntroduceParameterHandler类的具体用法?Java IntroduceParameterHandler怎么用?Java IntroduceParameterHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doTest

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private void doTest(String conflict) {
  boolean enabled = true;
  try {
    configureByFile("/refactoring/introduceFunctionalParameter/before" + getTestName(false) + ".java");
    enabled = myEditor.getSettings().isVariableInplaceRenameEnabled();
    myEditor.getSettings().setVariableInplaceRenameEnabled(false);
    new IntroduceParameterHandler().introduceStrategy(getProject(), getEditor(), getFile());
    checkResultByFile("/refactoring/introduceFunctionalParameter/after" + getTestName(false) + ".java");
    if (conflict != null) {
      fail("Conflict expected");
    }
  }
  catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
    if (conflict == null) {
      throw e;
    }
    assertEquals(conflict, e.getMessage());
  } finally {
    myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:IntroduceFunctionalParameterTest.java

示例2: doTestThroughHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private void doTestThroughHandler() throws Exception {
  configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
  boolean enabled = true;
  try {
    configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
    enabled = myEditor.getSettings().isVariableInplaceRenameEnabled();
    myEditor.getSettings().setVariableInplaceRenameEnabled(false);
    new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() {
      @Override
      @Nullable
      public Object getData(@NonNls final String dataId) {
        return null;
      }
    });
    checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
  }
  finally {
    myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:IntroduceParameterTest.java

示例3: doTestThroughHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private void doTestThroughHandler() throws Exception
{
	configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
	boolean enabled = true;
	try
	{
		configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
		enabled = myEditor.getSettings().isVariableInplaceRenameEnabled();
		myEditor.getSettings().setVariableInplaceRenameEnabled(false);
		new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext()
		{
			@Nullable
			@Override
			public <T> T getData(@NotNull Key<T> key)
			{
				return null;
			}
		});
		checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
	}
	finally
	{
		myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:IntroduceParameterTest.java

示例4: doTestThroughHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private void doTestThroughHandler() {
  configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
  boolean enabled = true;
  try {
    configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
    enabled = myEditor.getSettings().isVariableInplaceRenameEnabled();
    myEditor.getSettings().setVariableInplaceRenameEnabled(false);
    new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, DataContext.EMPTY_CONTEXT);
    checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
  }
  finally {
    myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:IntroduceParameterTest.java

示例5: invokeImpl

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
@Override
protected void invokeImpl(PsiClass targetClass) {
  if (CreateFromUsageUtils.isValidReference(myReferenceExpression, false)) return;

  final Project project = myReferenceExpression.getProject();

  PsiType[] expectedTypes = CreateFromUsageUtils.guessType(myReferenceExpression, false);
  PsiType type = expectedTypes[0];

  final String varName = myReferenceExpression.getReferenceName();
  PsiMethod method = PsiTreeUtil.getParentOfType(myReferenceExpression, PsiMethod.class);
  LOG.assertTrue(method != null);
  method = IntroduceParameterHandler.chooseEnclosingMethod(method);
  if (method == null) return;

  method = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
  if (method == null) return;

  final List<ParameterInfoImpl> parameterInfos =
    new ArrayList<ParameterInfoImpl>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
  ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, varName, type, varName, false);
  if (!method.isVarArgs()) {
    parameterInfos.add(parameterInfo);
  }
  else {
    parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
  }

  final Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    ParameterInfoImpl[] array = parameterInfos.toArray(new ParameterInfoImpl[parameterInfos.size()]);
    String modifier = PsiUtil.getAccessModifier(PsiUtil.getAccessLevel(method.getModifierList()));
    ChangeSignatureProcessor processor =
      new ChangeSignatureProcessor(project, method, false, modifier, method.getName(), method.getReturnType(), array);
    processor.run();
  }
  else {
    final PsiMethod finalMethod = method;
    application.invokeLater(new Runnable() {
      @Override
      public void run() {
        if (project.isDisposed()) return;
        try {
          JavaChangeSignatureDialog dialog =
            JavaChangeSignatureDialog.createAndPreselectNew(project, finalMethod, parameterInfos, true, myReferenceExpression);
          dialog.setParameterInfos(parameterInfos);
          if (dialog.showAndGet()) {
            for (ParameterInfoImpl info : parameterInfos) {
              if (info.getOldIndex() == -1) {
                final String newParamName = info.getName();
                if (!Comparing.strEqual(varName, newParamName)) {
                  final PsiExpression newExpr =
                    JavaPsiFacade.getElementFactory(project).createExpressionFromText(newParamName, finalMethod);
                  new WriteCommandAction(project) {
                    @Override
                    protected void run(@NotNull Result result) throws Throwable {
                      final PsiReferenceExpression[] refs =
                        CreateFromUsageUtils.collectExpressions(myReferenceExpression, PsiMember.class, PsiFile.class);
                      for (PsiReferenceExpression ref : refs) {
                        ref.replace(newExpr.copy());
                      }
                    }
                  }.execute();
                }
                break;
              }
            }
          }
        }
        catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:77,代码来源:CreateParameterFromUsageFix.java

示例6: getIntroduceParameterHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
@Override
public RefactoringActionHandler getIntroduceParameterHandler() {
  return new IntroduceParameterHandler();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:JavaRefactoringSupportProvider.java

示例7: createIntroduceParameterHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
public RefactoringActionHandler createIntroduceParameterHandler() {
  return new IntroduceParameterHandler();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:JavaRefactoringActionHandlerFactoryImpl.java

示例8: perform

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private static boolean perform(boolean replaceAllOccurrences,
                               int replaceFieldsWithGetters,
                               @NonNls String parameterName,
                               boolean searchForSuper,
                               boolean declareFinal,
                               boolean removeUnusedParameters,
                               boolean generateDelegate,
                               int enclosingLevel,
                               final boolean replaceDuplicates) {
  final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
  ElementToWorkOn.processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(),
                                         new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>() {
                                           @Override
                                           public boolean accept(ElementToWorkOn el) {
                                             return true;
                                           }

                                           @Override
                                           public void pass(final ElementToWorkOn e) {
                                             if (e != null) {
                                               elementToWorkOn[0] = e;
                                             }
                                           }
                                         });

  final PsiExpression expr = elementToWorkOn[0].getExpression();
  final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();

  PsiElement context = expr == null ? localVar : expr;
  PsiMethod method = Util.getContainingMethod(context);
  if (method == null) return false;

  final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
  assertTrue(methods.size() > enclosingLevel);
  method = methods.get(enclosingLevel);

  final PsiMethod methodToSearchFor;
  if (searchForSuper) {
    methodToSearchFor = method.findDeepestSuperMethods()[0];
  }
  else {
    methodToSearchFor = method;
  }
  PsiExpression[] occurrences;
  PsiExpression initializer;
  if (expr == null) {
    initializer = localVar.getInitializer();
    assertNotNull(initializer);
    occurrences = CodeInsightUtil.findReferenceExpressions(method, localVar);
  }
  else {
    initializer = expr;
    occurrences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
  }
  TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurrences)
                                                            : new TIntArrayList();
  IntroduceParameterProcessor processor = new IntroduceParameterProcessor(
    getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurrences,
    replaceFieldsWithGetters, declareFinal, generateDelegate, null, parametersToRemove
  ) {
    @Override
    protected boolean isReplaceDuplicates() {
      return replaceDuplicates;
    }
  };
  PsiType initializerType = initializer.getType();
  if (initializerType != null && initializerType != PsiType.NULL) {
    PsiExpression lambda = AnonymousCanBeLambdaInspection.replaceAnonymousWithLambda(initializer, initializerType);
    if (lambda != null) {
      processor.setParameterInitializer(lambda);
    }
  }
  processor.run();

  myEditor.getSelectionModel().removeSelection();
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:78,代码来源:IntroduceParameterTest.java

示例9: invokeImpl

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
@Override
protected void invokeImpl(PsiClass targetClass) {
  if (CreateFromUsageUtils.isValidReference(myReferenceExpression, false)) return;

  final Project project = myReferenceExpression.getProject();

  PsiType[] expectedTypes = CreateFromUsageUtils.guessType(myReferenceExpression, false);
  PsiType type = expectedTypes[0];

  final String varName = myReferenceExpression.getReferenceName();
  PsiMethod method = PsiTreeUtil.getParentOfType(myReferenceExpression, PsiMethod.class);
  LOG.assertTrue(method != null);
  method = IntroduceParameterHandler.chooseEnclosingMethod(method);
  if (method == null) return;

  method = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
  if (method == null) return;

  final List<ParameterInfoImpl> parameterInfos =
    new ArrayList<ParameterInfoImpl>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
  ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, varName, type, PsiTypesUtil.getDefaultValueOfType(type), false);
  if (!method.isVarArgs()) {
    parameterInfos.add(parameterInfo);
  }
  else {
    parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
  }

  final Application application = ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    ParameterInfoImpl[] array = parameterInfos.toArray(new ParameterInfoImpl[parameterInfos.size()]);
    String modifier = PsiUtil.getAccessModifier(PsiUtil.getAccessLevel(method.getModifierList()));
    ChangeSignatureProcessor processor =
      new ChangeSignatureProcessor(project, method, false, modifier, method.getName(), method.getReturnType(), array);
    processor.run();
  }
  else {
    final PsiMethod finalMethod = method;
    application.invokeLater(new Runnable() {
      @Override
      public void run() {
        if (project.isDisposed()) return;
        try {
          JavaChangeSignatureDialog dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, finalMethod, parameterInfos, true, myReferenceExpression);
          dialog.setParameterInfos(parameterInfos);
          dialog.show();
          if (dialog.isOK()) {
            for (ParameterInfoImpl info : parameterInfos) {
              if (info.getOldIndex() == -1) {
                final String newParamName = info.getName();
                if (!Comparing.strEqual(varName, newParamName)) {
                  final PsiExpression newExpr = JavaPsiFacade.getElementFactory(project).createExpressionFromText(newParamName, finalMethod);
                  new WriteCommandAction(project){
                    @Override
                    protected void run(Result result) throws Throwable {
                      final PsiReferenceExpression[] refs =
                        CreateFromUsageUtils.collectExpressions(myReferenceExpression, PsiMember.class, PsiFile.class);
                      for (PsiReferenceExpression ref : refs) {
                        ref.replace(newExpr.copy());
                      }
                    }
                  }.execute();
                }
                break;
              }
            }
          }
        }
        catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:76,代码来源:CreateParameterFromUsageFix.java

示例10: perform

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private static boolean perform(boolean replaceAllOccurences,
                               int replaceFieldsWithGetters,
                               @NonNls String parameterName,
                               boolean searchForSuper,
                               boolean declareFinal,
                               final boolean removeUnusedParameters,
                               final boolean generateDelegate,
                               int enclosingLevel) {
  final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
  ElementToWorkOn
        .processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>() {
          @Override
          public boolean accept(ElementToWorkOn el) {
            return true;
          }

          @Override
          public void pass(final ElementToWorkOn e) {
            if (e == null) return;

            elementToWorkOn[0] = e;
          }
        });

  final PsiExpression expr = elementToWorkOn[0].getExpression();
  final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();

  PsiElement context = expr == null ? localVar : expr;
  PsiMethod method = Util.getContainingMethod(context);
  if (method == null) return false;

  final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
  assertTrue(methods.size() > enclosingLevel);
  method = methods.get(enclosingLevel);

  final PsiMethod methodToSearchFor;
  if (searchForSuper) {
    methodToSearchFor = method.findDeepestSuperMethod();
  }
  else {
    methodToSearchFor = method;
  }
  PsiExpression[] occurences;
  PsiExpression initializer;
  if (expr == null) {
    initializer = localVar.getInitializer();
    occurences = CodeInsightUtil.findReferenceExpressions(method, localVar);
  }
  else {
    initializer = expr;
    occurences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
  }
  TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList();
  new IntroduceParameterProcessor(
    getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences,
    replaceFieldsWithGetters,
    declareFinal, generateDelegate, null, parametersToRemove).run();

  myEditor.getSelectionModel().removeSelection();
  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:62,代码来源:IntroduceParameterTest.java

示例11: getIntroduceParameterHandler

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
@Override
public RefactoringActionHandler getIntroduceParameterHandler()
{
	return new IntroduceParameterHandler();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:6,代码来源:JavaRefactoringSupportProvider.java

示例12: perform

import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; //导入依赖的package包/类
private static boolean perform(boolean replaceAllOccurences,
		int replaceFieldsWithGetters,
		@NonNls String parameterName,
		boolean searchForSuper,
		boolean declareFinal,
		final boolean removeUnusedParameters,
		final boolean generateDelegate,
		int enclosingLevel)
{
	final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
	ElementToWorkOn.processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>()
	{
		@Override
		public boolean accept(ElementToWorkOn el)
		{
			return true;
		}

		@Override
		public void pass(final ElementToWorkOn e)
		{
			if(e == null)
			{
				return;
			}

			elementToWorkOn[0] = e;
		}
	});

	final PsiExpression expr = elementToWorkOn[0].getExpression();
	final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();

	PsiElement context = expr == null ? localVar : expr;
	PsiMethod method = Util.getContainingMethod(context);
	if(method == null)
	{
		return false;
	}

	final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
	assertTrue(methods.size() > enclosingLevel);
	method = methods.get(enclosingLevel);

	final PsiMethod methodToSearchFor;
	if(searchForSuper)
	{
		methodToSearchFor = method.findDeepestSuperMethod();
	}
	else
	{
		methodToSearchFor = method;
	}
	PsiExpression[] occurences;
	PsiExpression initializer;
	if(expr == null)
	{
		initializer = localVar.getInitializer();
		occurences = CodeInsightUtil.findReferenceExpressions(method, localVar);
	}
	else
	{
		initializer = expr;
		occurences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
	}
	TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList();
	new IntroduceParameterProcessor(getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences, replaceFieldsWithGetters, declareFinal,
			generateDelegate, null, parametersToRemove).run();

	myEditor.getSelectionModel().removeSelection();
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:73,代码来源:IntroduceParameterTest.java


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