1 /******************************************************************************* 2 * Copyright (c) 2019 Mateusz Matela and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Mateusz Matela <mateusz.matela@gmail.com> - [code manipulation] [dcr] toString() builder wizard - https://bugs.eclipse.org/bugs/show_bug.cgi?id=26070 13 * Mateusz Matela <mateusz.matela@gmail.com> - [toString] finish toString() builder wizard - https://bugs.eclipse.org/bugs/show_bug.cgi?id=267710 14 * Red Hat Inc. - copied and modified to make ToStringGenerationSettingsCore 15 *******************************************************************************/ 16 package org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration; 17 18 import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; 19 20 public class ToStringGenerationSettingsCore extends CodeGenerationSettings { 21 22 public static final String SETTINGS_SELECTED_TEMPLATE= "ToStringTemplateSelected"; //$NON-NLS-1$ 23 24 public static final String SETTINGS_STRINGSTYLE= "StringStyle"; //$NON-NLS-1$ 25 26 public static final String SETTINGS_SKIPNULLS= "SkipNull"; //$NON-NLS-1$ 27 28 public static final String SETTINGS_IGNOREDEFAULT= "IgnoreDefault"; //$NON-NLS-1$ 29 30 public static final String SETTINGS_LIMITELEMENTS= "LimitElements"; //$NON-NLS-1$ 31 32 public static final String SETTINGS_LIMITVALUE= "LimitValue"; //$NON-NLS-1$ 33 34 public static final String SETTINGS_TEMPLATE_NAMES= "ToStringTemplateNames"; //$NON-NLS-1$ 35 36 public static final String SETTINGS_TEMPLATES= "ToStringTemplates"; //$NON-NLS-1$ 37 38 public static final String SETTINGS_CUSTOMBUILDER_CLASS= "CustomBuilderClass"; //$NON-NLS-1$ 39 40 public static final String SETTINGS_CUSTOMBUILDER_LABEL= "CustomBuilderLabel"; //$NON-NLS-1$ 41 42 public static final String SETTINGS_CUSTOMBUILDER_APPENDMETHOD= "CustomBuilderAppendMethod"; //$NON-NLS-1$ 43 44 public static final String SETTINGS_CUSTOMBUILDER_RESULTMETHOD= "CustomBuilderResultMethod"; //$NON-NLS-1$ 45 46 public static final String SETTINGS_CUSTOMBUILDER_CHAINCALLS= "CustomBuilderChainCalls"; //$NON-NLS-1$ 47 48 /** 49 * Container for settings specific for custom toString() generator code style 50 */ 51 public static class CustomBuilderSettings { 52 /** 53 * what class should be used as a custom toString() builder (this is a fully qualified and 54 * Parameterized name) 55 **/ 56 public String className; 57 58 /** identifier for the local variable that holds the custom toString() builder in generated code **/ 59 public String variableName; 60 61 /** name of a custom toString() builder's methods that should be called to append content **/ 62 public String appendMethod; 63 64 /** name of a custom toString() builder method that should be called to retrieve result **/ 65 public String resultMethod; 66 67 /** should custom toString() builder method calls be joined into chains? **/ 68 public boolean chainCalls; 69 } 70 71 /** which template should be used to format the output of the toString() method? */ 72 public int stringFormatTemplateNumber; 73 74 /** 75 * what is the template (redundancy - this field can be determined basing on 76 * <code>GenerateToStringDialog.getTemplates()</code> and 77 * <code>stringFormatTemplateNumber</code>, but this way it's more convenient) 78 */ 79 public String stringFormatTemplate; 80 81 /** what style of code should the toString() method have? */ 82 public int toStringStyle; 83 84 /** should the toString() method skip null values? */ 85 public boolean skipNulls; 86 87 /** should the toString() method use its own way to show elements of an array? */ 88 public boolean customArrayToString; 89 90 /** 91 * should the toString() limit maximum number of elements of arrays/Collections to be 92 * listed? 93 */ 94 public boolean limitElements; 95 96 /** what is the maximum number of elements in array/Collection to show? */ 97 public int limitValue; 98 99 /** should blocks be forced in if/for/while statements? */ 100 public boolean useBlocks; 101 102 /** can generated code use jdk 1.5 API? **/ 103 public boolean is50orHigher; 104 105 /** can generated code use jdk 1.6 API? **/ 106 public boolean is60orHigher; 107 108 /** settings specific for custom builder code style **/ 109 public CustomBuilderSettings customBuilderSettings; 110 111 /** 112 * Returns a copy of customBuilderSettings. Changes made in the returned object will not affect 113 * this settings object. To save changes made to the object, use: 114 * 115 * ToStringGenerationSettings#writeCustomBuilderSettings(ToStringGenerationSettings.CustomBuilderSettings) 116 * 117 * @return copy of custom builder settings object 118 */ getCustomBuilderSettings()119 public CustomBuilderSettings getCustomBuilderSettings() { 120 CustomBuilderSettings result= new CustomBuilderSettings(); 121 result.className= customBuilderSettings.className; 122 result.variableName= customBuilderSettings.variableName; 123 result.appendMethod= customBuilderSettings.appendMethod; 124 result.resultMethod= customBuilderSettings.resultMethod; 125 result.chainCalls= customBuilderSettings.chainCalls; 126 return result; 127 } 128 129 } 130