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

2004-08-25 Chris Wiebe

better handling of enclosing type
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardMessages.properties
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/ConstructorMethodStub.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/DestructorMethodStub.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
	* src/org/eclipse/cdt/internal/ui/wizards/NewClassCreationWizard.java
This commit is contained in:
Chris Wiebe 2004-08-26 02:25:32 +00:00
parent 2674ed534a
commit 2a2bfe1633
9 changed files with 669 additions and 561 deletions

View file

@ -1,3 +1,15 @@
2004-08-25 Chris Wiebe
better handling of enclosing type
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardMessages.properties
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/AbstractMethodStub.java
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/ConstructorMethodStub.java
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/DestructorMethodStub.java
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/IMethodStub.java
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
* src/org/eclipse/cdt/internal/ui/wizards/NewClassCreationWizard.java
2004-08-25 Chris Wiebe
support for matching enclosed type names

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
public abstract class AbstractMethodStub implements IMethodStub {
@ -78,7 +79,7 @@ public abstract class AbstractMethodStub implements IMethodStub {
return false;
}
public abstract String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public abstract String createMethodDeclaration(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public abstract String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public abstract String createMethodImplementation(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter);
}

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -25,10 +26,10 @@ public final class ConstructorMethodStub extends AbstractMethodStub {
super(NAME, access, false, isInline);
}
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
public String createMethodDeclaration(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
//TODO should use code templates
StringBuffer buf = new StringBuffer();
buf.append(className);
buf.append(className.toString());
buf.append("()"); //$NON-NLS-1$
if (fIsInline) {
buf.append(" {}"); //$NON-NLS-1$
@ -38,15 +39,15 @@ public final class ConstructorMethodStub extends AbstractMethodStub {
return buf.toString();
}
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
public String createMethodImplementation(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
//TODO should use code templates
if (fIsInline)
return ""; //$NON-NLS-1$
else {
StringBuffer buf = new StringBuffer();
buf.append(className);
buf.append(className.toString());
buf.append("::"); //$NON-NLS-1$
buf.append(className);
buf.append(className.toString());
buf.append("()"); //$NON-NLS-1$
buf.append(lineDelimiter);
buf.append('{');

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -25,14 +26,14 @@ public final class DestructorMethodStub extends AbstractMethodStub {
super(NAME, access, isVirtual, isInline);
}
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
public String createMethodDeclaration(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
//TODO should use code templates
StringBuffer buf = new StringBuffer();
if (fIsVirtual){
buf.append("virtual "); //$NON-NLS-1$
}
buf.append("~"); //$NON-NLS-1$
buf.append(className);
buf.append(className.toString());
buf.append("()"); //$NON-NLS-1$
if (fIsInline) {
buf.append(" {}"); //$NON-NLS-1$
@ -42,15 +43,15 @@ public final class DestructorMethodStub extends AbstractMethodStub {
return buf.toString();
}
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
public String createMethodImplementation(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
//TODO should use code templates
if (fIsInline)
return ""; //$NON-NLS-1$
else {
StringBuffer buf = new StringBuffer();
buf.append(className);
buf.append(className.toString());
buf.append("::~"); //$NON-NLS-1$
buf.append(className);
buf.append(className.toString());
buf.append("()"); //$NON-NLS-1$
buf.append(lineDelimiter);
buf.append('{');

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -32,6 +33,6 @@ public interface IMethodStub {
public boolean isConstructor();
public boolean isDestructor();
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public String createMethodDeclaration(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter);
public String createMethodImplementation(IQualifiedTypeName className, IBaseClassInfo[] baseClasses, String lineDelimiter);
}

View file

@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.model.CModelException;
@ -43,8 +44,8 @@ public class NewClassCodeGenerator {
private IPath fHeaderPath = null;
private IPath fSourcePath = null;
private String fClassName = null;
private String fNamespace = null;
private IQualifiedTypeName fClassName = null;
private IQualifiedTypeName fNamespace = null;
private String fLineDelimiter;
private IBaseClassInfo[] fBaseClasses = null;
private IMethodStub[] fMethodStubs = null;
@ -62,7 +63,7 @@ public class NewClassCodeGenerator {
}
}
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, String className, String namespace, IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs) {
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, IQualifiedTypeName className, IQualifiedTypeName namespace, IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs) {
fHeaderPath = headerPath;
fSourcePath = sourcePath;
fClassName = className;
@ -128,7 +129,7 @@ public class NewClassCodeGenerator {
headerWorkingCopy.commit(true, monitor);
monitor.worked(50);
createdClass = headerWorkingCopy.getElement(fClassName);
createdClass = headerWorkingCopy.getElement(fClassName.toString());
fCreatedClass = createdClass;
fCreatedHeaderTU = headerTU;
}
@ -203,7 +204,7 @@ public class NewClassCodeGenerator {
text.append(fLineDelimiter);
}
if (fNamespace != null && fNamespace.length() > 0) {
if (fNamespace != null) {
beginNamespace(text);
}
@ -230,7 +231,7 @@ public class NewClassCodeGenerator {
text.append("};"); //$NON-NLS-1$
text.append(fLineDelimiter);
if (fNamespace != null && fNamespace.length() > 0) {
if (fNamespace != null) {
endNamespace(text);
}
@ -265,20 +266,25 @@ public class NewClassCodeGenerator {
}
return insertPos;
}
private void beginNamespace(StringBuffer text) {
text.append("namespace "); //$NON-NLS-1$
text.append(fNamespace);
text.append(fLineDelimiter);
text.append('{');
text.append(fLineDelimiter);
text.append(fLineDelimiter);
String[] segments = fNamespace.segments();
for (int i = 0; i < segments.length; ++i) {
text.append("namespace "); //$NON-NLS-1$
text.append(segments[i]);
text.append(fLineDelimiter);
text.append('{');
text.append(fLineDelimiter);
text.append(fLineDelimiter);
}
}
private void endNamespace(StringBuffer text) {
text.append(fLineDelimiter);
text.append("};"); //$NON-NLS-1$
text.append(fLineDelimiter);
String[] segments = fNamespace.segments();
for (int i = 0; i < segments.length; ++i) {
text.append(fLineDelimiter);
text.append("};"); //$NON-NLS-1$
text.append(fLineDelimiter);
}
}
private void addMethodDeclarations(List publicMethods, List protectedMethods, List privateMethods, StringBuffer text) {
@ -573,13 +579,13 @@ public class NewClassCodeGenerator {
&& privateMethods.isEmpty()) {
// no methods
} else {
if (fNamespace != null && fNamespace.length() > 0) {
if (fNamespace != null) {
beginNamespace(text);
}
addMethodBodies(publicMethods, protectedMethods, privateMethods, text, new SubProgressMonitor(monitor, 50));
if (fNamespace != null && fNamespace.length() > 0) {
if (fNamespace != null) {
endNamespace(text);
}
}

View file

@ -31,48 +31,56 @@ NewClassCreationWizardPage.ChooseSourceFolderDialog.description=&Choose a source
NewClassCreationWizardPage.error.EnterSourceFolderName=Source folder name is empty.
NewClassCreationWizardPage.error.FolderDoesNotExist=Folder ''{0}'' does not exist.
NewClassCreationWizardPage.error.NotAFolder=''{0}'' is not a project or folder.
NewClassCreationWizardPage.error.NotASourceFolder=Folder ''{0}'' is not a valid source folder.
NewClassCreationWizardPage.error.NotASourceFolder=Folder ''{0}'' is not a source folder.
NewClassCreationWizardPage.error.ProjectClosed=Project ''{0}'' must be accessible.
NewClassCreationWizardPage.warning.NotACProject=Folder is not a C/C++ project.
NewClassCreationWizardPage.warning.NotInACProject=Folder is not in a C/C++ project.
NewClassCreationWizardPage.namespace.label=Namespace:
NewClassCreationWizardPage.namespace.button=Bro&wse...
NewClassCreationWizardPage.warning.NamespaceNotExists=Namespace does not exist. A new namespace will be created.
NewClassCreationWizardPage.error.NamespaceExistsDifferentCase=Namespace with same name but different case exists.
NewClassCreationWizardPage.error.InvalidNamespace=Namespace is not valid. {0}
NewClassCreationWizardPage.warning.NamespaceDiscouraged=Namespace is discouraged. {0}
NewClassCreationWizardPage.enclosingType.label=&Enclosing Type:
NewClassCreationWizardPage.enclosingType.namespace=Namespace
NewClassCreationWizardPage.enclosingType.class=Class
NewClassCreationWizardPage.enclosingType.button=Bro&wse...
NewClassCreationWizardPage.enclosingClassAccess.public=public
NewClassCreationWizardPage.enclosingClassAccess.protected=protected
NewClassCreationWizardPage.enclosingClassAccess.private=private
NewClassCreationWizardPage.error.EnterNamespace=Namespace is empty.
NewClassCreationWizardPage.error.EnclosingNamespaceNotExists=Enclosing namespace does not exist.
NewClassCreationWizardPage.error.NamespaceExistsDifferentCase=Namespace with the same name but different case exists.
NewClassCreationWizardPage.error.TypeMatchingNamespaceExists=Another type with the same name exists.
NewClassCreationWizardPage.error.TypeMatchingNamespaceExistsDifferentCase=Another type with the same name but different case exists.
NewClassCreationWizardPage.warning.NamespaceNotExists=Namespace does not exist. A new namespace will be created.
NewClassCreationWizardPage.error.InvalidNamespace=Namespace is not valid. {0}.
NewClassCreationWizardPage.warning.NamespaceDiscouraged=Namespace is discouraged. {0}.
NewClassCreationWizardPage.enclosingClass.label=&Enclosing Class:
NewClassCreationWizardPage.enclosingClass.button=Br&owse...
NewClassCreationWizardPage.error.EnterEnclosingClassName=Enclosing class name is empty.
NewClassCreationWizardPage.error.EnclosingClassNotExists=Enclosing class does not exist.
NewClassCreationWizardPage.error.EnclosingClassExistsDifferentCase=Enclosing class with same name but different case exists.
NewClassCreationWizardPage.error.InvalidEnclosingClassName=Enclosing class name is not valid. {0}
NewClassCreationWizardPage.error.EnclosingClassNotExistsInProject=Enclosing class does not exist in the current project.
NewClassCreationWizardPage.error.InvalidEnclosingClassName=Enclosing class name is not valid. {0}.
NewClassCreationWizardPage.error.noTypeCache=Unable to access type cache.
NewClassCreationWizardPage.className.label=Class &Name:
NewClassCreationWizardPage.error.EnterClassName=Class name is empty.
NewClassCreationWizardPage.error.ClassNameExists=Class already exists.
NewClassCreationWizardPage.error.ClassNameNotExists=Class does not exist.
NewClassCreationWizardPage.error.ClassNameExistsDifferentCase=Class with same name but different case exists.
NewClassCreationWizardPage.error.InvalidClassName=Class name is not valid. {0}
NewClassCreationWizardPage.error.QualifiedName=Class name must not be qualified.
NewClassCreationWizardPage.warning.ClassNameDiscouraged=Class name is discouraged. {0}
NewClassCreationWizardPage.error.TypeMatchingClassExists=Another type with the same name exists.
NewClassCreationWizardPage.error.TypeMatchingClassExistsDifferentCase=Another type with the same name but different case exists.
NewClassCreationWizardPage.error.InvalidClassName=Class name is not valid. {0}.
NewClassCreationWizardPage.error.QualifiedClassName=Class name must not be qualified.
NewClassCreationWizardPage.warning.ClassNameDiscouraged=Class name is discouraged. {0}.
NewClassCreationWizardPage.baseClasses.label=&Base Classes:
NewClassCreationWizardPage.error.InvalidBaseClassName=Base class name is not valid. {0}
NewClassCreationWizardPage.error.InvalidBaseClassName=Base class name is not valid. {0}.
NewClassCreationWizardPage.warning.BaseClassNotExistsInProject=Base class ''{0}'' not in include paths for current project.
NewClassCreationWizardPage.methodStubs.label=Method &Stubs:
NewClassCreationWizardPage.convention.filename.nullName=File name is blank.
NewClassCreationWizardPage.convention.filename.invalid=File name contains illegal characters.
NewClassCreationWizardPage.convention.filename.nameWithBlanks=File name contains spaces.
NewClassCreationWizardPage.convention.headerFilename.filetype=File extension does not correspond to known header file types.
NewClassCreationWizardPage.convention.sourceFilename.filetype=File extension does not correspond to known source file types.
NewClassCreationWizardPage.convention.filename.nullName=File name is blank
NewClassCreationWizardPage.convention.filename.invalid=File name contains illegal characters
NewClassCreationWizardPage.convention.filename.nameWithBlanks=File name contains spaces
NewClassCreationWizardPage.convention.headerFilename.filetype=File extension does not correspond to known header file types
NewClassCreationWizardPage.convention.sourceFilename.filetype=File extension does not correspond to known source file types
NewClassCreationWizardPage.error.NotAFile=''{0}'' is not a file.
NewClassCreationWizardPage.error.SourceFolderRequired=The source folder is required.
@ -83,9 +91,9 @@ NewClassCreationWizardPage.headerFile.button=Br&owse...
NewClassCreationWizardPage.ChooseHeaderFileDialog.title=Header File Selection
NewClassCreationWizardPage.error.EnterHeaderFileName=Header file name is empty.
NewClassCreationWizardPage.warning.NotAHeaderFile=''{0}'' is not a header file.
NewClassCreationWizardPage.warning.HeaderFileNameDiscouraged=Header file name is discouraged. {0}
NewClassCreationWizardPage.warning.HeaderFileNameDiscouraged=Header file name is discouraged. {0}.
NewClassCreationWizardPage.warning.HeaderFileExists=Header file already exists. Contents will be appended.
NewClassCreationWizardPage.error.InvalidHeaderFileName=Header file name is not valid. {0}
NewClassCreationWizardPage.error.InvalidHeaderFileName=Header file name is not valid. {0}.
NewClassCreationWizardPage.sourceFile.button=Br&owse...
NewClassCreationWizardPage.sourceFile.label=&Source:

View file

@ -48,7 +48,7 @@ public class NewClassCreationWizard extends NewElementWizard {
* @see org.eclipse.cdt.internal.ui.wizards.NewElementWizard#canRunForked()
*/
protected boolean canRunForked() {
return !fPage.isEnclosingClassSelected();
return !fPage.isEnclosingTypeSelected();
}
/*