use of org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo in project intellij-community by JetBrains.
the class GroovyGenerateMethodMissingHandler method generateMemberPrototypes.
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);
final GrMethod method = genMethod(aClass, template);
return method != null ? Collections.singletonList(new GroovyGenerationInfo<>(method, true)) : Collections.<GenerationInfo>emptyList();
}
use of org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo in project intellij-community by JetBrains.
the class GroovyGeneratePropertyMissingHandler method generateMemberPrototypes.
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);
final GrMethod getter = genGetter(aClass, template);
final GrMethod setter = genSetter(aClass, template);
final ArrayList<GroovyGenerationInfo<GrMethod>> result = new ArrayList<>();
if (getter != null)
result.add(new GroovyGenerationInfo<>(getter, true));
if (setter != null)
result.add(new GroovyGenerationInfo<>(setter, true));
return result;
}
use of org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo in project intellij-community by JetBrains.
the class GroovyGenerateConstructorHandler method generateMemberPrototypes.
@Override
@NotNull
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
final List<? extends GenerationInfo> list = super.generateMemberPrototypes(aClass, members);
List<PsiGenerationInfo<GrMethod>> grConstructors = new ArrayList<>();
final Project project = aClass.getProject();
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
for (GenerationInfo generationInfo : list) {
final PsiMember constructorMember = generationInfo.getPsiMember();
assert constructorMember instanceof PsiMethod;
final PsiMethod constructor = (PsiMethod) constructorMember;
final PsiCodeBlock block = constructor.getBody();
assert block != null;
final String constructorName = aClass.getName();
final String body = StringUtil.replace(StringUtil.replace(block.getText(), DEF_PSEUDO_ANNO, ""), ";", "");
final PsiParameterList list1 = constructor.getParameterList();
List<String> parametersNames = new ArrayList<>();
List<String> parametersTypes = new ArrayList<>();
for (PsiParameter parameter : list1.getParameters()) {
final String fullName = parameter.getName();
parametersNames.add(StringUtil.trimStart(fullName, DEF_PSEUDO_ANNO));
parametersTypes.add(fullName.startsWith(DEF_PSEUDO_ANNO) ? null : parameter.getType().getCanonicalText());
}
final String[] paramNames = ArrayUtil.toStringArray(parametersNames);
final String[] paramTypes = ArrayUtil.toStringArray(parametersTypes);
assert constructorName != null;
GrMethod grConstructor = factory.createConstructorFromText(constructorName, paramTypes, paramNames, body);
PsiReferenceList throwsList = grConstructor.getThrowsList();
for (PsiJavaCodeReferenceElement element : constructor.getThrowsList().getReferenceElements()) {
throwsList.add(element);
}
codeStyleManager.shortenClassReferences(grConstructor);
grConstructors.add(new GroovyGenerationInfo<>(grConstructor));
}
return grConstructors;
}
use of org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo in project intellij-community by JetBrains.
the class GroovyGenerateEqualsHandler method generateMemberPrototypes.
@Override
@NotNull
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] originalMembers) throws IncorrectOperationException {
Project project = aClass.getProject();
final boolean useInstanceofToCheckParameterType = CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER;
GroovyGenerateEqualsHelper helper = new GroovyGenerateEqualsHelper(project, aClass, myEqualsFields, myHashCodeFields, myNonNullFields, useInstanceofToCheckParameterType);
Collection<PsiMethod> methods = helper.generateMembers();
return ContainerUtil.map2List(methods, (Function<PsiMethod, PsiGenerationInfo<PsiMethod>>) s -> new GroovyGenerationInfo<>(s));
}
Aggregations