use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class AutoExternalizeContributor method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
GrTypeDefinition clazz = context.getCodeClass();
if (!hasGeneratedImplementations(clazz))
return;
final LightMethodBuilder write = new LightMethodBuilder(clazz.getManager(), "writeExternal");
write.addParameter("out", ObjectOutput.class.getName());
write.addException(IOException.class.getName());
write.setOriginInfo("created by @AutoExternalize");
context.addMethod(write);
final LightMethodBuilder read = new LightMethodBuilder(clazz.getManager(), "readExternal");
read.addParameter("oin", ObjectInput.class.getName());
read.setOriginInfo("created by @AutoExternalize");
context.addMethod(read);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition 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.api.statements.typedef.GrTypeDefinition 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.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class SimpleBuilderStrategySupport method applyTransformation.
@Override
public void applyTransformation(@NotNull TransformationContext context) {
GrTypeDefinition typeDefinition = context.getCodeClass();
final PsiAnnotation annotation = PsiImplUtil.getAnnotation(typeDefinition, BUILDER_FQN);
if (!isApplicable(annotation, SIMPLE_STRATEGY_NAME))
return;
for (GrField field : typeDefinition.getCodeFields()) {
context.addMethod(createFieldSetter(typeDefinition, field, annotation));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyPositionManager method findEnclosingTypeDefinition.
@Nullable
private static PsiClass findEnclosingTypeDefinition(SourcePosition position) {
PsiFile file = position.getFile();
if (!(file instanceof GroovyFileBase))
return null;
PsiElement element = file.findElementAt(position.getOffset());
while (true) {
element = PsiTreeUtil.getParentOfType(element, GrTypeDefinition.class, GroovyFileBase.class);
if (element instanceof GroovyFileBase) {
return ((GroovyFileBase) element).getScriptClass();
} else if (element instanceof GrTypeDefinition && !((GrTypeDefinition) element).isAnonymous()) {
return (GrTypeDefinition) element;
}
}
}
Aggregations