Search in sources :

Example 1 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class ClassItemGeneratorImpl method writeMethod.

@Override
public void writeMethod(StringBuilder builder, PsiMethod method) {
    if (method == null)
        return;
    GenerationUtil.writeDocComment(builder, method, true);
    String name = method.getName();
    boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
    PsiModifierList modifierList = method.getModifierList();
    final PsiClass containingClass = method.getContainingClass();
    if (method.isConstructor() && containingClass != null && containingClass.isEnum()) {
        ModifierListGenerator.writeModifiers(builder, modifierList, ModifierListGenerator.ENUM_CONSTRUCTOR_MODIFIERS);
    } else {
        ModifierListGenerator.writeModifiers(builder, modifierList);
    }
    if (method.hasTypeParameters()) {
        GenerationUtil.writeTypeParameters(builder, method, classNameProvider);
        builder.append(' ');
    }
    //append return type
    if (!method.isConstructor()) {
        PsiType retType = context.typeProvider.getReturnType(method);
        TypeWriter.writeType(builder, retType, method, classNameProvider);
        builder.append(' ');
    }
    builder.append(name);
    if (method instanceof GroovyPsiElement) {
        context.searchForLocalVarsToWrap((GroovyPsiElement) method);
    }
    GenerationUtil.writeParameterList(builder, method.getParameterList().getParameters(), classNameProvider, context);
    if (method instanceof GrAnnotationMethod) {
        GrAnnotationMemberValue defaultValue = ((GrAnnotationMethod) method).getDefaultValue();
        if (defaultValue != null) {
            builder.append("default ");
            defaultValue.accept(new AnnotationGenerator(builder, context));
        }
    }
    GenerationUtil.writeThrowsList(builder, method.getThrowsList(), getMethodExceptions(method), classNameProvider);
    if (!isAbstract) {
        /* ************ body ********* */
        if (method instanceof GrMethod) {
            if (method instanceof GrReflectedMethod && ((GrReflectedMethod) method).getSkippedParameters().length > 0) {
                builder.append("{\n").append(generateDelegateCall((GrReflectedMethod) method)).append("\n}\n");
            } else {
                new CodeBlockGenerator(builder, context.extend()).generateMethodBody((GrMethod) method);
            }
        } else if (method instanceof GrAccessorMethod) {
            writeAccessorBody(builder, method);
        } else if (method instanceof LightMethodBuilder && containingClass instanceof GroovyScriptClass) {
            if ("main".equals(method.getName())) {
                writeMainScriptMethodBody(builder, method);
            } else if ("run".equals(method.getName())) {
                writeRunScriptMethodBody(builder, method);
            }
        } else {
            builder.append("{//todo\n}");
        }
    } else {
        builder.append(';');
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)

Example 2 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class StubGenerator method mirrorMethod.

private static LightMethodBuilder mirrorMethod(PsiClass typeDefinition, PsiMethod method, PsiClass baseClass, PsiSubstitutor substitutor) {
    final LightMethodBuilder builder = new LightMethodBuilder(method.getManager(), method.getName());
    substitutor = substitutor.putAll(TypeConversionUtil.getSuperClassSubstitutor(baseClass, typeDefinition, PsiSubstitutor.EMPTY));
    for (PsiParameter parameter : method.getParameterList().getParameters()) {
        builder.addParameter(StringUtil.notNullize(parameter.getName()), substitutor.substitute(parameter.getType()));
    }
    builder.setMethodReturnType(substitutor.substitute(method.getReturnType()));
    for (String modifier : STUB_MODIFIERS) {
        if (method.hasModifierProperty(modifier)) {
            builder.addModifier(modifier);
        }
    }
    return builder;
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder)

Example 3 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder 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);
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ObjectOutput(java.io.ObjectOutput) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) IOException(java.io.IOException) ObjectInput(java.io.ObjectInput)

Example 4 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class DefaultBuilderStrategySupport method createBuildMethod.

@NotNull
public static LightMethodBuilder createBuildMethod(@NotNull PsiAnnotation annotation, @NotNull PsiType builtType) {
    final LightMethodBuilder buildMethod = new LightMethodBuilder(annotation.getManager(), getBuildMethodName(annotation));
    buildMethod.setOriginInfo(ORIGIN_INFO);
    buildMethod.setMethodReturnType(builtType);
    return buildMethod;
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class DefaultBuilderStrategySupport method createFieldSetter.

@NotNull
public static LightMethodBuilder createFieldSetter(@NotNull PsiClass builderClass, @NotNull String name, @NotNull PsiType type, @NotNull PsiAnnotation annotation, @NotNull PsiElement navigationElement) {
    final LightMethodBuilder fieldSetter = new LightMethodBuilder(builderClass.getManager(), getFieldMethodName(annotation, name));
    fieldSetter.addModifier(PsiModifier.PUBLIC);
    fieldSetter.addParameter(name, type);
    fieldSetter.setContainingClass(builderClass);
    fieldSetter.setMethodReturnType(JavaPsiFacade.getElementFactory(builderClass.getProject()).createType(builderClass));
    fieldSetter.setNavigationElement(navigationElement);
    fieldSetter.setOriginInfo(ORIGIN_INFO);
    return fieldSetter;
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)12 NotNull (org.jetbrains.annotations.NotNull)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)2 ReflectedProject (com.intellij.lang.ant.ReflectedProject)1 Project (com.intellij.openapi.project.Project)1 PsiArrayType (com.intellij.psi.PsiArrayType)1 PsiClass (com.intellij.psi.PsiClass)1 PsiType (com.intellij.psi.PsiType)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrAnnotationMemberValue (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue)1 GrLightMethodBuilder (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)1