本文整理汇总了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;
}
示例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());
}
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}