1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

2004-11-05 Chris Wiebe

Fix for 56204 - empty source files are no longer created
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
This commit is contained in:
Chris Wiebe 2004-11-05 21:15:24 +00:00
parent 46fc8f5c77
commit bbd3bc4e97
2 changed files with 49 additions and 33 deletions

View file

@ -1,3 +1,8 @@
2004-11-05 Chris Wiebe
Fix for 56204 - empty source files are no longer created
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCodeGenerator.java
2004-11-05 Chris Wiebe 2004-11-05 Chris Wiebe
Remove option to use an existing class as enclosing type (defer to future release) Remove option to use an existing class as enclosing type (defer to future release)

View file

@ -110,6 +110,12 @@ public class NewClassCodeGenerator {
IWorkingCopy sourceWorkingCopy = null; IWorkingCopy sourceWorkingCopy = null;
try { try {
if (fHeaderPath != null) { if (fHeaderPath != null) {
// get method stubs
List publicMethods = getStubs(ASTAccessVisibility.PUBLIC, false);
List protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, false);
List privateMethods = getStubs(ASTAccessVisibility.PRIVATE, false);
IFile headerFile = NewSourceFileGenerator.createHeaderFile(fHeaderPath, true, new SubProgressMonitor(monitor, 50)); IFile headerFile = NewSourceFileGenerator.createHeaderFile(fHeaderPath, true, new SubProgressMonitor(monitor, 50));
if (headerFile != null) { if (headerFile != null) {
headerTU = (ITranslationUnit) CoreModel.getDefault().create(headerFile); headerTU = (ITranslationUnit) CoreModel.getDefault().create(headerFile);
@ -119,7 +125,7 @@ public class NewClassCodeGenerator {
headerWorkingCopy = headerTU.getWorkingCopy(); headerWorkingCopy = headerTU.getWorkingCopy();
// headerWorkingCopy = headerTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory()); // headerWorkingCopy = headerTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory());
String headerContent = constructHeaderFileContent(headerTU, headerWorkingCopy.getBuffer().getContents(), new SubProgressMonitor(monitor, 100)); String headerContent = constructHeaderFileContent(headerTU, publicMethods, protectedMethods, privateMethods, headerWorkingCopy.getBuffer().getContents(), new SubProgressMonitor(monitor, 100));
headerWorkingCopy.getBuffer().setContents(headerContent); headerWorkingCopy.getBuffer().setContents(headerContent);
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
@ -136,6 +142,17 @@ public class NewClassCodeGenerator {
} }
if (fSourcePath != null) { if (fSourcePath != null) {
// get method stubs
List publicMethods = getStubs(ASTAccessVisibility.PUBLIC, true);
List protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, true);
List privateMethods = getStubs(ASTAccessVisibility.PRIVATE, true);
if (publicMethods.isEmpty() && protectedMethods.isEmpty() && privateMethods.isEmpty()) {
//TODO need prefs option
// don't create source file if no method bodies
monitor.worked(100);
} else {
IFile sourceFile = NewSourceFileGenerator.createSourceFile(fSourcePath, true, new SubProgressMonitor(monitor, 50)); IFile sourceFile = NewSourceFileGenerator.createSourceFile(fSourcePath, true, new SubProgressMonitor(monitor, 50));
if (sourceFile != null) { if (sourceFile != null) {
sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile); sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile);
@ -145,7 +162,7 @@ public class NewClassCodeGenerator {
// create a working copy with a new owner // create a working copy with a new owner
sourceWorkingCopy = sourceTU.getWorkingCopy(); sourceWorkingCopy = sourceTU.getWorkingCopy();
String sourceContent = constructSourceFileContent(sourceTU, headerTU, new SubProgressMonitor(monitor, 100)); String sourceContent = constructSourceFileContent(sourceTU, headerTU, publicMethods, protectedMethods, privateMethods, new SubProgressMonitor(monitor, 100));
sourceWorkingCopy.getBuffer().setContents(sourceContent); sourceWorkingCopy.getBuffer().setContents(sourceContent);
if (monitor.isCanceled()) { if (monitor.isCanceled()) {
@ -158,6 +175,7 @@ public class NewClassCodeGenerator {
fCreatedSourceTU = sourceTU; fCreatedSourceTU = sourceTU;
} }
}
} finally { } finally {
if (headerWorkingCopy != null) { if (headerWorkingCopy != null) {
headerWorkingCopy.destroy(); headerWorkingCopy.destroy();
@ -171,7 +189,7 @@ public class NewClassCodeGenerator {
return fCreatedClass; return fCreatedClass;
} }
public String constructHeaderFileContent(ITranslationUnit headerTU, String oldContents, IProgressMonitor monitor) throws CodeGeneratorException { public String constructHeaderFileContent(ITranslationUnit headerTU, List publicMethods, List protectedMethods, List privateMethods, String oldContents, IProgressMonitor monitor) throws CodeGeneratorException {
monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createType.task.header"), 100); //$NON-NLS-1$ monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createType.task.header"), 100); //$NON-NLS-1$
@ -217,10 +235,6 @@ public class NewClassCodeGenerator {
text.append(fLineDelimiter); text.append(fLineDelimiter);
//TODO sort methods (eg constructor always first?) //TODO sort methods (eg constructor always first?)
List publicMethods = getStubs(ASTAccessVisibility.PUBLIC, false);
List protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, false);
List privateMethods = getStubs(ASTAccessVisibility.PRIVATE, false);
if (!publicMethods.isEmpty() if (!publicMethods.isEmpty()
|| !protectedMethods.isEmpty() || !protectedMethods.isEmpty()
|| !privateMethods.isEmpty()) { || !privateMethods.isEmpty()) {
@ -265,6 +279,7 @@ public class NewClassCodeGenerator {
} }
return insertPos; return insertPos;
} }
private void beginNamespace(StringBuffer text) { private void beginNamespace(StringBuffer text) {
for (int i = 0; i < fNamespace.segmentCount(); ++i) { for (int i = 0; i < fNamespace.segmentCount(); ++i) {
text.append("namespace "); //$NON-NLS-1$ text.append("namespace "); //$NON-NLS-1$
@ -554,7 +569,7 @@ public class NewClassCodeGenerator {
return list; return list;
} }
public String constructSourceFileContent(ITranslationUnit sourceTU, ITranslationUnit headerTU, IProgressMonitor monitor) { public String constructSourceFileContent(ITranslationUnit sourceTU, ITranslationUnit headerTU, List publicMethods, List protectedMethods, List privateMethods, IProgressMonitor monitor) {
monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createType.task.source"), 150); //$NON-NLS-1$ monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createType.task.source"), 150); //$NON-NLS-1$
@ -567,10 +582,6 @@ public class NewClassCodeGenerator {
} }
//TODO sort methods (eg constructor always first?) //TODO sort methods (eg constructor always first?)
List publicMethods = getStubs(ASTAccessVisibility.PUBLIC, true);
List protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, true);
List privateMethods = getStubs(ASTAccessVisibility.PRIVATE, true);
if (publicMethods.isEmpty() if (publicMethods.isEmpty()
&& protectedMethods.isEmpty() && protectedMethods.isEmpty()
&& privateMethods.isEmpty()) { && privateMethods.isEmpty()) {