use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class JsonBuilderContributor method createMethod.
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiClass clazz, @NotNull PsiElement context) {
GrLightMethodBuilder method = new GrLightMethodBuilder(context.getManager(), name);
method.setOriginInfo(ORIGIN_INFO);
method.addModifier(PsiModifier.PUBLIC);
method.setReturnType(JAVA_UTIL_MAP, context.getResolveScope());
UtilsKt.setContainingClass(method, clazz);
return method;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class StreamingJsonBuilderContributor method processDynamicMethods.
@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
GrLightMethodBuilder method;
// ()
method = createMethod(name, place, qualifierType, clazz);
if (!processor.process(method))
return false;
// (Closure)
method = createMethod(name, place, qualifierType, clazz);
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Map)
method = createMethod(name, place, qualifierType, clazz);
method.addParameter("args", JAVA_UTIL_MAP);
if (!processor.process(method))
return false;
// (Map, Closure)
method = createMethod(name, place, qualifierType, clazz);
method.addParameter("args", JAVA_UTIL_MAP);
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Iterable, Closure)
method = createMethod(name, place, qualifierType, clazz);
method.addParameter("values", TypesUtil.createIterableType(place, null), false);
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Object[], Closure)
method = createMethod(name, place, qualifierType, clazz);
method.addParameter("values", TypesUtil.getJavaLangObject(place).createArrayType());
addClosureParameter(method);
return processor.process(method);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class ConstructorAnnotationsProcessor method generateFieldConstructor.
@NotNull
private static GrLightMethodBuilder generateFieldConstructor(@NotNull GrTypeDefinition typeDefinition, @Nullable PsiAnnotation tupleConstructor, boolean immutable, boolean canonical) {
final GrLightMethodBuilder fieldsConstructor = new GrLightMethodBuilder(typeDefinition.getManager(), typeDefinition.getName());
fieldsConstructor.setConstructor(true);
fieldsConstructor.setNavigationElement(typeDefinition);
fieldsConstructor.setContainingClass(typeDefinition);
Set<String> excludes = new HashSet<>();
if (tupleConstructor != null) {
for (String s : PsiUtil.getAnnoAttributeValue(tupleConstructor, "excludes", "").split(",")) {
final String name = s.trim();
if (StringUtil.isNotEmpty(name)) {
excludes.add(name);
}
}
}
if (tupleConstructor != null) {
final boolean superFields = PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeSuperFields", false);
final boolean superProperties = PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeSuperProperties", false);
if (superFields || superProperties) {
addParametersForSuper(typeDefinition, fieldsConstructor, superFields, superProperties, new HashSet<>(), excludes);
}
}
addParameters(typeDefinition, fieldsConstructor, tupleConstructor == null || PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeProperties", true), tupleConstructor != null ? PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeFields", false) : !canonical, !immutable, excludes);
if (immutable) {
fieldsConstructor.setOriginInfo("created by @Immutable");
} else if (tupleConstructor != null) {
fieldsConstructor.setOriginInfo("created by @TupleConstructor");
} else /*if (canonical != null)*/
{
fieldsConstructor.setOriginInfo("created by @Canonical");
}
return fieldsConstructor;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class ConstructorAnnotationsProcessor method generateMapConstructor.
@NotNull
private static GrLightMethodBuilder generateMapConstructor(@NotNull GrTypeDefinition typeDefinition) {
final GrLightMethodBuilder mapConstructor = new GrLightMethodBuilder(typeDefinition.getManager(), typeDefinition.getName());
mapConstructor.addParameter("args", CommonClassNames.JAVA_UTIL_HASH_MAP, false);
mapConstructor.setConstructor(true);
mapConstructor.setContainingClass(typeDefinition);
return mapConstructor;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder 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;
}
Aggregations