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:
parent
46fc8f5c77
commit
bbd3bc4e97
2 changed files with 49 additions and 33 deletions
|
@ -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)
|
||||||
|
|
|
@ -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,27 +142,39 @@ public class NewClassCodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fSourcePath != null) {
|
if (fSourcePath != null) {
|
||||||
IFile sourceFile = NewSourceFileGenerator.createSourceFile(fSourcePath, true, new SubProgressMonitor(monitor, 50));
|
|
||||||
if (sourceFile != null) {
|
// get method stubs
|
||||||
sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile);
|
List publicMethods = getStubs(ASTAccessVisibility.PUBLIC, true);
|
||||||
}
|
List protectedMethods = getStubs(ASTAccessVisibility.PROTECTED, true);
|
||||||
monitor.worked(50);
|
List privateMethods = getStubs(ASTAccessVisibility.PRIVATE, true);
|
||||||
|
|
||||||
// create a working copy with a new owner
|
if (publicMethods.isEmpty() && protectedMethods.isEmpty() && privateMethods.isEmpty()) {
|
||||||
sourceWorkingCopy = sourceTU.getWorkingCopy();
|
//TODO need prefs option
|
||||||
|
// don't create source file if no method bodies
|
||||||
String sourceContent = constructSourceFileContent(sourceTU, headerTU, new SubProgressMonitor(monitor, 100));
|
monitor.worked(100);
|
||||||
sourceWorkingCopy.getBuffer().setContents(sourceContent);
|
} else {
|
||||||
|
IFile sourceFile = NewSourceFileGenerator.createSourceFile(fSourcePath, true, new SubProgressMonitor(monitor, 50));
|
||||||
if (monitor.isCanceled()) {
|
if (sourceFile != null) {
|
||||||
throw new InterruptedException();
|
sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile);
|
||||||
}
|
}
|
||||||
|
monitor.worked(50);
|
||||||
sourceWorkingCopy.reconcile();
|
|
||||||
sourceWorkingCopy.commit(true, monitor);
|
// create a working copy with a new owner
|
||||||
monitor.worked(50);
|
sourceWorkingCopy = sourceTU.getWorkingCopy();
|
||||||
|
|
||||||
fCreatedSourceTU = sourceTU;
|
String sourceContent = constructSourceFileContent(sourceTU, headerTU, publicMethods, protectedMethods, privateMethods, new SubProgressMonitor(monitor, 100));
|
||||||
|
sourceWorkingCopy.getBuffer().setContents(sourceContent);
|
||||||
|
|
||||||
|
if (monitor.isCanceled()) {
|
||||||
|
throw new InterruptedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceWorkingCopy.reconcile();
|
||||||
|
sourceWorkingCopy.commit(true, monitor);
|
||||||
|
monitor.worked(50);
|
||||||
|
|
||||||
|
fCreatedSourceTU = sourceTU;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (headerWorkingCopy != null) {
|
if (headerWorkingCopy != null) {
|
||||||
|
@ -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$
|
||||||
|
@ -553,8 +568,8 @@ 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()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue