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:
parent
8ab6e1bb4c
commit
c27d3e4175
10 changed files with 219 additions and 223 deletions
|
@ -274,7 +274,7 @@ public interface ICElement extends IAdaptable {
|
|||
* @exception CModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its underlying resource
|
||||
*/
|
||||
IResource getUnderlyingResource() throws CModelException;
|
||||
IResource getUnderlyingResource();
|
||||
|
||||
/**
|
||||
* Returns the Corresponding resource for
|
||||
|
|
|
@ -69,13 +69,9 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
}
|
||||
|
||||
public IPath getPath() {
|
||||
try {
|
||||
IResource res = getUnderlyingResource();
|
||||
if (res != null)
|
||||
return res.getFullPath();
|
||||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IResource res = getUnderlyingResource();
|
||||
if (res != null)
|
||||
return res.getFullPath();
|
||||
return new Path(getElementName());
|
||||
}
|
||||
|
||||
|
@ -84,13 +80,10 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
}
|
||||
|
||||
public boolean isReadOnly () {
|
||||
try {
|
||||
IResource r = getUnderlyingResource();
|
||||
if (r != null) {
|
||||
return r.isReadOnly();
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
IResource r = getUnderlyingResource();
|
||||
if (r != null) {
|
||||
return r.isReadOnly();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -156,7 +149,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
fEndLine = endLine;
|
||||
}
|
||||
|
||||
public IResource getUnderlyingResource() throws CModelException {
|
||||
public IResource getUnderlyingResource() {
|
||||
IResource res = getResource();
|
||||
if (res == null) {
|
||||
ICElement p = getParent();
|
||||
|
|
|
@ -7,10 +7,8 @@ package org.eclipse.cdt.internal.core.model;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
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.
|
||||
|
@ -140,11 +138,7 @@ class CElementInfo {
|
|||
protected boolean hasChanged () {
|
||||
IResource r = null;
|
||||
boolean b = false;
|
||||
try {
|
||||
r = getElement().getUnderlyingResource();
|
||||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
r = getElement().getUnderlyingResource();
|
||||
if (r != null && r.exists()) {
|
||||
long modif = 0;
|
||||
switch(r.getType()) {
|
||||
|
|
|
@ -40,12 +40,7 @@ public class CModel extends CContainer implements ICModel {
|
|||
}
|
||||
|
||||
public IWorkspace getWorkspace() {
|
||||
try {
|
||||
return getUnderlyingResource().getWorkspace();
|
||||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return getUnderlyingResource().getWorkspace();
|
||||
}
|
||||
|
||||
public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings,
|
||||
|
|
|
@ -37,12 +37,7 @@ public class CProject extends CContainer implements ICProject {
|
|||
}
|
||||
|
||||
public IProject getProject() {
|
||||
try {
|
||||
return getUnderlyingResource().getProject();
|
||||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return getUnderlyingResource().getProject();
|
||||
}
|
||||
|
||||
public ICElement findElement(IPath path) throws CModelException {
|
||||
|
|
|
@ -137,7 +137,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
|
|||
/**
|
||||
* @see ICElement
|
||||
*/
|
||||
public IResource getUnderlyingResource() throws CModelException {
|
||||
public IResource getUnderlyingResource() {
|
||||
return getParent().getUnderlyingResource();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.ui;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBinary;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -47,36 +46,33 @@ public class CElementAdapterFactory implements IAdapterFactory {
|
|||
ICElement celem = (ICElement) element;
|
||||
IResource res = null;
|
||||
|
||||
try {
|
||||
if (IPropertySource.class.equals(key)) {
|
||||
if (celem instanceof IBinary) {
|
||||
return new BinaryPropertySource((IBinary)celem);
|
||||
} else if (celem.getElementType() == ICElement.C_UNIT) {
|
||||
IResource file = celem.getResource();
|
||||
if (file != null && file instanceof IFile) {
|
||||
return new FilePropertySource((IFile)file);
|
||||
}
|
||||
} else {
|
||||
res = celem.getResource();
|
||||
if (res != null) {
|
||||
return new ResourcePropertySource(res);
|
||||
}
|
||||
if (IPropertySource.class.equals(key)) {
|
||||
if (celem instanceof IBinary) {
|
||||
return new BinaryPropertySource((IBinary)celem);
|
||||
} else if (celem.getElementType() == ICElement.C_UNIT) {
|
||||
IResource file = celem.getResource();
|
||||
if (file != null && file instanceof IFile) {
|
||||
return new FilePropertySource((IFile)file);
|
||||
}
|
||||
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)) {
|
||||
} else {
|
||||
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;
|
||||
if (res != null) {
|
||||
return new ResourcePropertySource(res);
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.ResourceTransfer;
|
||||
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
|
||||
|
@ -368,10 +368,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
|||
Object obj = getCurrentTarget();
|
||||
IResource res = null;
|
||||
if (obj instanceof ICElement) {
|
||||
try {
|
||||
res = ((ICElement)obj).getUnderlyingResource();
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
res = ((ICElement)obj).getUnderlyingResource();
|
||||
}
|
||||
IContainer targetResource = getActualTarget(res);
|
||||
String[] names = (String[]) data;
|
||||
|
@ -392,10 +389,7 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
|||
Object obj = getCurrentTarget();
|
||||
IResource res = null;
|
||||
if (obj instanceof ICElement) {
|
||||
try {
|
||||
res = ((ICElement)obj).getUnderlyingResource();
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
res = ((ICElement)obj).getUnderlyingResource();
|
||||
}
|
||||
IContainer targetResource = getActualTarget(res);
|
||||
IResource[] sources = (IResource[]) data;
|
||||
|
@ -443,13 +437,10 @@ class CViewDropAdapter extends PluginDropAdapter implements IOverwriteQuery {
|
|||
*/
|
||||
protected IStatus validateTarget(Object target) {
|
||||
if (target instanceof ICElement) {
|
||||
try {
|
||||
IResource r = ((ICElement)target).getUnderlyingResource();
|
||||
if (r == null)
|
||||
return info("Target Must Be Resource"); //$NON-NLS-1$
|
||||
target = r;
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
IResource r = ((ICElement)target).getUnderlyingResource();
|
||||
if (r == null)
|
||||
return info("Target Must Be Resource"); //$NON-NLS-1$
|
||||
target = r;
|
||||
}
|
||||
if (!(target instanceof IResource)) {
|
||||
return info("Target Must Be Resource"); //$NON-NLS-1$
|
||||
|
|
|
@ -5,7 +5,6 @@ package org.eclipse.cdt.internal.ui.cview;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.IArchive;
|
||||
import org.eclipse.cdt.core.model.IArchiveContainer;
|
||||
|
@ -54,10 +53,7 @@ public class CViewSorter extends ViewerSorter {
|
|||
return 40;
|
||||
} else if (element instanceof ITranslationUnit) {
|
||||
IResource res = null;
|
||||
try {
|
||||
res = ((ITranslationUnit)element).getUnderlyingResource();
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
res = ((ITranslationUnit)element).getUnderlyingResource();
|
||||
if (res != null) {
|
||||
String ext = res.getFileExtension();
|
||||
if (ext != null) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.io.InputStream;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
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.IOpenable;
|
||||
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.internal.core.model.IWorkingCopy;
|
||||
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 {
|
||||
// the page name
|
||||
private final static String PAGE_NAME= "NewClassWizardPage";
|
||||
private final String HEADER_EXT = ".h";
|
||||
private final String BODY_EXT = ".cpp";
|
||||
|
||||
// the current resource selection
|
||||
private IStructuredSelection currentSelection;
|
||||
|
@ -96,6 +100,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
// cache of newly-created files
|
||||
private ITranslationUnit parentHeaderTU = null;
|
||||
private ITranslationUnit parentBodyTU = null;
|
||||
// the created class element
|
||||
private IStructure createdClass = null;
|
||||
|
||||
private ArrayList elementsOfTypeClassInProject = null;
|
||||
|
||||
// Controls
|
||||
private StringDialogField fClassNameDialogField;
|
||||
|
@ -115,7 +123,6 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
public NewClassWizardPage(IStructuredSelection selection) {
|
||||
super(PAGE_NAME);
|
||||
currentSelection = selection;
|
||||
eSelection = getSelectionCElement(currentSelection);
|
||||
|
||||
TypeFieldsAdapter adapter= new TypeFieldsAdapter();
|
||||
|
||||
|
@ -160,7 +167,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
public void init() {
|
||||
fAccessButtons.setEnabled(false);
|
||||
setPageComplete(false);
|
||||
|
||||
eSelection = getSelectionCElement(currentSelection);
|
||||
}
|
||||
|
||||
// ----------------- Creating Controls --------------------
|
||||
|
@ -308,14 +315,14 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
String text = fClassNameDialogField.getText();
|
||||
if(!linkedResourceGroupForHeader.linkCreated()){
|
||||
if (text.length() > 0) {
|
||||
linkedResourceGroupForHeader.setText(text + ".h");
|
||||
linkedResourceGroupForHeader.setText(text + HEADER_EXT);
|
||||
} else {
|
||||
linkedResourceGroupForHeader.setText(text);
|
||||
}
|
||||
}
|
||||
if(!linkedResourceGroupForBody.linkCreated()){
|
||||
if (text.length() > 0) {
|
||||
linkedResourceGroupForBody.setText(text + ".cpp");
|
||||
linkedResourceGroupForBody.setText(text + BODY_EXT);
|
||||
} else{
|
||||
linkedResourceGroupForBody.setText(text);
|
||||
}
|
||||
|
@ -337,7 +344,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
}
|
||||
|
||||
// --------------- Helper methods for creating controls -----
|
||||
private static ICElement getSelectionCElement(IStructuredSelection sel) {
|
||||
private ICElement getSelectionCElement(IStructuredSelection sel) {
|
||||
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
|
||||
List list= ((IStructuredSelection)sel).toList();
|
||||
if (list.size() == 1) {
|
||||
|
@ -368,35 +375,39 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
private ArrayList getClassElementsInProject(){
|
||||
return elementsOfTypeClassInProject;
|
||||
}
|
||||
|
||||
private ArrayList findClassElementsInProject(){
|
||||
final ArrayList elementsOfTypeClassInProject = new ArrayList();
|
||||
|
||||
IRunnableWithProgress runnable= new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
if (monitor == null) {
|
||||
monitor= new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask("", 5); //$NON-NLS-1$
|
||||
try{
|
||||
if(eSelection != null){
|
||||
ICProject cProject = eSelection.getCProject();
|
||||
getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||
if( elementsOfTypeClassInProject == null ){
|
||||
elementsOfTypeClassInProject = new ArrayList();
|
||||
IRunnableWithProgress runnable= new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
if (monitor == null) {
|
||||
monitor= new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask("", 5); //$NON-NLS-1$
|
||||
try{
|
||||
if(eSelection != null){
|
||||
ICProject cProject = eSelection.getCProject();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -418,24 +429,22 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
}
|
||||
|
||||
// ------------- getter methods for dialog controls -------------
|
||||
public String getHeaderFileName(){
|
||||
return linkedResourceGroupForHeader.getText();
|
||||
}
|
||||
public String getBodyFileName(){
|
||||
return linkedResourceGroupForBody.getText();
|
||||
}
|
||||
public String getNewClassName(){
|
||||
return fClassNameDialogField.getText();
|
||||
}
|
||||
|
||||
public String getBaseClassName(){
|
||||
return fBaseClassDialogField.getText();
|
||||
}
|
||||
|
||||
public boolean isVirtualDestructor(){
|
||||
return fConstDestButtons.isSelected(1);
|
||||
}
|
||||
|
||||
public boolean isInline(){
|
||||
return fConstDestButtons.isSelected(0);
|
||||
}
|
||||
|
||||
public String getAccess(){
|
||||
if(fAccessButtons.isSelected(0))
|
||||
return "public";
|
||||
|
@ -454,7 +463,14 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
return parentBodyTU;
|
||||
}
|
||||
|
||||
|
||||
public IStructure getCreatedClassElement(){
|
||||
return createdClass;
|
||||
}
|
||||
|
||||
public IStructure getBaseClassElement(){
|
||||
|
||||
return null;
|
||||
}
|
||||
// -------------- Create a new Class ----------------------
|
||||
|
||||
public void createClass(IProgressMonitor monitor){
|
||||
|
@ -465,10 +481,10 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
try{
|
||||
|
||||
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());
|
||||
parentBodyTU = createTranslationUnit(linkedResourceGroupForBody, getBodyFileName());
|
||||
parentHeaderTU = createTranslationUnit(linkedResourceGroupForHeader);
|
||||
parentBodyTU = createTranslationUnit(linkedResourceGroupForBody);
|
||||
monitor.worked(1);
|
||||
|
||||
if(parentHeaderTU != null){
|
||||
|
@ -479,6 +495,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
headerWC.reconcile();
|
||||
headerWC.commit(true, monitor);
|
||||
}
|
||||
createdClass= (IStructure)headerWC.getElement(getNewClassName());
|
||||
}
|
||||
if(parentBodyTU != null){
|
||||
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;
|
||||
IFile createdFile = null;
|
||||
createdFile= createNewFile(linkedGroup);
|
||||
|
@ -681,103 +698,108 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
|
||||
// ------------ Constructing File Contents -----------------
|
||||
protected String constructHeaderFileContent(String lineDelimiter){
|
||||
StringBuffer text = new StringBuffer();
|
||||
boolean extendingBase = false;
|
||||
String baseClassName = getBaseClassName();
|
||||
if((baseClassName != null) && (baseClassName.length() > 0))
|
||||
{
|
||||
extendingBase = true;
|
||||
}
|
||||
StringBuffer text = new StringBuffer();
|
||||
boolean extendingBase = false;
|
||||
String baseClassName = getBaseClassName();
|
||||
String baseClassFileName = "";
|
||||
if((baseClassName != null) && (baseClassName.length() > 0))
|
||||
{
|
||||
extendingBase = true;
|
||||
ArrayList classElements = findClassElementsInProject();
|
||||
ICElement baseClass = findInList(baseClassName, classElements);
|
||||
|
||||
if(baseClass != null){
|
||||
baseClassFileName = baseClass.getUnderlyingResource().getName();
|
||||
} else {
|
||||
baseClassFileName = baseClassName + HEADER_EXT;
|
||||
}
|
||||
}
|
||||
|
||||
if(extendingBase){
|
||||
text.append("#include \"");
|
||||
text.append(baseClassName);
|
||||
text.append('\"');
|
||||
text.append(lineDelimiter);
|
||||
text.append(lineDelimiter);
|
||||
}
|
||||
text.append("class ");
|
||||
text.append(getNewClassName());
|
||||
if(extendingBase){
|
||||
text.append(" : ");
|
||||
text.append(getAccess());
|
||||
text.append(" ");
|
||||
text.append(baseClassName);
|
||||
}
|
||||
text.append("{");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
text.append("public:");
|
||||
text.append(lineDelimiter);
|
||||
text.append(lineDelimiter);
|
||||
if(extendingBase){
|
||||
text.append("#include \"");
|
||||
text.append(baseClassFileName);
|
||||
text.append('\"');
|
||||
text.append(lineDelimiter);
|
||||
text.append(lineDelimiter);
|
||||
}
|
||||
text.append("class ");
|
||||
text.append(getNewClassName());
|
||||
if(extendingBase){
|
||||
text.append(" : ");
|
||||
text.append(getAccess());
|
||||
text.append(" ");
|
||||
text.append(baseClassName);
|
||||
}
|
||||
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);
|
||||
}
|
||||
text.append("public:");
|
||||
text.append(lineDelimiter);
|
||||
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
|
||||
text.append('\t');
|
||||
if(isVirtualDestructor()){
|
||||
text.append("virtual ");
|
||||
}
|
||||
text.append("~");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
if(isInline()){
|
||||
text.append(" {};");
|
||||
text.append(lineDelimiter);
|
||||
}else {
|
||||
text.append(";");
|
||||
text.append(lineDelimiter);
|
||||
}
|
||||
text.append("};");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
// destructor
|
||||
text.append('\t');
|
||||
if(isVirtualDestructor()){
|
||||
text.append("virtual ");
|
||||
}
|
||||
text.append("~");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
if(isInline()){
|
||||
text.append(" {};");
|
||||
text.append(lineDelimiter);
|
||||
}else {
|
||||
text.append(";");
|
||||
text.append(lineDelimiter);
|
||||
}
|
||||
text.append("};");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
return text.toString();
|
||||
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
protected String constructBodyFileContent(String lineDelimiter){
|
||||
StringBuffer text = new StringBuffer();
|
||||
text.append("#include \"");
|
||||
text.append(getNewClassName());
|
||||
text.append("\"");
|
||||
text.append(lineDelimiter);
|
||||
text.append(lineDelimiter);
|
||||
protected String constructBodyFileContent(String lineDelimiter){
|
||||
StringBuffer text = new StringBuffer();
|
||||
text.append("#include \"");
|
||||
text.append(getCreatedClassHeaderFile().getElementName());
|
||||
text.append("\"");
|
||||
text.append(lineDelimiter);
|
||||
text.append(lineDelimiter);
|
||||
|
||||
if(isInline())
|
||||
return text.toString();
|
||||
|
||||
// constructor
|
||||
text.append(getNewClassName());
|
||||
text.append("::");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
text.append(lineDelimiter);
|
||||
text.append("{};");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
// destructor
|
||||
text.append(getNewClassName());
|
||||
text.append("::~");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
text.append(lineDelimiter);
|
||||
text.append("{};");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
return text.toString();
|
||||
}
|
||||
if(isInline())
|
||||
return text.toString();
|
||||
|
||||
// constructor
|
||||
text.append(getNewClassName());
|
||||
text.append("::");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
text.append(lineDelimiter);
|
||||
text.append("{};");
|
||||
text.append(lineDelimiter);
|
||||
|
||||
// destructor
|
||||
text.append(getNewClassName());
|
||||
text.append("::~");
|
||||
text.append(getNewClassName());
|
||||
text.append("()");
|
||||
text.append(lineDelimiter);
|
||||
text.append("{};");
|
||||
text.append(lineDelimiter);
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
|
||||
// ------ validation --------
|
||||
|
@ -855,15 +877,29 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
// class name must follow the C/CPP convensions
|
||||
|
||||
// if class does not exist, give warning
|
||||
// ArrayList elementsFound = findClassElementsInProject();
|
||||
// if(!foundInList(getBaseClassName(), elementsFound)){
|
||||
// status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
|
||||
// }
|
||||
ArrayList elementsFound = findClassElementsInProject();
|
||||
if(!foundInList(getBaseClassName(), elementsFound)){
|
||||
status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
|
||||
}
|
||||
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){
|
||||
return false;
|
||||
if(findInList(name, elements) != null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue