package jetbrains.mps.ide.java.actions; /*Generated by MPS */ import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.project.Project; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.util.NameUtil; import jetbrains.mps.baseLanguage.util.CodeStyleSettings; import jetbrains.mps.baseLanguage.util.CodeStyleSettingsRegistry; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; public class GenerateGettersAndSettersUtil { public GenerateGettersAndSettersUtil() { } private static String getPreparedName(String fullName, String prefix, String suffix) { if (prefix == null) { prefix = ""; } if (suffix == null) { suffix = ""; } int preparedNameStart = (((prefix != null && prefix.length() > 0) && fullName.startsWith(prefix)) ? prefix.length() : 0); int preparedNameEnd = (((suffix != null && suffix.length() > 0) && fullName.endsWith(suffix)) ? fullName.indexOf(suffix) : fullName.length()); if (preparedNameStart >= preparedNameEnd) { return fullName; } return fullName.substring(preparedNameStart, preparedNameEnd); } public static String getFieldGetterName(SNode fieldDeclaration, Project project) { String get = "get"; if (SNodeOperations.isInstanceOf(SLinkOperations.getTarget(fieldDeclaration, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type")), MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940d6513eL, "jetbrains.mps.baseLanguage.structure.BooleanType"))) { get = "is"; } return get + NameUtil.capitalize(getPreparedFieldName(fieldDeclaration, project)); } public static String getFieldSetterName(SNode fieldDeclaration, Project project) { return "set" + NameUtil.capitalize(getPreparedFieldName(fieldDeclaration, project)); } public static String getParameterNameForField(SNode field, Project project) { String preparedFieldName = getPreparedFieldName(field, project); CodeStyleSettings codeStyleSettings = CodeStyleSettingsRegistry.getSettings(project); if (codeStyleSettings == null) { return NameUtil.decapitalize(preparedFieldName); } String prefix = (codeStyleSettings.getParameterPrefix() == null ? "" : codeStyleSettings.getParameterPrefix()); String suffix = (codeStyleSettings.getParameterSuffix() == null ? "" : codeStyleSettings.getParameterSuffix()); String paramName; if ((prefix == null || prefix.length() == 0)) { paramName = NameUtil.decapitalize(preparedFieldName + suffix); } else { paramName = prefix + preparedFieldName + suffix; } if (paramName.equals(SPropertyOperations.getString(field, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")))) { paramName = paramName + "1"; } return paramName; } public static String getPreparedFieldName(SNode fieldDeclaration, Project project) { String rawName = SPropertyOperations.getString(fieldDeclaration, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")); if (rawName == null || rawName.length() == 0) { return "unnamedField"; } CodeStyleSettings codeStyleSettings = CodeStyleSettingsRegistry.getSettings(project); if (codeStyleSettings == null) { return rawName; } return getPreparedName(rawName, codeStyleSettings.getFieldPrefix(), codeStyleSettings.getFieldSuffix()); } }