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

Patch for Hoda Amer

A fix for the incorrect inclusion problem in the New Class Wizard.
This commit is contained in:
John Camelon 2003-05-28 18:10:13 +00:00
parent 8ab6e1bb4c
commit c27d3e4175
10 changed files with 219 additions and 223 deletions

View file

@ -274,7 +274,7 @@ public interface ICElement extends IAdaptable {
* @exception CModelException if this element does not exist or if an * @exception CModelException if this element does not exist or if an
* exception occurs while accessing its underlying resource * exception occurs while accessing its underlying resource
*/ */
IResource getUnderlyingResource() throws CModelException; IResource getUnderlyingResource();
/** /**
* Returns the Corresponding resource for * Returns the Corresponding resource for

View file

@ -69,13 +69,9 @@ public abstract class CElement extends PlatformObject implements ICElement {
} }
public IPath getPath() { public IPath getPath() {
try { IResource res = getUnderlyingResource();
IResource res = getUnderlyingResource(); if (res != null)
if (res != null) return res.getFullPath();
return res.getFullPath();
} catch (CModelException e) {
e.printStackTrace();
}
return new Path(getElementName()); return new Path(getElementName());
} }
@ -84,13 +80,10 @@ public abstract class CElement extends PlatformObject implements ICElement {
} }
public boolean isReadOnly () { public boolean isReadOnly () {
try { IResource r = getUnderlyingResource();
IResource r = getUnderlyingResource(); if (r != null) {
if (r != null) { return r.isReadOnly();
return r.isReadOnly(); }
}
} catch (CModelException e) {
}
return false; return false;
} }
@ -156,7 +149,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
fEndLine = endLine; fEndLine = endLine;
} }
public IResource getUnderlyingResource() throws CModelException { public IResource getUnderlyingResource() {
IResource res = getResource(); IResource res = getResource();
if (res == null) { if (res == null) {
ICElement p = getParent(); ICElement p = getParent();

View file

@ -7,10 +7,8 @@ package org.eclipse.cdt.internal.core.model;
import java.io.File; import java.io.File;
import org.eclipse.core.resources.IResource;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.core.resources.IResource;
/** /**
* Holds cached structure and properties for a C element. * Holds cached structure and properties for a C element.
@ -140,11 +138,7 @@ class CElementInfo {
protected boolean hasChanged () { protected boolean hasChanged () {
IResource r = null; IResource r = null;
boolean b = false; boolean b = false;
try { r = getElement().getUnderlyingResource();
r = getElement().getUnderlyingResource();
} catch (CModelException e) {
e.printStackTrace();
}
if (r != null && r.exists()) { if (r != null && r.exists()) {
long modif = 0; long modif = 0;
switch(r.getType()) { switch(r.getType()) {

View file

@ -40,12 +40,7 @@ public class CModel extends CContainer implements ICModel {
} }
public IWorkspace getWorkspace() { public IWorkspace getWorkspace() {
try { return getUnderlyingResource().getWorkspace();
return getUnderlyingResource().getWorkspace();
} catch (CModelException e) {
e.printStackTrace();
}
return null;
} }
public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings, public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings,

View file

@ -37,12 +37,7 @@ public class CProject extends CContainer implements ICProject {
} }
public IProject getProject() { public IProject getProject() {
try { return getUnderlyingResource().getProject();
return getUnderlyingResource().getProject();
} catch (CModelException e) {
e.printStackTrace();
}
return null;
} }
public ICElement findElement(IPath path) throws CModelException { public ICElement findElement(IPath path) throws CModelException {

View file

@ -137,7 +137,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
/** /**
* @see ICElement * @see ICElement
*/ */
public IResource getUnderlyingResource() throws CModelException { public IResource getUnderlyingResource() {
return getParent().getUnderlyingResource(); return getParent().getUnderlyingResource();
} }

View file

@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.ui;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -47,36 +46,33 @@ public class CElementAdapterFactory implements IAdapterFactory {
ICElement celem = (ICElement) element; ICElement celem = (ICElement) element;
IResource res = null; IResource res = null;
try { if (IPropertySource.class.equals(key)) {
if (IPropertySource.class.equals(key)) { if (celem instanceof IBinary) {
if (celem instanceof IBinary) { return new BinaryPropertySource((IBinary)celem);
return new BinaryPropertySource((IBinary)celem); } else if (celem.getElementType() == ICElement.C_UNIT) {
} else if (celem.getElementType() == ICElement.C_UNIT) { IResource file = celem.getResource();
IResource file = celem.getResource(); if (file != null && file instanceof IFile) {
if (file != null && file instanceof IFile) { return new FilePropertySource((IFile)file);
return new FilePropertySource((IFile)file);
}
} else {
res = celem.getResource();
if (res != null) {
return new ResourcePropertySource(res);
}
} }
return new CElementPropertySource(celem); } else {
} else if (IWorkspaceRoot.class.equals(key)) {
res = celem.getUnderlyingResource();
if (res != null)
return res.getWorkspace().getRoot();
} else if (IProject.class.equals(key)) {
res = celem.getResource(); res = celem.getResource();
if (res != null) if (res != null) {
return res.getProject(); return new ResourcePropertySource(res);
} else if (IResource.class.equals(key)) { }
return celem.getResource();
} else if (IWorkbenchAdapter.class.equals(key)) {
return fgCWorkbenchAdapter;
} }
} catch (CModelException e) { return new CElementPropertySource(celem);
} else if (IWorkspaceRoot.class.equals(key)) {
res = celem.getUnderlyingResource();
if (res != null)
return res.getWorkspace().getRoot();
} else if (IProject.class.equals(key)) {
res = celem.getResource();
if (res != null)
return res.getProject();
} else if (IResource.class.equals(key)) {
return celem.getResource();
} else if (IWorkbenchAdapter.class.equals(key)) {
return fgCWorkbenchAdapter;
} }
return null; return null;
} }

View file

@ -10,7 +10,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
@ -42,7 +41,8 @@ import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.part.PluginDropAdapter; import org.eclipse.ui.part.PluginDropAdapter;
import org.eclipse.ui.part.ResourceTransfer; import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;; import org.eclipse.ui.wizards.datatransfer.ImportOperation;
;
/** /**
* Implements drop behaviour for drag and drop operations * Implements drop behaviour for drag and drop operations
@ -368,10 +368,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
Object obj = getCurrentTarget(); Object obj = getCurrentTarget();
IResource res = null; IResource res = null;
if (obj instanceof ICElement) { if (obj instanceof ICElement) {
try { res = ((ICElement)obj).getUnderlyingResource();
res = ((ICElement)obj).getUnderlyingResource();
} catch (CModelException e) {
}
} }
IContainer targetResource = getActualTarget(res); IContainer targetResource = getActualTarget(res);
String[] names = (String[]) data; String[] names = (String[]) data;
@ -392,10 +389,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
Object obj = getCurrentTarget(); Object obj = getCurrentTarget();
IResource res = null; IResource res = null;
if (obj instanceof ICElement) { if (obj instanceof ICElement) {
try { res = ((ICElement)obj).getUnderlyingResource();
res = ((ICElement)obj).getUnderlyingResource();
} catch (CModelException e) {
}
} }
IContainer targetResource = getActualTarget(res); IContainer targetResource = getActualTarget(res);
IResource[] sources = (IResource[]) data; IResource[] sources = (IResource[]) data;
@ -443,13 +437,10 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
*/ */
protected IStatus validateTarget(Object target) { protected IStatus validateTarget(Object target) {
if (target instanceof ICElement) { if (target instanceof ICElement) {
try { IResource r = ((ICElement)target).getUnderlyingResource();
IResource r = ((ICElement)target).getUnderlyingResource(); if (r == null)
if (r == null) return info("Target Must Be Resource"); //$NON-NLS-1$
return info("Target Must Be Resource"); //$NON-NLS-1$ target = r;
target = r;
} catch (CModelException e) {
}
} }
if (!(target instanceof IResource)) { if (!(target instanceof IResource)) {
return info("Target Must Be Resource"); //$NON-NLS-1$ return info("Target Must Be Resource"); //$NON-NLS-1$

View file

@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.ui.cview;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
@ -54,10 +53,7 @@ public class CViewSorter extends ViewerSorter {
return 40; return 40;
} else if (element instanceof ITranslationUnit) { } else if (element instanceof ITranslationUnit) {
IResource res = null; IResource res = null;
try { res = ((ITranslationUnit)element).getUnderlyingResource();
res = ((ITranslationUnit)element).getUnderlyingResource();
} catch (CModelException e) {
}
if (res != null) { if (res != null) {
String ext = res.getFileExtension(); String ext = res.getFileExtension();
if (ext != null) { if (ext != null) {

View file

@ -16,6 +16,7 @@ import java.io.InputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
@ -24,6 +25,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
@ -87,6 +89,8 @@ import org.eclipse.ui.internal.WorkbenchPlugin;
public class NewClassWizardPage extends WizardPage implements Listener { public class NewClassWizardPage extends WizardPage implements Listener {
// the page name // the page name
private final static String PAGE_NAME= "NewClassWizardPage"; private final static String PAGE_NAME= "NewClassWizardPage";
private final String HEADER_EXT = ".h";
private final String BODY_EXT = ".cpp";
// the current resource selection // the current resource selection
private IStructuredSelection currentSelection; private IStructuredSelection currentSelection;
@ -96,6 +100,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
// cache of newly-created files // cache of newly-created files
private ITranslationUnit parentHeaderTU = null; private ITranslationUnit parentHeaderTU = null;
private ITranslationUnit parentBodyTU = null; private ITranslationUnit parentBodyTU = null;
// the created class element
private IStructure createdClass = null;
private ArrayList elementsOfTypeClassInProject = null;
// Controls // Controls
private StringDialogField fClassNameDialogField; private StringDialogField fClassNameDialogField;
@ -115,7 +123,6 @@ public class NewClassWizardPage extends WizardPage implements Listener {
public NewClassWizardPage(IStructuredSelection selection) { public NewClassWizardPage(IStructuredSelection selection) {
super(PAGE_NAME); super(PAGE_NAME);
currentSelection = selection; currentSelection = selection;
eSelection = getSelectionCElement(currentSelection);
TypeFieldsAdapter adapter= new TypeFieldsAdapter(); TypeFieldsAdapter adapter= new TypeFieldsAdapter();
@ -160,7 +167,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
public void init() { public void init() {
fAccessButtons.setEnabled(false); fAccessButtons.setEnabled(false);
setPageComplete(false); setPageComplete(false);
eSelection = getSelectionCElement(currentSelection);
} }
// ----------------- Creating Controls -------------------- // ----------------- Creating Controls --------------------
@ -308,14 +315,14 @@ public class NewClassWizardPage extends WizardPage implements Listener {
String text = fClassNameDialogField.getText(); String text = fClassNameDialogField.getText();
if(!linkedResourceGroupForHeader.linkCreated()){ if(!linkedResourceGroupForHeader.linkCreated()){
if (text.length() > 0) { if (text.length() > 0) {
linkedResourceGroupForHeader.setText(text + ".h"); linkedResourceGroupForHeader.setText(text + HEADER_EXT);
} else { } else {
linkedResourceGroupForHeader.setText(text); linkedResourceGroupForHeader.setText(text);
} }
} }
if(!linkedResourceGroupForBody.linkCreated()){ if(!linkedResourceGroupForBody.linkCreated()){
if (text.length() > 0) { if (text.length() > 0) {
linkedResourceGroupForBody.setText(text + ".cpp"); linkedResourceGroupForBody.setText(text + BODY_EXT);
} else{ } else{
linkedResourceGroupForBody.setText(text); linkedResourceGroupForBody.setText(text);
} }
@ -337,7 +344,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
// --------------- Helper methods for creating controls ----- // --------------- Helper methods for creating controls -----
private static ICElement getSelectionCElement(IStructuredSelection sel) { private ICElement getSelectionCElement(IStructuredSelection sel) {
if (!sel.isEmpty() && sel instanceof IStructuredSelection) { if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
List list= ((IStructuredSelection)sel).toList(); List list= ((IStructuredSelection)sel).toList();
if (list.size() == 1) { if (list.size() == 1) {
@ -368,35 +375,39 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
} }
private ArrayList getClassElementsInProject(){
return elementsOfTypeClassInProject;
}
private ArrayList findClassElementsInProject(){ private ArrayList findClassElementsInProject(){
final ArrayList elementsOfTypeClassInProject = new ArrayList(); if( elementsOfTypeClassInProject == null ){
elementsOfTypeClassInProject = new ArrayList();
IRunnableWithProgress runnable= new IRunnableWithProgress() { IRunnableWithProgress runnable= new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();
} }
monitor.beginTask("", 5); //$NON-NLS-1$ monitor.beginTask("", 5); //$NON-NLS-1$
try{ try{
if(eSelection != null){ if(eSelection != null){
ICProject cProject = eSelection.getCProject(); ICProject cProject = eSelection.getCProject();
getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1); getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
}
monitor.worked(5);
} finally{
monitor.done();
} }
monitor.worked(5);
} finally{
monitor.done();
} }
};
try {
getWizard().getContainer().run(false, true, runnable);
} catch (InvocationTargetException e) {
} catch (InterruptedException e) {
}
finally {
} }
}; }
try {
getWizard().getContainer().run(false, true, runnable);
} catch (InvocationTargetException e) {
} catch (InterruptedException e) {
}
finally {
}
return elementsOfTypeClassInProject; return elementsOfTypeClassInProject;
} }
@ -418,24 +429,22 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
// ------------- getter methods for dialog controls ------------- // ------------- getter methods for dialog controls -------------
public String getHeaderFileName(){
return linkedResourceGroupForHeader.getText();
}
public String getBodyFileName(){
return linkedResourceGroupForBody.getText();
}
public String getNewClassName(){ public String getNewClassName(){
return fClassNameDialogField.getText(); return fClassNameDialogField.getText();
} }
public String getBaseClassName(){ public String getBaseClassName(){
return fBaseClassDialogField.getText(); return fBaseClassDialogField.getText();
} }
public boolean isVirtualDestructor(){ public boolean isVirtualDestructor(){
return fConstDestButtons.isSelected(1); return fConstDestButtons.isSelected(1);
} }
public boolean isInline(){ public boolean isInline(){
return fConstDestButtons.isSelected(0); return fConstDestButtons.isSelected(0);
} }
public String getAccess(){ public String getAccess(){
if(fAccessButtons.isSelected(0)) if(fAccessButtons.isSelected(0))
return "public"; return "public";
@ -454,7 +463,14 @@ public class NewClassWizardPage extends WizardPage implements Listener {
return parentBodyTU; return parentBodyTU;
} }
public IStructure getCreatedClassElement(){
return createdClass;
}
public IStructure getBaseClassElement(){
return null;
}
// -------------- Create a new Class ---------------------- // -------------- Create a new Class ----------------------
public void createClass(IProgressMonitor monitor){ public void createClass(IProgressMonitor monitor){
@ -465,10 +481,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
try{ try{
String lineDelimiter= null; String lineDelimiter= null;
lineDelimiter= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ lineDelimiter= System.getProperty("line.separator", "\n");
parentHeaderTU = createTranslationUnit(linkedResourceGroupForHeader, getHeaderFileName()); parentHeaderTU = createTranslationUnit(linkedResourceGroupForHeader);
parentBodyTU = createTranslationUnit(linkedResourceGroupForBody, getBodyFileName()); parentBodyTU = createTranslationUnit(linkedResourceGroupForBody);
monitor.worked(1); monitor.worked(1);
if(parentHeaderTU != null){ if(parentHeaderTU != null){
@ -479,6 +495,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
headerWC.reconcile(); headerWC.reconcile();
headerWC.commit(true, monitor); headerWC.commit(true, monitor);
} }
createdClass= (IStructure)headerWC.getElement(getNewClassName());
} }
if(parentBodyTU != null){ if(parentBodyTU != null){
String body = constructBodyFileContent(lineDelimiter); String body = constructBodyFileContent(lineDelimiter);
@ -498,7 +515,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
protected ITranslationUnit createTranslationUnit(LinkToFileGroup linkedGroup, String fileName){ protected ITranslationUnit createTranslationUnit(LinkToFileGroup linkedGroup){
ITranslationUnit createdUnit = null; ITranslationUnit createdUnit = null;
IFile createdFile = null; IFile createdFile = null;
createdFile= createNewFile(linkedGroup); createdFile= createNewFile(linkedGroup);
@ -681,103 +698,108 @@ public class NewClassWizardPage extends WizardPage implements Listener {
// ------------ Constructing File Contents ----------------- // ------------ Constructing File Contents -----------------
protected String constructHeaderFileContent(String lineDelimiter){ protected String constructHeaderFileContent(String lineDelimiter){
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
boolean extendingBase = false; boolean extendingBase = false;
String baseClassName = getBaseClassName(); String baseClassName = getBaseClassName();
if((baseClassName != null) && (baseClassName.length() > 0)) String baseClassFileName = "";
{ if((baseClassName != null) && (baseClassName.length() > 0))
extendingBase = true; {
} extendingBase = true;
ArrayList classElements = findClassElementsInProject();
ICElement baseClass = findInList(baseClassName, classElements);
if(baseClass != null){
baseClassFileName = baseClass.getUnderlyingResource().getName();
} else {
baseClassFileName = baseClassName + HEADER_EXT;
}
}
if(extendingBase){ if(extendingBase){
text.append("#include \""); text.append("#include \"");
text.append(baseClassName); text.append(baseClassFileName);
text.append('\"'); text.append('\"');
text.append(lineDelimiter); text.append(lineDelimiter);
text.append(lineDelimiter); text.append(lineDelimiter);
} }
text.append("class "); text.append("class ");
text.append(getNewClassName()); text.append(getNewClassName());
if(extendingBase){ if(extendingBase){
text.append(" : "); text.append(" : ");
text.append(getAccess()); text.append(getAccess());
text.append(" "); text.append(" ");
text.append(baseClassName); text.append(baseClassName);
} }
text.append("{"); text.append("{");
text.append(lineDelimiter); text.append(lineDelimiter);
text.append("public:");
text.append(lineDelimiter);
text.append(lineDelimiter);
// constructor text.append("public:");
text.append('\t'); text.append(lineDelimiter);
text.append(getNewClassName()); text.append(lineDelimiter);
text.append("()");
if(isInline()){
text.append(" {};");
text.append(lineDelimiter);
}else {
text.append(";");
text.append(lineDelimiter);
}
// constructor
text.append('\t');
text.append(getNewClassName());
text.append("()");
if(isInline()){
text.append(" {};");
text.append(lineDelimiter);
}else {
text.append(";");
text.append(lineDelimiter);
}
// destructor // destructor
text.append('\t'); text.append('\t');
if(isVirtualDestructor()){ if(isVirtualDestructor()){
text.append("virtual "); text.append("virtual ");
} }
text.append("~"); text.append("~");
text.append(getNewClassName()); text.append(getNewClassName());
text.append("()"); text.append("()");
if(isInline()){ if(isInline()){
text.append(" {};"); text.append(" {};");
text.append(lineDelimiter); text.append(lineDelimiter);
}else { }else {
text.append(";"); text.append(";");
text.append(lineDelimiter); text.append(lineDelimiter);
} }
text.append("};"); text.append("};");
text.append(lineDelimiter); text.append(lineDelimiter);
return text.toString(); return text.toString();
}
}
protected String constructBodyFileContent(String lineDelimiter){ protected String constructBodyFileContent(String lineDelimiter){
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
text.append("#include \""); text.append("#include \"");
text.append(getNewClassName()); text.append(getCreatedClassHeaderFile().getElementName());
text.append("\""); text.append("\"");
text.append(lineDelimiter); text.append(lineDelimiter);
text.append(lineDelimiter); text.append(lineDelimiter);
if(isInline()) if(isInline())
return text.toString(); return text.toString();
// constructor // constructor
text.append(getNewClassName()); text.append(getNewClassName());
text.append("::"); text.append("::");
text.append(getNewClassName()); text.append(getNewClassName());
text.append("()"); text.append("()");
text.append(lineDelimiter); text.append(lineDelimiter);
text.append("{};"); text.append("{};");
text.append(lineDelimiter); text.append(lineDelimiter);
// destructor // destructor
text.append(getNewClassName()); text.append(getNewClassName());
text.append("::~"); text.append("::~");
text.append(getNewClassName()); text.append(getNewClassName());
text.append("()"); text.append("()");
text.append(lineDelimiter); text.append(lineDelimiter);
text.append("{};"); text.append("{};");
text.append(lineDelimiter); text.append(lineDelimiter);
return text.toString();
return text.toString(); }
}
// ------ validation -------- // ------ validation --------
@ -855,15 +877,29 @@ public class NewClassWizardPage extends WizardPage implements Listener {
// class name must follow the C/CPP convensions // class name must follow the C/CPP convensions
// if class does not exist, give warning // if class does not exist, give warning
// ArrayList elementsFound = findClassElementsInProject(); ArrayList elementsFound = findClassElementsInProject();
// if(!foundInList(getBaseClassName(), elementsFound)){ if(!foundInList(getBaseClassName(), elementsFound)){
// status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$ status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
// } }
return status; return status;
} }
private ICElement findInList(String name, ArrayList elements){
Iterator i = elements.iterator();
while (i.hasNext()){
ICElement element = (ICElement)i.next();
if (name.equals(element.getElementName()))
return element;
}
return null;
}
private boolean foundInList(String name, ArrayList elements){ private boolean foundInList(String name, ArrayList elements){
return false; if(findInList(name, elements) != null)
return true;
else
return false;
} }
} }