mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55:24 +02:00
Bug 273529. Configurable name style for getters setters and file names.
This commit is contained in:
parent
fbcf246a20
commit
ae1e9fa9b4
27 changed files with 1803 additions and 322 deletions
|
@ -592,8 +592,8 @@ int gooo = 1;
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||||
//@.config
|
//@.config
|
||||||
filename=GaS.h
|
filename=GaS.h
|
||||||
getters=i,isOk
|
getters=i,ok
|
||||||
setters=i,isOk
|
setters=i,ok
|
||||||
inHeader=true
|
inHeader=true
|
||||||
//@GaS.cpp
|
//@GaS.cpp
|
||||||
#include "Getters.h"
|
#include "Getters.h"
|
||||||
|
@ -612,8 +612,8 @@ class GaS {
|
||||||
public:
|
public:
|
||||||
GaS();
|
GaS();
|
||||||
virtual ~GaS();
|
virtual ~GaS();
|
||||||
bool /*$*/isOk/*$$*/;
|
bool /*$*/ok/*$$*/;
|
||||||
void methode2();
|
void method2();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int i;
|
int i;
|
||||||
|
@ -629,16 +629,16 @@ class GaS {
|
||||||
public:
|
public:
|
||||||
GaS();
|
GaS();
|
||||||
virtual ~GaS();
|
virtual ~GaS();
|
||||||
bool isOk;
|
bool ok;
|
||||||
void methode2();
|
void method2();
|
||||||
int getI() const
|
int getI() const
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getIsOk() const
|
bool isOk() const
|
||||||
{
|
{
|
||||||
return isOk;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setI(int i)
|
void setI(int i)
|
||||||
|
@ -646,9 +646,9 @@ public:
|
||||||
this->i = i;
|
this->i = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsOk(bool isOk)
|
void setOk(bool ok)
|
||||||
{
|
{
|
||||||
this->isOk = isOk;
|
this->ok = ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,6 @@ import junit.framework.TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Thomas Corbat
|
* @author Thomas Corbat
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class IdentifierHelperTest extends TestSuite {
|
public class IdentifierHelperTest extends TestSuite {
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ public class IdentifierHelperTest extends TestSuite {
|
||||||
suite.addTest(new EmptyCaseTest());
|
suite.addTest(new EmptyCaseTest());
|
||||||
suite.addTest(new IllegalCharCaseTest());
|
suite.addTest(new IllegalCharCaseTest());
|
||||||
suite.addTest(new KeywordCaseTest());
|
suite.addTest(new KeywordCaseTest());
|
||||||
suite.addTestSuite(NameHelperTest.class);
|
suite.addTestSuite(AccessorNameGeneratorTest.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.refactoring.utils;
|
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("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.addTest(RefactoringTester.suite("DefinitionFinderTest", "resources/refactoring/DefinitionFinder.rts")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
suite.addTestSuite(PseudoNameGeneratorTest.class);
|
suite.addTestSuite(PseudoNameGeneratorTest.class);
|
||||||
|
suite.addTestSuite(NameComposerTest.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ CPluginGlobalBuildLogPreferencePage.name=Logging
|
||||||
CPluginFileTypesPreferencePage.name=File Types
|
CPluginFileTypesPreferencePage.name=File Types
|
||||||
CodeFormatterPreferencePage.name=Code Style
|
CodeFormatterPreferencePage.name=Code Style
|
||||||
codeTemplatePreferencePage.name=Code Templates
|
codeTemplatePreferencePage.name=Code Templates
|
||||||
|
nameStylePreferencePage.name=Name Style
|
||||||
CodeAssistPreferencePage.name=Content Assist
|
CodeAssistPreferencePage.name=Content Assist
|
||||||
CodeAssistAdvancedPreferencePage.name=Advanced
|
CodeAssistAdvancedPreferencePage.name=Advanced
|
||||||
SmartTypingPreferencePage.name=Typing
|
SmartTypingPreferencePage.name=Typing
|
||||||
|
@ -548,6 +549,7 @@ workingSetConfigurationsExtensionPoint=Working Set Configurations
|
||||||
preferenceKeywords.common=c cpp cplusplus cdt
|
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.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.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.todo=case sensitive task tag todo xxx fix fixme project comments
|
||||||
preferenceKeywords.indexer=index skip references type macro search build configuration cache memory performance
|
preferenceKeywords.indexer=index skip references type macro search build configuration cache memory performance
|
||||||
|
|
||||||
|
|
|
@ -745,6 +745,14 @@
|
||||||
<keywordReference id="org.eclipse.cdt.ui.codetemplates"/>
|
<keywordReference id="org.eclipse.cdt.ui.codetemplates"/>
|
||||||
<keywordReference id="org.eclipse.cdt.ui.common"/>
|
<keywordReference id="org.eclipse.cdt.ui.common"/>
|
||||||
</page>
|
</page>
|
||||||
|
<page
|
||||||
|
name="%nameStylePreferencePage.name"
|
||||||
|
category="org.eclipse.cdt.ui.preferences.CodeFormatterPreferencePage"
|
||||||
|
class="org.eclipse.cdt.internal.ui.preferences.NameStylePreferencePage"
|
||||||
|
id="org.eclipse.cdt.ui.preferences.NameStylePreferencePage">
|
||||||
|
<keywordReference id="org.eclipse.cdt.ui.namestyle"/>
|
||||||
|
<keywordReference id="org.eclipse.cdt.ui.common"/>
|
||||||
|
</page>
|
||||||
<page
|
<page
|
||||||
name="%markOccurrencesPreferencePage.name"
|
name="%markOccurrencesPreferencePage.name"
|
||||||
category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
|
category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
|
||||||
|
@ -795,6 +803,9 @@
|
||||||
<keyword
|
<keyword
|
||||||
label="%preferenceKeywords.codetemplates"
|
label="%preferenceKeywords.codetemplates"
|
||||||
id="org.eclipse.cdt.ui.codetemplates"/>
|
id="org.eclipse.cdt.ui.codetemplates"/>
|
||||||
|
<keyword
|
||||||
|
label="%preferenceKeywords.namestyle"
|
||||||
|
id="org.eclipse.cdt.ui.namestyle"/>
|
||||||
<keyword
|
<keyword
|
||||||
label="%preferenceKeywords.todo"
|
label="%preferenceKeywords.todo"
|
||||||
id="org.eclipse.cdt.ui.todo"/>
|
id="org.eclipse.cdt.ui.todo"/>
|
||||||
|
|
|
@ -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 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 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 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
|
// Console view
|
||||||
public static final String CLEAR_CONSOLE_ACTION = PREFIX + "clear_console_action_context"; //$NON-NLS-1$
|
public static final String CLEAR_CONSOLE_ACTION = PREFIX + "clear_console_action_context"; //$NON-NLS-1$
|
||||||
|
|
|
@ -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<Category> 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<Category>(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<Object> 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<Category> 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<Category>();
|
||||||
|
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<Category>, IDialogFieldListener {
|
||||||
|
|
||||||
|
public void selectionChanged(TreeListDialogField<Category> field) {
|
||||||
|
updateConfigurationBlock(field.getSelectedElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void customButtonPressed(TreeListDialogField<Category> field, int index) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doubleClicked(TreeListDialogField<Category> field) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category[] getChildren(TreeListDialogField<Category> field, Object element) {
|
||||||
|
return ((Category) element).getChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category getParent(TreeListDialogField<Category> field, Object element) {
|
||||||
|
return ((Category) element).parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasChildren(TreeListDialogField<Category> field, Object element) {
|
||||||
|
return ((Category) element).hasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dialogFieldChanged(DialogField field) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(TreeListDialogField<Category> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -181,7 +181,8 @@ public abstract class OptionsConfigurationBlock {
|
||||||
|
|
||||||
private int fRebuildCount; // used to prevent multiple dialogs that ask for a rebuild
|
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;
|
fContext= context;
|
||||||
fProject= project;
|
fProject= project;
|
||||||
fAllKeys= allKeys;
|
fAllKeys= allKeys;
|
||||||
|
@ -336,7 +337,8 @@ public abstract class OptionsConfigurationBlock {
|
||||||
return checkBox;
|
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);
|
ControlData data= new ControlData(key, values);
|
||||||
|
|
||||||
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false);
|
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false);
|
||||||
|
@ -378,8 +380,9 @@ public abstract class OptionsConfigurationBlock {
|
||||||
return checkBox;
|
return checkBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Combo addComboBox(Composite parent, String label, Key key, String[] values, String[] valueLabels, int indent) {
|
protected Combo addComboBox(Composite parent, String label, Key key, String[] values,
|
||||||
GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
|
String[] valueLabels, int indent) {
|
||||||
|
GridData gd= new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1);
|
||||||
gd.horizontalIndent= indent;
|
gd.horizontalIndent= indent;
|
||||||
|
|
||||||
Label labelControl= new Label(parent, SWT.LEFT);
|
Label labelControl= new Label(parent, SWT.LEFT);
|
||||||
|
@ -395,7 +398,8 @@ public abstract class OptionsConfigurationBlock {
|
||||||
return comboBox;
|
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);
|
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||||
gd.horizontalIndent= indent;
|
gd.horizontalIndent= indent;
|
||||||
gd.horizontalSpan= 3;
|
gd.horizontalSpan= 3;
|
||||||
|
@ -439,30 +443,37 @@ public abstract class OptionsConfigurationBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Text addTextField(Composite parent, String label, Key key, int indent, int widthHint) {
|
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);
|
Label labelControl= new Label(parent, SWT.WRAP);
|
||||||
labelControl.setText(label);
|
labelControl.setText(label);
|
||||||
labelControl.setFont(JFaceResources.getDialogFont());
|
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.setData(key);
|
||||||
textBox.setLayoutData(new GridData());
|
|
||||||
|
|
||||||
makeScrollableCompositeAware(textBox);
|
makeScrollableCompositeAware(textBox);
|
||||||
|
|
||||||
fLabels.put(textBox, labelControl);
|
fLabels.put(textBox, labelControl);
|
||||||
|
|
||||||
|
if (key != null) {
|
||||||
String currValue= getValue(key);
|
String currValue= getValue(key);
|
||||||
if (currValue != null) {
|
if (currValue != null) {
|
||||||
textBox.setText(currValue);
|
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) {
|
if (widthHint != 0) {
|
||||||
data.widthHint= widthHint;
|
data.widthHint= widthHint;
|
||||||
}
|
}
|
||||||
data.horizontalIndent= indent;
|
|
||||||
data.horizontalSpan= 2;
|
data.horizontalSpan= 2;
|
||||||
textBox.setLayoutData(data);
|
textBox.setLayoutData(data);
|
||||||
|
|
||||||
|
@ -570,9 +581,9 @@ public abstract class OptionsConfigurationBlock {
|
||||||
ControlData data= (ControlData) widget.getData();
|
ControlData data= (ControlData) widget.getData();
|
||||||
String newValue= null;
|
String newValue= null;
|
||||||
if (widget instanceof Button) {
|
if (widget instanceof Button) {
|
||||||
newValue= data.getValue(((Button)widget).getSelection());
|
newValue= data.getValue(((Button) widget).getSelection());
|
||||||
} else if (widget instanceof Combo) {
|
} else if (widget instanceof Combo) {
|
||||||
newValue= data.getValue(((Combo)widget).getSelectionIndex());
|
newValue= data.getValue(((Combo) widget).getSelectionIndex());
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -582,9 +593,11 @@ public abstract class OptionsConfigurationBlock {
|
||||||
|
|
||||||
protected void textChanged(Text textControl) {
|
protected void textChanged(Text textControl) {
|
||||||
Key key= (Key) textControl.getData();
|
Key key= (Key) textControl.getData();
|
||||||
String number= textControl.getText();
|
if (key != null) {
|
||||||
String oldValue= setValue(key, number);
|
String newValue= textControl.getText();
|
||||||
validateSettings(key, oldValue, number);
|
String oldValue= setValue(key, newValue);
|
||||||
|
validateSettings(key, oldValue, newValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkValue(Key key, String value) {
|
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 abstract void validateSettings(Key changedKey, String oldValue, String newValue);
|
||||||
|
|
||||||
|
|
||||||
protected String[] getTokens(String text, String separator) {
|
protected String[] getTokens(String text, String separator) {
|
||||||
StringTokenizer tok= new StringTokenizer(text, separator);
|
StringTokenizer tok= new StringTokenizer(text, separator);
|
||||||
int nTokens= tok.countTokens();
|
int nTokens= tok.countTokens();
|
||||||
|
@ -815,12 +827,13 @@ public abstract class OptionsConfigurationBlock {
|
||||||
|
|
||||||
protected void updateText(Text curr) {
|
protected void updateText(Text curr) {
|
||||||
Key key= (Key) curr.getData();
|
Key key= (Key) curr.getData();
|
||||||
|
if (key != null) {
|
||||||
String currValue= getValue(key);
|
String currValue= getValue(key);
|
||||||
if (currValue != null) {
|
if (currValue != null) {
|
||||||
curr.setText(currValue);
|
curr.setText(currValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Button getCheckBox(Key key) {
|
protected Button getCheckBox(Key key) {
|
||||||
for (int i= fCheckBoxes.size() - 1; i >= 0; i--) {
|
for (int i= fCheckBoxes.size() - 1; i >= 0; i--) {
|
||||||
|
@ -871,6 +884,10 @@ public abstract class OptionsConfigurationBlock {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Control getLabel(Control control) {
|
||||||
|
return fLabels.get(control);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setComboEnabled(Key key, boolean enabled) {
|
protected void setComboEnabled(Key key, boolean enabled) {
|
||||||
Combo combo= getComboBox(key);
|
Combo combo= getComboBox(key);
|
||||||
Label label= fLabels.get(combo);
|
Label label= fLabels.get(combo);
|
||||||
|
|
|
@ -20,13 +20,6 @@ package org.eclipse.cdt.internal.ui.preferences;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
public final class PreferencesMessages extends 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_category_column_title;
|
||||||
public static String CodeAssistAdvancedConfigurationBlock_default_table_description;
|
public static String CodeAssistAdvancedConfigurationBlock_default_table_description;
|
||||||
public static String CodeAssistAdvancedConfigurationBlock_default_table_keybinding_column_title;
|
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_hidden;
|
||||||
public static String CodeTemplateBlock_export_error_canNotWrite;
|
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_noname;
|
||||||
public static String EditTemplateDialog_error_invalidName;
|
public static String EditTemplateDialog_error_invalidName;
|
||||||
public static String EditTemplateDialog_title_new;
|
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_preferenceOnlyForNewEditors;
|
||||||
public static String ScalabilityPreferencePage_contentAssist_autoActivation;
|
public static String ScalabilityPreferencePage_contentAssist_autoActivation;
|
||||||
|
|
||||||
|
private PreferencesMessages() {
|
||||||
|
// Do not instantiate
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NLS.initializeMessages(BUNDLE_NAME, PreferencesMessages.class);
|
NLS.initializeMessages(PreferencesMessages.class.getName(), PreferencesMessages.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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_hidden= Export failed.\n{0} is a hidden file.
|
||||||
CodeTemplateBlock_export_error_canNotWrite= Export failed.\n{0} cannot be modified.
|
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
|
# edit template dialog
|
||||||
EditTemplateDialog_error_noname=Template name cannot be empty.
|
EditTemplateDialog_error_noname=Template name cannot be empty.
|
||||||
EditTemplateDialog_error_invalidName=Template name contains invalid characters.
|
EditTemplateDialog_error_invalidName=Template name contains invalid characters.
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||||
|
|
||||||
|
@ -37,42 +38,39 @@ 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.CPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
|
|
||||||
|
|
||||||
public class FunctionFactory {
|
public class FunctionFactory {
|
||||||
|
|
||||||
public static IASTFunctionDefinition createGetterDefinition(String varName,
|
public static IASTFunctionDefinition createGetterDefinition(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||||
IASTFunctionDefinition getter = new CPPASTFunctionDefinition();
|
IASTFunctionDefinition getter = new CPPASTFunctionDefinition();
|
||||||
|
|
||||||
getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations));
|
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
|
// IASTFunctionDefinition. expects the outermost IASTFunctionDeclarator in declarator hierarchy
|
||||||
while (!(getterDeclarator instanceof IASTFunctionDeclarator)) {
|
while (!(getterDeclarator instanceof IASTFunctionDeclarator)) {
|
||||||
getterDeclarator = getterDeclarator.getNestedDeclarator();
|
getterDeclarator = getterDeclarator.getNestedDeclarator();
|
||||||
}
|
}
|
||||||
getter.setDeclarator((IASTFunctionDeclarator) getterDeclarator);
|
getter.setDeclarator((IASTFunctionDeclarator) getterDeclarator);
|
||||||
getter.setBody(getGetterBody(varName));
|
getter.setBody(getGetterBody(fieldName));
|
||||||
return getter;
|
return getter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CPPASTCompoundStatement getGetterBody(String varName) {
|
private static CPPASTCompoundStatement getGetterBody(IASTName fieldName) {
|
||||||
CPPASTCompoundStatement compound = new CPPASTCompoundStatement();
|
CPPASTCompoundStatement compound = new CPPASTCompoundStatement();
|
||||||
CPPASTReturnStatement returnStatement = new CPPASTReturnStatement();
|
CPPASTReturnStatement returnStatement = new CPPASTReturnStatement();
|
||||||
CPPASTIdExpression idExpr = new CPPASTIdExpression();
|
CPPASTIdExpression idExpr = new CPPASTIdExpression();
|
||||||
CPPASTName returnVal = new CPPASTName();
|
CPPASTName returnVal = new CPPASTName();
|
||||||
returnVal.setName(varName.toCharArray());
|
returnVal.setName(fieldName.toCharArray());
|
||||||
idExpr.setName(returnVal);
|
idExpr.setName(returnVal);
|
||||||
returnStatement.setReturnValue(idExpr);
|
returnStatement.setReturnValue(idExpr);
|
||||||
compound.addStatement(returnStatement);
|
compound.addStatement(returnStatement);
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTDeclarator getGetterDeclarator(String varName,
|
private static IASTDeclarator getGetterDeclarator(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||||
CPPASTName getterName = new CPPASTName();
|
CPPASTName getterName = new CPPASTName();
|
||||||
String varPartOfGetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName));
|
getterName.setName(GetterSetterNameGenerator.generateGetterName(fieldName).toCharArray());
|
||||||
getterName.setName("get".concat(varPartOfGetterName).toCharArray()); //$NON-NLS-1$
|
|
||||||
|
|
||||||
// copy declarator hierarchy
|
// copy declarator hierarchy
|
||||||
IASTDeclarator topDeclarator = fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations);
|
IASTDeclarator topDeclarator = fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations);
|
||||||
|
@ -107,11 +105,11 @@ public class FunctionFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTFunctionDefinition createSetterDefinition(String varName,
|
public static IASTFunctionDefinition createSetterDefinition(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||||
IASTFunctionDefinition setter = new CPPASTFunctionDefinition();
|
IASTFunctionDefinition setter = new CPPASTFunctionDefinition();
|
||||||
setter.setDeclSpecifier(getVoidDeclSpec());
|
setter.setDeclSpecifier(getVoidDeclSpec());
|
||||||
setter.setDeclarator(getSetterDeclarator(varName, fieldDeclaration, name));
|
setter.setDeclarator(getSetterDeclarator(fieldName, fieldDeclaration, name));
|
||||||
setter.setBody(getSetterBody(fieldDeclaration));
|
setter.setBody(getSetterBody(fieldDeclaration));
|
||||||
return setter;
|
return setter;
|
||||||
}
|
}
|
||||||
|
@ -141,11 +139,10 @@ public class FunctionFactory {
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CPPASTFunctionDeclarator getSetterDeclarator(String varName,
|
private static CPPASTFunctionDeclarator getSetterDeclarator(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||||
CPPASTName setterName = new CPPASTName();
|
CPPASTName setterName = new CPPASTName();
|
||||||
String varPartOfSetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName));
|
setterName.setName(GetterSetterNameGenerator.generateSetterName(fieldName).toCharArray());
|
||||||
setterName.setName("set".concat(varPartOfSetterName).toCharArray()); //$NON-NLS-1$
|
|
||||||
CPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator();
|
CPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator();
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
name.addName(setterName);
|
name.addName(setterName);
|
||||||
|
@ -167,20 +164,19 @@ public class FunctionFactory {
|
||||||
return declSpecifier;
|
return declSpecifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTSimpleDeclaration createGetterDeclaration(String name,
|
public static IASTSimpleDeclaration createGetterDeclaration(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration) {
|
IASTSimpleDeclaration fieldDeclaration) {
|
||||||
IASTSimpleDeclaration getter = new CPPASTSimpleDeclaration();
|
IASTSimpleDeclaration getter = new CPPASTSimpleDeclaration();
|
||||||
getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations));
|
getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations));
|
||||||
getter.addDeclarator(getGetterDeclarator(name, fieldDeclaration, null));
|
getter.addDeclarator(getGetterDeclarator(fieldName, fieldDeclaration, null));
|
||||||
|
|
||||||
return getter;
|
return getter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTSimpleDeclaration createSetterDeclaration(String name,
|
public static IASTSimpleDeclaration createSetterDeclaration(IASTName fieldName,
|
||||||
IASTSimpleDeclaration fieldDeclaration) {
|
IASTSimpleDeclaration fieldDeclaration) {
|
||||||
IASTSimpleDeclaration setter = new CPPASTSimpleDeclaration();
|
IASTSimpleDeclaration setter = new CPPASTSimpleDeclaration();
|
||||||
setter.setDeclSpecifier(getVoidDeclSpec());
|
setter.setDeclSpecifier(getVoidDeclSpec());
|
||||||
setter.addDeclarator(getSetterDeclarator(name, fieldDeclaration, null));
|
setter.addDeclarator(getSetterDeclarator(fieldName, fieldDeclaration, null));
|
||||||
return setter;
|
return setter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
|
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterAndSetterContext.FieldWrapper;
|
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 {
|
public class GenerateGettersAndSettersInputPage extends UserInputWizardPage {
|
||||||
private GetterAndSetterContext context;
|
private GetterAndSetterContext context;
|
||||||
|
@ -115,7 +115,7 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage {
|
||||||
selectGetter.addSelectionListener(new SelectionAdapter(){
|
selectGetter.addSelectionListener(new SelectionAdapter(){
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
selectMethods(Type.getter);
|
selectMethods(AccessorKind.GETTER);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -124,14 +124,14 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage {
|
||||||
selectSetter.addSelectionListener(new SelectionAdapter(){
|
selectSetter.addSelectionListener(new SelectionAdapter(){
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
selectMethods(Type.setter);
|
selectMethods(AccessorKind.SETTER);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return btComp;
|
return btComp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectMethods(Type type) {
|
private void selectMethods(AccessorKind type) {
|
||||||
Object[] items = context.getElements(null);
|
Object[] items = context.getElements(null);
|
||||||
Set<GetterSetterInsertEditProvider> checked = context.selectedFunctions;
|
Set<GetterSetterInsertEditProvider> checked = context.selectedFunctions;
|
||||||
for (Object treeItem : items) {
|
for (Object treeItem : items) {
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
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.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
|
|
||||||
|
|
||||||
public class GetterAndSetterContext implements ITreeContentProvider {
|
public class GetterAndSetterContext implements ITreeContentProvider {
|
||||||
public ArrayList<IASTSimpleDeclaration> existingFields = new ArrayList<IASTSimpleDeclaration>();
|
public ArrayList<IASTSimpleDeclaration> existingFields = new ArrayList<IASTSimpleDeclaration>();
|
||||||
|
@ -54,13 +54,13 @@ public class GetterAndSetterContext implements ITreeContentProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
||||||
String varName = getFieldDeclarationName(simpleDeclaration).toString();
|
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
|
||||||
return new GetterSetterInsertEditProvider(varName, simpleDeclaration, Type.getter);
|
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.GETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
||||||
String varName = getFieldDeclarationName(simpleDeclaration).toString();
|
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
|
||||||
return new GetterSetterInsertEditProvider(varName, simpleDeclaration, Type.setter);
|
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.SETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getParent(Object element) {
|
public Object getParent(Object element) {
|
||||||
|
@ -111,10 +111,8 @@ public class GetterAndSetterContext implements ITreeContentProvider {
|
||||||
|
|
||||||
private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) {
|
private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) {
|
||||||
FunctionWrapper wrapper = new FunctionWrapper();
|
FunctionWrapper wrapper = new FunctionWrapper();
|
||||||
String trimmedName = NameHelper.trimFieldName(getFieldDeclarationName(currentField).toString());
|
String name = GetterSetterNameGenerator.generateGetterName(getFieldDeclarationName(currentField));
|
||||||
String getterName = "get" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$
|
setFunctionToWrapper(wrapper, name);
|
||||||
|
|
||||||
setFunctionToWrapper(wrapper, getterName);
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,10 +126,8 @@ public class GetterAndSetterContext implements ITreeContentProvider {
|
||||||
|
|
||||||
private FunctionWrapper getSetterForField(IASTSimpleDeclaration currentField) {
|
private FunctionWrapper getSetterForField(IASTSimpleDeclaration currentField) {
|
||||||
FunctionWrapper wrapper = new FunctionWrapper();
|
FunctionWrapper wrapper = new FunctionWrapper();
|
||||||
String trimmedName = NameHelper.trimFieldName(getFieldDeclarationName(currentField).toString());
|
String name = GetterSetterNameGenerator.generateSetterName(getFieldDeclarationName(currentField));
|
||||||
String setterName = "set" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$
|
setFunctionToWrapper(wrapper, name);
|
||||||
|
|
||||||
setFunctionToWrapper(wrapper, setterName);
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -8,12 +8,14 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
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;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
|
import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
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;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||||
|
|
||||||
public class GetterSetterInsertEditProvider implements Comparable<GetterSetterInsertEditProvider> {
|
public class GetterSetterInsertEditProvider implements Comparable<GetterSetterInsertEditProvider> {
|
||||||
public enum Type {
|
public enum AccessorKind {
|
||||||
getter,
|
GETTER,
|
||||||
setter;
|
SETTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTSimpleDeclaration functionDeclaration;
|
private IASTSimpleDeclaration functionDeclaration;
|
||||||
private Type type;
|
private AccessorKind kind;
|
||||||
private String name;
|
private IASTName fieldName;
|
||||||
private IASTSimpleDeclaration fieldDeclaration;
|
private IASTSimpleDeclaration fieldDeclaration;
|
||||||
|
|
||||||
public GetterSetterInsertEditProvider(String name, IASTSimpleDeclaration fieldDeclaration, Type type) {
|
public GetterSetterInsertEditProvider(IASTName fieldName, IASTSimpleDeclaration fieldDeclaration,
|
||||||
switch (type) {
|
AccessorKind kind) {
|
||||||
case getter:
|
switch (kind) {
|
||||||
this.functionDeclaration = FunctionFactory.createGetterDeclaration(name, fieldDeclaration);
|
case GETTER:
|
||||||
|
this.functionDeclaration = FunctionFactory.createGetterDeclaration(fieldName, fieldDeclaration);
|
||||||
break;
|
break;
|
||||||
case setter:
|
case SETTER:
|
||||||
this.functionDeclaration = FunctionFactory.createSetterDeclaration(name, fieldDeclaration);
|
this.functionDeclaration = FunctionFactory.createSetterDeclaration(fieldName, fieldDeclaration);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = type;
|
this.kind = kind;
|
||||||
this.name = name;
|
this.fieldName = fieldName;
|
||||||
this.fieldDeclaration = fieldDeclaration;
|
this.fieldDeclaration = fieldDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +68,12 @@ public class GetterSetterInsertEditProvider implements Comparable<GetterSetterIn
|
||||||
qname = null;
|
qname = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (kind) {
|
||||||
case getter:
|
case GETTER:
|
||||||
definition = FunctionFactory.createGetterDefinition(name, fieldDeclaration, qname);
|
definition = FunctionFactory.createGetterDefinition(fieldName, fieldDeclaration, qname);
|
||||||
break;
|
break;
|
||||||
case setter:
|
case SETTER:
|
||||||
definition = FunctionFactory.createSetterDefinition(name, fieldDeclaration, qname);
|
definition = FunctionFactory.createSetterDefinition(fieldName, fieldDeclaration, qname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return definition;
|
return definition;
|
||||||
|
@ -92,8 +95,8 @@ public class GetterSetterInsertEditProvider implements Comparable<GetterSetterIn
|
||||||
return functionDeclaration;
|
return functionDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public AccessorKind getType() {
|
||||||
return type;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(GetterSetterInsertEditProvider o) {
|
public int compareTo(GetterSetterInsertEditProvider o) {
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2010, 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.refactoring.gettersandsetters;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
||||||
|
|
||||||
|
import com.ibm.icu.text.BreakIterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CBreakIterator;
|
||||||
|
import org.eclipse.cdt.internal.ui.util.NameComposer;
|
||||||
|
|
||||||
|
public class GetterSetterNameGenerator {
|
||||||
|
|
||||||
|
// Do not instantiate.
|
||||||
|
private GetterSetterNameGenerator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String generateGetterName(IASTName fieldName) {
|
||||||
|
IPreferencesService preferences = Platform.getPreferencesService();
|
||||||
|
int capitalization = preferences.getInt(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_GETTER_CAPITALIZATION,
|
||||||
|
PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE, null);
|
||||||
|
String wordDelimiter = preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_GETTER_WORD_DELIMITER, "", null); //$NON-NLS-1$
|
||||||
|
String prefix = isBooleanDecaratorName(fieldName) ?
|
||||||
|
preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_GETTER_PREFIX_FOR_BOOLEAN, "is", null) : //$NON-NLS-1$
|
||||||
|
preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_GETTER_PREFIX, "get", null); //$NON-NLS-1$
|
||||||
|
String suffix = preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_GETTER_SUFFIX, "", null); //$NON-NLS-1$
|
||||||
|
NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix);
|
||||||
|
String name = GetterSetterNameGenerator.trimFieldName(fieldName.toString());
|
||||||
|
return composer.compose(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isBooleanDecaratorName(IASTName name) {
|
||||||
|
if (IASTDeclarator.DECLARATOR_NAME.equals(name.getPropertyInParent())) {
|
||||||
|
IASTDeclarator declarator = (IASTDeclarator) name.getParent();
|
||||||
|
IType type = CPPVisitor.createType(declarator);
|
||||||
|
if (type instanceof IBasicType && ((IBasicType) type).getKind() == IBasicType.Kind.eBoolean) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String generateSetterName(IASTName fieldName) {
|
||||||
|
IPreferencesService preferences = Platform.getPreferencesService();
|
||||||
|
int capitalization = preferences.getInt(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_SETTER_CAPITALIZATION,
|
||||||
|
PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE, null);
|
||||||
|
String wordDelimiter = preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_SETTER_WORD_DELIMITER, "", null); //$NON-NLS-1$
|
||||||
|
String prefix = preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_SETTER_PREFIX, "set", null); //$NON-NLS-1$
|
||||||
|
String suffix = preferences.getString(CUIPlugin.PLUGIN_ID,
|
||||||
|
PreferenceConstants.NAME_STYLE_SETTER_SUFFIX, "", null); //$NON-NLS-1$
|
||||||
|
NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix);
|
||||||
|
String name = GetterSetterNameGenerator.trimFieldName(fieldName.toString());
|
||||||
|
return composer.compose(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the trimmed field name. Leading and trailing non-alphanumeric characters are trimmed.
|
||||||
|
* If the first word of the name consists of a single letter and the name contains more than
|
||||||
|
* one word, the first word is removed.
|
||||||
|
*
|
||||||
|
* @param fieldName a field name to trim
|
||||||
|
* @return the trimmed field name
|
||||||
|
*/
|
||||||
|
public static String trimFieldName(String fieldName){
|
||||||
|
CBreakIterator iterator = new CBreakIterator();
|
||||||
|
iterator.setText(fieldName);
|
||||||
|
int firstWordStart = -1;
|
||||||
|
int firstWordEnd = -1;
|
||||||
|
int secondWordStart = -1;
|
||||||
|
int lastWordEnd = -1;
|
||||||
|
int end;
|
||||||
|
for (int start = iterator.first(); (end = iterator.next()) != BreakIterator.DONE; start = end) {
|
||||||
|
if (Character.isLetterOrDigit(fieldName.charAt(start))) {
|
||||||
|
int pos = end;
|
||||||
|
while (--pos >= 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.utils;
|
package org.eclipse.cdt.internal.ui.refactoring.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -35,14 +36,12 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
||||||
* Helps with IASTNames.
|
* Helps with IASTNames.
|
||||||
*
|
*
|
||||||
* @author Mirko Stocker
|
* @author Mirko Stocker
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class NameHelper {
|
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) {
|
public static boolean isValidLocalVariableName(String name) {
|
||||||
boolean valid = Pattern.compile(localVariableRegexp).matcher(name).matches();
|
return localVariableRegexp.matcher(name).matches();
|
||||||
return valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyword(String name) {
|
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
|
* Constructs the fully qualified name from the given parameters. The file and offset parameters
|
||||||
* the namespace at the declaration position and the target namespace at the target position.
|
* 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 declaratorName of the method or function
|
||||||
* @param declarationTu translation unit of the method or function declaration
|
* @param declarationTu translation unit of the method or function declaration
|
||||||
* @param insertFileTu translation unit of the file where the implementation is being inserted
|
* @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
|
* @param insertLocation
|
||||||
* @return the correct name for the target
|
* @return the correct name for the target
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName, ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu, int insertLocation, RefactoringASTCache astCache)
|
public static ICPPASTQualifiedName createQualifiedNameFor(IASTName declaratorName,
|
||||||
throws CoreException {
|
ITranslationUnit declarationTu, int selectionOffset, ITranslationUnit insertFileTu,
|
||||||
|
int insertLocation, RefactoringASTCache astCache) throws CoreException {
|
||||||
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
|
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
|
||||||
|
|
||||||
IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, selectionOffset, astCache).getNames();
|
IASTName[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu,
|
||||||
IASTName[] implementationNames = NamespaceHelper.getSurroundingNamespace(insertFileTu, insertLocation, astCache).getNames();
|
selectionOffset, astCache).getNames();
|
||||||
|
IASTName[] implementationNames = NamespaceHelper.getSurroundingNamespace(insertFileTu,
|
||||||
|
insertLocation, astCache).getNames();
|
||||||
|
|
||||||
for (int i = 0; i < declarationNames.length; i++) {
|
for (int i = 0; i < declarationNames.length; i++) {
|
||||||
if (i >= implementationNames.length) {
|
if (i >= implementationNames.length) {
|
||||||
qname.addName(declarationNames[i]);
|
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]);
|
qname.addName(declarationNames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,63 +88,6 @@ public class NameHelper {
|
||||||
return qname;
|
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) {
|
public static String getTypeName(IASTParameterDeclaration parameter) {
|
||||||
IASTName name = parameter.getDeclarator().getName();
|
IASTName name = parameter.getDeclarator().getName();
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
|
|
|
@ -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: <ul>
|
||||||
|
* <li>PreferenceConstants.NAME_STYLE_CAPITALIZATION_ORIGINAL,</li>
|
||||||
|
* <li>PreferenceConstants.NAME_STYLE_CAPITALIZATION_UPPER_CASE,</li>
|
||||||
|
* <li>PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CASE,</li>
|
||||||
|
* <li>PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE,</li>
|
||||||
|
* <li>PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE.</li>
|
||||||
|
* </ul>
|
||||||
|
* @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<CharSequence> 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<CharSequence> 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<CharSequence> splitIntoWords(CharSequence name) {
|
||||||
|
List<CharSequence> words = new ArrayList<CharSequence>();
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -63,7 +63,6 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
|
|
||||||
|
|
||||||
public class NewClassWizardUtil {
|
public class NewClassWizardUtil {
|
||||||
|
|
||||||
|
@ -257,28 +256,6 @@ public class NewClassWizardUtil {
|
||||||
return null;
|
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.
|
* 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 type the class to resolve
|
||||||
* @param context the runnable context
|
* @param context the runnable context
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Layout;
|
||||||
|
|
||||||
public class LayoutUtil {
|
public class LayoutUtil {
|
||||||
|
|
||||||
|
@ -23,11 +24,20 @@ public class LayoutUtil {
|
||||||
* Calculates the number of columns needed by field editors
|
* Calculates the number of columns needed by field editors
|
||||||
*/
|
*/
|
||||||
public static int getNumberOfColumns(DialogField[] editors) {
|
public static int getNumberOfColumns(DialogField[] editors) {
|
||||||
int nCulumns= 0;
|
int nColumns= 0;
|
||||||
for (int i= 0; i < editors.length; i++) {
|
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 minWidth The minimal width of the composite
|
||||||
* @param minHeight The minimal height 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);
|
doDefaultLayout(parent, editors, labelOnTop, minWidth, minHeight, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +66,9 @@ public class LayoutUtil {
|
||||||
* @param minHeight The minimal height of the composite
|
* @param minHeight The minimal height of the composite
|
||||||
* @param marginWidth The margin width to be used by the composite
|
* @param marginWidth The margin width to be used by the composite
|
||||||
* @param marginHeight The margin height to be used by the composite
|
* @param marginHeight The margin height to be used by the composite
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
private static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop,
|
||||||
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int minWidth, int minHeight, int marginWidth, int marginHeight) {
|
int minWidth, int minHeight, int marginWidth, int marginHeight) {
|
||||||
int nCulumns= getNumberOfColumns(editors);
|
int nCulumns= getNumberOfColumns(editors);
|
||||||
Control[][] controls= new Control[editors.length][];
|
Control[][] controls= new Control[editors.length][];
|
||||||
for (int i= 0; i < editors.length; i++) {
|
for (int i= 0; i < editors.length; i++) {
|
||||||
|
@ -91,7 +101,7 @@ public class LayoutUtil {
|
||||||
public static void setHorizontalSpan(Control control, int span) {
|
public static void setHorizontalSpan(Control control, int span) {
|
||||||
Object ld= control.getLayoutData();
|
Object ld= control.getLayoutData();
|
||||||
if (ld instanceof GridData) {
|
if (ld instanceof GridData) {
|
||||||
((GridData)ld).horizontalSpan= span;
|
((GridData) ld).horizontalSpan= span;
|
||||||
} else if (span != 1) {
|
} else if (span != 1) {
|
||||||
GridData gd= new GridData();
|
GridData gd= new GridData();
|
||||||
gd.horizontalSpan= span;
|
gd.horizontalSpan= span;
|
||||||
|
@ -105,7 +115,7 @@ public class LayoutUtil {
|
||||||
public static void setWidthHint(Control control, int widthHint) {
|
public static void setWidthHint(Control control, int widthHint) {
|
||||||
Object ld= control.getLayoutData();
|
Object ld= control.getLayoutData();
|
||||||
if (ld instanceof GridData) {
|
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) {
|
public static void setHeightHint(Control control, int heigthHint) {
|
||||||
Object ld= control.getLayoutData();
|
Object ld= control.getLayoutData();
|
||||||
if (ld instanceof GridData) {
|
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) {
|
public static void setHorizontalIndent(Control control, int horizontalIndent) {
|
||||||
Object ld= control.getLayoutData();
|
Object ld= control.getLayoutData();
|
||||||
if (ld instanceof GridData) {
|
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) {
|
public static void setHorizontalGrabbing(Control control) {
|
||||||
Object ld= control.getLayoutData();
|
Object ld= control.getLayoutData();
|
||||||
if (ld instanceof GridData) {
|
if (ld instanceof GridData) {
|
||||||
((GridData)ld).grabExcessHorizontalSpace= true;
|
((GridData) ld).grabExcessHorizontalSpace= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceStatus;
|
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.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
||||||
import org.eclipse.ui.dialogs.ContainerGenerator;
|
import org.eclipse.ui.dialogs.ContainerGenerator;
|
||||||
|
|
||||||
public class NewSourceFileGenerator {
|
public class NewSourceFileGenerator {
|
||||||
|
|
||||||
//TODO these should all be configurable in prefs
|
/**
|
||||||
private static final String HEADER_EXT = ".h"; //$NON-NLS-1$
|
* Creates a header file name from the given class name. This is the file name
|
||||||
private static final String SOURCE_EXT = ".cpp"; //$NON-NLS-1$
|
* 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) {
|
public static String generateHeaderFileNameFromClass(String className) {
|
||||||
//TODO eventually make this a prefs option - filename pattern
|
IPreferencesService preferences = Platform.getPreferencesService();
|
||||||
return className + HEADER_EXT;
|
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) {
|
public static String generateSourceFileNameFromClass(String className) {
|
||||||
//TODO eventually make this a prefs option - filename pattern
|
IPreferencesService preferences = Platform.getPreferencesService();
|
||||||
return className + SOURCE_EXT;
|
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 {
|
public static IFile createHeaderFile(IPath filePath, boolean force, IProgressMonitor monitor) throws CoreException {
|
||||||
|
|
|
@ -1508,6 +1508,298 @@ public class PreferenceConstants {
|
||||||
*/
|
*/
|
||||||
public static final int CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH = 2;
|
public static final int CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_PATH = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A named preference that controls how capitalization of a constant name.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>Integer</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @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.
|
||||||
|
* <p>
|
||||||
|
* Value is of type <code>String</code>.
|
||||||
|
*
|
||||||
|
* @since 5.3
|
||||||
|
*/
|
||||||
|
public static final String NAME_STYLE_CPP_TEST_WORD_DELIMITER = "nameStyle.cpp.test.wordDelimiter"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of <code>NAME_STYLE_*_CAPITALIZATION</code> 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 <code>NAME_STYLE_*_CAPITALIZATION</code> 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 <code>NAME_STYLE_*_CAPITALIZATION</code> 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 <code>NAME_STYLE_*_CAPITALIZATION</code> 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 <code>NAME_STYLE_*_CAPITALIZATION</code> 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.
|
* Returns the CDT-UI preference store.
|
||||||
*
|
*
|
||||||
|
@ -1682,7 +1974,7 @@ public class PreferenceConstants {
|
||||||
store.setDefault(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD, 20);
|
store.setDefault(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD, 20);
|
||||||
store.setDefault(PreferenceConstants.SPELLING_PROBLEMS_THRESHOLD, 100);
|
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.
|
* cannot return word proposals but only correction proposals.
|
||||||
*/
|
*/
|
||||||
store.setToDefault(PreferenceConstants.SPELLING_ENABLE_CONTENTASSIST);
|
store.setToDefault(PreferenceConstants.SPELLING_ENABLE_CONTENTASSIST);
|
||||||
|
@ -1708,6 +2000,37 @@ public class PreferenceConstants {
|
||||||
// Code Templates
|
// Code Templates
|
||||||
store.setDefault(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME,
|
store.setDefault(PreferenceConstants.CODE_TEMPLATES_INCLUDE_GUARD_SCHEME,
|
||||||
CODE_TEMPLATES_INCLUDE_GUARD_SCHEME_FILE_NAME);
|
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$
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.browser.TypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
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.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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
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.Separator;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
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.dialogfields.StringDialogField;
|
||||||
|
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
|
||||||
|
|
||||||
public class NewClassCreationWizardPage extends NewElementWizardPage {
|
public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
|
|
||||||
protected final static String PAGE_NAME = "NewClassWizardPage"; //$NON-NLS-1$
|
protected final static String PAGE_NAME = "NewClassWizardPage"; //$NON-NLS-1$
|
||||||
protected static final int MAX_FIELD_CHARS = 50;
|
protected static final int MAX_FIELD_CHARS = 50;
|
||||||
|
|
||||||
|
@ -141,9 +140,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
protected IStatus fSourceFileStatus;
|
protected IStatus fSourceFileStatus;
|
||||||
protected final IStatus STATUS_OK = new StatusInfo();
|
protected final IStatus STATUS_OK = new StatusInfo();
|
||||||
|
|
||||||
protected IFile fCreatedSourceFile = null;
|
protected IFile fCreatedSourceFile;
|
||||||
protected IFile fCreatedHeaderFile = null;
|
protected IFile fCreatedHeaderFile;
|
||||||
protected ICElement fCreatedClass = null;
|
protected ICElement fCreatedClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag isFirstTime is used to keep a note
|
* This flag isFirstTime is used to keep a note
|
||||||
|
@ -1307,20 +1306,20 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
String sourceName = null;
|
String sourceName = null;
|
||||||
|
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
headerName = NewClassWizardUtil.createHeaderFileName(className);
|
headerName = NewSourceFileGenerator.generateHeaderFileNameFromClass(className);
|
||||||
sourceName = NewClassWizardUtil.createSourceFileName(className);
|
sourceName = NewSourceFileGenerator.generateSourceFileNameFromClass(className);
|
||||||
} else {
|
} else {
|
||||||
// make sure the file names are unique
|
// make sure the file names are unique
|
||||||
String currName = className;
|
String currName = className;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
String separator = ""; //$NON-NLS-1$
|
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$
|
separator = "_"; //$NON-NLS-1$
|
||||||
while (count < MAX_UNIQUE_CLASSNAME) {
|
while (count < MAX_UNIQUE_CLASSNAME) {
|
||||||
String header = NewClassWizardUtil.createHeaderFileName(currName);
|
String header = NewSourceFileGenerator.generateHeaderFileNameFromClass(currName);
|
||||||
IPath path = folder.append(header);
|
IPath path = folder.append(header);
|
||||||
if (!path.toFile().exists()) {
|
if (!path.toFile().exists()) {
|
||||||
String source = NewClassWizardUtil.createSourceFileName(currName);
|
String source = NewSourceFileGenerator.generateSourceFileNameFromClass(currName);
|
||||||
path = folder.append(source);
|
path = folder.append(source);
|
||||||
if (!path.toFile().exists()) {
|
if (!path.toFile().exists()) {
|
||||||
headerName = header;
|
headerName = header;
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class ControlFactory {
|
||||||
*
|
*
|
||||||
* @param parent the parent of the new composite
|
* @param parent the parent of the new composite
|
||||||
* @param color the separator color
|
* @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) {
|
public static Composite createCompositeSeparator(Composite parent, Color color, int preferedHeight) {
|
||||||
Composite separator = createComposite(parent, 1);
|
Composite separator = createComposite(parent, 1);
|
||||||
|
@ -206,8 +206,8 @@ public class ControlFactory {
|
||||||
* @param style - control style
|
* @param style - control style
|
||||||
* @return the new label
|
* @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 label = new Label(parent, style);
|
||||||
label.setFont(parent.getFont());
|
label.setFont(parent.getFont());
|
||||||
label.setText(text);
|
label.setText(text);
|
||||||
|
@ -241,11 +241,11 @@ public class ControlFactory {
|
||||||
* @return the new label
|
* @return the new label
|
||||||
*/
|
*/
|
||||||
public static Label createBoldLabel(Composite parent, String text) {
|
public static Label createBoldLabel(Composite parent, String text) {
|
||||||
Label label = createLabel( parent, text );
|
Label label = createLabel(parent, text);
|
||||||
FontData[] fd = label.getFont().getFontData();
|
FontData[] fd = label.getFont().getFontData();
|
||||||
fd[0].setStyle( SWT.BOLD );
|
fd[0].setStyle(SWT.BOLD);
|
||||||
Font font = new Font( Display.getCurrent(), fd[0] );
|
Font font = new Font(Display.getCurrent(), fd[0]);
|
||||||
label.setFont( font );
|
label.setFont(font);
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,8 @@ public class ControlFactory {
|
||||||
* @param value the string to identify radiobutton
|
* @param value the string to identify radiobutton
|
||||||
* @return the new checkbox
|
* @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 button = new Button(group, SWT.RADIO | SWT.LEFT);
|
||||||
button.setFont(group.getFont());
|
button.setFont(group.getFont());
|
||||||
button.setText(label);
|
button.setText(label);
|
||||||
|
@ -574,7 +575,8 @@ public class ControlFactory {
|
||||||
return createSelectCCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
|
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);
|
CCombo combo = new CCombo(parent, style);
|
||||||
combo.setFont(parent.getFont());
|
combo.setFont(parent.getFont());
|
||||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||||
|
@ -657,7 +659,7 @@ public class ControlFactory {
|
||||||
int n_sel = combo.indexOf(selData);
|
int n_sel = combo.indexOf(selData);
|
||||||
if (0 > n_sel) {
|
if (0 > n_sel) {
|
||||||
if ((combo.getStyle() & SWT.READ_ONLY) == 0) {
|
if ((combo.getStyle() & SWT.READ_ONLY) == 0) {
|
||||||
combo.setText( selData );
|
combo.setText(selData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n_sel = 0;
|
n_sel = 0;
|
||||||
|
@ -668,39 +670,36 @@ public class ControlFactory {
|
||||||
/**
|
/**
|
||||||
* Create a dialog shell, child to the top level workbench shell.
|
* 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() {
|
public static Shell createDialogShell() {
|
||||||
Shell parent = PlatformUI.getWorkbench()
|
Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
|
||||||
.getActiveWorkbenchWindow()
|
return new Shell(parent, SWT.DIALOG_TRIM);
|
||||||
.getShell();
|
|
||||||
return new Shell( parent, SWT.DIALOG_TRIM );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Composite insertSpace(Composite parent, int nSpan, int height) {
|
public static Composite insertSpace(Composite parent, int nSpan, int height) {
|
||||||
Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(),
|
Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(),
|
||||||
(SWT.DEFAULT != height ? height : 5));
|
(SWT.DEFAULT != height ? height : 5));
|
||||||
((GridData)space.getLayoutData()).horizontalSpan = nSpan;
|
((GridData) space.getLayoutData()).horizontalSpan = nSpan;
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageBox createDialog( String title, String message, int style ) {
|
public static MessageBox createDialog(String title, String message, int style) {
|
||||||
MessageBox box = new MessageBox( createDialogShell(), style | SWT.APPLICATION_MODAL );
|
MessageBox box = new MessageBox(createDialogShell(), style | SWT.APPLICATION_MODAL);
|
||||||
box.setText( title );
|
box.setText(title);
|
||||||
box.setMessage( message );
|
box.setMessage(message);
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageBox createYesNoDialog( String title, String message ) {
|
public static MessageBox createYesNoDialog(String title, String message) {
|
||||||
return createDialog( title, message, SWT.YES | SWT.NO | SWT.ICON_QUESTION );
|
return createDialog(title, message, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageBox createOkDialog( String title, String message ) {
|
public static MessageBox createOkDialog(String title, String message) {
|
||||||
return createDialog( title, message, SWT.OK | SWT.ICON_INFORMATION );
|
return createDialog(title, message, SWT.OK | SWT.ICON_INFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageBox createOkCancelDialog( String title, String message ) {
|
public static MessageBox createOkCancelDialog(String title, String message) {
|
||||||
return createDialog( title, message, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION );
|
return createDialog(title, message, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue