diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java index d3e9a12f78f..46970bc3395 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java @@ -104,4 +104,9 @@ public abstract class AbstractMethodStub implements IMethodStub { @Override public abstract String createMethodImplementation(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, String lineDelimiter) throws CoreException; + + @Override + public boolean isEnabledByDefault() { + return true; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AssignOpMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AssignOpMethodStub.java new file mode 100644 index 00000000000..9609dd37ed6 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/AssignOpMethodStub.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2019 Marco Stornelli + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Marco Stornelli - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.classwizard; + +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.core.runtime.CoreException; + +public final class AssignOpMethodStub extends AbstractMethodStub { + private static String NAME = NewClassWizardMessages.NewClassCodeGeneration_stub_assign_op_name; + + public AssignOpMethodStub() { + this(ASTAccessVisibility.PUBLIC, false); + } + + public AssignOpMethodStub(ASTAccessVisibility access, boolean isInline) { + super(NAME, access, false, isInline); + } + + @Override + public String createMethodDeclaration(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("& operator=(const "); //$NON-NLS-1$ + buf.append(className); + buf.append("& other)"); //$NON-NLS-1$ + if (fIsInline) { + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getMethodBodyContent(tu, className, "operator=", null, lineDelimiter); //$NON-NLS-1$ + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + } else { + buf.append(";"); //$NON-NLS-1$ + } + return buf.toString(); + } + + @Override + public String createMethodImplementation(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + if (fIsInline) { + return ""; //$NON-NLS-1$ + } + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("& "); //$NON-NLS-1$ + buf.append(className); + buf.append("::"); //$NON-NLS-1$ + buf.append("operator=(const "); //$NON-NLS-1$ + buf.append(className); + buf.append("& other)"); //$NON-NLS-1$ + buf.append(lineDelimiter); + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getMethodBodyContent(tu, className, "operator=", null, lineDelimiter); //$NON-NLS-1$ + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + return buf.toString(); + } + + @Override + public boolean isConstructor() { + return false; + } + + @Override + public boolean isEnabledByDefault() { + return false; + } + + @Override + public boolean canModifyVirtual() { + return false; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/CopyConstructorMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/CopyConstructorMethodStub.java new file mode 100644 index 00000000000..2dbae40e58d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/CopyConstructorMethodStub.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2019 Marco Stornelli + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Marco Stornelli - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.classwizard; + +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.core.runtime.CoreException; + +public final class CopyConstructorMethodStub extends AbstractMethodStub { + private static String NAME = NewClassWizardMessages.NewClassCodeGeneration_stub_copy_constructor_name; + + public CopyConstructorMethodStub() { + this(ASTAccessVisibility.PUBLIC, false); + } + + public CopyConstructorMethodStub(ASTAccessVisibility access, boolean isInline) { + super(NAME, access, false, isInline); + } + + @Override + public String createMethodDeclaration(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("(const "); //$NON-NLS-1$ + buf.append(className); + buf.append("& other)"); //$NON-NLS-1$ + if (fIsInline) { + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getConstructorBodyContent(tu, className, null, lineDelimiter); + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + } else { + buf.append(";"); //$NON-NLS-1$ + } + return buf.toString(); + } + + @Override + public String createMethodImplementation(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + if (fIsInline) { + return ""; //$NON-NLS-1$ + } + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("::"); //$NON-NLS-1$ + buf.append(className); + buf.append("(const "); //$NON-NLS-1$ + buf.append(className); + buf.append("& other)"); //$NON-NLS-1$ + buf.append(lineDelimiter); + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getConstructorBodyContent(tu, className, null, lineDelimiter); + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + return buf.toString(); + } + + @Override + public boolean isConstructor() { + return true; + } + + @Override + public boolean isEnabledByDefault() { + return false; + } + + @Override + public boolean canModifyVirtual() { + return false; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java index 9026edc9ff6..7191ce89130 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java @@ -45,6 +45,8 @@ public interface IMethodStub { public boolean isDestructor(); + public boolean isEnabledByDefault(); + public String createMethodDeclaration(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, String lineDelimiter) throws CoreException; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveAssignOpMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveAssignOpMethodStub.java new file mode 100644 index 00000000000..b337e182383 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveAssignOpMethodStub.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2019 Marco Stornelli + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Marco Stornelli - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.classwizard; + +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.core.runtime.CoreException; + +public final class MoveAssignOpMethodStub extends AbstractMethodStub { + private static String NAME = NewClassWizardMessages.NewClassCodeGeneration_stub_move_op_name; + + public MoveAssignOpMethodStub() { + this(ASTAccessVisibility.PUBLIC, false); + } + + public MoveAssignOpMethodStub(ASTAccessVisibility access, boolean isInline) { + super(NAME, access, false, isInline); + } + + @Override + public String createMethodDeclaration(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("& operator=("); //$NON-NLS-1$ + buf.append(className); + buf.append("&& other)"); //$NON-NLS-1$ + if (fIsInline) { + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getMethodBodyContent(tu, className, "operator=", null, lineDelimiter); //$NON-NLS-1$ + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + } else { + buf.append(";"); //$NON-NLS-1$ + } + return buf.toString(); + } + + @Override + public String createMethodImplementation(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + if (fIsInline) { + return ""; //$NON-NLS-1$ + } + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("& "); //$NON-NLS-1$ + buf.append(className); + buf.append("::"); //$NON-NLS-1$ + buf.append("operator=("); //$NON-NLS-1$ + buf.append(className); + buf.append("&& other)"); //$NON-NLS-1$ + buf.append(lineDelimiter); + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getMethodBodyContent(tu, className, "operator=", null, lineDelimiter); //$NON-NLS-1$ + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + return buf.toString(); + } + + @Override + public boolean isConstructor() { + return false; + } + + @Override + public boolean isEnabledByDefault() { + return false; + } + + @Override + public boolean canModifyVirtual() { + return false; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveConstructorMethodStub.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveConstructorMethodStub.java new file mode 100644 index 00000000000..8213eede309 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/MoveConstructorMethodStub.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2019 Marco Stornelli + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Marco Stornelli - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.classwizard; + +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; +import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.core.runtime.CoreException; + +public final class MoveConstructorMethodStub extends AbstractMethodStub { + private static String NAME = NewClassWizardMessages.NewClassCodeGeneration_stub_move_constructor_name; + + public MoveConstructorMethodStub() { + this(ASTAccessVisibility.PUBLIC, false); + } + + public MoveConstructorMethodStub(ASTAccessVisibility access, boolean isInline) { + super(NAME, access, false, isInline); + } + + @Override + public String createMethodDeclaration(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("("); //$NON-NLS-1$ + buf.append(className); + buf.append("&& other)"); //$NON-NLS-1$ + if (fIsInline) { + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getConstructorBodyContent(tu, className, null, lineDelimiter); + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + } else { + buf.append(";"); //$NON-NLS-1$ + } + return buf.toString(); + } + + @Override + public String createMethodImplementation(ITranslationUnit tu, String className, IBaseClassInfo[] baseClasses, + String lineDelimiter) throws CoreException { + if (fIsInline) { + return ""; //$NON-NLS-1$ + } + StringBuilder buf = new StringBuilder(); + buf.append(className); + buf.append("::"); //$NON-NLS-1$ + buf.append(className); + buf.append("("); //$NON-NLS-1$ + buf.append(className); + buf.append("&& other)"); //$NON-NLS-1$ + buf.append(lineDelimiter); + buf.append('{'); + buf.append(lineDelimiter); + String body = CodeGeneration.getConstructorBodyContent(tu, className, null, lineDelimiter); + if (body != null) { + buf.append(body); + buf.append(lineDelimiter); + } + buf.append('}'); + return buf.toString(); + } + + @Override + public boolean isConstructor() { + return true; + } + + @Override + public boolean isEnabledByDefault() { + return false; + } + + @Override + public boolean canModifyVirtual() { + return false; + } +} 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 c6d9839e735..056d1e88789 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 @@ -123,6 +123,10 @@ public final class NewClassWizardMessages extends NLS { public static String NewClassCodeGeneration_createType_task_source; public static String NewClassCodeGeneration_stub_constructor_name; public static String NewClassCodeGeneration_stub_destructor_name; + public static String NewClassCodeGeneration_stub_copy_constructor_name; + public static String NewClassCodeGeneration_stub_move_constructor_name; + public static String NewClassCodeGeneration_stub_assign_op_name; + public static String NewClassCodeGeneration_stub_move_op_name; static { NLS.initializeMessages(NewClassWizardMessages.class.getName(), NewClassWizardMessages.class); 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 6bdf9721799..66386faa77a 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 @@ -151,3 +151,7 @@ NewClassCodeGeneration_createType_task_header_addIncludePaths=Adding new include NewClassCodeGeneration_createType_task_source=Creating source file.... NewClassCodeGeneration_stub_constructor_name=Constructor NewClassCodeGeneration_stub_destructor_name=Destructor +NewClassCodeGeneration_stub_copy_constructor_name=Copy constructor +NewClassCodeGeneration_stub_move_constructor_name=Move constructor +NewClassCodeGeneration_stub_assign_op_name=Copy assignment operator +NewClassCodeGeneration_stub_move_op_name=Move assignment operator 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 5608e93590f..1d2a9d3b45b 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 @@ -44,13 +44,17 @@ import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; import org.eclipse.cdt.internal.ui.util.SWTUtil; import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage; import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog; +import org.eclipse.cdt.internal.ui.wizards.classwizard.AssignOpMethodStub; import org.eclipse.cdt.internal.ui.wizards.classwizard.BaseClassInfo; import org.eclipse.cdt.internal.ui.wizards.classwizard.BaseClassesListDialogField; import org.eclipse.cdt.internal.ui.wizards.classwizard.ConstructorMethodStub; +import org.eclipse.cdt.internal.ui.wizards.classwizard.CopyConstructorMethodStub; import org.eclipse.cdt.internal.ui.wizards.classwizard.DestructorMethodStub; import org.eclipse.cdt.internal.ui.wizards.classwizard.IBaseClassInfo; import org.eclipse.cdt.internal.ui.wizards.classwizard.IMethodStub; import org.eclipse.cdt.internal.ui.wizards.classwizard.MethodStubsListDialogField; +import org.eclipse.cdt.internal.ui.wizards.classwizard.MoveAssignOpMethodStub; +import org.eclipse.cdt.internal.ui.wizards.classwizard.MoveConstructorMethodStub; import org.eclipse.cdt.internal.ui.wizards.classwizard.NamespaceSelectionDialog; import org.eclipse.cdt.internal.ui.wizards.classwizard.NewBaseClassSelectionDialog; import org.eclipse.cdt.internal.ui.wizards.classwizard.NewBaseClassSelectionDialog.ITypeSelectionListener; @@ -491,7 +495,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { if (stub.canModifyInline()) { stub.setInline(getBooleanSettingWithDefault(KEY_STUB_INLINE + i, stub.isInline())); } - addMethodStub(stub, getBooleanSettingWithDefault(KEY_STUB_SELECTED + i, true)); + addMethodStub(stub, getBooleanSettingWithDefault(KEY_STUB_SELECTED + i, stub.isEnabledByDefault())); } setTestFileSelection(fDialogSettings.getBoolean(KEY_TEST_FILE_SELECTED), true); @@ -574,7 +578,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { * @nooverride This method is not intended to be re-implemented or extended by clients. */ protected IMethodStub[] getDefaultMethodStubs() { - return new IMethodStub[] { new ConstructorMethodStub(), new DestructorMethodStub() }; + return new IMethodStub[] { new ConstructorMethodStub(), new DestructorMethodStub(), + new CopyConstructorMethodStub(), new MoveConstructorMethodStub(), new AssignOpMethodStub(), + new MoveAssignOpMethodStub() }; } /**