Java: generated toString() should use getters when so configured (IDEA-340449)

GitOrigin-RevId: 4a13c080bc8796a7932a57f186f3ac849accc09f
This commit is contained in:
Bas Leijdekkers
2023-12-11 15:43:52 +00:00
committed by intellij-monorepo-bot
parent cf1b240751
commit 8d52822c7c
2 changed files with 12 additions and 21 deletions
@@ -313,8 +313,8 @@ generate.tostring.exclude.constant.fields=Exclude constant fields
generate.tostring.exclude.enum.fields=Exclude enum fields
generate.tostring.exclude.logger=Exclude logger fields (Log4j, JDK Logging, Jakarta Commons Logging)
generate.tostring.exclude.static.fields=Exclude static fields
generate.tostring.fully.qualified.class.name=Use fully qualified class name in code generation ($classname)
generate.tostring.getters.in.generated.code=Enable getters in code generation ($methods)
generate.tostring.fully.qualified.class.name=Use fully qualified class name in generated toString() ($classname)
generate.tostring.getters.in.generated.code=Use getters in generated toString() when available ($methods)
generate.tostring.handle.exception.error.message=An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n{0}
generate.tostring.handle.exception.plugin.warning.message=A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n{0}
generate.tostring.handle.exception.velocity.error.message=Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n{0}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
/*
* @author max
@@ -102,10 +88,15 @@ public class GenerateToStringWorker {
}
private PsiMethod getMethodPrototype(Collection<PsiMember> selectedMembers, Map<String, String> params, TemplateResource template) {
// generate code using velocity
String evaluatedText = GenerationUtil
.velocityGenerateCode(clazz, selectedMembers, params, template.getTemplate(), config.getSortElements(), config.isUseFullyQualifiedName());
// create psi newMethod named toString()
String evaluatedText = GenerationUtil.velocityGenerateCode(clazz,
selectedMembers,
Set.of(),
params,
Map.of(),
template.getTemplate(),
config.getSortElements(),
config.isUseFullyQualifiedName(),
config.isEnableMethods());
final JVMElementFactory topLevelFactory = JVMElementFactories.getFactory(clazz.getLanguage(), clazz.getProject());
if (topLevelFactory == null) {
return null;