use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class ConstructorAnnotationsProcessor method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
GrTypeDefinition typeDefinition = context.getCodeClass();
if (typeDefinition.getName() == null)
return;
PsiModifierList modifierList = typeDefinition.getModifierList();
if (modifierList == null)
return;
final PsiAnnotation tupleConstructor = modifierList.findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR);
final boolean immutable = PsiImplUtil.hasImmutableAnnotation(modifierList);
final boolean canonical = modifierList.findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_CANONICAL) != null;
if (!immutable && !canonical && tupleConstructor == null) {
return;
}
if (tupleConstructor != null && typeDefinition.getCodeConstructors().length > 0 && !PsiUtil.getAnnoAttributeValue(tupleConstructor, "force", false)) {
return;
}
final GrLightMethodBuilder fieldsConstructor = generateFieldConstructor(typeDefinition, tupleConstructor, immutable, canonical);
final GrLightMethodBuilder mapConstructor = generateMapConstructor(typeDefinition);
context.addMethod(fieldsConstructor);
context.addMethod(mapConstructor);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class InheritConstructorContributor method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
GrTypeDefinition psiClass = context.getCodeClass();
if (psiClass.isAnonymous() || psiClass.isInterface() || psiClass.isEnum()) {
return;
}
if (!hasInheritConstructorsAnnotation(psiClass))
return;
final PsiClass superClass = context.getSuperClass();
if (superClass == null)
return;
final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, PsiSubstitutor.EMPTY);
for (PsiMethod constructor : superClass.getConstructors()) {
if (constructor.hasModifierProperty(PsiModifier.PRIVATE))
continue;
final GrLightMethodBuilder inheritedConstructor = new GrLightMethodBuilder(context.getManager(), context.getClassName());
inheritedConstructor.setConstructor(true);
inheritedConstructor.setNavigationElement(psiClass);
inheritedConstructor.addModifier(VisibilityUtil.getVisibilityModifier(constructor.getModifierList()));
inheritedConstructor.setOriginInfo("created by @InheritConstructors");
for (PsiParameter parameter : constructor.getParameterList().getParameters()) {
String name = StringUtil.notNullize(parameter.getName());
PsiType type = superClassSubstitutor.substitute(parameter.getType());
inheritedConstructor.addParameter(name, type, false);
}
context.addMethod(inheritedConstructor);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class TransformationContextImpl method doAddMethod.
private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
if (method instanceof GrLightMethodBuilder) {
((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
} else if (method instanceof LightMethodBuilder) {
((LightMethodBuilder) method).setContainingClass(myCodeClass);
}
MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
if (signatures.add(signature)) {
if (prepend) {
myMethods.addFirst(method);
} else {
myMethods.addLast(method);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class StreamingJsonBuilderDelegateContributor method createMethod.
@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiElement place, @NotNull PsiClass clazz) {
GrLightMethodBuilder method = new GrLightMethodBuilder(place.getManager(), name);
method.setModifiers(GrModifierFlags.PUBLIC_MASK);
method.setReturnType(TypesUtil.getJavaLangObject(place));
UtilsKt.setContainingClass(method, clazz);
method.setOriginInfo(StreamingJsonBuilderContributor.ORIGIN_INFO);
return method;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class XmlMarkupBuilderNonCodeMemberContributor method createMethod.
@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiClass clazz, @NotNull PsiElement place) {
GrLightMethodBuilder res = new GrLightMethodBuilder(place.getManager(), name);
res.setReturnType(JAVA_LANG_STRING, place.getResolveScope());
res.setOriginInfo(ORIGIN_INFO);
UtilsKt.setContainingClass(res, clazz);
return res;
}
Aggregations