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


Java GrArgumentList.getAllArguments方法代碼示例

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


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

示例1: getGrMethodArumentsCount

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
public static int getGrMethodArumentsCount(@NotNull GrArgumentList args) {
  int argsCount = 0;
  boolean namedArgProcessed = false;
  for (GroovyPsiElement arg : args.getAllArguments()) {
    if (arg instanceof GrNamedArgument) {
      if (!namedArgProcessed) {
        namedArgProcessed = true;
        argsCount++;
      }
    }
    else {
      argsCount++;
    }
  }
  return argsCount;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:GradleResolverUtil.java

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

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

示例4: isGetterInvocation

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
private static boolean isGetterInvocation(@NotNull GrMethodCall call) {
  GrExpression expr = call.getInvokedExpression();
  if (!(expr instanceof GrReferenceExpression)) return false;

  PsiMethod method = call.resolveMethod();
  if (!GroovyPropertyUtils.isSimplePropertyGetter(method)) return false;
  LOG.assertTrue(method != null);
  if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameByGetterName(method.getName(), true),
                                        ((GrReferenceExpression)expr).getQualifier() != null,
                                        call.getProject())) {
    return false;
  }

  GrArgumentList args = call.getArgumentList();
  if (args == null || args.getAllArguments().length != 0) {
    return false;
  }

  GrExpression ref = genRefForGetter(call, ((GrReferenceExpression)expr).getReferenceName());
  if (ref instanceof GrReferenceExpression) {
    PsiElement resolved = ((GrReferenceExpression)ref).resolve();
    PsiManager manager = call.getManager();
    if (manager.areElementsEquivalent(resolved, method) || areEquivalentAccessors(method, resolved, manager)) {
      return true;
    }
  }

  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:JavaStylePropertiesUtil.java

示例5: getExpressionArgumentsOfCall

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
@Nullable
public static List<GrExpression> getExpressionArgumentsOfCall(@NotNull GrArgumentList argumentList) {
  final ArrayList<GrExpression> args = ContainerUtil.newArrayList();

  for (GroovyPsiElement arg : argumentList.getAllArguments()) {
    if (arg instanceof GrSpreadArgument) {
      GrExpression spreaded = ((GrSpreadArgument)arg).getArgument();
      if (spreaded instanceof GrListOrMap && !((GrListOrMap)spreaded).isMap()) {
        Collections.addAll(args, ((GrListOrMap)spreaded).getInitializers());
      }
      else {
        return null;
      }
    }
    else if (arg instanceof GrExpression) {
      args.add((GrExpression)arg);
    }
    else if (arg instanceof GrNamedArgument) {
      args.add(((GrNamedArgument)arg).getExpression());
    }
  }

  final PsiElement parent = argumentList.getParent();
  if (parent instanceof GrIndexProperty && PsiUtil.isLValue((GroovyPsiElement)parent)) {
    args.add(TypeInferenceHelper.getInitializerFor((GrExpression)parent));
  }
  else if (parent instanceof GrMethodCallExpression) {
    ContainerUtil.addAll(args, ((GrMethodCallExpression)parent).getClosureArguments());
  }
  return args;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:32,代碼來源:GroovyTypeCheckVisitorHelper.java

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

示例7: getArguments

import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList; //導入方法依賴的package包/類
/**
 * Returns an array of arguments for the given method call. Note that it returns only regular arguments (via the
 * {@link org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall#getArgumentList()} call), not closure arguments
 * (via the {@link org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall#getClosureArguments()} call).
 *
 * @return the array of arguments. This method never returns null; even in the case of a nonexistent argument list or error, it will
 * return an empty array.
 */
protected static @NotNull GroovyPsiElement[] getArguments(@NotNull GrCall gmc) {
  GrArgumentList argList = gmc.getArgumentList();
  if (argList == null) {
    return GroovyPsiElement.EMPTY_ARRAY;
  }
  return argList.getAllArguments();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:GradleGroovyFile.java


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