use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class ExpressionGenerator method visitIndexProperty.
@Override
public void visitIndexProperty(@NotNull GrIndexProperty expression) {
final GrExpression selectedExpression = expression.getInvokedExpression();
final PsiType thisType = selectedExpression.getType();
final GrArgumentList argList = expression.getArgumentList();
if (argList.getAllArguments().length == 0) {
// int[] or String[]
if (selectedExpression instanceof GrBuiltinTypeClassExpression) {
selectedExpression.accept(this);
return;
} else if (selectedExpression instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) selectedExpression).resolve();
if (resolved instanceof PsiClass) {
builder.append(((PsiClass) resolved).getQualifiedName());
builder.append("[].class");
return;
}
}
}
final PsiType[] argTypes = PsiUtil.getArgumentTypes(argList);
final GrExpression[] exprArgs = argList.getExpressionArguments();
final GrNamedArgument[] namedArgs = argList.getNamedArguments();
if (!PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, expression, PsiUtil.isLValue(expression))) {
final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(expression.multiResolve(false));
PsiElement element = candidate.getElement();
if (element != null || !PsiUtil.isLValue(expression)) {
//see the case of l-value in assignment expression
if (element instanceof GrGdkMethod && ((GrGdkMethod) element).getStaticMethod().getParameterList().getParameters()[0].getType().equalsToText("java.util.Map<K,V>")) {
PsiClass map = JavaPsiFacade.getInstance(context.project).findClass(CommonClassNames.JAVA_UTIL_MAP, expression.getResolveScope());
if (map != null) {
PsiMethod[] gets = map.findMethodsByName("get", false);
invokeMethodOn(gets[0], selectedExpression, exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, PsiSubstitutor.EMPTY, expression);
return;
}
} else if (element instanceof GrGdkMethod && ((GrGdkMethod) element).getStaticMethod().getParameterList().getParameters()[0].getType().equalsToText("java.util.List<T>")) {
PsiClass list = JavaPsiFacade.getInstance(context.project).findClass(CommonClassNames.JAVA_UTIL_LIST, expression.getResolveScope());
if (list != null) {
PsiMethod[] gets = list.findMethodsByName("get", false);
invokeMethodOn(gets[0], selectedExpression, exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, PsiSubstitutor.EMPTY, expression);
return;
}
}
GenerationUtil.invokeMethodByResolveResult(selectedExpression, candidate, "getAt", exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, this, expression);
return;
}
}
selectedExpression.accept(this);
builder.append('[');
final GrExpression arg = exprArgs[0];
arg.accept(this);
builder.append(']');
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class SetterWriter method inferActualParameters.
@NotNull
private PsiParameter[] inferActualParameters(boolean aStatic, @NotNull PsiParameter[] parameters, @NotNull PsiParameter parameter) {
//parameters
parameters[parameters.length - 1] = parameter;
PsiParameter[] actual;
if (aStatic) {
actual = parameters;
} else {
final String typeText;
final PsiClass containingClass = mySetter.getContainingClass();
if (containingClass == null) {
if (mySetter instanceof GrGdkMethod) {
typeText = ((GrGdkMethod) mySetter).getStaticMethod().getParameterList().getParameters()[0].getType().getCanonicalText();
} else {
typeText = CommonClassNames.JAVA_LANG_OBJECT;
}
} else {
typeText = containingClass.getQualifiedName();
}
final GrParameter propOwner = GroovyPsiElementFactory.getInstance(myContext.project).createParameter("propOwner", typeText, null);
actual = new PsiParameter[parameters.length + 1];
actual[0] = propOwner;
System.arraycopy(parameters, 0, actual, 1, parameters.length);
}
return actual;
}
Aggregations