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(';');
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations