Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2020-02-02 15:15:30 +0000
committerMarco Stornelli2020-02-08 07:13:59 +0000
commitccabaa21186315d47323d8c077b7b886c70aa14a (patch)
tree6d8ebf7d4f88f46d1983a763fa916c5a13476b23
parent5403404e09113fedf02ad25aa789f21324dfb53b (diff)
downloadorg.eclipse.cdt-ccabaa21186315d47323d8c077b7b886c70aa14a.tar.gz
org.eclipse.cdt-ccabaa21186315d47323d8c077b7b886c70aa14a.tar.xz
org.eclipse.cdt-ccabaa21186315d47323d8c077b7b886c70aa14a.zip
Bug 510789 - Added final field to class wizard
Change-Id: I4c404b8f0106e976b25b232a65bc3d313be1449f Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java1
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java90
4 files changed, 94 insertions, 6 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
index b5bbb7e4933..d2617974e7c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
@@ -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
@@ -125,7 +126,7 @@ public class NewClassCodeGenerator {
* @param methodStubs the method stubs
*/
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, IPath testPath, String className, String namespace,
- IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs) {
+ IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs, boolean isFinal) {
fHeaderPath = headerPath;
fSourcePath = sourcePath;
fTestPath = testPath;
@@ -142,6 +143,7 @@ public class NewClassCodeGenerator {
}
fBaseClasses = baseClasses;
fMethodStubs = methodStubs;
+ fIsFinal = isFinal;
}
public ICElement getCreatedClass() {
@@ -466,6 +468,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);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java
index 9ce8764e9d2..a5cc3daf353 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java
@@ -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;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
index d0d4b1b366d..2f5f6d457c5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
@@ -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.
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java
index 2365b4055e6..bfd01c3a0fe 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java
@@ -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 6.7*/
+ 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 6.7
+ */
+ 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 6.7
+ */
+ 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);
@@ -360,6 +378,16 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
/**
+ * Creates the controls for the final class field.
+ *
+ * @param composite the parent composite
+ * @since 6.7
+ */
+ 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);
}
@@ -717,6 +746,16 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
/**
+ * Check if the class is final
+ *
+ * @return true if final, false otherwise
+ * @since 6.7
+ */
+ public boolean isFinalClass() {
+ return fIsFinalClassField.isSelected();
+ }
+
+ /**
* Sets the text of the class name input field.
*
* @param name the new class name
@@ -1086,6 +1125,21 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
/**
+ * 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
*/
private final class NamespaceFieldAdapter implements IStringButtonAdapter, IDialogFieldListener {
@@ -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;
}
@@ -1727,6 +1787,15 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
/**
+ * Final class field changed
+ * @return the status of the validation
+ * @since 6.7
+ */
+ 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);
@@ -2157,6 +2228,15 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
/**
+ * @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.
*

Back to the top