use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class GdkMethodUtil method categoryIteration.
public static boolean categoryIteration(GrClosableBlock place, final PsiScopeProcessor processor, ResolveState state) {
if (!ResolveUtil.shouldProcessMethods(processor.getHint(ElementClassHint.KEY)) && !(processor instanceof GroovyResolverProcessor && ((GroovyResolverProcessor) processor).isPropertyResolve())) {
return true;
}
final GrMethodCall call = checkMethodCall(place, USE);
if (call == null)
return true;
final GrClosableBlock[] closures = call.getClosureArguments();
GrExpression[] args = call.getExpressionArguments();
if (!(placeEqualsSingleClosureArg(place, closures) || placeEqualsLastArg(place, args)))
return true;
if (!(call.resolveMethod() instanceof GrGdkMethod))
return true;
state = state.put(ClassHint.RESOLVE_CONTEXT, call);
if ((args.length == 1 || args.length == 2 && placeEqualsLastArg(place, args))) {
PsiType type = args[0].getType();
if (type instanceof GrTupleType) {
return processTypesFromTuple((GrTupleType) type, processor, state, place);
}
}
return processTypesFomArgs(args, processor, state, place);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class GrMethodComparator method compareMethods.
/**
* @return <ul>
* <li>1 if second is more preferable</li>
* <li>0 if methods are equal</li>
* <li>-1 if first is more preferable</li>
* </ul>
*/
public static int compareMethods(@NotNull GroovyMethodResult result1, @NotNull GroovyMethodResult result2, @NotNull Context context) {
final PsiMethod method1 = result1.getElement();
final PsiMethod method2 = result2.getElement();
if (!method1.getName().equals(method2.getName()))
return 0;
boolean firstIsPreferable = checkDominated(result2, result1, context);
boolean secondIsPreferable = checkDominated(result1, result2, context);
if (secondIsPreferable) {
if (firstIsPreferable) {
if (method2 instanceof GrGdkMethod && !(method1 instanceof GrGdkMethod)) {
return -1;
}
}
return 1;
}
if (firstIsPreferable) {
return -1;
}
return 0;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class ResolveUtil method getSelfOrWithQualifier.
@Nullable
public static GrExpression getSelfOrWithQualifier(GrReferenceExpression ref) {
final GrExpression qualifier = ref.getQualifierExpression();
if (qualifier != null) {
return qualifier;
}
PsiElement place = ref;
while (true) {
final GrClosableBlock closure = PsiTreeUtil.getParentOfType(place, GrClosableBlock.class, true, GrMember.class, GroovyFile.class);
if (closure == null)
break;
place = closure;
PsiElement clParent = closure.getParent();
if (clParent instanceof GrArgumentList)
clParent = clParent.getParent();
if (!(clParent instanceof GrMethodCall))
continue;
final GrExpression expression = ((GrMethodCall) clParent).getInvokedExpression();
if (expression instanceof GrReferenceExpression && GdkMethodUtil.isWithName(((GrReferenceExpression) expression).getReferenceName()) && ((GrReferenceExpression) expression).resolve() instanceof GrGdkMethod) {
final GrExpression withQualifier = ((GrReferenceExpression) expression).getQualifierExpression();
if (withQualifier != null) {
return withQualifier;
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class ResolveUtil method dominated.
public static boolean dominated(PsiMethod method1, PsiSubstitutor substitutor1, PsiMethod method2, PsiSubstitutor substitutor2) {
//method1 has more general parameter types then method2
if (!method1.getName().equals(method2.getName()))
return false;
PsiParameter[] params1 = method1.getParameterList().getParameters();
PsiParameter[] params2 = method2.getParameterList().getParameters();
if (params1.length != params2.length)
return false;
for (int i = 0; i < params2.length; i++) {
PsiType type1 = TypeConversionUtil.erasure(substitutor1.substitute(params1[i].getType()));
PsiType type2 = TypeConversionUtil.erasure(substitutor2.substitute(params2[i].getType()));
if (!type1.equals(type2))
return false;
}
if (method1 instanceof GrGdkMethod && method2 instanceof GrGdkMethod) {
PsiMethod static1 = ((GrGdkMethod) method1).getStaticMethod();
PsiMethod static2 = ((GrGdkMethod) method2).getStaticMethod();
PsiParameter p1 = static1.getParameterList().getParameters()[0];
PsiParameter p2 = static2.getParameterList().getParameters()[0];
PsiType t1 = substitutor1.substitute(p1.getType());
PsiType t2 = substitutor2.substitute(p2.getType());
if (!t1.equals(t2)) {
if (t1 instanceof PsiClassType)
t1 = TypeConversionUtil.erasure(t1);
if (t2 instanceof PsiClassType)
t2 = TypeConversionUtil.erasure(t2);
//method1 is more general than method2
return t1.isAssignableFrom(t2);
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.
the class GroovyDocumentationProvider method getQuickNavigateInfo.
@Override
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
if (element instanceof GrVariable || element instanceof GrImplicitVariable) {
StringBuilder buffer = new StringBuilder();
PsiVariable variable = (PsiVariable) element;
if (originalElement instanceof GrVariableDeclaration && ((GrVariableDeclaration) originalElement).getVariables().length > 1) {
for (GrVariable var : ((GrVariableDeclaration) originalElement).getVariables()) {
generateVariableInfo(originalElement, buffer, var);
buffer.append("\n\n");
}
} else {
generateVariableInfo(originalElement, buffer, variable);
}
return buffer.toString();
} else if (element instanceof PsiMethod) {
StringBuilder buffer = new StringBuilder();
PsiMethod method = (PsiMethod) element;
if (method instanceof GrGdkMethod) {
buffer.append("[GDK] ");
} else {
PsiClass hisClass = method.getContainingClass();
if (hisClass != null) {
String qName = hisClass.getQualifiedName();
if (qName != null) {
buffer.append(qName).append("\n");
}
}
}
PsiSubstitutor substitutor = calcSubstitutor(originalElement);
if (!method.isConstructor()) {
final PsiType substituted = substitutor.substitute(PsiUtil.getSmartReturnType(method));
PsiImplUtil.appendTypeString(buffer, substituted, originalElement);
buffer.append(" ");
}
buffer.append(method.getName()).append(" ");
buffer.append("(");
PsiParameter[] parameters = method.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
PsiParameter parameter = parameters[i];
if (i > 0)
buffer.append(", ");
if (parameter instanceof GrParameter) {
GroovyPresentationUtil.appendParameterPresentation((GrParameter) parameter, substitutor, TypePresentation.LINK, buffer);
} else {
PsiType type = parameter.getType();
PsiImplUtil.appendTypeString(buffer, substitutor.substitute(type), originalElement);
buffer.append(" ");
buffer.append(parameter.getName());
}
}
buffer.append(")");
final PsiClassType[] referencedTypes = method.getThrowsList().getReferencedTypes();
if (referencedTypes.length > 0) {
buffer.append("\nthrows ");
for (PsiClassType referencedType : referencedTypes) {
PsiImplUtil.appendTypeString(buffer, referencedType, originalElement);
buffer.append(", ");
}
buffer.delete(buffer.length() - 2, buffer.length());
}
return buffer.toString();
} else if (element instanceof GrTypeDefinition) {
return generateClassInfo((GrTypeDefinition) element);
}
return null;
}
Aggregations