1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 510789 - Added final field to class wizard

Change-Id: Ib2f0168b897e665f3577511144692bb446d5ab84
This commit is contained in:
Marco Stornelli 2020-04-04 09:16:28 +02:00
parent 1d4d637d72
commit 31b748e7b9
9 changed files with 117 additions and 14 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.make.ui; singleton:=true
Bundle-Version: 7.3.300.qualifier
Bundle-Version: 7.3.400.qualifier
Bundle-Activator: org.eclipse.cdt.make.internal.ui.MakeUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@ -29,7 +29,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.cdt.core;bundle-version="[5.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[6.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[7.0.0,8.0.0)",
org.eclipse.cdt.make.core;bundle-version="[7.0.0,8.1.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)",

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.ui; singleton:=true
Bundle-Version: 9.1.500.qualifier
Bundle-Version: 9.1.600.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@ -18,7 +18,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.cdt.make.core,
org.eclipse.cdt.make.ui,
org.eclipse.cdt.managedbuilder.core;bundle-version="[8.7.0,9.0.0)",
org.eclipse.cdt.ui;bundle-version="[6.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[7.0.0,8.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.console;bundle-version="[3.5.100,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
Bundle-Version: 6.7.100.qualifier
Bundle-Version: 7.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -91,6 +91,7 @@ public class NewClassCodeGenerator {
private ICElement fCreatedClass;
private String fFullyQualifiedClassName;
private boolean fForceSourceFileCreation;
private final boolean fIsFinal;
/**
* When set to <code>true</code>, the source file is created, even if no stubs have
@ -126,6 +127,21 @@ public class NewClassCodeGenerator {
*/
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, IPath testPath, String className, String namespace,
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs) {
this(headerPath, sourcePath, testPath, className, namespace, baseClasses, methodStubs, false);
}
/**
* @param headerPath the header file path
* @param sourcePath the source file path
* @param testPath the test file path, can be {@code null}
* @param className the class name
* @param namespace the namespace name
* @param baseClasses the base classes
* @param methodStubs the method stubs
* @param isFinal True if final, false otherwise
*/
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, IPath testPath, String className, String namespace,
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, boolean isFinal) {
fHeaderPath = headerPath;
fSourcePath = sourcePath;
fTestPath = testPath;
@ -142,6 +158,7 @@ public class NewClassCodeGenerator {
}
fBaseClasses = baseClasses;
fMethodStubs = methodStubs;
fIsFinal = isFinal;
}
public ICElement getCreatedClass() {
@ -466,6 +483,9 @@ public class NewClassCodeGenerator {
}
code.append("class "); //$NON-NLS-1$
code.append(fClassName);
if (fIsFinal) {
code.append(" final "); //$NON-NLS-1$
}
code.append(constructBaseClassInheritance());
code.append(" {"); //$NON-NLS-1$
code.append(lineDelimiter);

View file

@ -30,6 +30,7 @@ public final class NewClassWizardMessages extends NLS {
public static String NewClassCreationWizardPage_warning_NotACProject;
public static String NewClassCreationWizardPage_warning_NotInACProject;
public static String NewClassCreationWizardPage_namespace_label;
public static String NewClassCreationWizardPage_final_label;
public static String NewClassCreationWizardPage_namespace_button;
public static String NewClassCreationWizardPage_error_EnterNamespace;
public static String NewClassCreationWizardPage_error_NamespaceExistsDifferentCase;

View file

@ -36,6 +36,8 @@ NewClassCreationWizardPage_warning_NotInACProject=Folder is not in a C/C++ proje
NewClassCreationWizardPage_namespace_label=&Namespace:
NewClassCreationWizardPage_namespace_button=Bro&wse...
NewClassCreationWizardPage_final_label=Final class
NewClassCreationWizardPage_error_EnterNamespace=Namespace is empty.
NewClassCreationWizardPage_error_NamespaceExistsDifferentCase=Namespace with the same name exists in a different scope.
NewClassCreationWizardPage_error_TypeMatchingNamespaceExists=Another type with the same name as specified namespace exists.

View file

@ -122,6 +122,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
private static final String KEY_STUB_SELECTED = "stubSelected"; //$NON-NLS-1$
private static final String KEY_STUB_VIRTUAL = "stubVirtual"; //$NON-NLS-1$
private static final String KEY_STUB_IMPL = "stubImpl"; //$NON-NLS-1$
private static final String KEY_FINAL_SELECTED = "finalSelected"; //$NON-NLS-1$
// Field IDs
protected static final int SOURCE_FOLDER_ID = 1;
@ -133,8 +134,10 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
protected static final int SOURCE_FILE_ID = 64;
/** @since 5.3 */
protected static final int TEST_FILE_ID = 128;
/** @since 7.0*/
protected static final int FINAL_ID = 256;
protected static final int ALL_FIELDS = SOURCE_FOLDER_ID | NAMESPACE_ID | CLASS_NAME_ID | BASE_CLASSES_ID
| METHOD_STUBS_ID | HEADER_FILE_ID | SOURCE_FILE_ID | TEST_FILE_ID;
| METHOD_STUBS_ID | HEADER_FILE_ID | SOURCE_FILE_ID | TEST_FILE_ID | FINAL_ID;
protected int fLastFocusedField = 0;
protected StringButtonDialogField fSourceFolderDialogField;
@ -145,6 +148,10 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
protected MethodStubsListDialogField fMethodStubsDialogField;
protected StringButtonDialogField fHeaderFileDialogField;
protected StringButtonDialogField fSourceFileDialogField;
/**
* @since 7.0
*/
protected SelectionButtonDialogField fIsFinalClassField;
/** @since 5.3 */
protected StringButtonDialogField fTestFileDialogField;
/** @since 5.3 */
@ -165,6 +172,10 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
protected IStatus fSourceFileStatus;
/** @since 5.3 */
protected IStatus fTestFileStatus;
/**
* @since 7.0
*/
protected IStatus fIsFinalStatus;
protected final IStatus STATUS_OK = new StatusInfo();
protected IFile fCreatedHeaderFile;
@ -216,6 +227,11 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
fMethodStubsDialogField = new MethodStubsListDialogField(
NewClassWizardMessages.NewClassCreationWizardPage_methodStubs_label, methodStubsAdapter);
FinalFieldAdapter finalAdapter = new FinalFieldAdapter();
fIsFinalClassField = new SelectionButtonDialogField(SWT.CHECK);
fIsFinalClassField.setDialogFieldListener(finalAdapter);
fIsFinalClassField.setLabelText(NewClassWizardMessages.NewClassCreationWizardPage_final_label);
FileGroupFieldAdapter fileGroupAdapter = new FileGroupFieldAdapter();
fHeaderFileDialogField = new StringButtonDialogField(fileGroupAdapter);
fHeaderFileDialogField.setDialogFieldListener(fileGroupAdapter);
@ -244,6 +260,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
fHeaderFileStatus = STATUS_OK;
fSourceFileStatus = STATUS_OK;
fTestFileStatus = STATUS_OK;
fIsFinalStatus = STATUS_OK;
fLastFocusedField = 0;
isFirstTime = true;
@ -275,6 +292,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
createClassNameControls(composite, nColumns);
createBaseClassesControls(composite, nColumns);
createMethodStubsControls(composite, nColumns);
createFinalClassControls(composite, nColumns);
createSeparator(composite, nColumns);
@ -359,6 +377,16 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
textControl.addFocusListener(new StatusFocusListener(CLASS_NAME_ID));
}
/**
* Creates the controls for the final class field.
*
* @param composite the parent composite
* @since 7.0
*/
protected void createFinalClassControls(Composite composite, int nColumns) {
fIsFinalClassField.doFillIntoGrid(composite, nColumns - 1);
}
/**
* Creates the controls for the base classes field. Expects a <code>GridLayout</code> with
* at least 3 columns.
@ -499,6 +527,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
addMethodStub(stub, getBooleanSettingWithDefault(KEY_STUB_SELECTED + i, stub.isEnabledByDefault()));
}
fIsFinalClassField.setSelection(fDialogSettings.getBoolean(KEY_FINAL_SELECTED));
setTestFileSelection(fDialogSettings.getBoolean(KEY_TEST_FILE_SELECTED), true);
handleFieldChanged(ALL_FIELDS);
}
@ -716,6 +745,16 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
return fClassNameDialogField.getText().trim();
}
/**
* Check if the class is final
*
* @return true if final, false otherwise
* @since 7.0
*/
public boolean isFinalClass() {
return fIsFinalClassField.isSelected();
}
/**
* Sets the text of the class name input field.
*
@ -1085,6 +1124,21 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
return null;
}
/**
* handles changes to the final field
*/
private final class FinalFieldAdapter implements IStringButtonAdapter, IDialogFieldListener {
@Override
public void changeControlPressed(DialogField field) {
handleFieldChanged(FINAL_ID);
}
@Override
public void dialogFieldChanged(DialogField field) {
handleFieldChanged(FINAL_ID);
}
}
/**
* handles changes to the namespace field
*/
@ -1471,6 +1525,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
if (fieldChanged(fields, TEST_FILE_ID)) {
fTestFileStatus = testFileChanged();
}
if (fieldChanged(fields, FINAL_ID)) {
fIsFinalStatus = finalChanged();
}
doStatusUpdate();
}
@ -1503,7 +1560,8 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
(fMethodStubsStatus != lastStatus) ? fMethodStubsStatus : STATUS_OK,
(fHeaderFileStatus != lastStatus) ? fHeaderFileStatus : STATUS_OK,
(fSourceFileStatus != lastStatus) ? fSourceFileStatus : STATUS_OK,
(fTestFileStatus != lastStatus) ? fTestFileStatus : STATUS_OK, };
(fTestFileStatus != lastStatus) ? fTestFileStatus : STATUS_OK,
(fIsFinalStatus != lastStatus) ? fIsFinalStatus : STATUS_OK, };
// the mode severe status will be displayed and the ok button enabled/disabled.
updateStatus(status);
@ -1532,6 +1590,8 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
return fSourceFileStatus;
case TEST_FILE_ID:
return fTestFileStatus;
case FINAL_ID:
return fIsFinalStatus;
default:
return STATUS_OK;
}
@ -1726,6 +1786,15 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
return status;
}
/**
* Final class field changed
* @return the status of the validation
* @since 7.0
*/
protected IStatus finalChanged() {
return Status.OK_STATUS;
}
/**
* Hook method that gets called when the list of base classes has changed. The method
* validates the base classes and returns the status of the validation.
@ -2080,6 +2149,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
// Update dialog settings.
fDialogSettings.put(KEY_NAMESPACE_SELECTED, fNamespaceSelection.isSelected());
fDialogSettings.put(KEY_TEST_FILE_SELECTED, fTestFileSelection.isSelected());
fDialogSettings.put(KEY_FINAL_SELECTED, fIsFinalClassField.isSelected());
String namespace = fNamespaceSelection.isSelected() ? getNamespaceText() : null;
fDialogSettings.put(KEY_NAMESPACE, namespace);
IMethodStub[] stubs = fMethodStubsDialogField.getMethodStubs();
@ -2103,7 +2173,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
IPath sourcePath = getSourceFileFullPath();
IPath testPath = getTestFileFullPath();
createClass(headerPath, sourcePath, testPath, getClassName(), namespace, getBaseClasses(),
getSelectedMethodStubs(), monitor);
getSelectedMethodStubs(), isFinalClass(), monitor);
}
/**
@ -2135,9 +2205,10 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/
protected void createClass(IPath headerPath, IPath sourcePath, IPath testPath, String className, String namespace,
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor) throws CoreException {
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, boolean isFinal, IProgressMonitor monitor)
throws CoreException {
NewClassCodeGenerator generator = new NewClassCodeGenerator(headerPath, sourcePath, testPath, className,
namespace, baseClasses, methodStubs);
namespace, baseClasses, methodStubs, isFinal);
generator.setForceSourceFileCreation(true);
generator.createClass(monitor);
@ -2156,6 +2227,15 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
createClass(headerPath, sourcePath, null, className, namespace, baseClasses, methodStubs, monitor);
}
/**
* @noreference This method is not intended to be referenced by clients.
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/
protected void createClass(IPath headerPath, IPath sourcePath, IPath testPath, String className, String namespace,
IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, IProgressMonitor monitor) throws CoreException {
createClass(headerPath, sourcePath, null, className, namespace, baseClasses, methodStubs, false, monitor);
}
/**
* Returns the created class. The method only returns a valid class
* after {@link #createClass} has been called.

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
Bundle-Version: 8.3.400.qualifier
Bundle-Version: 8.3.500.qualifier
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@ -50,7 +50,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.16.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.7.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.7.0,4.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[7.0.0,9.0.0)",
org.eclipse.cdt.ui;bundle-version="[6.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[7.0.0,8.0.0)",
org.eclipse.cdt.core;bundle-version="[5.0.0,7.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.console;bundle-version="[3.1.100,4.0.0)",

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true
Bundle-Version: 9.3.200.qualifier
Bundle-Version: 9.3.300.qualifier
Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.cdt.core;bundle-version="[5.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[6.0.0,7.0.0)",
org.eclipse.cdt.ui;bundle-version="[7.0.0,8.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[7.0.0,9.0.0)",
org.eclipse.cdt.debug.ui;bundle-version="[7.0.0,9.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",