use of org.jetbrains.plugins.groovy.lang.completion.closureParameters.ClosureDescriptor in project intellij-community by JetBrains.
the class GdslClosureCompleter method getParameterInfos.
@Override
protected List<ClosureParameterInfo> getParameterInfos(InsertionContext context, PsiMethod method, PsiSubstitutor substitutor, PsiElement place) {
final ArrayList<ClosureDescriptor> descriptors = new ArrayList<>();
GrReferenceExpression ref = (GrReferenceExpression) place;
PsiType qtype = PsiImplUtil.getQualifierType(ref);
if (qtype == null)
return null;
GrExpression qualifier = ref.getQualifier();
if (qualifier != null) {
PsiType type = qualifier.getType();
if (type == null)
return null;
processExecutors(qtype, ref, descriptors);
} else {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
for (PsiElement parent = ref.getParent(); parent != null; parent = parent.getParent()) {
if (parent instanceof GrClosableBlock) {
processExecutors(TypesUtil.createTypeByFQClassName(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, ref), ref, descriptors);
} else if (parent instanceof GrTypeDefinition) {
processExecutors(factory.createType(((GrTypeDefinition) parent), PsiType.EMPTY_ARRAY), ref, descriptors);
}
}
}
for (ClosureDescriptor descriptor : descriptors) {
if (descriptor.isMethodApplicable(method, ref)) {
return descriptor.getParameters();
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.completion.closureParameters.ClosureDescriptor in project intellij-community by JetBrains.
the class NonCodeMembersHolder method createClosureDescriptor.
@Nullable
private static PsiElement createClosureDescriptor(Map prop, PsiElement place, PsiManager manager) {
final ClosureDescriptor closure = new ClosureDescriptor(manager);
final Object method = prop.get("method");
if (!(method instanceof Map))
return null;
closure.setMethod(((Map) method));
// closure.setReturnType(convertToPsiType(String.valueOf(prop.get("type")), place));
final Object closureParams = prop.get("params");
if (closureParams instanceof Map) {
boolean first = true;
for (Object paramName : ((Map) closureParams).keySet()) {
Object value = ((Map) closureParams).get(paramName);
boolean isNamed = first && value instanceof List;
first = false;
String typeName = isNamed ? CommonClassNames.JAVA_UTIL_MAP : String.valueOf(value);
closure.addParameter(typeName, String.valueOf(paramName));
}
}
Object doc = prop.get("doc");
if (doc instanceof String) {
closure.putUserData(DOCUMENTATION, (String) doc);
}
Object docUrl = prop.get("docUrl");
if (docUrl instanceof String) {
closure.putUserData(DOCUMENTATION_URL, (String) docUrl);
}
return closure;
}
Aggregations