diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts index 218ba95eb6b..bd0232174f5 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts @@ -592,8 +592,8 @@ int gooo = 1; //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config filename=GaS.h -getters=i,isOk -setters=i,isOk +getters=i,ok +setters=i,ok inHeader=true //@GaS.cpp #include "Getters.h" @@ -612,8 +612,8 @@ class GaS { public: GaS(); virtual ~GaS(); - bool /*$*/isOk/*$$*/; - void methode2(); + bool /*$*/ok/*$$*/; + void method2(); private: int i; @@ -629,16 +629,16 @@ class GaS { public: GaS(); virtual ~GaS(); - bool isOk; - void methode2(); + bool ok; + void method2(); int getI() const { return i; } - bool getIsOk() const + bool isOk() const { - return isOk; + return ok; } void setI(int i) @@ -646,9 +646,9 @@ public: this->i = i; } - void setIsOk(bool isOk) + void setOk(bool ok) { - this->isOk = isOk; + this->ok = ok; } private: diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java new file mode 100644 index 00000000000..df82a4d5dde --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2010 Marc-Andre Laperle and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring.utils; + +import junit.framework.TestCase; + +import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterNameGenerator; + +public class AccessorNameGeneratorTest extends TestCase { + + public void testTrimFieldName() { + assertEquals("f", GetterSetterNameGenerator.trimFieldName("f_")); + assertEquals("F", GetterSetterNameGenerator.trimFieldName("F_")); + assertEquals("oo", GetterSetterNameGenerator.trimFieldName("F_oo")); + assertEquals("o", GetterSetterNameGenerator.trimFieldName("f_o")); + + assertEquals("M", GetterSetterNameGenerator.trimFieldName("a_M_")); + assertEquals("bs", GetterSetterNameGenerator.trimFieldName("a_bs_")); + assertEquals("foo_bar", GetterSetterNameGenerator.trimFieldName("foo_bar")); + assertEquals("foo_bar", GetterSetterNameGenerator.trimFieldName("foo_bar_")); + + assertEquals("foo_b", GetterSetterNameGenerator.trimFieldName("foo_b_")); + + assertEquals("foo", GetterSetterNameGenerator.trimFieldName("foo")); + assertEquals("foo", GetterSetterNameGenerator.trimFieldName("_foo")); + assertEquals("bar", GetterSetterNameGenerator.trimFieldName("_f_bar")); + + assertEquals("f", GetterSetterNameGenerator.trimFieldName("f__")); + assertEquals("f", GetterSetterNameGenerator.trimFieldName("__f")); + assertEquals("O__b", GetterSetterNameGenerator.trimFieldName("fO__b")); + assertEquals("Oo", GetterSetterNameGenerator.trimFieldName("fOo")); + assertEquals("O", GetterSetterNameGenerator.trimFieldName("fO")); + assertEquals("MyStatic", GetterSetterNameGenerator.trimFieldName("sMyStatic")); + assertEquals("MyMember", GetterSetterNameGenerator.trimFieldName("mMyMember")); + + assertEquals("8", GetterSetterNameGenerator.trimFieldName("_8")); + + assertEquals("8bar", GetterSetterNameGenerator.trimFieldName("_8bar_")); + assertEquals("8bar_8", GetterSetterNameGenerator.trimFieldName("_8bar_8")); + assertEquals("8bAr", GetterSetterNameGenerator.trimFieldName("_8bAr")); + assertEquals("b8Ar", GetterSetterNameGenerator.trimFieldName("_b8Ar")); + + assertEquals("Id", GetterSetterNameGenerator.trimFieldName("Id")); + assertEquals("ID", GetterSetterNameGenerator.trimFieldName("ID")); + assertEquals("IDS", GetterSetterNameGenerator.trimFieldName("IDS")); + assertEquals("ID", GetterSetterNameGenerator.trimFieldName("bID")); + assertEquals("Id", GetterSetterNameGenerator.trimFieldName("MId")); + assertEquals("IdA", GetterSetterNameGenerator.trimFieldName("IdA")); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java index 802a8a76abf..181b0b7d544 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.utils; @@ -16,7 +16,6 @@ import junit.framework.TestSuite; /** * @author Thomas Corbat - * */ public class IdentifierHelperTest extends TestSuite { @@ -31,7 +30,7 @@ public class IdentifierHelperTest extends TestSuite { suite.addTest(new EmptyCaseTest()); suite.addTest(new IllegalCharCaseTest()); suite.addTest(new KeywordCaseTest()); - suite.addTestSuite(NameHelperTest.class); + suite.addTestSuite(AccessorNameGeneratorTest.class); return suite; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java new file mode 100644 index 00000000000..8fddfe0be19 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring.utils; + +import org.eclipse.cdt.ui.PreferenceConstants; + +import junit.framework.TestCase; + +import org.eclipse.cdt.internal.ui.util.NameComposer; + +public class NameComposerTest extends TestCase { + private static final int CAPITALIZATION_ORIGINAL = PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL; + private static final int CAPITALIZATION_UPPER_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_UPPER_CASE; + private static final int CAPITALIZATION_LOWER_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CASE; + private static final int CAPITALIZATION_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE; + private static final int CAPITALIZATION_LOWER_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE; + + public void testTrimFieldName() { + NameComposer composer = new NameComposer(CAPITALIZATION_ORIGINAL, "", "", ".h"); + assertEquals("MyClass.h", composer.compose("MyClass")); + composer = new NameComposer(CAPITALIZATION_LOWER_CASE, "-", "", ".cc"); + assertEquals("my-class.cc", composer.compose("MyClass")); + composer = new NameComposer(CAPITALIZATION_UPPER_CASE, "_", "", ""); + assertEquals("MY_CONSTANT", composer.compose("MyConstant")); + composer = new NameComposer(CAPITALIZATION_CAMEL_CASE, "", "get", ""); + assertEquals("getMyField", composer.compose("myField")); + assertEquals("getMyField", composer.compose("my_field_")); + composer = new NameComposer(CAPITALIZATION_LOWER_CAMEL_CASE, "", "", ""); + assertEquals("myField", composer.compose("MyField")); + composer = new NameComposer(CAPITALIZATION_LOWER_CASE, "_", "", "_"); + assertEquals("my_field_", composer.compose("MyField")); + composer = new NameComposer(CAPITALIZATION_ORIGINAL, "_", "", ""); + assertEquals("red_Green_blue", composer.compose("_red_Green_blue")); + composer = new NameComposer(CAPITALIZATION_CAMEL_CASE, "", "", ""); + assertEquals("RgbValue", composer.compose("RGBValue")); + composer = new NameComposer(CAPITALIZATION_ORIGINAL, "_", "", ""); + assertEquals("RGB_Value", composer.compose("RGBValue")); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameHelperTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameHelperTest.java deleted file mode 100644 index 937d9b038cb..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameHelperTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Marc-Andre Laperle and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Marc-Andre Laperle - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.refactoring.utils; - -import junit.framework.TestCase; - -import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; - -public class NameHelperTest extends TestCase { - - public void testTrimFieldName() { - assertEquals("f", NameHelper.trimFieldName("f_")); - assertEquals("F", NameHelper.trimFieldName("F_")); - assertEquals("oo", NameHelper.trimFieldName("F_oo")); - assertEquals("o", NameHelper.trimFieldName("f_o")); - - assertEquals("M", NameHelper.trimFieldName("a_M_")); - assertEquals("bs", NameHelper.trimFieldName("a_bs_")); - assertEquals("foo_bar", NameHelper.trimFieldName("foo_bar")); - assertEquals("foo_bar", NameHelper.trimFieldName("foo_bar_")); - - assertEquals("foo_b", NameHelper.trimFieldName("foo_b_")); - - assertEquals("foo", NameHelper.trimFieldName("foo")); - assertEquals("foo", NameHelper.trimFieldName("_foo")); - assertEquals("bar", NameHelper.trimFieldName("_f_bar")); - - assertEquals("f", NameHelper.trimFieldName("f__")); - assertEquals("f", NameHelper.trimFieldName("__f")); - assertEquals("O__b", NameHelper.trimFieldName("fO__b")); - assertEquals("Oo", NameHelper.trimFieldName("fOo")); - assertEquals("O", NameHelper.trimFieldName("fO")); - assertEquals("MyStatic", NameHelper.trimFieldName("sMyStatic")); - assertEquals("MyMember", NameHelper.trimFieldName("mMyMember")); - - assertEquals("8", NameHelper.trimFieldName("_8")); - - assertEquals("8bar", NameHelper.trimFieldName("_8bar_")); - assertEquals("8bar_8", NameHelper.trimFieldName("_8bar_8")); - assertEquals("8bAr", NameHelper.trimFieldName("_8bAr")); - assertEquals("b8Ar", NameHelper.trimFieldName("_b8Ar")); - - assertEquals("Id", NameHelper.trimFieldName("Id")); - assertEquals("ID", NameHelper.trimFieldName("ID")); - assertEquals("IDS", NameHelper.trimFieldName("IDS")); - assertEquals("ID", NameHelper.trimFieldName("bID")); - assertEquals("IdA", NameHelper.trimFieldName("IdA")); - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java index c5eaae6de90..00bc10a9a74 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.utils; @@ -27,6 +28,7 @@ public class UtilTestSuite extends TestSuite { suite.addTest(RefactoringTester.suite("TranslationUnitHelperTest", "resources/refactoring/TranslationunitHelper.rts")); //$NON-NLS-1$ //$NON-NLS-2$ suite.addTest(RefactoringTester.suite("DefinitionFinderTest", "resources/refactoring/DefinitionFinder.rts")); //$NON-NLS-1$ //$NON-NLS-2$ suite.addTestSuite(PseudoNameGeneratorTest.class); + suite.addTestSuite(NameComposerTest.class); return suite; } } diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index fdb9bd8a949..cbd9e969238 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -187,6 +187,7 @@ CPluginGlobalBuildLogPreferencePage.name=Logging CPluginFileTypesPreferencePage.name=File Types CodeFormatterPreferencePage.name=Code Style codeTemplatePreferencePage.name=Code Templates +nameStylePreferencePage.name=Name Style CodeAssistPreferencePage.name=Content Assist CodeAssistAdvancedPreferencePage.name=Advanced SmartTypingPreferencePage.name=Typing @@ -548,6 +549,7 @@ workingSetConfigurationsExtensionPoint=Working Set Configurations preferenceKeywords.common=c cpp cplusplus cdt preferenceKeywords.codestyle=profile codestyle project specific comment indentation brace white space blank line new control statement wrapping tab parenthesis bracket preferenceKeywords.codetemplates=comment code constructor method file type content +preferenceKeywords.namestyle=name file getter setter preferenceKeywords.todo=case sensitive task tag todo xxx fix fixme project comments preferenceKeywords.indexer=index skip references type macro search build configuration cache memory performance diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index b4e7b83af0d..29c377359c1 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -745,6 +745,14 @@ + + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java index fc98491dae7..a639db045b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java @@ -86,6 +86,7 @@ public interface ICHelpContextIds { public static final String APPEARANCE_PREFERENCE_PAGE = PREFIX + "appearance_preference_page_context"; //$NON-NLS-1$ public static final String SPELLING_CONFIGURATION_BLOCK= PREFIX + "spelling_configuration_block_context"; //$NON-NLS-1$ public static final String CODE_TEMPLATES_PREFERENCE_PAGE = PREFIX + "code_templates_preference_context"; //$NON-NLS-1$ + public static final String NAME_STYLE_PREFERENCE_PAGE = PREFIX + "name_style_preference_context"; //$NON-NLS-1$ // Console view public static final String CLEAR_CONSOLE_ACTION = PREFIX + "clear_console_action_context"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java new file mode 100644 index 00000000000..8ee4b80cc10 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java @@ -0,0 +1,653 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.preferences; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +import org.eclipse.cdt.ui.PreferenceConstants; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; + +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.util.NameComposer; +import org.eclipse.cdt.internal.ui.viewsupport.ProjectTemplateStore; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; + +/** + * The preference block for configuring styles of names. + */ +public class NameStyleBlock extends OptionsConfigurationBlock { +// private static final String EXAMPLE_CONSTANT_NAME = "MY_CONSTANT"; //$NON-NLS-1$ + private static final String EXAMPLE_CLASS_NAME = "MyClass"; //$NON-NLS-1$ + private static final String EXAMPLE_FIELD_NAME = "myField"; //$NON-NLS-1$ + + private final String[] CAPITALIZATION_VALUES = { + String.valueOf(PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL), + String.valueOf(PreferenceConstants.NAME_STYLE_CAPITALIZATION_UPPER_CASE), + String.valueOf(PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CASE), + String.valueOf(PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE), + String.valueOf(PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE), + }; + + private final String[] CAPITALIZATION_LABELS = { + String.valueOf(PreferencesMessages.NameStyleBlock_capitalization_original), + String.valueOf(PreferencesMessages.NameStyleBlock_capitalization_upper_case), + String.valueOf(PreferencesMessages.NameStyleBlock_capitalization_lower_case), + String.valueOf(PreferencesMessages.NameStyleBlock_capitalization_camel_case), + String.valueOf(PreferencesMessages.NameStyleBlock_capitalization_lower_camel_case), + }; + + private static final Key KEY_CONSTANT_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_CONSTANT_CAPITALIZATION); + private static final Key KEY_CONSTANT_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_CONSTANT_WORD_DELIMITER); + private static final Key KEY_CONSTANT_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CONSTANT_PREFIX); + private static final Key KEY_CONSTANT_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CONSTANT_SUFFIX); + private static final Key KEY_FIELD_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_FIELD_CAPITALIZATION); + private static final Key KEY_FIELD_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_FIELD_WORD_DELIMITER); + private static final Key KEY_FIELD_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_FIELD_PREFIX); + private static final Key KEY_FIELD_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_FIELD_SUFFIX); + private static final Key KEY_GETTER_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_GETTER_CAPITALIZATION); + private static final Key KEY_GETTER_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_GETTER_WORD_DELIMITER); + private static final Key KEY_GETTER_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_GETTER_PREFIX); + private static final Key KEY_GETTER_PREFIX_FOR_BOOLEAN = getCDTUIKey(PreferenceConstants.NAME_STYLE_GETTER_PREFIX_FOR_BOOLEAN); + private static final Key KEY_GETTER_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_GETTER_SUFFIX); + private static final Key KEY_SETTER_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_SETTER_CAPITALIZATION); + private static final Key KEY_SETTER_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_SETTER_WORD_DELIMITER); + private static final Key KEY_SETTER_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_SETTER_PREFIX); + private static final Key KEY_SETTER_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_SETTER_SUFFIX); + private static final Key KEY_CPP_SOURCE_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_SOURCE_CAPITALIZATION); + private static final Key KEY_CPP_SOURCE_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_SOURCE_WORD_DELIMITER); + private static final Key KEY_CPP_SOURCE_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_SOURCE_PREFIX); + private static final Key KEY_CPP_SOURCE_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_SOURCE_SUFFIX); + private static final Key KEY_CPP_HEADER_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_HEADER_CAPITALIZATION); + private static final Key KEY_CPP_HEADER_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_HEADER_WORD_DELIMITER); + private static final Key KEY_CPP_HEADER_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_HEADER_PREFIX); + private static final Key KEY_CPP_HEADER_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_HEADER_SUFFIX); + private static final Key KEY_CPP_TEST_CAPITALIZATION = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_CAPITALIZATION); + private static final Key KEY_CPP_TEST_WORD_DELIMITER = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_WORD_DELIMITER); + private static final Key KEY_CPP_TEST_PREFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_PREFIX); + private static final Key KEY_CPP_TEST_SUFFIX = getCDTUIKey(PreferenceConstants.NAME_STYLE_CPP_TEST_SUFFIX); + + private static final IdentifierValidator IDENTIFIER_VALIDATOR = new IdentifierValidator(); + private static final FilenameValidator FILENAME_VALIDATOR = new FilenameValidator(); + + private static Key[] getAllKeys() { + return new Key[] { + KEY_CONSTANT_CAPITALIZATION, + KEY_CONSTANT_WORD_DELIMITER, + KEY_CONSTANT_PREFIX, + KEY_CONSTANT_SUFFIX, + KEY_FIELD_CAPITALIZATION, + KEY_FIELD_WORD_DELIMITER, + KEY_FIELD_PREFIX, + KEY_FIELD_SUFFIX, + KEY_GETTER_CAPITALIZATION, + KEY_GETTER_WORD_DELIMITER, + KEY_GETTER_PREFIX, + KEY_GETTER_PREFIX_FOR_BOOLEAN, + KEY_GETTER_SUFFIX, + KEY_SETTER_CAPITALIZATION, + KEY_SETTER_WORD_DELIMITER, + KEY_SETTER_PREFIX, + KEY_SETTER_SUFFIX, + KEY_CPP_SOURCE_CAPITALIZATION, + KEY_CPP_SOURCE_WORD_DELIMITER, + KEY_CPP_SOURCE_PREFIX, + KEY_CPP_SOURCE_SUFFIX, + KEY_CPP_HEADER_CAPITALIZATION, + KEY_CPP_HEADER_WORD_DELIMITER, + KEY_CPP_HEADER_PREFIX, + KEY_CPP_HEADER_SUFFIX, + KEY_CPP_TEST_CAPITALIZATION, + KEY_CPP_TEST_WORD_DELIMITER, + KEY_CPP_TEST_PREFIX, + KEY_CPP_TEST_SUFFIX, + }; + } + + private final Category[] rootCategories; + private TreeListDialogField categoryTree; + private PixelConverter pixelConverter; + private StackLayout editorAreaStack; + private Category selectedCategory; + + public NameStyleBlock(IStatusChangeListener context, IProject project, + IWorkbenchPreferenceContainer container) { + super(context, project, getAllKeys(), container); + rootCategories = createCategories(); + } + + private static Category[] createCategories() { + Category codeCategory = new Category(PreferencesMessages.NameStyleBlock_code_node); +// new Category(PreferencesMessages.NameStyleBlock_constant_node, +// PreferencesMessages.NameStyleBlock_constant_node_description, EXAMPLE_CONSTANT_NAME, +// null) +// .setCapitalizationKey(KEY_CONSTANT_CAPITALIZATION) +// .setWordDelimiterKey(KEY_CONSTANT_WORD_DELIMITER) +// .setPrefixKey(KEY_CONSTANT_PREFIX) +// .setSuffixKey(KEY_CONSTANT_SUFFIX) +// .setNameValidator(IDENTIFIER_VALIDATOR); + // TODO(sprigogin): Unhide the field name style category + Category fieldCategory = new Category(PreferencesMessages.NameStyleBlock_field_node, + PreferencesMessages.NameStyleBlock_field_node_description, EXAMPLE_FIELD_NAME, + null) // Hidden for now. + .setCapitalizationKey(KEY_FIELD_CAPITALIZATION) + .setWordDelimiterKey(KEY_FIELD_WORD_DELIMITER) + .setPrefixKey(KEY_FIELD_PREFIX) + .setSuffixKey(KEY_FIELD_SUFFIX) + .setNameValidator(IDENTIFIER_VALIDATOR); + new Category(PreferencesMessages.NameStyleBlock_getter_node, + PreferencesMessages.NameStyleBlock_getter_node_description, EXAMPLE_FIELD_NAME, + codeCategory) + .setCapitalizationKey(KEY_GETTER_CAPITALIZATION) + .setWordDelimiterKey(KEY_GETTER_WORD_DELIMITER) + .setPrefixKey(KEY_GETTER_PREFIX) + .setAlternativePrefixKey(KEY_GETTER_PREFIX_FOR_BOOLEAN) + .setSuffixKey(KEY_GETTER_SUFFIX) + .setSeedNameGenerator(fieldCategory) + .setNameValidator(IDENTIFIER_VALIDATOR); + new Category(PreferencesMessages.NameStyleBlock_setter_node, + PreferencesMessages.NameStyleBlock_setter_node_description, EXAMPLE_FIELD_NAME, + codeCategory) + .setCapitalizationKey(KEY_SETTER_CAPITALIZATION) + .setWordDelimiterKey(KEY_SETTER_WORD_DELIMITER) + .setPrefixKey(KEY_SETTER_PREFIX) + .setSuffixKey(KEY_SETTER_SUFFIX) + .setSeedNameGenerator(fieldCategory) + .setNameValidator(IDENTIFIER_VALIDATOR); + Category fileCategory = new Category(PreferencesMessages.NameStyleBlock_files_node); + new Category(PreferencesMessages.NameStyleBlock_cpp_source_node, + PreferencesMessages.NameStyleBlock_cpp_source_node_description, EXAMPLE_CLASS_NAME, + fileCategory) + .setCapitalizationKey(KEY_CPP_SOURCE_CAPITALIZATION) + .setWordDelimiterKey(KEY_CPP_SOURCE_WORD_DELIMITER) + .setPrefixKey(KEY_CPP_SOURCE_PREFIX) + .setSuffixKey(KEY_CPP_SOURCE_SUFFIX) + .setNameValidator(FILENAME_VALIDATOR); + new Category(PreferencesMessages.NameStyleBlock_cpp_header_node, + PreferencesMessages.NameStyleBlock_cpp_header_node_description, EXAMPLE_CLASS_NAME, + fileCategory) + .setCapitalizationKey(KEY_CPP_HEADER_CAPITALIZATION) + .setWordDelimiterKey(KEY_CPP_HEADER_WORD_DELIMITER) + .setPrefixKey(KEY_CPP_HEADER_PREFIX) + .setSuffixKey(KEY_CPP_HEADER_SUFFIX) + .setNameValidator(FILENAME_VALIDATOR); + // TODO(sprigogin): Unhide the test name style category + new Category(PreferencesMessages.NameStyleBlock_cpp_test_node, + PreferencesMessages.NameStyleBlock_cpp_test_node_description, EXAMPLE_CLASS_NAME, + null) // Hidden for now. + .setCapitalizationKey(KEY_CPP_TEST_CAPITALIZATION) + .setWordDelimiterKey(KEY_CPP_TEST_WORD_DELIMITER) + .setPrefixKey(KEY_CPP_TEST_PREFIX) + .setSuffixKey(KEY_CPP_TEST_SUFFIX) + .setNameValidator(FILENAME_VALIDATOR); + return new Category[] { codeCategory, fileCategory }; + } + + public void postSetSelection(Object element) { + categoryTree.postSetSelection(new StructuredSelection(element)); + } + + @Override + public boolean hasProjectSpecificOptions(IProject project) { + if (super.hasProjectSpecificOptions(project)) + return true; + + if (project != null) { + return ProjectTemplateStore.hasProjectSpecificTempates(project); + } + return false; + } + + @Override + protected Control createContents(Composite parent) { + pixelConverter = new PixelConverter(parent); + + setShell(parent.getShell()); + + Composite composite = new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + composite.setLayout(layout); + + NameStyleAdapter adapter = new NameStyleAdapter(); + categoryTree = new TreeListDialogField(adapter, null, new NameStyleLabelProvider()); + categoryTree.setDialogFieldListener(adapter); + categoryTree.setLabelText(PreferencesMessages.NameStyleBlock_categories_label); + categoryTree.setViewerComparator(adapter); + + createCategories(); + + for (Category category : rootCategories) { + categoryTree.addElement(category); + } + + Label label = categoryTree.getLabelControl(composite); + GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.verticalAlignment = GridData.BEGINNING; + label.setLayoutData(gd); + + Control tree = categoryTree.getTreeControl(composite); + gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = true; + gd.verticalAlignment = GridData.FILL; + gd.grabExcessVerticalSpace = false; + gd.widthHint = pixelConverter.convertWidthInCharsToPixels(50); + gd.heightHint = pixelConverter.convertHeightInCharsToPixels(12); + tree.setLayoutData(gd); + + createCategoryEditorArea(composite); + + categoryTree.setTreeExpansionLevel(2); + categoryTree.selectFirstElement(); + + updateControls(); + return composite; + } + + private void createCategoryEditorArea(Composite parent) { + Composite editorArea = new Composite(parent, SWT.NONE); + editorArea.setLayoutData(new GridData(GridData.FILL_BOTH)); + editorArea.setFont(parent.getFont()); + editorAreaStack = new StackLayout(); + editorArea.setLayout(editorAreaStack); + for (Category category : rootCategories) { + createCategoryEditor(editorArea, category); + } + } + + private void createCategoryEditor(Composite parent, Category category) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = pixelConverter.convertHeightInCharsToPixels(1); + layout.marginWidth = 0; + composite.setLayout(layout); + composite.setFont(parent.getFont()); + + if (category.isConcrete()) { + Group group = ControlFactory.createGroup(composite, category.description, 1); + + Composite envelope = new Composite(group, SWT.NONE); + layout = new GridLayout(4, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + envelope.setLayout(layout); + + Control control = addComboBox(envelope, PreferencesMessages.NameStyleBlock_capitalization_label, + category.getCapitalizationKey(), CAPITALIZATION_VALUES, + CAPITALIZATION_LABELS, 0); + LayoutUtil.setHorizontalSpan(getLabel(control), 1); + LayoutUtil.setHorizontalSpan(control, 3); + control = addTextField(envelope, PreferencesMessages.NameStyleBlock_word_delimiter_label, + category.getWordDelimiterKey(), 0, pixelConverter.convertWidthInCharsToPixels(10)); + LayoutUtil.setHorizontalSpan(control, 3); + LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); + control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_label, + category.getPrefixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10)); + boolean getter = PreferencesMessages.NameStyleBlock_getter_node.equals(category.name); + LayoutUtil.setHorizontalSpan(control, getter ? 1 : 3); + LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); + if (getter) { + control = addTextField(envelope, PreferencesMessages.NameStyleBlock_prefix_for_boolean_label, + category.getAlternativePrefixKey(), pixelConverter.convertWidthInCharsToPixels(2), + pixelConverter.convertWidthInCharsToPixels(10)); + LayoutUtil.setHorizontalSpan(control, 1); + LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); + } + control = addTextField(envelope, PreferencesMessages.NameStyleBlock_suffix_label, + category.getSuffixKey(), 0, pixelConverter.convertWidthInCharsToPixels(10)); + LayoutUtil.setHorizontalSpan(control, 3); + LayoutUtil.setHorizontalAlignment(control, SWT.BEGINNING); + + ControlFactory.insertSpace(envelope, 4, pixelConverter.convertHeightInCharsToPixels(1)); + ControlFactory.createLabel(envelope, PreferencesMessages.NameStyleBlock_preview_label); + Text previewText = ControlFactory.createTextField(envelope, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); + LayoutUtil.setWidthHint(previewText, pixelConverter.convertWidthInCharsToPixels(35)); + LayoutUtil.setHorizontalSpan(previewText, 3); + category.setPreviewControl(previewText); + } else { + ControlFactory.createLabel(composite, PreferencesMessages.NameStyleBlock_select_concrete_category); + } + category.setEditorArea(composite); + + for (Category child : category.getChildren()) { + createCategoryEditor(parent, child); + } + } + + @Override + protected void updateControls() { + super.updateControls(); + updatePreview(); + } + + private void updateConfigurationBlock(List selection) { + if (selection.size() == 0) + return; + selectedCategory = (Category) selection.get(0); + editorAreaStack.topControl = selectedCategory.getEditorArea(); + editorAreaStack.topControl.getParent().layout(); + updatePreview(); + } + + private void updatePreview() { + Text text = selectedCategory.getPreviewControl(); + if (text != null) { + text.setText(selectedCategory.composeExampleName(this)); + } + } + + @Override + public void performDefaults() { + super.performDefaults(); + + // Refresh + categoryTree.refresh(); + updateConfigurationBlock(categoryTree.getSelectedElements()); + } + + @Override + public boolean performOk() { + return super.performOk(); + } + + @Override + protected void validateSettings(Key changedKey, String oldValue, String newValue) { + StatusInfo status = new StatusInfo(); + if (selectedCategory != null) { + NameValidator validator = selectedCategory.getNameValidator(); + if (changedKey.equals(selectedCategory.getPrefixKey()) || + changedKey.equals(selectedCategory.getAlternativePrefixKey())) { + if (!validator.isValidStart(newValue)) { + status.setError(PreferencesMessages.NameStyleBlock_invalid_prefix); + } + } else if (changedKey.equals(selectedCategory.getWordDelimiterKey())) { + if (!validator.isValidPart(newValue)) { + status.setError(PreferencesMessages.NameStyleBlock_invalid_word_delimiter); + } + } else if (changedKey.equals(selectedCategory.getSuffixKey())) { + if (!validator.isValidPart(newValue)) { + status.setError(PreferencesMessages.NameStyleBlock_invalid_suffix); + } + } + } + updatePreview(); + fContext.statusChanged(status); + } + + /** + * Represents a category of settings. + */ + private final static class Category { + public final String name; + public final String description; + public final Category parent; + public final int index; // Index in the siblings list + private final List children; + private Key capitalizationKey; + private Key wordDelimiterKey; + private Key prefixKey; + private Key alternativePrefixKey; + private Key suffixKey; + private String seedName; + private Category seedNameGenerator; + private NameValidator nameValidator; + + private Text previewText; + private Composite editorArea; + + Category(String name, String description, String seedName, Category parent) { + this.name = name; + this.description = description; + this.seedName = seedName; + this.parent = parent; + children = new ArrayList(); + index = parent != null ? parent.addChild(this) : 0; + } + + /** + * @param name Category name + */ + Category(String name) { + this(name, null, null, null); + } + + private int addChild(Category category) { + children.add(category); + return children.size() - 1; + } + + Category[] getChildren() { + return children.toArray(new Category[children.size()]); + } + + boolean hasChildren() { + return !children.isEmpty(); + } + + @Override + public String toString() { + return name; + } + + Key getCapitalizationKey() { + return capitalizationKey; + } + + Category setCapitalizationKey(Key capitalizationKey) { + this.capitalizationKey = capitalizationKey; + return this; + } + + Key getWordDelimiterKey() { + return wordDelimiterKey; + } + + Category setWordDelimiterKey(Key wordDelimiterKey) { + this.wordDelimiterKey = wordDelimiterKey; + return this; + } + + Key getPrefixKey() { + return prefixKey; + } + + Category setPrefixKey(Key prefixKey) { + this.prefixKey = prefixKey; + return this; + } + + Key getAlternativePrefixKey() { + return alternativePrefixKey; + } + + Category setAlternativePrefixKey(Key alternativePrefixKey) { + this.alternativePrefixKey = alternativePrefixKey; + return this; + } + + Key getSuffixKey() { + return suffixKey; + } + + Category setSuffixKey(Key suffixKey) { + this.suffixKey = suffixKey; + return this; + } + + boolean isConcrete() { + return capitalizationKey != null; + } + + Composite getEditorArea() { + return editorArea; + } + + Category setEditorArea(Composite editorArea) { + this.editorArea = editorArea; + return this; + } + + Text getPreviewControl() { + return previewText; + } + + Category setPreviewControl(Text previewText) { + this.previewText = previewText; + return this; + } + + NameValidator getNameValidator() { + return nameValidator; + } + + Category setNameValidator(NameValidator nameValidator) { + this.nameValidator = nameValidator; + return this; + } + + Category setSeedNameGenerator(Category seedNameGenerator) { + this.seedNameGenerator = seedNameGenerator; + return this; + } + + String composeExampleName(NameStyleBlock settings) { + int capitalization = Integer.parseInt(settings.getValue(capitalizationKey)); + String wordDelimiter = settings.getValue(wordDelimiterKey); + String prefix = settings.getValue(prefixKey); + String suffix = settings.getValue(suffixKey); + NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); + String name = seedNameGenerator != null ? + seedNameGenerator.composeExampleName(settings) : seedName; + return composer.compose(name); + } + } + + private abstract static class NameValidator { + boolean isValidStart(String prefix) { + for (int i = 0; i < prefix.length(); i++) { + if (i == 0 ? !isValidStart(prefix.charAt(i)) : !isValidPart(prefix.charAt(i))) + return false; + } + return true; + } + + boolean isValidPart(String part) { + for (int i = 0; i < part.length(); i++) { + if (!isValidPart(part.charAt(i))) + return false; + } + return true; + } + + abstract boolean isValidStart(char ch); + abstract boolean isValidPart(char ch); + } + + private static class IdentifierValidator extends NameValidator { + @Override + boolean isValidStart(char ch) { + return Character.isJavaIdentifierStart(ch); + } + + @Override + boolean isValidPart(char ch) { + return Character.isJavaIdentifierPart(ch); + } + } + + private static class FilenameValidator extends NameValidator { + @Override + boolean isValidStart(char ch) { + return isValidPart(ch); + } + + @Override + boolean isValidPart(char ch) { + return "\\/:*?<>|\" ".indexOf(ch) == -1; //$NON-NLS-1$ + } + } + + private class NameStyleAdapter extends ViewerComparator + implements ITreeListAdapter, IDialogFieldListener { + + public void selectionChanged(TreeListDialogField field) { + updateConfigurationBlock(field.getSelectedElements()); + } + + public void customButtonPressed(TreeListDialogField field, int index) { + } + + public void doubleClicked(TreeListDialogField field) { + } + + public Category[] getChildren(TreeListDialogField field, Object element) { + return ((Category) element).getChildren(); + } + + public Category getParent(TreeListDialogField field, Object element) { + return ((Category) element).parent; + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + return ((Category) element).hasChildren(); + } + + public void dialogFieldChanged(DialogField field) { + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + } + + @Override + public int category(Object element) { + return ((Category) element).index; + } + } + + private static class NameStyleLabelProvider extends LabelProvider { + @Override + public Image getImage(Object element) { + return null; + } + + @Override + public String getText(Object element) { + return ((Category) element).name; + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStylePreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStylePreferencePage.java new file mode 100644 index 00000000000..b501ace9195 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStylePreferencePage.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.preferences; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +import org.eclipse.cdt.ui.CUIPlugin; + +import org.eclipse.cdt.internal.ui.ICHelpContextIds; +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; + +/* + * The preference page for configuring styles of names. + */ +public class NameStylePreferencePage extends PropertyAndPreferencePage { + public static final String PREF_ID= "org.eclipse.cdt.ui.preferences.NameStylePreferencePage"; //$NON-NLS-1$ + public static final String PROP_ID= "org.eclipse.cdt.ui.propertyPages.NameStylePreferencePage"; //$NON-NLS-1$ + + private NameStyleBlock fConfigurationBlock; + + public NameStylePreferencePage() { + setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore()); + // Only used when the page is shown programmatically. + setTitle(PreferencesMessages.NameStylePreferencePage_title); + } + + @Override + public void createControl(Composite parent) { + IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) getContainer(); + fConfigurationBlock= new NameStyleBlock(getNewStatusChangedListener(), + getProject(), container); + + super.createControl(parent); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), + ICHelpContextIds.NAME_STYLE_PREFERENCE_PAGE); + } + + @Override + protected Control createPreferenceContent(Composite composite) { + return fConfigurationBlock.createContents(composite); + } + + @Override + protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) { + super.enableProjectSpecificSettings(useProjectSpecificSettings); + if (fConfigurationBlock != null) { + fConfigurationBlock.useProjectSpecificSettings(useProjectSpecificSettings); + } + } + + @Override + public boolean performOk() { + if (fConfigurationBlock != null) { + return fConfigurationBlock.performOk(); + } + return true; + } + + @Override + protected void performDefaults() { + super.performDefaults(); + if (fConfigurationBlock != null) { + fConfigurationBlock.performDefaults(); + } + } + + @Override + public void dispose() { + if (fConfigurationBlock != null) { + fConfigurationBlock.dispose(); + } + super.dispose(); + } + + public void statusChanged(IStatus status) { + setValid(!status.matches(IStatus.ERROR)); + StatusUtil.applyToStatusLine(this, status); + } + + @Override + public void performApply() { + if (fConfigurationBlock != null) { + fConfigurationBlock.performApply(); + } + } + + @Override + protected boolean hasProjectSpecificOptions(IProject project) { + return fConfigurationBlock.hasProjectSpecificOptions(project); + } + + @Override + protected String getPreferencePageID() { + return PREF_ID; + } + + @Override + protected String getPropertyPageID() { + return null; + // TODO(sprigogin): Project specific settings +// return PROP_ID; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java index bd3d4450434..9bec48d4428 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OptionsConfigurationBlock.java @@ -181,7 +181,8 @@ public abstract class OptionsConfigurationBlock { private int fRebuildCount; // used to prevent multiple dialogs that ask for a rebuild - public OptionsConfigurationBlock(IStatusChangeListener context, IProject project, Key[] allKeys, IWorkbenchPreferenceContainer container) { + public OptionsConfigurationBlock(IStatusChangeListener context, IProject project, Key[] allKeys, + IWorkbenchPreferenceContainer container) { fContext= context; fProject= project; fAllKeys= allKeys; @@ -336,7 +337,8 @@ public abstract class OptionsConfigurationBlock { return checkBox; } - protected Button addCheckBoxWithLink(Composite parent, String label, Key key, String[] values, int indent, int widthHint, SelectionListener listener) { + protected Button addCheckBoxWithLink(Composite parent, String label, Key key, String[] values, + int indent, int widthHint, SelectionListener listener) { ControlData data= new ControlData(key, values); GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false); @@ -378,8 +380,9 @@ public abstract class OptionsConfigurationBlock { return checkBox; } - protected Combo addComboBox(Composite parent, String label, Key key, String[] values, String[] valueLabels, int indent) { - GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1); + protected Combo addComboBox(Composite parent, String label, Key key, String[] values, + String[] valueLabels, int indent) { + GridData gd= new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1); gd.horizontalIndent= indent; Label labelControl= new Label(parent, SWT.LEFT); @@ -395,7 +398,8 @@ public abstract class OptionsConfigurationBlock { return comboBox; } - protected Combo addInversedComboBox(Composite parent, String label, Key key, String[] values, String[] valueLabels, int indent) { + protected Combo addInversedComboBox(Composite parent, String label, Key key, String[] values, + String[] valueLabels, int indent) { GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= indent; gd.horizontalSpan= 3; @@ -439,30 +443,37 @@ public abstract class OptionsConfigurationBlock { } protected Text addTextField(Composite parent, String label, Key key, int indent, int widthHint) { + return addTextField(parent, label, key, indent, widthHint, SWT.NONE); + } + + protected Text addTextField(Composite parent, String label, Key key, int indent, int widthHint, + int extraStyle) { Label labelControl= new Label(parent, SWT.WRAP); labelControl.setText(label); labelControl.setFont(JFaceResources.getDialogFont()); - labelControl.setLayoutData(new GridData()); + GridData data= new GridData(); + data.horizontalIndent= indent; + labelControl.setLayoutData(data); - Text textBox= new Text(parent, SWT.BORDER | SWT.SINGLE); + Text textBox= new Text(parent, SWT.BORDER | SWT.SINGLE | extraStyle); textBox.setData(key); - textBox.setLayoutData(new GridData()); makeScrollableCompositeAware(textBox); fLabels.put(textBox, labelControl); - String currValue= getValue(key); - if (currValue != null) { - textBox.setText(currValue); + if (key != null) { + String currValue= getValue(key); + if (currValue != null) { + textBox.setText(currValue); + } + textBox.addModifyListener(getTextModifyListener()); } - textBox.addModifyListener(getTextModifyListener()); - GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL); + data= new GridData(GridData.HORIZONTAL_ALIGN_FILL); if (widthHint != 0) { data.widthHint= widthHint; } - data.horizontalIndent= indent; data.horizontalSpan= 2; textBox.setLayoutData(data); @@ -570,9 +581,9 @@ public abstract class OptionsConfigurationBlock { ControlData data= (ControlData) widget.getData(); String newValue= null; if (widget instanceof Button) { - newValue= data.getValue(((Button)widget).getSelection()); + newValue= data.getValue(((Button) widget).getSelection()); } else if (widget instanceof Combo) { - newValue= data.getValue(((Combo)widget).getSelectionIndex()); + newValue= data.getValue(((Combo) widget).getSelectionIndex()); } else { return; } @@ -582,9 +593,11 @@ public abstract class OptionsConfigurationBlock { protected void textChanged(Text textControl) { Key key= (Key) textControl.getData(); - String number= textControl.getText(); - String oldValue= setValue(key, number); - validateSettings(key, oldValue, number); + if (key != null) { + String newValue= textControl.getText(); + String oldValue= setValue(key, newValue); + validateSettings(key, oldValue, newValue); + } } protected boolean checkValue(Key key, String value) { @@ -631,7 +644,6 @@ public abstract class OptionsConfigurationBlock { */ protected abstract void validateSettings(Key changedKey, String oldValue, String newValue); - protected String[] getTokens(String text, String separator) { StringTokenizer tok= new StringTokenizer(text, separator); int nTokens= tok.countTokens(); @@ -815,10 +827,11 @@ public abstract class OptionsConfigurationBlock { protected void updateText(Text curr) { Key key= (Key) curr.getData(); - - String currValue= getValue(key); - if (currValue != null) { - curr.setText(currValue); + if (key != null) { + String currValue= getValue(key); + if (currValue != null) { + curr.setText(currValue); + } } } @@ -871,6 +884,10 @@ public abstract class OptionsConfigurationBlock { return null; } + protected Control getLabel(Control control) { + return fLabels.get(control); + } + protected void setComboEnabled(Key key, boolean enabled) { Combo combo= getComboBox(key); Label label= fLabels.get(combo); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java index 66d55bc62a7..13cd389f659 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java @@ -20,13 +20,6 @@ package org.eclipse.cdt.internal.ui.preferences; import org.eclipse.osgi.util.NLS; public final class PreferencesMessages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.preferences.PreferencesMessages";//$NON-NLS-1$ - - private PreferencesMessages() { - // Do not instantiate - } - public static String CodeAssistAdvancedConfigurationBlock_default_table_category_column_title; public static String CodeAssistAdvancedConfigurationBlock_default_table_description; public static String CodeAssistAdvancedConfigurationBlock_default_table_keybinding_column_title; @@ -377,6 +370,40 @@ public final class PreferencesMessages extends NLS { public static String CodeTemplateBlock_export_error_hidden; public static String CodeTemplateBlock_export_error_canNotWrite; + public static String NameStylePreferencePage_title; + public static String NameStyleBlock_code_node; + public static String NameStyleBlock_files_node; + public static String NameStyleBlock_constant_node; + public static String NameStyleBlock_constant_node_description; + public static String NameStyleBlock_field_node; + public static String NameStyleBlock_field_node_description; + public static String NameStyleBlock_getter_node; + public static String NameStyleBlock_getter_node_description; + public static String NameStyleBlock_setter_node; + public static String NameStyleBlock_setter_node_description; + public static String NameStyleBlock_cpp_source_node; + public static String NameStyleBlock_cpp_source_node_description; + public static String NameStyleBlock_cpp_header_node; + public static String NameStyleBlock_cpp_header_node_description; + public static String NameStyleBlock_cpp_test_node; + public static String NameStyleBlock_cpp_test_node_description; + public static String NameStyleBlock_categories_label; + public static String NameStyleBlock_capitalization_label; + public static String NameStyleBlock_capitalization_original; + public static String NameStyleBlock_capitalization_upper_case; + public static String NameStyleBlock_capitalization_lower_case; + public static String NameStyleBlock_capitalization_camel_case; + public static String NameStyleBlock_capitalization_lower_camel_case; + public static String NameStyleBlock_word_delimiter_label; + public static String NameStyleBlock_prefix_label; + public static String NameStyleBlock_prefix_for_boolean_label; + public static String NameStyleBlock_suffix_label; + public static String NameStyleBlock_preview_label; + public static String NameStyleBlock_select_concrete_category; + public static String NameStyleBlock_invalid_prefix; + public static String NameStyleBlock_invalid_word_delimiter; + public static String NameStyleBlock_invalid_suffix; + public static String EditTemplateDialog_error_noname; public static String EditTemplateDialog_error_invalidName; public static String EditTemplateDialog_title_new; @@ -417,7 +444,11 @@ public final class PreferencesMessages extends NLS { public static String ScalabilityPreferencePage_preferenceOnlyForNewEditors; public static String ScalabilityPreferencePage_contentAssist_autoActivation; + private PreferencesMessages() { + // Do not instantiate + } + static { - NLS.initializeMessages(BUNDLE_NAME, PreferencesMessages.class); + NLS.initializeMessages(PreferencesMessages.class.getName(), PreferencesMessages.class); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties index 45f2c69d30d..092b51a35ae 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties @@ -432,6 +432,41 @@ CodeTemplateBlock_export_error_title= Export Templates CodeTemplateBlock_export_error_hidden= Export failed.\n{0} is a hidden file. CodeTemplateBlock_export_error_canNotWrite= Export failed.\n{0} cannot be modified. +NameStylePreferencePage_title=Name Style +NameStyleBlock_code_node=Code +NameStyleBlock_files_node=Files +NameStyleBlock_constant_node=Constant +NameStyleBlock_constant_node_description=Constant name +NameStyleBlock_field_node=Class field +NameStyleBlock_field_node_description=Class field name +NameStyleBlock_getter_node=Getter Method +NameStyleBlock_getter_node_description=Getter name based on the field name +NameStyleBlock_setter_node=Setter Method +NameStyleBlock_setter_node_description=Setter name based on the field name +NameStyleBlock_cpp_source_node=C++ Source File +NameStyleBlock_cpp_source_node_description=C++ source file name based on the class name +NameStyleBlock_cpp_header_node=C++ Header File +NameStyleBlock_cpp_header_node_description=C++ header file name based on the class name +NameStyleBlock_cpp_test_node=C++ Test File +NameStyleBlock_cpp_test_node_description=C++ test file name based on the class name +NameStyleBlock_categories_label=Name &Categories: +NameStyleBlock_capitalization_label=C&apitalization: +NameStyleBlock_capitalization_original=Original +NameStyleBlock_capitalization_upper_case=Upper Case +NameStyleBlock_capitalization_lower_case=Lower Case +NameStyleBlock_capitalization_camel_case=Camel Case +NameStyleBlock_capitalization_lower_camel_case=Lower Camel Case +NameStyleBlock_word_delimiter_label=Word &Delimiter: +NameStyleBlock_prefix_label=&Prefix: +NameStyleBlock_prefix_for_boolean_label=For &Boolean: +NameStyleBlock_suffix_label=&Suffix: +NameStyleBlock_preview_label=Pre&view: +NameStyleBlock_select_concrete_category=Select a specific name category +NameStyleBlock_invalid_prefix=Invalid prefix +NameStyleBlock_invalid_word_delimiter=Invalid word delimiter +NameStyleBlock_invalid_suffix=Invalid suffix + + # edit template dialog EditTemplateDialog_error_noname=Template name cannot be empty. EditTemplateDialog_error_invalidName=Template name contains invalid characters. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java index 1ff242c4da8..b8f7de5d12f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; @@ -37,43 +38,40 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; -import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; - public class FunctionFactory { - public static IASTFunctionDefinition createGetterDefinition(String varName, + public static IASTFunctionDefinition createGetterDefinition(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) { IASTFunctionDefinition getter = new CPPASTFunctionDefinition(); getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations)); - IASTDeclarator getterDeclarator = getGetterDeclarator(varName, fieldDeclaration, name); + IASTDeclarator getterDeclarator = getGetterDeclarator(fieldName, fieldDeclaration, name); // IASTFunctionDefinition. expects the outermost IASTFunctionDeclarator in declarator hierarchy while (!(getterDeclarator instanceof IASTFunctionDeclarator)) { getterDeclarator = getterDeclarator.getNestedDeclarator(); } getter.setDeclarator((IASTFunctionDeclarator) getterDeclarator); - getter.setBody(getGetterBody(varName)); + getter.setBody(getGetterBody(fieldName)); return getter; } - private static CPPASTCompoundStatement getGetterBody(String varName) { + private static CPPASTCompoundStatement getGetterBody(IASTName fieldName) { CPPASTCompoundStatement compound = new CPPASTCompoundStatement(); CPPASTReturnStatement returnStatement = new CPPASTReturnStatement(); CPPASTIdExpression idExpr = new CPPASTIdExpression(); CPPASTName returnVal = new CPPASTName(); - returnVal.setName(varName.toCharArray()); + returnVal.setName(fieldName.toCharArray()); idExpr.setName(returnVal); returnStatement.setReturnValue(idExpr); compound.addStatement(returnStatement); return compound; } - private static IASTDeclarator getGetterDeclarator(String varName, + private static IASTDeclarator getGetterDeclarator(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) { CPPASTName getterName = new CPPASTName(); - String varPartOfGetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName)); - getterName.setName("get".concat(varPartOfGetterName).toCharArray()); //$NON-NLS-1$ - + getterName.setName(GetterSetterNameGenerator.generateGetterName(fieldName).toCharArray()); + // copy declarator hierarchy IASTDeclarator topDeclarator = fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations); @@ -106,12 +104,12 @@ public class FunctionFactory { return topDeclarator; } } - - public static IASTFunctionDefinition createSetterDefinition(String varName, + + public static IASTFunctionDefinition createSetterDefinition(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) { IASTFunctionDefinition setter = new CPPASTFunctionDefinition(); setter.setDeclSpecifier(getVoidDeclSpec()); - setter.setDeclarator(getSetterDeclarator(varName, fieldDeclaration, name)); + setter.setDeclarator(getSetterDeclarator(fieldName, fieldDeclaration, name)); setter.setBody(getSetterBody(fieldDeclaration)); return setter; } @@ -141,11 +139,10 @@ public class FunctionFactory { return compound; } - private static CPPASTFunctionDeclarator getSetterDeclarator(String varName, + private static CPPASTFunctionDeclarator getSetterDeclarator(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) { CPPASTName setterName = new CPPASTName(); - String varPartOfSetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName)); - setterName.setName("set".concat(varPartOfSetterName).toCharArray()); //$NON-NLS-1$ + setterName.setName(GetterSetterNameGenerator.generateSetterName(fieldName).toCharArray()); CPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator(); if (name != null) { name.addName(setterName); @@ -167,20 +164,19 @@ public class FunctionFactory { return declSpecifier; } - public static IASTSimpleDeclaration createGetterDeclaration(String name, + public static IASTSimpleDeclaration createGetterDeclaration(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration) { IASTSimpleDeclaration getter = new CPPASTSimpleDeclaration(); getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations)); - getter.addDeclarator(getGetterDeclarator(name, fieldDeclaration, null)); - + getter.addDeclarator(getGetterDeclarator(fieldName, fieldDeclaration, null)); return getter; } - public static IASTSimpleDeclaration createSetterDeclaration(String name, + public static IASTSimpleDeclaration createSetterDeclaration(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration) { IASTSimpleDeclaration setter = new CPPASTSimpleDeclaration(); setter.setDeclSpecifier(getVoidDeclSpec()); - setter.addDeclarator(getSetterDeclarator(name, fieldDeclaration, null)); + setter.addDeclarator(getSetterDeclarator(fieldName, fieldDeclaration, null)); return setter; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java index b77eb647755..48624481448 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java @@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterAndSetterContext.FieldWrapper; -import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.Type; +import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind; public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { private GetterAndSetterContext context; @@ -115,7 +115,7 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { selectGetter.addSelectionListener(new SelectionAdapter(){ @Override public void widgetSelected(SelectionEvent e) { - selectMethods(Type.getter); + selectMethods(AccessorKind.GETTER); } }); @@ -124,14 +124,14 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { selectSetter.addSelectionListener(new SelectionAdapter(){ @Override public void widgetSelected(SelectionEvent e) { - selectMethods(Type.setter); + selectMethods(AccessorKind.SETTER); } }); return btComp; } - private void selectMethods(Type type) { + private void selectMethods(AccessorKind type) { Object[] items = context.getElements(null); Set checked = context.selectedFunctions; for (Object treeItem : items) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterAndSetterContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterAndSetterContext.java index 780c6a3b746..7888123c7f3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterAndSetterContext.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterAndSetterContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; @@ -23,8 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.Type; -import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; +import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind; public class GetterAndSetterContext implements ITreeContentProvider { public ArrayList existingFields = new ArrayList(); @@ -54,13 +54,13 @@ public class GetterAndSetterContext implements ITreeContentProvider { } public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) { - String varName = getFieldDeclarationName(simpleDeclaration).toString(); - return new GetterSetterInsertEditProvider(varName, simpleDeclaration, Type.getter); + IASTName fieldName = getFieldDeclarationName(simpleDeclaration); + return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.GETTER); } public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) { - String varName = getFieldDeclarationName(simpleDeclaration).toString(); - return new GetterSetterInsertEditProvider(varName, simpleDeclaration, Type.setter); + IASTName fieldName = getFieldDeclarationName(simpleDeclaration); + return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.SETTER); } public Object getParent(Object element) { @@ -111,10 +111,8 @@ public class GetterAndSetterContext implements ITreeContentProvider { private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) { FunctionWrapper wrapper = new FunctionWrapper(); - String trimmedName = NameHelper.trimFieldName(getFieldDeclarationName(currentField).toString()); - String getterName = "get" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$ - - setFunctionToWrapper(wrapper, getterName); + String name = GetterSetterNameGenerator.generateGetterName(getFieldDeclarationName(currentField)); + setFunctionToWrapper(wrapper, name); return wrapper; } @@ -128,10 +126,8 @@ public class GetterAndSetterContext implements ITreeContentProvider { private FunctionWrapper getSetterForField(IASTSimpleDeclaration currentField) { FunctionWrapper wrapper = new FunctionWrapper(); - String trimmedName = NameHelper.trimFieldName(getFieldDeclarationName(currentField).toString()); - String setterName = "set" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$ - - setFunctionToWrapper(wrapper, setterName); + String name = GetterSetterNameGenerator.generateSetterName(getFieldDeclarationName(currentField)); + setFunctionToWrapper(wrapper, name); return wrapper; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java index d0b76f23f35..7a17d6604b1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,12 +8,14 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -22,28 +24,29 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName; public class GetterSetterInsertEditProvider implements Comparable { - public enum Type { - getter, - setter; + public enum AccessorKind { + GETTER, + SETTER; } private IASTSimpleDeclaration functionDeclaration; - private Type type; - private String name; + private AccessorKind kind; + private IASTName fieldName; private IASTSimpleDeclaration fieldDeclaration; - public GetterSetterInsertEditProvider(String name, IASTSimpleDeclaration fieldDeclaration, Type type) { - switch (type) { - case getter: - this.functionDeclaration = FunctionFactory.createGetterDeclaration(name, fieldDeclaration); + public GetterSetterInsertEditProvider(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration, + AccessorKind kind) { + switch (kind) { + case GETTER: + this.functionDeclaration = FunctionFactory.createGetterDeclaration(fieldName, fieldDeclaration); break; - case setter: - this.functionDeclaration = FunctionFactory.createSetterDeclaration(name, fieldDeclaration); + case SETTER: + this.functionDeclaration = FunctionFactory.createSetterDeclaration(fieldName, fieldDeclaration); break; } - this.type = type; - this.name = name; + this.kind = kind; + this.fieldName = fieldName; this.fieldDeclaration = fieldDeclaration; } @@ -65,12 +68,12 @@ public class GetterSetterInsertEditProvider implements Comparable= start && !Character.isLetterOrDigit(fieldName.charAt(pos))) { + } + lastWordEnd = pos + 1; + if (firstWordStart < 0) { + firstWordStart = start; + firstWordEnd = lastWordEnd; + } else if (secondWordStart < 0) { + secondWordStart = start; + } + } + } + // Skip the first word if it consists of a single letter and the name contains more than + // one word. + if (firstWordStart >= 0 && firstWordStart + 1 == firstWordEnd && secondWordStart >= 0) { + firstWordStart = secondWordStart; + } + if (firstWordStart < 0) { + return fieldName; + } else { + return fieldName.substring(firstWordStart, lastWordEnd); + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java index 6b2b3889fb4..a1b0ad6b310 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java @@ -7,10 +7,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.utils; +import java.util.Arrays; import java.util.regex.Pattern; import org.eclipse.core.runtime.CoreException; @@ -35,14 +36,12 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache; * Helps with IASTNames. * * @author Mirko Stocker - * */ public class NameHelper { - private static final String localVariableRegexp = "[a-z_A-Z]\\w*"; //$NON-NLS-1$ + private static final Pattern localVariableRegexp = Pattern.compile("[a-z_A-Z]\\w*"); //$NON-NLS-1$ public static boolean isValidLocalVariableName(String name) { - boolean valid = Pattern.compile(localVariableRegexp).matcher(name).matches(); - return valid; + return localVariableRegexp.matcher(name).matches(); } public static boolean isKeyword(String name) { @@ -54,28 +53,33 @@ public class NameHelper { } /** - * Constructs the fully qualified name from the given parameters. The file and offset parameters are used to determine - * the namespace at the declaration position and the target namespace at the target position. + * Constructs the fully qualified name from the given parameters. The file and offset parameters + * are used to determine the namespace at the declaration position and the target namespace at + * the target position. * * @param declaratorName of the method or function * @param declarationTu translation unit of the method or function declaration * @param insertFileTu translation unit of the file where the implementation is being inserted - * @param selectionOffset the offset in the declarationFile, usually the position or selection of the declaration + * @param selectionOffset the offset in the declarationFile, usually the position or selection + * of the declaration * @param insertLocation * @return the correct name for the target * @throws CoreException */ - public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName, ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu, int insertLocation, RefactoringASTCache astCache) - throws CoreException { + public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName, + ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu, + int insertLocation, RefactoringASTCache astCache) throws CoreException { ICPPASTQualifiedName qname = new CPPASTQualifiedName(); - IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, selectionOffset, astCache).getNames(); - IASTName[] implementationNames = NamespaceHelper.getSurroundingNamespace(insertFileTu, insertLocation, astCache).getNames(); + IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, + selectionOffset, astCache).getNames(); + IASTName[] implementationNames = NamespaceHelper.getSurroundingNamespace(insertFileTu, + insertLocation, astCache).getNames(); for (int i = 0; i < declarationNames.length; i++) { if (i >= implementationNames.length) { qname.addName(declarationNames[i]); - } else if (!String.valueOf(declarationNames[i].toCharArray()).equals(String.valueOf(implementationNames[i].toCharArray()))) { + } else if (!Arrays.equals(declarationNames[i].toCharArray(), implementationNames[i].toCharArray())) { qname.addName(declarationNames[i]); } } @@ -84,63 +88,6 @@ public class NameHelper { return qname; } - /** - * Returns the trimmed field name. Leading and trailing non-letters-digits are trimmed. - * If the first letter-digit is in lower case and the next is in upper case, - * the first letter is trimmed. - * - * @param fieldName Complete, unmodified name of the field to trim - * @return Trimmed field - */ - public static String trimFieldName(String fieldName){ - char[] letters = fieldName.toCharArray(); - int start = 0; - int end = letters.length - 1; - try { - // Trim, non-letters at the beginning - while (!Character.isLetterOrDigit(letters[start]) && start < end) { - ++start; - } - - // If the next character is not a letter or digit, - // look ahead because the first letter might not be needed - if (start + 1 <= end - && !Character.isLetterOrDigit(letters[start + 1])) { - int lookAhead = 1; - while (start + lookAhead <= end) { - // Only change the start if something is found after the non-letters - if (Character.isLetterOrDigit(letters[start + lookAhead])) { - start += lookAhead; - break; - } - lookAhead++; - } - - } - // Sometimes, a one letter lower case prefix is used to add some info - // Example: mMyMember, sMyStatic - // Trim the first letter - else if (!Character.isUpperCase(letters[start]) && start + 1 <= end && Character.isUpperCase(letters[start + 1])) { - start++; - } - - // Trim, non-letters at the end - while ((!Character.isLetter(letters[end]) && !Character.isDigit(letters[end])) && start < end) { - --end; - } - } catch (IndexOutOfBoundsException e) { - } - - return new String(letters, start, end - start + 1); - } - - public static String makeFirstCharUpper(String name) { - if (Character.isLowerCase(name.charAt(0))){ - name = Character.toUpperCase(name.charAt(0)) + name.substring(1); - } - return name; - } - public static String getTypeName(IASTParameterDeclaration parameter) { IASTName name = parameter.getDeclarator().getName(); IBinding binding = name.resolveBinding(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java new file mode 100644 index 00000000000..133d216cdbe --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2011 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.util; + +import java.util.ArrayList; +import java.util.List; + +import com.ibm.icu.text.BreakIterator; + +import org.eclipse.cdt.ui.PreferenceConstants; + +import org.eclipse.cdt.internal.ui.text.CBreakIterator; + +/** + * Composes names according to a particular style. A seed name is split into + * words at non-alphanumeric characters and camel case boundaries. The resulting + * words are capitalized according to the given capitalization style, joined + * using the given delimiter and combined with the given prefix and suffix. + */ +public class NameComposer { + private static final int CAPITALIZATION_ORIGINAL = PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL; + private static final int CAPITALIZATION_UPPER_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_UPPER_CASE; + private static final int CAPITALIZATION_LOWER_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CASE; + private static final int CAPITALIZATION_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE; + private static final int CAPITALIZATION_LOWER_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE; + + private final int capitalization; + private final String wordDelimiter; + private final String prefix; + private final String suffix; + + /** + * Creates a name composer for a given style. + * + * @param capitalization capitalization transformation applied to name. Possible values:
    + *
  • PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL,
  • + *
  • PreferenceConstants.NAME_STYLE_CAPITALIZATION_UPPER_CASE,
  • + *
  • PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CASE,
  • + *
  • PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE,
  • + *
  • PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE.
  • + *
+ * @param wordDelimiter delimiter inserted between words + * @param prefix prefix prepended to the name + * @param suffix suffix appended to the name + */ + public NameComposer(int capitalization, String wordDelimiter, String prefix, String suffix) { + this.capitalization = capitalization; + this.wordDelimiter = wordDelimiter; + this.prefix = prefix; + this.suffix = suffix; + } + + /** + * Composes a name according to the composer's style based on a seed name. + * + * @param seedName the name used as an inspiration + * @return the composed name + */ + public String compose(String seedName) { + List words = splitIntoWords(seedName); + return compose(words); + } + + /** + * Composes a name according to the composer's style based on a seed words. + * + * @param words the words that that should be combined to form the name + * @return the composed name + */ + public String compose(List words) { + StringBuilder buf = new StringBuilder(); + buf.append(prefix); + for (int i = 0; i < words.size(); i++) { + if (i > 0) { + buf.append(wordDelimiter); + } + CharSequence word = words.get(i); + switch (capitalization) { + case CAPITALIZATION_ORIGINAL: + buf.append(word); + break; + case CAPITALIZATION_UPPER_CASE: + appendUpperCase(buf, word); + break; + case CAPITALIZATION_LOWER_CASE: + appendLowerCase(buf, word); + break; + case CAPITALIZATION_CAMEL_CASE: + appendTitleCase(buf, word); + break; + case CAPITALIZATION_LOWER_CAMEL_CASE: + if (i == 0) { + appendLowerCase(buf, word); + } else { + appendTitleCase(buf, word); + } + break; + } + } + buf.append(suffix); + return buf.toString(); + } + + /** + * Splits a name into words at non-alphanumeric characters and camel case boundaries. + */ + public List splitIntoWords(CharSequence name) { + List words = new ArrayList(); + CBreakIterator iterator = new CBreakIterator(); + iterator.setText(name); + int end; + for (int start = iterator.first(); (end = iterator.next()) != BreakIterator.DONE; start = end) { + if (Character.isLetterOrDigit(name.charAt(start))) { + int pos = end; + while (--pos >= start && !Character.isLetterOrDigit(name.charAt(pos))) { + } + words.add(name.subSequence(start, pos + 1)); + } + } + return words; + } + + private void appendUpperCase(StringBuilder buf, CharSequence word) { + for (int i = 0; i < word.length(); i++) { + buf.append(Character.toUpperCase(word.charAt(i))); + } + } + + private void appendLowerCase(StringBuilder buf, CharSequence word) { + for (int i = 0; i < word.length(); i++) { + buf.append(Character.toLowerCase(word.charAt(i))); + } + } + + private void appendTitleCase(StringBuilder buf, CharSequence word) { + for (int i = 0; i < word.length(); i++) { + buf.append(i == 0 ? + Character.toUpperCase(word.charAt(i)) : Character.toLowerCase(word.charAt(i))); + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java index c0589297fed..3beb305e7df 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java @@ -63,7 +63,6 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider; -import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator; public class NewClassWizardUtil { @@ -257,28 +256,6 @@ public class NewClassWizardUtil { return null; } - /** - * Creates a header file name from the given class name. This is the file name - * to be used when the class is created. eg. "MyClass" -> "MyClass.h" - * - * @param className the class name - * @return the header file name for the given class - */ - public static String createHeaderFileName(String className) { - return NewSourceFileGenerator.generateHeaderFileNameFromClass(className); - } - - /** - * Creates a source file name from the given class name. This is the file name - * to be used when the class is created. eg. "MyClass" -> "MyClass.cpp" - * - * @param className the class name - * @return the source file name for the given class - */ - public static String createSourceFileName(String className) { - return NewSourceFileGenerator.generateSourceFileNameFromClass(className); - } - /** * Returns the workspace root. * @@ -289,7 +266,7 @@ public class NewClassWizardUtil { } /** - * Resolve the location of the given class. + * Resolves the location of the given class. * * @param type the class to resolve * @param context the runnable context diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LayoutUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LayoutUtil.java index 3c3ddda0f6c..e5e9c73eca5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LayoutUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LayoutUtil.java @@ -16,6 +16,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Layout; public class LayoutUtil { @@ -23,11 +24,20 @@ public class LayoutUtil { * Calculates the number of columns needed by field editors */ public static int getNumberOfColumns(DialogField[] editors) { - int nCulumns= 0; + int nColumns= 0; for (int i= 0; i < editors.length; i++) { - nCulumns= Math.max(editors[i].getNumberOfControls(), nCulumns); + nColumns= Math.max(editors[i].getNumberOfControls(), nColumns); } - return nCulumns; + return nColumns; + } + + /** + * Returns the number of columns in the layout of a composite, + * or 1 if the composite doesn't have a grid layout. + */ + public static int getNumberOfColumns(Composite composite) { + Layout layout = composite.getLayout(); + return layout instanceof GridLayout ? ((GridLayout) layout).numColumns : 1; } /** @@ -44,7 +54,8 @@ public class LayoutUtil { * @param minWidth The minimal width of the composite * @param minHeight The minimal height of the composite */ - public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int minWidth, int minHeight) { + public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, + int minWidth, int minHeight) { doDefaultLayout(parent, editors, labelOnTop, minWidth, minHeight, 0, 0); } @@ -55,10 +66,9 @@ public class LayoutUtil { * @param minHeight The minimal height of the composite * @param marginWidth The margin width to be used by the composite * @param marginHeight The margin height to be used by the composite - * @deprecated */ - @Deprecated - public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int minWidth, int minHeight, int marginWidth, int marginHeight) { + private static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, + int minWidth, int minHeight, int marginWidth, int marginHeight) { int nCulumns= getNumberOfColumns(editors); Control[][] controls= new Control[editors.length][]; for (int i= 0; i < editors.length; i++) { @@ -91,7 +101,7 @@ public class LayoutUtil { public static void setHorizontalSpan(Control control, int span) { Object ld= control.getLayoutData(); if (ld instanceof GridData) { - ((GridData)ld).horizontalSpan= span; + ((GridData) ld).horizontalSpan= span; } else if (span != 1) { GridData gd= new GridData(); gd.horizontalSpan= span; @@ -105,7 +115,7 @@ public class LayoutUtil { public static void setWidthHint(Control control, int widthHint) { Object ld= control.getLayoutData(); if (ld instanceof GridData) { - ((GridData)ld).widthHint= widthHint; + ((GridData) ld).widthHint= widthHint; } } @@ -115,7 +125,7 @@ public class LayoutUtil { public static void setHeightHint(Control control, int heigthHint) { Object ld= control.getLayoutData(); if (ld instanceof GridData) { - ((GridData)ld).heightHint= heigthHint; + ((GridData) ld).heightHint= heigthHint; } } @@ -125,18 +135,27 @@ public class LayoutUtil { public static void setHorizontalIndent(Control control, int horizontalIndent) { Object ld= control.getLayoutData(); if (ld instanceof GridData) { - ((GridData)ld).horizontalIndent= horizontalIndent; + ((GridData) ld).horizontalIndent= horizontalIndent; } } /** - * Sets the horizontal indent of a control. Assumes that GridData is used. + * Sets the horizontal alignment of a control. Assumes that GridData is used. + */ + public static void setHorizontalAlignment(Control control, int horizontalAlignment) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData) ld).horizontalAlignment= horizontalAlignment; + } + } + + /** + * Makes a control grab all available horizontal space. Assumes that GridData is used. */ public static void setHorizontalGrabbing(Control control) { Object ld= control.getLayoutData(); if (ld instanceof GridData) { - ((GridData)ld).grabExcessHorizontalSpace= true; + ((GridData) ld).grabExcessHorizontalSpace= true; } - } - + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileGenerator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileGenerator.java index fc60ace62d0..397e6cd86d5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileGenerator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileGenerator.java @@ -15,6 +15,10 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; + +import org.eclipse.cdt.internal.ui.util.NameComposer; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; @@ -23,23 +27,55 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.ui.dialogs.ContainerGenerator; public class NewSourceFileGenerator { - //TODO these should all be configurable in prefs - private static final String HEADER_EXT = ".h"; //$NON-NLS-1$ - private static final String SOURCE_EXT = ".cpp"; //$NON-NLS-1$ - + /** + * Creates a header file name from the given class name. This is the file name + * to be used when the class is created. eg. "MyClass" -> "MyClass.h" + * + * @param className the class name + * @return the header file name for the given class + */ public static String generateHeaderFileNameFromClass(String className) { - //TODO eventually make this a prefs option - filename pattern - return className + HEADER_EXT; + IPreferencesService preferences = Platform.getPreferencesService(); + int capitalization = preferences.getInt(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_HEADER_CAPITALIZATION, + PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL, null); + String wordDelimiter = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_HEADER_WORD_DELIMITER, "", null); //$NON-NLS-1$ + String prefix = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_HEADER_PREFIX, "", null); //$NON-NLS-1$ + String suffix = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_HEADER_SUFFIX, ".h", null); //$NON-NLS-1$ + NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); + return composer.compose(className); } + /** + * Creates a source file name from the given class name. This is the file name + * to be used when the class is created. e.g. "MyClass" -> "MyClass.cpp" + * + * @param className the class name + * @return the source file name for the given class + */ public static String generateSourceFileNameFromClass(String className) { - //TODO eventually make this a prefs option - filename pattern - return className + SOURCE_EXT; + IPreferencesService preferences = Platform.getPreferencesService(); + int capitalization = preferences.getInt(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_SOURCE_CAPITALIZATION, + PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL, null); + String wordDelimiter = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_SOURCE_WORD_DELIMITER, "", null); //$NON-NLS-1$ + String prefix = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_SOURCE_PREFIX, "", null); //$NON-NLS-1$ + String suffix = preferences.getString(CUIPlugin.PLUGIN_ID, + PreferenceConstants.NAME_STYLE_CPP_SOURCE_SUFFIX, ".cpp", null); //$NON-NLS-1$ + NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); + return composer.compose(className); } public static IFile createHeaderFile(IPath filePath, boolean force, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java index d9b15e0333e..de2f6053fd4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java @@ -1507,6 +1507,298 @@ public class PreferenceConstants { * @since 5.2 */ public static final int CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH = 2; + + /** + * A named preference that controls how capitalization of a constant name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CONSTANT_CAPITALIZATION = "nameStyle.constant.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of a constant name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CONSTANT_PREFIX = "nameStyle.constant.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of a constant name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CONSTANT_SUFFIX = "nameStyle.constant.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * of a constant name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CONSTANT_WORD_DELIMITER = "nameStyle.constant.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of a field name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_FIELD_CAPITALIZATION = "nameStyle.field.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of a field name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_FIELD_PREFIX = "nameStyle.field.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of a field name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_FIELD_SUFFIX = "nameStyle.field.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * of a field name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_FIELD_WORD_DELIMITER = "nameStyle.field.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of the getter name + * depends on capitalization of the field name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_GETTER_CAPITALIZATION = "nameStyle.getter.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the getter name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_GETTER_PREFIX = "nameStyle.getter.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the getter name for a boolean field. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_GETTER_PREFIX_FOR_BOOLEAN = "nameStyle.getter.prefixForBoolean"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of the getter name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_GETTER_SUFFIX = "nameStyle.getter.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * when composing the getter name from the field name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_GETTER_WORD_DELIMITER = "nameStyle.getter.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of the setter name + * depends on capitalization of the field name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_SETTER_CAPITALIZATION = "nameStyle.setter.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the setter name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_SETTER_PREFIX = "nameStyle.setter.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of the setter name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_SETTER_SUFFIX = "nameStyle.setter.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * when composing the setter name from the field name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_SETTER_WORD_DELIMITER = "nameStyle.setter.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of the C++ source file name + * depends on capitalization of the class name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_SOURCE_CAPITALIZATION = "nameStyle.cpp.source.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the C++ source file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_SOURCE_PREFIX = "nameStyle.cpp.source.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of the C++ source file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_SOURCE_SUFFIX = "nameStyle.cpp.source.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * when composing the C++ source file name from the class name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_SOURCE_WORD_DELIMITER = "nameStyle.cpp.source.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of the C++ header file name + * depends on capitalization of the class name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_HEADER_CAPITALIZATION = "nameStyle.cpp.header.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the C++ header file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_HEADER_PREFIX = "nameStyle.cpp.header.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of the C++ header file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_HEADER_SUFFIX = "nameStyle.cpp.header.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * when composing the C++ header file name from the class name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_HEADER_WORD_DELIMITER = "nameStyle.cpp.header.wordDelimiter"; //$NON-NLS-1$ + + /** + * A named preference that controls how capitalization of the C++ test file name + * depends on capitalization of the class name. + *

+ * Value is of type Integer. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_TEST_CAPITALIZATION = "nameStyle.cpp.test.capitalization"; //$NON-NLS-1$ + /** + * A named preference that controls prefix of the C++ test file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_TEST_PREFIX = "nameStyle.cpp.test.prefix"; //$NON-NLS-1$ + /** + * A named preference that controls suffix of the C++ test file name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_TEST_SUFFIX = "nameStyle.cpp.test.suffix"; //$NON-NLS-1$ + /** + * A named preference that controls delimiter that is inserted between words + * when composing the C++ test file name from the class name. + *

+ * Value is of type String. + * + * @since 5.3 + */ + public static final String NAME_STYLE_CPP_TEST_WORD_DELIMITER = "nameStyle.cpp.test.wordDelimiter"; //$NON-NLS-1$ + + /** + * The value of NAME_STYLE_*_CAPITALIZATION specifying that the name + * is to be derived from the class or the variable name without changing + * capitalization. + * + * @since 5.3 + */ + public static final int NAME_STYLE_CAPITALIZATION_ORIGINAL = 0; + /** + * The value of NAME_STYLE_*_CAPITALIZATION specifying that the name + * is to be derived from the class or the variable name by converting it to upper + * case. + * + * @since 5.3 + */ + public static final int NAME_STYLE_CAPITALIZATION_UPPER_CASE = 1; + /** + * The value of NAME_STYLE_*_CAPITALIZATION specifying that the name + * is to be derived from the class or the variable name by converting it to lower + * case. + * + * @since 5.3 + */ + public static final int NAME_STYLE_CAPITALIZATION_LOWER_CASE = 2; + /** + * The value of NAME_STYLE_*_CAPITALIZATION specifying that the name + * is to be derived from the class or the variable name by capitalizing first + * letter of every word. + * + * @since 5.3 + */ + public static final int NAME_STYLE_CAPITALIZATION_CAMEL_CASE = 3; + /** + * The value of NAME_STYLE_*_CAPITALIZATION specifying that the name + * is to be derived from the class or the variable name by capitalizing first + * letter of every word except the first one. + * + * @since 5.3 + */ + public static final int NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE = 4; /** * Returns the CDT-UI preference store. @@ -1682,7 +1974,7 @@ public class PreferenceConstants { store.setDefault(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD, 20); store.setDefault(PreferenceConstants.SPELLING_PROBLEMS_THRESHOLD, 100); /* - * XXX: This is currently disabled because the spelling engine + * TODO: This is currently disabled because the spelling engine * cannot return word proposals but only correction proposals. */ store.setToDefault(PreferenceConstants.SPELLING_ENABLE_CONTENTASSIST); @@ -1708,6 +2000,37 @@ public class PreferenceConstants { // Code Templates store.setDefault(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME, CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_NAME); + + // Name Style + store.setDefault(NAME_STYLE_FIELD_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE); + store.setDefault(NAME_STYLE_FIELD_PREFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_FIELD_SUFFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_FIELD_WORD_DELIMITER, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CONSTANT_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_UPPER_CASE); + store.setDefault(NAME_STYLE_CONSTANT_PREFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CONSTANT_SUFFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CONSTANT_WORD_DELIMITER, "_"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_GETTER_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_CAMEL_CASE); + store.setDefault(NAME_STYLE_GETTER_PREFIX, "get"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_GETTER_PREFIX_FOR_BOOLEAN, "is"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_GETTER_SUFFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_GETTER_WORD_DELIMITER, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_SETTER_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_CAMEL_CASE); + store.setDefault(NAME_STYLE_SETTER_PREFIX, "set"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_SETTER_SUFFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_SETTER_WORD_DELIMITER, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_HEADER_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_ORIGINAL); + store.setDefault(NAME_STYLE_CPP_HEADER_PREFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_HEADER_SUFFIX, ".h"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_HEADER_WORD_DELIMITER, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_SOURCE_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_ORIGINAL); + store.setDefault(NAME_STYLE_CPP_SOURCE_PREFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_SOURCE_SUFFIX, ".cpp"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_SOURCE_WORD_DELIMITER, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_TEST_CAPITALIZATION, NAME_STYLE_CAPITALIZATION_ORIGINAL); + store.setDefault(NAME_STYLE_CPP_TEST_PREFIX, ""); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_TEST_SUFFIX, "_test.cpp"); //$NON-NLS-1$ + store.setDefault(NAME_STYLE_CPP_TEST_WORD_DELIMITER, ""); //$NON-NLS-1$ } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java index 48ce730723e..364c948afca 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 QNX Software Systems and others. + * Copyright (c) 2004, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,7 +60,6 @@ import org.eclipse.cdt.core.browser.TypeSearchScope; import org.eclipse.cdt.core.browser.TypeUtil; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; -import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICContainer; @@ -103,9 +102,9 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFie import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator; import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField; +import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator; public class NewClassCreationWizardPage extends NewElementWizardPage { - protected final static String PAGE_NAME = "NewClassWizardPage"; //$NON-NLS-1$ protected static final int MAX_FIELD_CHARS = 50; @@ -141,9 +140,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { protected IStatus fSourceFileStatus; protected final IStatus STATUS_OK = new StatusInfo(); - protected IFile fCreatedSourceFile = null; - protected IFile fCreatedHeaderFile = null; - protected ICElement fCreatedClass = null; + protected IFile fCreatedSourceFile; + protected IFile fCreatedHeaderFile; + protected ICElement fCreatedClass; /** * This flag isFirstTime is used to keep a note @@ -1307,20 +1306,20 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { String sourceName = null; if (folder == null) { - headerName = NewClassWizardUtil.createHeaderFileName(className); - sourceName = NewClassWizardUtil.createSourceFileName(className); + headerName = NewSourceFileGenerator.generateHeaderFileNameFromClass(className); + sourceName = NewSourceFileGenerator.generateSourceFileNameFromClass(className); } else { // make sure the file names are unique String currName = className; int count = 0; String separator = ""; //$NON-NLS-1$ - if (Character.isDigit(className.charAt(className.length()-1))) + if (Character.isDigit(className.charAt(className.length() - 1))) separator = "_"; //$NON-NLS-1$ while (count < MAX_UNIQUE_CLASSNAME) { - String header = NewClassWizardUtil.createHeaderFileName(currName); + String header = NewSourceFileGenerator.generateHeaderFileNameFromClass(currName); IPath path = folder.append(header); if (!path.toFile().exists()) { - String source = NewClassWizardUtil.createSourceFileName(currName); + String source = NewSourceFileGenerator.generateSourceFileNameFromClass(currName); path = folder.append(source); if (!path.toFile().exists()) { headerName = header; diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java index 7ac7822c09f..483bb1d6e26 100644 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java +++ b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/ControlFactory.java @@ -93,7 +93,7 @@ public class ControlFactory { * * @param parent the parent of the new composite * @param color the separator color - * @return preferedThickness - the prefered thickness of separator (or 2 if SWT.DEFAULT) + * @return preferedThickness - the preferred thickness of separator (or 2 if SWT.DEFAULT) */ public static Composite createCompositeSeparator(Composite parent, Color color, int preferedHeight) { Composite separator = createComposite(parent, 1); @@ -206,8 +206,8 @@ public class ControlFactory { * @param style - control style * @return the new label */ - public static Label createLabel(Composite parent, String text, int widthHint, int heightHint, int style) { - + public static Label createLabel(Composite parent, String text, int widthHint, int heightHint, + int style) { Label label = new Label(parent, style); label.setFont(parent.getFont()); label.setText(text); @@ -241,11 +241,11 @@ public class ControlFactory { * @return the new label */ public static Label createBoldLabel(Composite parent, String text) { - Label label = createLabel( parent, text ); + Label label = createLabel(parent, text); FontData[] fd = label.getFont().getFontData(); - fd[0].setStyle( SWT.BOLD ); - Font font = new Font( Display.getCurrent(), fd[0] ); - label.setFont( font ); + fd[0].setStyle(SWT.BOLD); + Font font = new Font(Display.getCurrent(), fd[0]); + label.setFont(font); return label; } @@ -310,7 +310,8 @@ public class ControlFactory { * @param value the string to identify radiobutton * @return the new checkbox */ - public static Button createRadioButton(Composite group, String label, String value, SelectionListener listener) { + public static Button createRadioButton(Composite group, String label, String value, + SelectionListener listener) { Button button = new Button(group, SWT.RADIO | SWT.LEFT); button.setFont(group.getFont()); button.setText(label); @@ -574,7 +575,8 @@ public class ControlFactory { return createSelectCCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); } - public static CCombo createSelectCCombo(Composite parent, String[] strdata, String selData, int style) { + public static CCombo createSelectCCombo(Composite parent, String[] strdata, String selData, + int style) { CCombo combo = new CCombo(parent, style); combo.setFont(parent.getFont()); GridData data = new GridData(GridData.FILL_HORIZONTAL); @@ -657,7 +659,7 @@ public class ControlFactory { int n_sel = combo.indexOf(selData); if (0 > n_sel) { if ((combo.getStyle() & SWT.READ_ONLY) == 0) { - combo.setText( selData ); + combo.setText(selData); return; } n_sel = 0; @@ -668,39 +670,36 @@ public class ControlFactory { /** * Create a dialog shell, child to the top level workbench shell. * - * @return The new Shell useable for a dialog. - * + * @return The new Shell usable for a dialog. */ public static Shell createDialogShell() { - Shell parent = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getShell(); - return new Shell( parent, SWT.DIALOG_TRIM ); + Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + return new Shell(parent, SWT.DIALOG_TRIM); } public static Composite insertSpace(Composite parent, int nSpan, int height) { Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(), (SWT.DEFAULT != height ? height : 5)); - ((GridData)space.getLayoutData()).horizontalSpan = nSpan; + ((GridData) space.getLayoutData()).horizontalSpan = nSpan; return space; } - public static MessageBox createDialog( String title, String message, int style ) { - MessageBox box = new MessageBox( createDialogShell(), style | SWT.APPLICATION_MODAL ); - box.setText( title ); - box.setMessage( message ); + public static MessageBox createDialog(String title, String message, int style) { + MessageBox box = new MessageBox(createDialogShell(), style | SWT.APPLICATION_MODAL); + box.setText(title); + box.setMessage(message); return box; } - public static MessageBox createYesNoDialog( String title, String message ) { - return createDialog( title, message, SWT.YES | SWT.NO | SWT.ICON_QUESTION ); + public static MessageBox createYesNoDialog(String title, String message) { + return createDialog(title, message, SWT.YES | SWT.NO | SWT.ICON_QUESTION); } - public static MessageBox createOkDialog( String title, String message ) { - return createDialog( title, message, SWT.OK | SWT.ICON_INFORMATION ); + public static MessageBox createOkDialog(String title, String message) { + return createDialog(title, message, SWT.OK | SWT.ICON_INFORMATION); } - public static MessageBox createOkCancelDialog( String title, String message ) { - return createDialog( title, message, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION ); + public static MessageBox createOkCancelDialog(String title, String message) { + return createDialog(title, message, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION); } }