use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class JavaStylePropertiesUtil method isGetterInvocation.
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.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;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GroovyConstructorNamedArgumentProvider method getNamedArguments.
@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
if (!(call instanceof GrNewExpression))
return;
PsiElement resolve = resolveResult.getElement();
if (resolve != null) {
if (!(resolve instanceof PsiMethod))
return;
PsiMethod method = (PsiMethod) resolve;
if (!method.isConstructor())
return;
}
GrNewExpression newCall = (GrNewExpression) call;
GrArgumentList argumentList = newCall.getArgumentList();
if (argumentList == null)
return;
GrExpression[] expressionArguments = argumentList.getExpressionArguments();
if (expressionArguments.length > 1 || (expressionArguments.length == 1 && !(expressionArguments[0] instanceof GrReferenceExpression))) {
return;
}
for (GroovyResolveResult newResult : newCall.multiResolveClass()) {
PsiElement element = newResult.getElement();
if (!(element instanceof PsiClass))
continue;
PsiClass aClass = (PsiClass) element;
if (!isClassHasConstructorWithMap(aClass))
continue;
PsiClassType classType = JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass);
processClass(call, classType, argumentName, result);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GrNewExpressionImpl method resolveImpl.
private GroovyResolveResult[] resolveImpl(boolean incompleteCode) {
GrCodeReferenceElement ref = getReferenceElement();
if (ref == null)
return GroovyResolveResult.EMPTY_ARRAY;
GroovyResolveResult classCandidate = inferClassCandidate(ref);
if (classCandidate == null)
return GroovyResolveResult.EMPTY_ARRAY;
assert classCandidate.getElement() instanceof PsiClass;
if (incompleteCode) {
return PsiUtil.getConstructorCandidates(ref, classCandidate, null);
}
final GrArgumentList argumentList = getArgumentList();
if (argumentList == null)
return GroovyResolveResult.EMPTY_ARRAY;
if (argumentList.getNamedArguments().length > 0 && argumentList.getExpressionArguments().length == 0) {
PsiType mapType = GrMapType.createFromNamedArgs(argumentList, getNamedArguments());
//one Map parameter, actually
GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classCandidate, new PsiType[] { mapType });
for (GroovyResolveResult result : constructorResults) {
final PsiElement resolved = result.getElement();
if (resolved instanceof PsiMethod) {
PsiMethod constructor = (PsiMethod) resolved;
final PsiParameter[] parameters = constructor.getParameterList().getParameters();
if (parameters.length == 1 && InheritanceUtil.isInheritor(parameters[0].getType(), CommonClassNames.JAVA_UTIL_MAP)) {
return constructorResults;
}
}
}
final GroovyResolveResult[] emptyConstructors = PsiUtil.getConstructorCandidates(ref, classCandidate, PsiType.EMPTY_ARRAY);
if (emptyConstructors.length > 0) {
return emptyConstructors;
}
}
PsiType[] types = PsiUtil.getArgumentTypes(ref, true);
if (types != null) {
types = GrInnerClassConstructorUtil.addEnclosingArgIfNeeded(types, this, (PsiClass) classCandidate.getElement());
}
return PsiUtil.getConstructorCandidates(ref, classCandidate, types);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class DefaultCallExpressionTypeCalculator method getClosureMethodsReturnType.
@Nullable
private static PsiType getClosureMethodsReturnType(GrMethodCall callExpression, GrReferenceExpression refExpr, PsiMethod resolved) {
PsiClass clazz = resolved.getContainingClass();
if (clazz == null || !GroovyCommonClassNames.GROOVY_LANG_CLOSURE.equals(clazz.getQualifiedName()))
return null;
if (!CLOSURE_METHODS.contains(resolved.getName()))
return null;
GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null)
return null;
PsiType qType = qualifier.getType();
if (!(qType instanceof GrClosureType))
return null;
if ("call".equals(resolved.getName())) {
return GrClosureSignatureUtil.getReturnType(((GrClosureType) qType).getSignature(), callExpression);
} else if ("curry".equals(resolved.getName()) || "trampoline".equals(resolved.getName())) {
return ((GrClosureType) qType).curry(PsiUtil.getArgumentTypes(refExpr, false), 0, callExpression);
} else if ("memoize".equals(resolved.getName())) {
return qType;
} else if ("rcurry".equals(resolved.getName())) {
return ((GrClosureType) qType).curry(PsiUtil.getArgumentTypes(refExpr, false), -1, callExpression);
} else if ("ncurry".equals(resolved.getName())) {
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
if (arguments.length > 0) {
final GrExpression first = arguments[0];
if (first instanceof GrLiteral) {
final Object value = ((GrLiteral) first).getValue();
if (value instanceof Integer) {
final PsiType[] argTypes = PsiUtil.getArgumentTypes(refExpr, false);
if (argTypes != null) {
return ((GrClosureType) qType).curry(ArrayUtil.remove(argTypes, 0), (Integer) value, callExpression);
}
}
}
}
return qType;
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GrIndexPropertyImpl method inferType.
private PsiType inferType(@Nullable Boolean isSetter) {
PsiType arrayType = inferArrayType();
if (arrayType != null) {
return arrayType;
}
GrExpression selected = getInvokedExpression();
PsiType thisType = selected.getType();
if (thisType == null) {
thisType = TypesUtil.getJavaLangObject(this);
}
GrArgumentList argList = getArgumentList();
PsiType[] argTypes = PsiUtil.getArgumentTypes(argList);
if (argTypes == null)
return null;
final PsiManager manager = getManager();
final GlobalSearchScope resolveScope = getResolveScope();
if (PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, this, isSetter != null ? isSetter.booleanValue() : PsiUtil.isLValue(this))) {
return TypesUtil.boxPrimitiveType(((PsiArrayType) thisType).getComponentType(), manager, resolveScope);
}
final GroovyResolveResult[] candidates;
if (isSetter != null) {
candidates = isSetter.booleanValue() ? multiResolveSetter(false) : multiResolveGetter(false);
} else {
candidates = multiResolve(false);
}
//don't use short PsiUtil.getArgumentTypes(...) because it use incorrect 'isSetter' value
PsiType[] args = PsiUtil.getArgumentTypes(argList.getNamedArguments(), argList.getExpressionArguments(), GrClosableBlock.EMPTY_ARRAY, true, null);
final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(candidates);
final PsiElement element = candidate.getElement();
if (element instanceof PsiNamedElement) {
final String name = ((PsiNamedElement) element).getName();
if ("putAt".equals(name) && args != null) {
args = ArrayUtil.append(args, TypeInferenceHelper.getInitializerTypeFor(this), PsiType.class);
}
}
PsiType overloadedOperatorType = ResolveUtil.extractReturnTypeFromCandidate(candidate, this, args);
PsiType componentType = extractMapValueType(thisType, args, manager, resolveScope);
if (overloadedOperatorType != null && (componentType == null || !TypesUtil.isAssignableByMethodCallConversion(overloadedOperatorType, componentType, selected))) {
return TypesUtil.boxPrimitiveType(overloadedOperatorType, manager, resolveScope);
}
return componentType;
}
Aggregations