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


Java GrArgumentList.addAfter方法代碼示例

本文整理匯總了Java中org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList.addAfter方法的典型用法代碼示例。如果您正苦於以下問題:Java GrArgumentList.addAfter方法的具體用法?Java GrArgumentList.addAfter怎麽用?Java GrArgumentList.addAfter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList的用法示例。


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

示例1: processChangedMethodCall

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
private static void processChangedMethodCall(PsiElement element, GrIntroduceParameterSettings settings) {
  if (element.getParent() instanceof GrMethodCallExpression) {
    GrMethodCallExpression methodCall = (GrMethodCallExpression)element.getParent();

    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject());
    GrExpression expression = factory.createExpressionFromText(settings.getName(), null);
    final GrArgumentList argList = methodCall.getArgumentList();
    final PsiElement[] exprs = argList.getAllArguments();

    if (exprs.length > 0) {
      argList.addAfter(expression, exprs[exprs.length - 1]);
    }
    else {
      argList.add(expression);
    }

    removeParametersFromCall(methodCall, settings);

  }
  else {
    LOG.error(element.getParent());
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:GrIntroduceClosureParameterProcessor.java

示例2: processChangedMethodCall

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
public static void processChangedMethodCall(PsiElement element, GrIntroduceParameterSettings settings, Project project) {
  if (!(element.getParent() instanceof GrMethodCallExpression)) {
    LOG.error(element.getParent());
    return;
  }

  GrMethodCallExpression methodCall = (GrMethodCallExpression)element.getParent();

  GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
  final String name = settings.getName();
  LOG.assertTrue(name != null);
  GrExpression expression = factory.createExpressionFromText(name, null);
  final GrArgumentList argList = methodCall.getArgumentList();
  final PsiElement[] exprs = argList.getAllArguments();

  if (exprs.length > 0) {
    argList.addAfter(expression, exprs[exprs.length - 1]);
  }
  else {
    argList.add(expression);
  }

  removeParametersFromCall(methodCall, settings);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:GroovyIntroduceParameterUtil.java

示例3: processChangeMethodUsage

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
@Override
public boolean processChangeMethodUsage(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
  GrCall callExpression = GroovyRefactoringUtil.getCallExpressionByMethodReference(usage.getElement());
  if (callExpression == null) return true;
  GrArgumentList argList = callExpression.getArgumentList();
  GrExpression[] oldArgs = argList.getExpressionArguments();

  final GrExpression anchor;
  if (!data.getMethodToSearchFor().isVarArgs()) {
    anchor = getLast(oldArgs);
  }
  else {
    final PsiParameter[] parameters = data.getMethodToSearchFor().getParameterList().getParameters();
    if (parameters.length > oldArgs.length) {
      anchor = getLast(oldArgs);
    }
    else {
      final int lastNonVararg = parameters.length - 2;
      anchor = lastNonVararg >= 0 ? oldArgs[lastNonVararg] : null;
    }
  }

  PsiMethod method = PsiTreeUtil.getParentOfType(argList, PsiMethod.class);

  GrClosureSignature signature = GrClosureSignatureUtil.createSignature(callExpression);
  if (signature == null) signature = GrClosureSignatureUtil.createSignature(data.getMethodToSearchFor(), PsiSubstitutor.EMPTY);

  final GrClosureSignatureUtil.ArgInfo<PsiElement>[] actualArgs = GrClosureSignatureUtil
    .mapParametersToArguments(signature, callExpression.getNamedArguments(), callExpression.getExpressionArguments(),
                              callExpression.getClosureArguments(), callExpression, false, true);

  final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(data.getProject());

  if (method != null && IntroduceParameterUtil.isMethodInUsages(data, method, usages)) {
    argList.addAfter(factory.createExpressionFromText(data.getParameterName()), anchor);
  }
  else {
    final PsiElement _expr = data.getParameterInitializer().getExpression();
    PsiElement initializer = ExpressionConverter.getExpression(_expr, GroovyLanguage.INSTANCE, data.getProject());
    LOG.assertTrue(initializer instanceof GrExpression);

    GrExpression newArg = GroovyIntroduceParameterUtil.addClosureToCall(initializer, argList);
    if (newArg == null) {
      final PsiElement dummy = argList.addAfter(factory.createExpressionFromText("1"), anchor);
      newArg = ((GrExpression)dummy).replaceWithExpression((GrExpression)initializer, true);
    }
    final PsiMethod methodToReplaceIn = data.getMethodToReplaceIn();
    new OldReferencesResolver(callExpression, newArg, methodToReplaceIn, data.getReplaceFieldsWithGetters(), initializer,
                              signature, actualArgs, methodToReplaceIn.getParameterList().getParameters()).resolve();
    ChangeContextUtil.clearContextInfo(initializer);

    //newArg can be replaced by OldReferenceResolver
    if (newArg.isValid()) {
      JavaCodeStyleManager.getInstance(newArg.getProject()).shortenClassReferences(newArg);
      CodeStyleManager.getInstance(data.getProject()).reformat(newArg);
    }
  }

  if (actualArgs == null) {
    removeParamsFromUnresolvedCall(callExpression, data);
  }
  else {
    removeParametersFromCall(actualArgs, data.getParametersToRemove());
  }

  if (argList.getAllArguments().length == 0 && PsiImplUtil.hasClosureArguments(callExpression)) {
    final GrArgumentList emptyArgList = ((GrMethodCallExpression)factory.createExpressionFromText("foo{}")).getArgumentList();
    LOG.assertTrue(emptyArgList != null);
    argList.replace(emptyArgList);
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:73,代碼來源:GroovyIntroduceParameterMethodUsagesProcessor.java


注:本文中的org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList.addAfter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。