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

Patch form Christophe Juniet to add a #ifdef guard

when generating a class file.
This commit is contained in:
Alain Magloire 2003-06-06 01:16:10 +00:00
parent d7275746e2
commit b18a703288
2 changed files with 32 additions and 5 deletions

View file

@ -146,6 +146,7 @@ NewClassWizardPage.baseclass.access.label=Access:
NewClassWizardPage.constdest.virtualdestructor=&Virtual Destructor NewClassWizardPage.constdest.virtualdestructor=&Virtual Destructor
NewClassWizardPage.constdest.inline=&Inline NewClassWizardPage.constdest.inline=&Inline
NewClassWizardPage.constdest.includeguard=Include &Guard
NewClassWizardPage.files.header=Header File: NewClassWizardPage.files.header=Header File:
NewClassWizardPage.files.body=Body File: NewClassWizardPage.files.body=Body File:

View file

@ -101,7 +101,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
private ITranslationUnit parentHeaderTU = null; private ITranslationUnit parentHeaderTU = null;
private ITranslationUnit parentBodyTU = null; private ITranslationUnit parentBodyTU = null;
// the created class element // the created class element
private IStructure createdClass = null; private /*IStructure*/ ICElement createdClass = null;
private ArrayList elementsOfTypeClassInProject = null; private ArrayList elementsOfTypeClassInProject = null;
@ -149,9 +149,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
String[] buttonNames2= new String[] { String[] buttonNames2= new String[] {
/* 0 == INLINE_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.inline"), /* 0 == INLINE_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.inline"),
/* 1 == VIRTUAL_DEST_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.virtualdestructor"), /* 1 == VIRTUAL_DEST_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.virtualdestructor"),
/* 2 == INCLUDE_GUARD_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.includeguard"),
}; };
fConstDestButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 4); fConstDestButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 3);
fConstDestButtons.setDialogFieldListener(adapter); fConstDestButtons.setDialogFieldListener(adapter);
linkedResourceGroupForHeader = new LinkToFileGroup(adapter, this); linkedResourceGroupForHeader = new LinkToFileGroup(adapter, this);
@ -456,6 +457,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
return fBaseClassDialogField.getText(); return fBaseClassDialogField.getText();
} }
public boolean isIncludeGuard(){
return fConstDestButtons.isSelected(2);
}
public boolean isVirtualDestructor(){ public boolean isVirtualDestructor(){
return fConstDestButtons.isSelected(1); return fConstDestButtons.isSelected(1);
} }
@ -482,7 +487,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
return parentBodyTU; return parentBodyTU;
} }
public IStructure getCreatedClassElement(){ public /*IStructure*/ ICElement getCreatedClassElement(){
return createdClass; return createdClass;
} }
@ -514,7 +519,8 @@ public class NewClassWizardPage extends WizardPage implements Listener {
headerWC.reconcile(); headerWC.reconcile();
headerWC.commit(true, monitor); headerWC.commit(true, monitor);
} }
createdClass= (IStructure)headerWC.getElement(getNewClassName()); //createdClass= (IStructure)headerWC.getElement(getNewClassName());
createdClass= headerWC.getElement(getNewClassName());
} }
if(parentBodyTU != null){ if(parentBodyTU != null){
String body = constructBodyFileContent(lineDelimiter); String body = constructBodyFileContent(lineDelimiter);
@ -742,6 +748,18 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
} }
if(isIncludeGuard()){
text.append("#ifndef ");
text.append(getNewClassName().toUpperCase());
text.append("_H");
text.append(lineDelimiter);
text.append("#define ");
text.append(getNewClassName().toUpperCase());
text.append("_H");
text.append(lineDelimiter);
text.append(lineDelimiter);
}
if(extendingBase){ if(extendingBase){
text.append("#include \""); text.append("#include \"");
text.append(baseClassFileName); text.append(baseClassFileName);
@ -794,6 +812,14 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append("};"); text.append("};");
text.append(lineDelimiter); text.append(lineDelimiter);
if(isIncludeGuard()){
text.append(lineDelimiter);
text.append("#endif // ");
text.append(getNewClassName().toUpperCase());
text.append("_H");
text.append(lineDelimiter);
}
return text.toString(); return text.toString();
} }