use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor in project intellij-community by JetBrains.
the class NonCodeMembersHolder method createMethod.
private static GrLightMethodBuilder createMethod(Map prop, PsiElement place, PsiManager manager) {
String name = String.valueOf(prop.get("name"));
final GrLightMethodBuilder method = new GrLightMethodBuilder(manager, name).addModifier(PsiModifier.PUBLIC);
if (Boolean.TRUE.equals(prop.get("constructor"))) {
method.setConstructor(true);
} else {
method.setReturnType(convertToPsiType(String.valueOf(prop.get("type")), place));
}
final Object params = prop.get("params");
if (params instanceof Map) {
boolean first = true;
for (Object paramName : ((Map) params).keySet()) {
Object value = ((Map) params).get(paramName);
boolean isNamed = first && value instanceof List;
first = false;
String typeName = isNamed ? CommonClassNames.JAVA_UTIL_MAP : String.valueOf(value);
method.addParameter(String.valueOf(paramName), convertToPsiType(typeName, place), false);
if (isNamed) {
Map<String, NamedArgumentDescriptor> namedParams = ContainerUtil.newHashMap();
for (Object o : (List) value) {
if (o instanceof CustomMembersGenerator.ParameterDescriptor) {
namedParams.put(((CustomMembersGenerator.ParameterDescriptor) o).name, ((CustomMembersGenerator.ParameterDescriptor) o).descriptor);
}
}
method.setNamedParameters(namedParams);
}
}
}
if (Boolean.TRUE.equals(prop.get("isStatic"))) {
method.addModifier(PsiModifier.STATIC);
}
final Object bindsTo = prop.get("bindsTo");
if (bindsTo instanceof PsiElement) {
method.setNavigationElement((PsiElement) bindsTo);
}
final Object toThrow = prop.get(CustomMembersGenerator.THROWS);
if (toThrow instanceof List) {
for (Object o : ((List) toThrow)) {
final PsiType psiType = convertToPsiType(String.valueOf(o), place);
if (psiType instanceof PsiClassType) {
method.addException((PsiClassType) psiType);
}
}
}
Object doc = prop.get("doc");
if (doc instanceof String) {
method.putUserData(DOCUMENTATION, (String) doc);
}
Object docUrl = prop.get("docUrl");
if (docUrl instanceof String) {
method.putUserData(DOCUMENTATION_URL, (String) docUrl);
}
Object qName = prop.get("containingClass");
if (qName instanceof String) {
PsiClass foundClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(((String) qName), place.getResolveScope());
if (foundClass != null) {
method.setContainingClass(foundClass);
}
}
return method;
}
use of org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor in project intellij-community by JetBrains.
the class GrFieldImpl method getNamedParameters.
@Override
@NotNull
public Map<String, NamedArgumentDescriptor> getNamedParameters() {
final GrFieldStub stub = getStub();
if (stub != null) {
String[] namedParameters = stub.getNamedParameters();
if (namedParameters.length == 0)
return Collections.emptyMap();
Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap();
for (String parameter : namedParameters) {
result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR);
}
return result;
}
return GrNamedArgumentSearchVisitor.find(this);
}
Aggregations