mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
2004-08-012 Chris Wiebe
Initial draft of new class wizard. * src/org/eclipse/cdt/ui/wizards/NewClassCreationWizard.java * src/org/eclipse/cdt/internal/ui/wizards/classwizard/*
This commit is contained in:
parent
3ead56997c
commit
d45d99f463
21 changed files with 3427 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-08-012 Chris Wiebe
|
||||
|
||||
Initial draft of new class wizard.
|
||||
* src/org/eclipse/cdt/ui/wizards/NewClassCreationWizard.java
|
||||
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/*
|
||||
|
||||
2004-08-012 Chris Wiebe
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/wizards/dialogsfields/ListDialogField.java
|
||||
|
|
|
@ -324,6 +324,21 @@
|
|||
%NewWizards.class.description
|
||||
</description>
|
||||
</wizard>
|
||||
<!--
|
||||
<wizard
|
||||
name="New C++ Class"
|
||||
icon="icons/full/ctool16/newclass_wiz.gif"
|
||||
category="org.eclipse.cdt.ui.newCCWizards"
|
||||
finalPerspective="org.eclipse.cdt.ui.CPerspective"
|
||||
id="org.eclipse.cdt.ui.wizards.NewClassCreationWizard">
|
||||
<class class="org.eclipse.cdt.ui.wizards.NewClassCreationWizard">
|
||||
<parameter name="ctype" value="true"/>
|
||||
</class>
|
||||
<description>
|
||||
%NewWizards.class.description
|
||||
</description>
|
||||
</wizard>
|
||||
-->
|
||||
</extension>
|
||||
<!-- Define the document provider and partitionner for the CEditor -->
|
||||
<extension
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
public abstract class AbstractMethodStub implements IMethodStub {
|
||||
protected String fName;
|
||||
protected String fDescription;
|
||||
protected ASTAccessVisibility fAccess;
|
||||
protected boolean fIsVirtual;
|
||||
protected boolean fIsInline;
|
||||
|
||||
public AbstractMethodStub(String name, ASTAccessVisibility access, boolean isVirtual, boolean isInline) {
|
||||
fName = name;
|
||||
fAccess = access;
|
||||
fIsVirtual = isVirtual;
|
||||
fIsInline = isInline;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return fName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return fDescription;
|
||||
}
|
||||
|
||||
public ASTAccessVisibility getAccess() {
|
||||
return fAccess;
|
||||
}
|
||||
|
||||
public void setAccess(ASTAccessVisibility access) {
|
||||
fAccess = access;
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return fIsVirtual;
|
||||
}
|
||||
|
||||
public void setVirtual(boolean isVirtual) {
|
||||
fIsVirtual = isVirtual;
|
||||
}
|
||||
|
||||
public boolean isInline() {
|
||||
return fIsInline;
|
||||
}
|
||||
|
||||
public void setInline(boolean isInline) {
|
||||
fIsInline = isInline;
|
||||
}
|
||||
|
||||
public boolean canModifyAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canModifyVirtual() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canModifyInline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isConstructor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDestructor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
|
||||
|
||||
public abstract String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
|
||||
public class BaseClassInfo implements IBaseClassInfo {
|
||||
|
||||
private ITypeInfo fType;
|
||||
private ASTAccessVisibility fAccess;
|
||||
private boolean fIsVirtual;
|
||||
|
||||
public BaseClassInfo(ITypeInfo type, ASTAccessVisibility access, boolean isVirtual) {
|
||||
fType = type;
|
||||
fAccess = access;
|
||||
fIsVirtual = isVirtual;
|
||||
}
|
||||
|
||||
public ITypeInfo getType() {
|
||||
return fType;
|
||||
}
|
||||
|
||||
public ASTAccessVisibility getAccess() {
|
||||
return fAccess;
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return fIsVirtual;
|
||||
}
|
||||
|
||||
public void setAccess(ASTAccessVisibility access) {
|
||||
fAccess = access;
|
||||
}
|
||||
|
||||
public void setVirtual(boolean isVirtual) {
|
||||
fIsVirtual = isVirtual;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||
import org.eclipse.jface.viewers.ILabelProviderListener;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
|
||||
public final class BaseClassesLabelProvider implements ITableLabelProvider {
|
||||
|
||||
private static final String YES_VALUE = NewClassWizardMessages.getString("BaseClassesLabelProvider.boolean.yes.label"); //$NON-NLS-1$
|
||||
private static final String NO_VALUE = NewClassWizardMessages.getString("BaseClassesLabelProvider.boolean.no.label"); //$NON-NLS-1$
|
||||
private static final String ACCESS_PUBLIC = NewClassWizardMessages.getString("BaseClassesLabelProvider.access.public.label"); //$NON-NLS-1$
|
||||
private static final String ACCESS_PROTECTED = NewClassWizardMessages.getString("BaseClassesLabelProvider.access.protected.label"); //$NON-NLS-1$
|
||||
private static final String ACCESS_PRIVATE = NewClassWizardMessages.getString("BaseClassesLabelProvider.access.private.label"); //$NON-NLS-1$
|
||||
|
||||
public static final String getYesNoText(boolean value) {
|
||||
return value ? YES_VALUE : NO_VALUE;
|
||||
}
|
||||
|
||||
public static final String getAccessText(ASTAccessVisibility access) {
|
||||
if (access == ASTAccessVisibility.PRIVATE)
|
||||
return ACCESS_PRIVATE;
|
||||
if (access == ASTAccessVisibility.PROTECTED)
|
||||
return ACCESS_PROTECTED;
|
||||
else
|
||||
return ACCESS_PUBLIC;
|
||||
}
|
||||
|
||||
private static TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED);
|
||||
|
||||
/*
|
||||
* @see ITableLabelProvider#getColumnImage(Object, int)
|
||||
*/
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
if (columnIndex != 0)
|
||||
return null;
|
||||
|
||||
IBaseClassInfo info = (IBaseClassInfo) element;
|
||||
return fTypeInfoLabelProvider.getImage(info.getType());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITableLabelProvider#getColumnText(Object, int)
|
||||
*/
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
IBaseClassInfo info = (IBaseClassInfo) element;
|
||||
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return fTypeInfoLabelProvider.getText(info.getType());
|
||||
case 1:
|
||||
return getAccessText(info.getAccess());
|
||||
case 2:
|
||||
return getYesNoText(info.isVirtual());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
||||
*/
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
||||
*/
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
|
||||
import org.eclipse.jface.viewers.CellEditor;
|
||||
import org.eclipse.jface.viewers.ColumnLayoutData;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.viewers.ComboBoxCellEditor;
|
||||
import org.eclipse.jface.viewers.ICellModifier;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Item;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
|
||||
public class BaseClassesListDialogField extends ListDialogField {
|
||||
|
||||
// column properties
|
||||
private static final String CP_NAME = "name"; //$NON-NLS-1$
|
||||
private static final String CP_ACCESS = "access"; //$NON-NLS-1$
|
||||
private static final String CP_VIRTUAL = "virtual"; //$NON-NLS-1$
|
||||
static final Integer INDEX_YES = new Integer(0);
|
||||
static final Integer INDEX_NO = new Integer(1);
|
||||
static final Integer INDEX_PUBLIC = new Integer(0);
|
||||
static final Integer INDEX_PROTECTED = new Integer(1);
|
||||
static final Integer INDEX_PRIVATE = new Integer(2);
|
||||
|
||||
private final class CellHandler implements ICellModifier {
|
||||
public boolean canModify(Object element, String property) {
|
||||
return (element instanceof IBaseClassInfo)
|
||||
&& (property.equals(CP_ACCESS) || property.equals(CP_VIRTUAL));
|
||||
}
|
||||
|
||||
public Object getValue(Object element, String property) {
|
||||
if (!(element instanceof IBaseClassInfo))
|
||||
return null;
|
||||
|
||||
IBaseClassInfo baseClass = (IBaseClassInfo) element;
|
||||
if (property.equals(CP_ACCESS)) {
|
||||
if (baseClass.getAccess() == ASTAccessVisibility.PRIVATE) {
|
||||
return INDEX_PRIVATE;
|
||||
} else if (baseClass.getAccess() == ASTAccessVisibility.PROTECTED) {
|
||||
return INDEX_PROTECTED;
|
||||
} else {
|
||||
return INDEX_PUBLIC;
|
||||
}
|
||||
} else if (property.equals(CP_VIRTUAL)) {
|
||||
if (baseClass.isVirtual())
|
||||
return INDEX_YES;
|
||||
else
|
||||
return INDEX_NO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void modify(Object element, String property, Object value) {
|
||||
IBaseClassInfo baseClass = null;
|
||||
if (element instanceof IBaseClassInfo) {
|
||||
baseClass = (IBaseClassInfo) element;
|
||||
} else if (element instanceof Item) {
|
||||
Object data = ((Item)element).getData();
|
||||
if (data instanceof IBaseClassInfo)
|
||||
baseClass = (IBaseClassInfo) data;
|
||||
}
|
||||
if (baseClass != null) {
|
||||
if (property.equals(CP_ACCESS) && value instanceof Integer) {
|
||||
Integer access = (Integer)value;
|
||||
if (access.equals(INDEX_PRIVATE)) {
|
||||
baseClass.setAccess(ASTAccessVisibility.PRIVATE);
|
||||
} else if (access.equals(INDEX_PROTECTED)) {
|
||||
baseClass.setAccess(ASTAccessVisibility.PROTECTED);
|
||||
} else {
|
||||
baseClass.setAccess(ASTAccessVisibility.PUBLIC);
|
||||
}
|
||||
refresh();
|
||||
} else if (property.equals(CP_VIRTUAL) && value instanceof Integer) {
|
||||
Integer yesno = (Integer)value;
|
||||
baseClass.setVirtual(yesno.equals(INDEX_YES));
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseClassesListDialogField(String title, IListAdapter listAdapter) {
|
||||
super(listAdapter,
|
||||
new String[] {
|
||||
/* 0 */ NewClassWizardMessages.getString("BaseClassesListDialogField.buttons.add"), //$NON-NLS-1$
|
||||
/* 1 */ NewClassWizardMessages.getString("BaseClassesListDialogField.buttons.remove"), //$NON-NLS-1$
|
||||
/* 2 */ NewClassWizardMessages.getString("BaseClassesListDialogField.buttons.up"), //$NON-NLS-1$
|
||||
/* 3 */ NewClassWizardMessages.getString("BaseClassesListDialogField.buttons.down") //$NON-NLS-1$
|
||||
}, new BaseClassesLabelProvider());
|
||||
setRemoveButtonIndex(1);
|
||||
setUpButtonIndex(2);
|
||||
setDownButtonIndex(3);
|
||||
setLabelText(title);
|
||||
|
||||
String[] headers = new String[] {
|
||||
NewClassWizardMessages.getString("BaseClassesListDialogField.headings.name"), //$NON-NLS-1$
|
||||
NewClassWizardMessages.getString("BaseClassesListDialogField.headings.access"), //$NON-NLS-1$
|
||||
NewClassWizardMessages.getString("BaseClassesListDialogField.headings.virtual") //$NON-NLS-1$
|
||||
};
|
||||
ColumnLayoutData[] columns = new ColumnLayoutData[] {
|
||||
new ColumnWeightData(70, 30),
|
||||
new ColumnWeightData(30, 30),
|
||||
new ColumnWeightData(25, 25),
|
||||
};
|
||||
setTableColumns(new ListDialogField.ColumnsDescription(columns, headers, true));
|
||||
}
|
||||
|
||||
protected boolean managedButtonPressed(int index) {
|
||||
super.managedButtonPressed(index);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected TableViewer createTableViewer(Composite parent) {
|
||||
TableViewer viewer = super.createTableViewer(parent);
|
||||
Table table = viewer.getTable();
|
||||
|
||||
CellEditor virtualCellEditor = new ComboBoxCellEditor(table,
|
||||
new String[] {
|
||||
/* INDEX_YES */BaseClassesLabelProvider.getYesNoText(true),
|
||||
/* INDEX_NO */BaseClassesLabelProvider.getYesNoText(false)
|
||||
}, SWT.READ_ONLY);
|
||||
|
||||
CellEditor accessCellEditor = new ComboBoxCellEditor(table,
|
||||
new String[] {
|
||||
/* INDEX_PUBLIC */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PUBLIC),
|
||||
/* INDEX_PROTECTED */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PROTECTED),
|
||||
/* INDEX_PRIVATE */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PRIVATE)
|
||||
}, SWT.READ_ONLY);
|
||||
|
||||
viewer.setCellEditors(new CellEditor[] {
|
||||
null,
|
||||
accessCellEditor,
|
||||
virtualCellEditor
|
||||
});
|
||||
viewer.setColumnProperties(new String[] {
|
||||
CP_NAME,
|
||||
CP_ACCESS,
|
||||
CP_VIRTUAL
|
||||
});
|
||||
viewer.setCellModifier(new CellHandler());
|
||||
return viewer;
|
||||
}
|
||||
|
||||
public void addBaseClass(IBaseClassInfo baseClass) {
|
||||
addElement(baseClass);
|
||||
}
|
||||
|
||||
public IBaseClassInfo[] getBaseClasses() {
|
||||
List baseClasses = getElements();
|
||||
return (IBaseClassInfo[]) baseClasses.toArray(new IBaseClassInfo[baseClasses.size()]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
|
||||
public final class ConstructorMethodStub extends AbstractMethodStub {
|
||||
|
||||
private static String NAME = NewClassWizardMessages.getString("NewClassCodeGeneration.stub.constructor.name"); //$NON-NLS-1$
|
||||
|
||||
public ConstructorMethodStub() {
|
||||
this(ASTAccessVisibility.PUBLIC, false);
|
||||
}
|
||||
|
||||
public ConstructorMethodStub(ASTAccessVisibility access, boolean isInline) {
|
||||
super(NAME, access, false, isInline);
|
||||
}
|
||||
|
||||
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
|
||||
//TODO should use code templates
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(className);
|
||||
buf.append("()"); //$NON-NLS-1$
|
||||
if (fIsInline) {
|
||||
buf.append(" {}"); //$NON-NLS-1$
|
||||
} else {
|
||||
buf.append(";"); //$NON-NLS-1$
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
|
||||
//TODO should use code templates
|
||||
if (fIsInline)
|
||||
return ""; //$NON-NLS-1$
|
||||
else {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(className);
|
||||
buf.append("::"); //$NON-NLS-1$
|
||||
buf.append(className);
|
||||
buf.append("()"); //$NON-NLS-1$
|
||||
buf.append(" {"); //$NON-NLS-1$
|
||||
buf.append(lineDelimiter);
|
||||
//buf.append("// TODO Auto-generated constructor stub");
|
||||
//buf.append(lineDelimiter);
|
||||
buf.append("}"); //$NON-NLS-1$
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConstructor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canModifyVirtual() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
|
||||
public final class DestructorMethodStub extends AbstractMethodStub {
|
||||
|
||||
private static String NAME = NewClassWizardMessages.getString("NewClassCodeGeneration.stub.destructor.name"); //$NON-NLS-1$
|
||||
|
||||
public DestructorMethodStub() {
|
||||
this(ASTAccessVisibility.PUBLIC, true, false);
|
||||
}
|
||||
|
||||
public DestructorMethodStub(ASTAccessVisibility access, boolean isVirtual, boolean isInline) {
|
||||
super(NAME, access, isVirtual, isInline);
|
||||
}
|
||||
|
||||
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
|
||||
//TODO should use code templates
|
||||
StringBuffer buf = new StringBuffer();
|
||||
if (fIsVirtual){
|
||||
buf.append("virtual "); //$NON-NLS-1$
|
||||
}
|
||||
buf.append("~"); //$NON-NLS-1$
|
||||
buf.append(className);
|
||||
buf.append("()"); //$NON-NLS-1$
|
||||
if (fIsInline) {
|
||||
buf.append(" {}"); //$NON-NLS-1$
|
||||
} else {
|
||||
buf.append(";"); //$NON-NLS-1$
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter) {
|
||||
//TODO should use code templates
|
||||
if (fIsInline)
|
||||
return ""; //$NON-NLS-1$
|
||||
else {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(className);
|
||||
buf.append("::~"); //$NON-NLS-1$
|
||||
buf.append(className);
|
||||
buf.append("()"); //$NON-NLS-1$
|
||||
buf.append(" {"); //$NON-NLS-1$
|
||||
buf.append(lineDelimiter);
|
||||
//buf.append("// TODO Auto-generated destructor stub");
|
||||
//buf.append(lineDelimiter);
|
||||
buf.append("}"); //$NON-NLS-1$
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDestructor() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class EnclosingClassSelectionDialog extends TypeSelectionDialog {
|
||||
|
||||
private static final String DIALOG_SETTINGS = EnclosingClassSelectionDialog.class.getName();
|
||||
private static final int[] VISIBLE_TYPES = { ICElement.C_CLASS };
|
||||
|
||||
public EnclosingClassSelectionDialog(Shell parent) {
|
||||
super(parent);
|
||||
setTitle(NewClassWizardMessages.getString("EnclosingClassSelectionDialog.title")); //$NON-NLS-1$
|
||||
setMessage(NewClassWizardMessages.getString("EnclosingClassSelectionDialog.message")); //$NON-NLS-1$
|
||||
setDialogSettings(DIALOG_SETTINGS);
|
||||
setVisibleTypes(VISIBLE_TYPES);
|
||||
setFilter("*", true); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
|
||||
public interface IBaseClassInfo {
|
||||
public ITypeInfo getType();
|
||||
public ASTAccessVisibility getAccess();
|
||||
public boolean isVirtual();
|
||||
|
||||
public void setAccess(ASTAccessVisibility access);
|
||||
public void setVirtual(boolean isVirtual);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
||||
|
||||
public interface IMethodStub {
|
||||
public String getName();
|
||||
public String getDescription();
|
||||
|
||||
public ASTAccessVisibility getAccess();
|
||||
public boolean canModifyAccess();
|
||||
public void setAccess(ASTAccessVisibility access);
|
||||
|
||||
public boolean isVirtual();
|
||||
public boolean canModifyVirtual();
|
||||
public void setVirtual(boolean isVirtual);
|
||||
|
||||
public boolean isInline();
|
||||
public boolean canModifyInline();
|
||||
public void setInline(boolean isVirtual);
|
||||
|
||||
public boolean isConstructor();
|
||||
public boolean isDestructor();
|
||||
|
||||
public String createMethodDeclaration(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
|
||||
public String createMethodImplementation(String className, IBaseClassInfo[] baseClasses, String lineDelimiter);
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ILabelProviderListener;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
|
||||
public final class MethodStubsLabelProvider implements ITableLabelProvider {
|
||||
|
||||
/*
|
||||
* @see ITableLabelProvider#getColumnImage(Object, int)
|
||||
*/
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
if (columnIndex != 0)
|
||||
return null;
|
||||
|
||||
IMethodStub stub = (IMethodStub) element;
|
||||
ImageDescriptor descriptor = CElementImageProvider.getMethodImageDescriptor(stub.getAccess());
|
||||
if (descriptor != null) {
|
||||
return CUIPlugin.getImageDescriptorRegistry().get(descriptor);
|
||||
}
|
||||
return CPluginImages.get(CPluginImages.IMG_OBJS_PUBLIC_METHOD);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITableLabelProvider#getColumnText(Object, int)
|
||||
*/
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
IMethodStub stub = (IMethodStub) element;
|
||||
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return stub.getName();
|
||||
case 1:
|
||||
return BaseClassesLabelProvider.getAccessText(stub.getAccess());
|
||||
case 2:
|
||||
return BaseClassesLabelProvider.getYesNoText(stub.isVirtual());
|
||||
case 3:
|
||||
return BaseClassesLabelProvider.getYesNoText(stub.isInline());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
||||
*/
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
||||
*/
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
||||
*/
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
|
||||
import org.eclipse.jface.viewers.CellEditor;
|
||||
import org.eclipse.jface.viewers.ColumnLayoutData;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.viewers.ComboBoxCellEditor;
|
||||
import org.eclipse.jface.viewers.ICellModifier;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Item;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
|
||||
public class MethodStubsListDialogField extends CheckedListDialogField {
|
||||
|
||||
// column properties
|
||||
private static final String CP_NAME = "name"; //$NON-NLS-1$
|
||||
private static final String CP_ACCESS = "access"; //$NON-NLS-1$
|
||||
private static final String CP_VIRTUAL = "virtual"; //$NON-NLS-1$
|
||||
private static final String CP_INLINE = "inline"; //$NON-NLS-1$
|
||||
static final Integer INDEX_YES = new Integer(0);
|
||||
static final Integer INDEX_NO = new Integer(1);
|
||||
static final Integer INDEX_PUBLIC = new Integer(0);
|
||||
static final Integer INDEX_PROTECTED = new Integer(1);
|
||||
static final Integer INDEX_PRIVATE = new Integer(2);
|
||||
|
||||
private final class CellHandler implements ICellModifier {
|
||||
public boolean canModify(Object element, String property) {
|
||||
if (element instanceof IMethodStub) {
|
||||
IMethodStub stub = (IMethodStub) element;
|
||||
if (property.equals(CP_ACCESS)) {
|
||||
return stub.canModifyAccess();
|
||||
} else if (property.equals(CP_VIRTUAL)) {
|
||||
return stub.canModifyVirtual();
|
||||
} else if (property.equals(CP_INLINE)) {
|
||||
return stub.canModifyInline();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getValue(Object element, String property) {
|
||||
if (!(element instanceof IMethodStub))
|
||||
return null;
|
||||
|
||||
IMethodStub stub = (IMethodStub) element;
|
||||
if (property.equals(CP_ACCESS)) {
|
||||
if (stub.getAccess() == ASTAccessVisibility.PRIVATE) {
|
||||
return INDEX_PRIVATE;
|
||||
} else if (stub.getAccess() == ASTAccessVisibility.PROTECTED) {
|
||||
return INDEX_PROTECTED;
|
||||
} else {
|
||||
return INDEX_PUBLIC;
|
||||
}
|
||||
} else if (property.equals(CP_VIRTUAL)) {
|
||||
if (stub.isVirtual())
|
||||
return INDEX_YES;
|
||||
else
|
||||
return INDEX_NO;
|
||||
} else if (property.equals(CP_INLINE)) {
|
||||
if (stub.isInline())
|
||||
return INDEX_YES;
|
||||
else
|
||||
return INDEX_NO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void modify(Object element, String property, Object value) {
|
||||
IMethodStub stub = null;
|
||||
if (element instanceof IMethodStub) {
|
||||
stub = (IMethodStub)element;
|
||||
} else if (element instanceof Item) {
|
||||
Object data = ((Item)element).getData();
|
||||
if (data instanceof IMethodStub)
|
||||
stub = (IMethodStub)data;
|
||||
}
|
||||
if (stub != null) {
|
||||
if (property.equals(CP_ACCESS) && value instanceof Integer) {
|
||||
Integer access = (Integer) value;
|
||||
if (access.equals(INDEX_PRIVATE)) {
|
||||
stub.setAccess(ASTAccessVisibility.PRIVATE);
|
||||
} else if (access.equals(INDEX_PROTECTED)) {
|
||||
stub.setAccess(ASTAccessVisibility.PROTECTED);
|
||||
} else {
|
||||
stub.setAccess(ASTAccessVisibility.PUBLIC);
|
||||
}
|
||||
refresh();
|
||||
} else if (property.equals(CP_VIRTUAL) && value instanceof Integer) {
|
||||
Integer yesno = (Integer) value;
|
||||
stub.setVirtual(yesno.equals(INDEX_YES));
|
||||
refresh();
|
||||
} else if (property.equals(CP_INLINE) && value instanceof Integer) {
|
||||
Integer yesno = (Integer) value;
|
||||
stub.setInline(yesno.equals(INDEX_YES));
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MethodStubsListDialogField(String title, IListAdapter listAdapter) {
|
||||
super(listAdapter, null, new MethodStubsLabelProvider());
|
||||
setLabelText(title);
|
||||
|
||||
String[] headers = new String[] {
|
||||
NewClassWizardMessages.getString("MethodStubsDialogField.headings.name"), //$NON-NLS-1$
|
||||
NewClassWizardMessages.getString("MethodStubsDialogField.headings.access"), //$NON-NLS-1$
|
||||
NewClassWizardMessages.getString("MethodStubsDialogField.headings.virtual"), //$NON-NLS-1$
|
||||
NewClassWizardMessages.getString("MethodStubsDialogField.headings.inline") //$NON-NLS-1$
|
||||
};
|
||||
ColumnLayoutData[] columns = new ColumnLayoutData[] {
|
||||
new ColumnWeightData(70, 30),
|
||||
new ColumnWeightData(40, 30),
|
||||
new ColumnWeightData(30, 25),
|
||||
new ColumnWeightData(30, 25),
|
||||
};
|
||||
setTableColumns(new ListDialogField.ColumnsDescription(columns, headers, true));
|
||||
}
|
||||
|
||||
protected boolean managedButtonPressed(int index) {
|
||||
super.managedButtonPressed(index);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected TableViewer createTableViewer(Composite parent) {
|
||||
TableViewer viewer = super.createTableViewer(parent);
|
||||
Table table = viewer.getTable();
|
||||
|
||||
CellEditor virtualCellEditor = new ComboBoxCellEditor(table,
|
||||
new String[] {
|
||||
/* INDEX_YES */BaseClassesLabelProvider.getYesNoText(true),
|
||||
/* INDEX_NO */BaseClassesLabelProvider.getYesNoText(false)
|
||||
}, SWT.READ_ONLY);
|
||||
|
||||
CellEditor accessCellEditor = new ComboBoxCellEditor(table,
|
||||
new String[] {
|
||||
/* INDEX_PUBLIC */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PUBLIC),
|
||||
/* INDEX_PROTECTED */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PROTECTED),
|
||||
/* INDEX_PRIVATE */BaseClassesLabelProvider.getAccessText(ASTAccessVisibility.PRIVATE)
|
||||
}, SWT.READ_ONLY);
|
||||
|
||||
viewer.setCellEditors(new CellEditor[] {
|
||||
null,
|
||||
accessCellEditor,
|
||||
virtualCellEditor,
|
||||
virtualCellEditor
|
||||
});
|
||||
viewer.setColumnProperties(new String[] {
|
||||
CP_NAME,
|
||||
CP_ACCESS,
|
||||
CP_VIRTUAL,
|
||||
CP_INLINE
|
||||
});
|
||||
viewer.setCellModifier(new CellHandler());
|
||||
return viewer;
|
||||
}
|
||||
|
||||
public void addMethodStub(IMethodStub methodStub, boolean checked) {
|
||||
addElement(methodStub);
|
||||
setChecked(methodStub, checked);
|
||||
}
|
||||
|
||||
public IMethodStub[] getMethodStubs() {
|
||||
List allStubs = getElements();
|
||||
return (IMethodStub[]) allStubs.toArray(new IMethodStub[allStubs.size()]);
|
||||
}
|
||||
|
||||
public IMethodStub[] getCheckedMethodStubs() {
|
||||
List checkedStubs = getCheckedElements();
|
||||
return (IMethodStub[]) checkedStubs.toArray(new IMethodStub[checkedStubs.size()]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class NamespaceSelectionDialog extends TypeSelectionDialog {
|
||||
|
||||
private static final String DIALOG_SETTINGS = NamespaceSelectionDialog.class.getName();
|
||||
private static final int[] VISIBLE_TYPES = { ICElement.C_NAMESPACE };
|
||||
|
||||
public NamespaceSelectionDialog(Shell parent) {
|
||||
super(parent);
|
||||
setTitle(NewClassWizardMessages.getString("NamespaceSelectionDialog.title")); //$NON-NLS-1$
|
||||
setMessage(NewClassWizardMessages.getString("NamespaceSelectionDialog.message")); //$NON-NLS-1$
|
||||
setDialogSettings(DIALOG_SETTINGS);
|
||||
setVisibleTypes(VISIBLE_TYPES);
|
||||
setFilter("*", true); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.browser.AllTypesCache;
|
||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.progress.IProgressService;
|
||||
|
||||
public class NewBaseClassSelectionDialog extends TypeSelectionDialog {
|
||||
|
||||
private static final String DIALOG_SETTINGS = NewBaseClassSelectionDialog.class.getName();
|
||||
private static final int[] VISIBLE_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT };
|
||||
private static final int ADD_ID = IDialogConstants.CLIENT_ID + 1;
|
||||
private List fTypeList;
|
||||
private List fTypeListeners;
|
||||
|
||||
public interface ITypeSelectionListener {
|
||||
void typeAdded(ITypeInfo baseClass);
|
||||
}
|
||||
|
||||
public NewBaseClassSelectionDialog(Shell parent) {
|
||||
super(parent);
|
||||
setTitle(NewClassWizardMessages.getString("NewBaseClassSelectionDialog.title")); //$NON-NLS-1$
|
||||
setMessage(NewClassWizardMessages.getString("NewBaseClassSelectionDialog.message")); //$NON-NLS-1$
|
||||
setDialogSettings(DIALOG_SETTINGS);
|
||||
setVisibleTypes(VISIBLE_TYPES);
|
||||
setFilter("*", true); //$NON-NLS-1$
|
||||
setStatusLineAboveButtons(true);
|
||||
fTypeList = new ArrayList();
|
||||
fTypeListeners = new ArrayList();
|
||||
}
|
||||
|
||||
public void addListener(ITypeSelectionListener listener) {
|
||||
if (!fTypeListeners.contains(listener))
|
||||
fTypeListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ITypeSelectionListener listener) {
|
||||
fTypeListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyTypeAddedListeners(ITypeInfo type) {
|
||||
// first copy listeners in case one calls removeListener
|
||||
List list = new ArrayList(fTypeListeners);
|
||||
for (Iterator i = list.iterator(); i.hasNext(); ) {
|
||||
ITypeSelectionListener listener = (ITypeSelectionListener) i.next();
|
||||
listener.typeAdded(type);
|
||||
}
|
||||
}
|
||||
|
||||
public ITypeInfo[] getAddedTypes() {
|
||||
return (ITypeInfo[])fTypeList.toArray(new ITypeInfo[fTypeList.size()]);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Dialog#createButtonsForButtonBar
|
||||
*/
|
||||
protected void createButtonsForButtonBar(Composite parent) {
|
||||
createButton(parent, ADD_ID, NewClassWizardMessages.getString("NewBaseClassSelectionDialog.addButton.label"), true); //$NON-NLS-1$
|
||||
super.createButtonsForButtonBar(parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Dialog#buttonPressed
|
||||
*/
|
||||
protected void buttonPressed(int buttonId) {
|
||||
if (buttonId == ADD_ID){
|
||||
addType(getLowerSelectedElement());
|
||||
}
|
||||
super.buttonPressed(buttonId);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Dialog#okPressed
|
||||
*/
|
||||
protected void okPressed() {
|
||||
addType(getLowerSelectedElement());
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
private void addType(Object elem) {
|
||||
if (elem instanceof ITypeInfo) {
|
||||
ITypeInfo type = (ITypeInfo)elem;
|
||||
if (!fTypeList.contains(type)) {
|
||||
String qualifiedName = type.getQualifiedTypeName().getFullyQualifiedName();
|
||||
String message = NewClassWizardMessages.getFormattedString("NewBaseClassSelectionDialog.addingclass.info", qualifiedName); //$NON-NLS-1$
|
||||
updateStatus(new StatusInfo(IStatus.INFO, message));
|
||||
|
||||
// resolve location of base class
|
||||
if (type.getResolvedReference() == null) {
|
||||
final ITypeInfo[] typesToResolve = new ITypeInfo[] { type };
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
|
||||
AllTypesCache.resolveTypeLocation(typesToResolve[0], progressMonitor);
|
||||
if (progressMonitor.isCanceled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IProgressService service = PlatformUI.getWorkbench().getProgressService();
|
||||
try {
|
||||
service.busyCursorWhile(runnable);
|
||||
} catch (InvocationTargetException e) {
|
||||
String title= NewClassWizardMessages.getString("NewBaseClassSelectionDialog.getClasses.exception.title"); //$NON-NLS-1$
|
||||
String errorMessage= NewClassWizardMessages.getString("NewBaseClassSelectionDialog.getClasses.exception.message"); //$NON-NLS-1$
|
||||
ExceptionHandler.handle(e, title, errorMessage);
|
||||
} catch (InterruptedException e) {
|
||||
// cancelled by user
|
||||
}
|
||||
}
|
||||
|
||||
if (type.getResolvedReference() != null) {
|
||||
fTypeList.add(type);
|
||||
|
||||
message = NewClassWizardMessages.getFormattedString("NewBaseClassSelectionDialog.classadded.info", qualifiedName); //$NON-NLS-1$
|
||||
updateStatus(new StatusInfo(IStatus.INFO, message));
|
||||
|
||||
notifyTypeAddedListeners(type);
|
||||
} else {
|
||||
message = NewClassWizardMessages.getFormattedString("NewBaseClassSelectionDialog.error.classnotadded", qualifiedName); //$NON-NLS-1$
|
||||
updateStatus(new StatusInfo(IStatus.ERROR, message));
|
||||
}
|
||||
} else {
|
||||
String qualifiedName = type.getQualifiedTypeName().getFullyQualifiedName();
|
||||
String message = NewClassWizardMessages.getFormattedString("NewBaseClassSelectionDialog.classalreadyadded.info", qualifiedName); //$NON-NLS-1$
|
||||
updateStatus(new StatusInfo(IStatus.INFO, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractElementListSelectionDialog#handleDefaultSelected()
|
||||
*/
|
||||
protected void handleDefaultSelected() {
|
||||
if (validateCurrentSelection())
|
||||
buttonPressed(ADD_ID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,461 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
public class NewClassCodeGenerator {
|
||||
|
||||
private IPath fHeaderPath = null;
|
||||
private IPath fSourcePath = null;
|
||||
private String fClassName = null;
|
||||
private String fLineDelimiter;
|
||||
private IBaseClassInfo[] fBaseClasses = null;
|
||||
private IMethodStub[] fMethodStubs = null;
|
||||
private ITranslationUnit fCreatedHeaderTU = null;
|
||||
private ITranslationUnit fCreatedSourceTU = null;
|
||||
private ICElement fCreatedClass = null;
|
||||
|
||||
public NewClassCodeGenerator(IPath headerPath, IPath sourcePath, String className, IBaseClassInfo[] baseClasses, IMethodStub[] methodStubs) {
|
||||
fHeaderPath = headerPath;
|
||||
fSourcePath = sourcePath;
|
||||
fClassName = className;
|
||||
fBaseClasses = baseClasses;
|
||||
fMethodStubs = methodStubs;
|
||||
fLineDelimiter = NewSourceFileGenerator.getLineDelimiter();
|
||||
}
|
||||
|
||||
public ICElement getCreatedClass() {
|
||||
return fCreatedClass;
|
||||
}
|
||||
|
||||
public ITranslationUnit getCreatedHeaderTU() {
|
||||
return fCreatedHeaderTU;
|
||||
}
|
||||
|
||||
public ITranslationUnit getCreatedSourceTU() {
|
||||
return fCreatedSourceTU;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the new class.
|
||||
*
|
||||
* @param monitor
|
||||
* a progress monitor to report progress.
|
||||
* @throws CoreException
|
||||
* Thrown when the creation failed.
|
||||
* @throws InterruptedException
|
||||
* Thrown when the operation was cancelled.
|
||||
*/
|
||||
public ICElement createClass(IProgressMonitor monitor) throws CoreException, InterruptedException {
|
||||
if (monitor == null)
|
||||
monitor = new NullProgressMonitor();
|
||||
|
||||
monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createType.task"), 10); //$NON-NLS-1$
|
||||
|
||||
ITranslationUnit headerTU = null;
|
||||
ITranslationUnit sourceTU = null;
|
||||
ICElement createdClass = null;
|
||||
|
||||
IWorkingCopy headerWorkingCopy = null;
|
||||
IWorkingCopy sourceWorkingCopy = null;
|
||||
try {
|
||||
monitor.worked(1);
|
||||
|
||||
if (fHeaderPath != null) {
|
||||
IFile headerFile = NewSourceFileGenerator.createHeaderFile(fHeaderPath, true, monitor);
|
||||
if (headerFile != null) {
|
||||
headerTU = (ITranslationUnit) CoreModel.getDefault().create(headerFile);
|
||||
}
|
||||
monitor.worked(1);
|
||||
|
||||
// create a working copy with a new owner
|
||||
headerWorkingCopy = headerTU.getWorkingCopy();
|
||||
// headerWorkingCopy = headerTU.getSharedWorkingCopy(null, CUIPlugin.getDefault().getBufferFactory());
|
||||
|
||||
String headerContent = constructHeaderFileContent(headerTU, headerWorkingCopy.getBuffer().getContents());
|
||||
headerWorkingCopy.getBuffer().setContents(headerContent);
|
||||
|
||||
if (monitor.isCanceled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
headerWorkingCopy.reconcile();
|
||||
headerWorkingCopy.commit(true, monitor);
|
||||
|
||||
createdClass = headerWorkingCopy.getElement(fClassName);
|
||||
fCreatedClass = createdClass;
|
||||
fCreatedHeaderTU = headerTU;
|
||||
}
|
||||
|
||||
if (fSourcePath != null) {
|
||||
IFile sourceFile = NewSourceFileGenerator.createHeaderFile(fSourcePath, true, monitor);
|
||||
if (sourceFile != null) {
|
||||
sourceTU = (ITranslationUnit) CoreModel.getDefault().create(sourceFile);
|
||||
}
|
||||
monitor.worked(1);
|
||||
|
||||
// create a working copy with a new owner
|
||||
sourceWorkingCopy = sourceTU.getWorkingCopy();
|
||||
|
||||
String sourceContent = constructSourceFileContent(sourceTU, headerTU);
|
||||
sourceWorkingCopy.getBuffer().setContents(sourceContent);
|
||||
|
||||
if (monitor.isCanceled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
sourceWorkingCopy.reconcile();
|
||||
sourceWorkingCopy.commit(true, monitor);
|
||||
|
||||
fCreatedSourceTU = sourceTU;
|
||||
}
|
||||
} finally {
|
||||
if (headerWorkingCopy != null) {
|
||||
headerWorkingCopy.destroy();
|
||||
}
|
||||
if (sourceWorkingCopy != null) {
|
||||
sourceWorkingCopy.destroy();
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
|
||||
return fCreatedClass;
|
||||
}
|
||||
|
||||
public String constructHeaderFileContent(ITranslationUnit headerTU, String oldContents) {
|
||||
//TODO should use code templates
|
||||
StringBuffer text = new StringBuffer();
|
||||
|
||||
int insertionPos = -1;
|
||||
if (oldContents != null) {
|
||||
insertionPos = getInsertionPos(oldContents);
|
||||
if (insertionPos == -1)
|
||||
text.append(oldContents);
|
||||
else
|
||||
text.append(oldContents.substring(0, insertionPos));
|
||||
}
|
||||
|
||||
addBaseClassIncludes(headerTU, text);
|
||||
|
||||
text.append("class "); //$NON-NLS-1$
|
||||
text.append(fClassName);
|
||||
|
||||
addBaseClassInheritance(text);
|
||||
text.append(fLineDelimiter);
|
||||
text.append('{');
|
||||
|
||||
//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()
|
||||
&& protectedMethods.isEmpty()
|
||||
&& privateMethods.isEmpty()) {
|
||||
text.append(' ');
|
||||
} else {
|
||||
addMethodDeclarations(publicMethods, protectedMethods, privateMethods, text);
|
||||
}
|
||||
|
||||
text.append("};"); //$NON-NLS-1$
|
||||
text.append(fLineDelimiter);
|
||||
|
||||
if (oldContents != null && insertionPos != -1) {
|
||||
text.append(fLineDelimiter);
|
||||
text.append(oldContents.substring(insertionPos));
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private int getInsertionPos(String contents) {
|
||||
//TODO temporary hack
|
||||
int insertPos = contents.lastIndexOf("#endif"); //$NON-NLS-1$
|
||||
if (insertPos != -1) {
|
||||
// check if any code follows the #endif
|
||||
if ((contents.indexOf('}', insertPos) != -1)
|
||||
|| (contents.indexOf(';', insertPos) != -1)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return insertPos;
|
||||
}
|
||||
|
||||
private void addMethodDeclarations(List publicMethods, List protectedMethods, List privateMethods, StringBuffer text) {
|
||||
if (!publicMethods.isEmpty()) {
|
||||
text.append(fLineDelimiter);
|
||||
text.append("public:"); //$NON-NLS-1$
|
||||
text.append(fLineDelimiter);
|
||||
for (Iterator i = publicMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodDeclaration(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append('\t');
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protectedMethods.isEmpty()) {
|
||||
text.append(fLineDelimiter);
|
||||
text.append("protected:"); //$NON-NLS-1$
|
||||
text.append(fLineDelimiter);
|
||||
for (Iterator i = protectedMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodDeclaration(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append('\t');
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!privateMethods.isEmpty()) {
|
||||
text.append(fLineDelimiter);
|
||||
text.append("private:"); //$NON-NLS-1$
|
||||
text.append(fLineDelimiter);
|
||||
for (Iterator i = privateMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodDeclaration(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append('\t');
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List getStubs(ASTAccessVisibility access, boolean skipInline) {
|
||||
List list = new ArrayList();
|
||||
if (fMethodStubs != null) {
|
||||
for (int i = 0; i < fMethodStubs.length; ++i) {
|
||||
IMethodStub stub = fMethodStubs[i];
|
||||
if (stub.getAccess() == access && (!skipInline || !stub.isInline())) {
|
||||
list.add(stub);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void addBaseClassInheritance(StringBuffer text) {
|
||||
if (fBaseClasses != null && fBaseClasses.length > 0) {
|
||||
text.append(" : "); //$NON-NLS-1$
|
||||
for (int i = 0; i < fBaseClasses.length; ++i) {
|
||||
IBaseClassInfo baseClass = fBaseClasses[i];
|
||||
String baseClassName = baseClass.getType().getQualifiedTypeName().getFullyQualifiedName();
|
||||
if (i > 0)
|
||||
text.append(", "); //$NON-NLS-1$
|
||||
if (baseClass.getAccess() == ASTAccessVisibility.PRIVATE)
|
||||
text.append("private"); //$NON-NLS-1$
|
||||
else if (baseClass.getAccess() == ASTAccessVisibility.PROTECTED)
|
||||
text.append("private"); //$NON-NLS-1$
|
||||
else
|
||||
text.append("public"); //$NON-NLS-1$
|
||||
text.append(' ');
|
||||
|
||||
if (baseClass.isVirtual())
|
||||
text.append("virtual "); //$NON-NLS-1$
|
||||
|
||||
text.append(baseClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addBaseClassIncludes(ITranslationUnit headerTU, StringBuffer text) {
|
||||
if (fBaseClasses != null && fBaseClasses.length > 0) {
|
||||
IProject project = headerTU.getCProject().getProject();
|
||||
IPath projectLocation = project.getLocation();
|
||||
IPath headerLocation = headerTU.getResource().getLocation();
|
||||
for (int i = 0; i < fBaseClasses.length; ++i) {
|
||||
String baseClassFileName = null;
|
||||
boolean isSystemIncludePath = false;
|
||||
IBaseClassInfo baseClass = fBaseClasses[i];
|
||||
ITypeReference ref = baseClass.getType().getResolvedReference();
|
||||
if (ref != null) {
|
||||
IPath baseClassLocation = ref.getLocation();
|
||||
IPath includePath = makeRelativePathToProjectIncludes(baseClassLocation, project);
|
||||
if (includePath != null && !projectLocation.isPrefixOf(baseClassLocation)) {
|
||||
isSystemIncludePath = true;
|
||||
} else if (projectLocation.isPrefixOf(baseClassLocation)
|
||||
&& projectLocation.isPrefixOf(headerLocation)) {
|
||||
includePath = makeRelativePath(baseClassLocation, headerLocation);
|
||||
}
|
||||
if (includePath == null)
|
||||
includePath = baseClassLocation;
|
||||
baseClassFileName = includePath.toString();
|
||||
}
|
||||
if (baseClassFileName == null) {
|
||||
baseClassFileName = NewSourceFileGenerator.generateHeaderFileNameFromClass(baseClass.getType().getName());
|
||||
}
|
||||
|
||||
// add the include statement if we are extending a base class
|
||||
// and we are not already in the base class header file
|
||||
// (enclosing type)
|
||||
if (!(headerTU.getElementName().equals(baseClassFileName))) {
|
||||
String include = getIncludeString(baseClassFileName, isSystemIncludePath);
|
||||
text.append(include);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
public String constructSourceFileContent(ITranslationUnit sourceTU, ITranslationUnit headerTU) {
|
||||
//TODO should use code templates
|
||||
StringBuffer text = new StringBuffer();
|
||||
|
||||
if (headerTU != null) {
|
||||
addHeaderInclude(sourceTU, headerTU, text);
|
||||
}
|
||||
|
||||
//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()
|
||||
&& protectedMethods.isEmpty()
|
||||
&& privateMethods.isEmpty()) {
|
||||
text.append(' ');
|
||||
} else {
|
||||
addMethodBodies(publicMethods, protectedMethods, privateMethods, text);
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private void addHeaderInclude(ITranslationUnit sourceTU, ITranslationUnit headerTU, StringBuffer text) {
|
||||
IProject project = headerTU.getCProject().getProject();
|
||||
IPath projectLocation = project.getLocation();
|
||||
IPath headerLocation = headerTU.getResource().getLocation();
|
||||
IPath sourceLocation = sourceTU.getResource().getLocation();
|
||||
|
||||
IPath includePath = makeRelativePathToProjectIncludes(headerLocation, project);
|
||||
boolean isSystemIncludePath = false;
|
||||
if (includePath != null && !projectLocation.isPrefixOf(headerLocation)) {
|
||||
isSystemIncludePath = true;
|
||||
} else if (projectLocation.isPrefixOf(headerLocation)
|
||||
&& projectLocation.isPrefixOf(sourceLocation)) {
|
||||
includePath = makeRelativePath(headerLocation, sourceLocation);
|
||||
}
|
||||
if (includePath == null)
|
||||
includePath = headerLocation;
|
||||
|
||||
String include = getIncludeString(includePath.toString(), isSystemIncludePath);
|
||||
text.append(include);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
|
||||
private void addMethodBodies(List publicMethods, List protectedMethods, List privateMethods, StringBuffer text) {
|
||||
if (!publicMethods.isEmpty()) {
|
||||
for (Iterator i = publicMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodImplementation(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append(fLineDelimiter);
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protectedMethods.isEmpty()) {
|
||||
for (Iterator i = protectedMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodImplementation(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append(fLineDelimiter);
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
if (!privateMethods.isEmpty()) {
|
||||
for (Iterator i = privateMethods.iterator(); i.hasNext();) {
|
||||
IMethodStub stub = (IMethodStub) i.next();
|
||||
String code = stub.createMethodImplementation(fClassName, fBaseClasses, fLineDelimiter);
|
||||
text.append(fLineDelimiter);
|
||||
text.append(code);
|
||||
text.append(fLineDelimiter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IPath makeRelativePathToProjectIncludes(IPath fullPath, IProject project) {
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||
if (provider != null) {
|
||||
IScannerInfo info = provider.getScannerInformation(project);
|
||||
if (info != null) {
|
||||
String[] includePaths = info.getIncludePaths();
|
||||
IPath relativePath = null;
|
||||
int mostSegments = 0;
|
||||
for (int i = 0; i < includePaths.length; ++i) {
|
||||
IPath includePath = new Path(includePaths[i]);
|
||||
if (includePath.isPrefixOf(fullPath)) {
|
||||
int segments = includePath.matchingFirstSegments(fullPath);
|
||||
if (segments > mostSegments) {
|
||||
relativePath = fullPath.removeFirstSegments(segments).setDevice(null);
|
||||
mostSegments = segments;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (relativePath != null)
|
||||
return relativePath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IPath makeRelativePath(IPath path, IPath relativeTo) {
|
||||
int segments = relativeTo.matchingFirstSegments(path);
|
||||
if (segments > 0) {
|
||||
IPath prefix = relativeTo.removeFirstSegments(segments).removeLastSegments(1);
|
||||
IPath suffix = path.removeFirstSegments(segments);
|
||||
IPath relativePath = new Path(""); //$NON-NLS-1$
|
||||
for (int i = 0; i < prefix.segmentCount(); ++i) {
|
||||
relativePath = relativePath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
|
||||
}
|
||||
return relativePath.append(suffix);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getIncludeString(String fileName, boolean isSystemInclude) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("#include "); //$NON-NLS-1$
|
||||
if (isSystemInclude)
|
||||
buf.append('<'); //$NON-NLS-1$
|
||||
else
|
||||
buf.append('\"'); //$NON-NLS-1$
|
||||
buf.append(fileName);
|
||||
if (isSystemInclude)
|
||||
buf.append('>'); //$NON-NLS-1$
|
||||
else
|
||||
buf.append('\"'); //$NON-NLS-1$
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
public class NewClassWizardMessages {
|
||||
|
||||
private static final String RESOURCE_BUNDLE= NewClassWizardMessages.class.getName();
|
||||
private static ResourceBundle fgResourceBundle;
|
||||
static {
|
||||
try {
|
||||
fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
||||
} catch (MissingResourceException x) {
|
||||
fgResourceBundle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private NewClassWizardMessages() {
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return fgResourceBundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
} catch (NullPointerException e) {
|
||||
return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with the argument
|
||||
*
|
||||
* @param key the string used to get the bundle value, must not be null
|
||||
*/
|
||||
public static String getFormattedString(String key, Object arg) {
|
||||
return MessageFormat.format(getString(key), new Object[] { arg });
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with arguments
|
||||
*/
|
||||
public static String getFormattedString(String key, Object[] args) {
|
||||
return MessageFormat.format(getString(key), args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2004 QNX Software Systems and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Common Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/cpl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# QNX Software Systems - Initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
# ------- NewClassCreationWizard -------
|
||||
NewClassCreationWizard.title=New C++ Class
|
||||
|
||||
# -----------NewClassCreationWizardPage -------------
|
||||
NewClassCreationWizardPage.title=C++ Class
|
||||
NewClassCreationWizardPage.description=Create a new C++ class.
|
||||
NewClassCreationWizardPage.error.SelectedProjectError=Error in determining the selected project.
|
||||
NewClassCreationWizardPage.error.DefaultSourceFolderError=Error in determining the default source folder.
|
||||
NewClassCreationWizardPage.error.NotAvailableForNonCppProjects= The wizard is not available for non C++ projects.
|
||||
|
||||
NewClassCreationWizardPage.getClasses.exception.title=Exception
|
||||
NewClassCreationWizardPage.getClasses.exception.message=Unexpected exception. See log for details.
|
||||
NewClassCreationWizardPage.getClasses.noclasses.title=Class Selection
|
||||
NewClassCreationWizardPage.getClasses.noclasses.message=No classes available.
|
||||
|
||||
NewClassCreationWizardPage.sourceFolder.label=Source &Folder:
|
||||
NewClassCreationWizardPage.sourceFolder.button=Br&owse...
|
||||
NewClassCreationWizardPage.ChooseSourceFolderDialog.title=Folder Selection
|
||||
NewClassCreationWizardPage.ChooseSourceFolderDialog.description=&Choose a folder:
|
||||
NewClassCreationWizardPage.error.EnterSourceFolderName=Folder name is empty.
|
||||
NewClassCreationWizardPage.error.SourceFolderDoesNotExist=Folder ''{0}'' does not exist.
|
||||
NewClassCreationWizardPage.error.NotAFolder=''{0}'' must be a project or folder.
|
||||
NewClassCreationWizardPage.error.ProjectClosed=Project ''{0}'' must be accessible.
|
||||
NewClassCreationWizardPage.warning.NotACProject=Folder is not a C/C++ project.
|
||||
NewClassCreationWizardPage.warning.NotInACProject=Folder is not in a C/C++ project.
|
||||
|
||||
NewClassCreationWizardPage.namespace.label=Namespace:
|
||||
NewClassCreationWizardPage.namespace.button=Bro&wse...
|
||||
|
||||
NewClassCreationWizardPage.enclosingClass.label=&Enclosing Class:
|
||||
NewClassCreationWizardPage.enclosingClass.button=Br&owse...
|
||||
|
||||
NewClassCreationWizardPage.className.label=Class &Name:
|
||||
NewClassCreationWizardPage.error.EnterClassName=Class name is empty.
|
||||
NewClassCreationWizardPage.error.ClassNameExists=Class already exists.
|
||||
NewClassCreationWizardPage.error.ClassNameExistsDifferentCase=Class with same name but different case exists.
|
||||
NewClassCreationWizardPage.error.InvalidClassName=Class name is not valid. {0}
|
||||
NewClassCreationWizardPage.error.QualifiedName=Class name must not be qualified.
|
||||
NewClassCreationWizardPage.warning.ClassNameDiscouraged=Class name is discouraged. {0}
|
||||
|
||||
NewClassCreationWizardPage.baseClasses.label=&Base Classes:
|
||||
NewClassCreationWizardPage.error.InvalidBaseClassName=Base class name is not valid.
|
||||
|
||||
NewClassCreationWizardPage.methodStubs.label=Method &Stubs:
|
||||
|
||||
NewClassCreationWizardPage.classDefinition.label=Class &Definition:
|
||||
NewClassCreationWizardPage.classDefinition.button=Br&owse...
|
||||
|
||||
NewClassCreationWizardPage.classImplementation.button=Br&owse...
|
||||
NewClassCreationWizardPage.classImplementation.label=Class &Implementation:
|
||||
|
||||
# -----------BaseClassesListDialogField -------------
|
||||
BaseClassesListDialogField.buttons.add=&Add...
|
||||
BaseClassesListDialogField.buttons.remove=&Remove
|
||||
BaseClassesListDialogField.buttons.up=&Up
|
||||
BaseClassesListDialogField.buttons.down=&Down
|
||||
BaseClassesListDialogField.headings.name=Name
|
||||
BaseClassesListDialogField.headings.access=Access
|
||||
BaseClassesListDialogField.headings.virtual=Virtual
|
||||
|
||||
# -----------BaseClassesLabelProvider -------------
|
||||
BaseClassesLabelProvider.boolean.yes.label=yes
|
||||
BaseClassesLabelProvider.boolean.no.label=no
|
||||
BaseClassesLabelProvider.access.public.label=public
|
||||
BaseClassesLabelProvider.access.protected.label=protected
|
||||
BaseClassesLabelProvider.access.private.label=private
|
||||
|
||||
# -----------MethodStubsDialogField -------------
|
||||
MethodStubsDialogField.headings.name=Name
|
||||
MethodStubsDialogField.headings.access=Access
|
||||
MethodStubsDialogField.headings.virtual=Virtual
|
||||
MethodStubsDialogField.headings.inline=Inline
|
||||
|
||||
# ------- NamespaceSelectionDialog -----
|
||||
NamespaceSelectionDialog.title=Choose Namespace
|
||||
NamespaceSelectionDialog.message=&Choose a namespace (? = any character, * = any string):
|
||||
NamespaceSelectionDialog.filter=
|
||||
|
||||
# ------- EnclosingClassSelectionDialog -----
|
||||
EnclosingClassSelectionDialog.title=Choose Enclosing Class
|
||||
EnclosingClassSelectionDialog.message=&Choose a class (? = any character, * = any string):
|
||||
EnclosingClassSelectionDialog.filter=
|
||||
|
||||
# ------- NewBaseClassSelectionDialog -----
|
||||
NewBaseClassSelectionDialog.title=Choose Base Class
|
||||
NewBaseClassSelectionDialog.message=&Choose a class (? = any character, * = any string):
|
||||
NewBaseClassSelectionDialog.filter=
|
||||
NewBaseClassSelectionDialog.access.label=Access
|
||||
NewBaseClassSelectionDialog.virtual.label=Virtual
|
||||
NewBaseClassSelectionDialog.addButton.label=&Add
|
||||
NewBaseClassSelectionDialog.classadded.info=''{0}'' added.
|
||||
NewBaseClassSelectionDialog.classalreadyadded.info=''{0}'' already added.
|
||||
NewBaseClassSelectionDialog.addingclass.info=Adding ''{0}''...
|
||||
NewBaseClassSelectionDialog.error.classnotadded=''{0}'' could not be added.
|
||||
NewBaseClassSelectionDialog.getClasses.exception.title=Exception
|
||||
NewBaseClassSelectionDialog.getClasses.exception.message=Unexpected exception. See log for details.
|
||||
NewBaseClassSelectionDialog.getClasses.noclasses.title=Class Selection
|
||||
NewBaseClassSelectionDialog.getClasses.noclasses.message=No classes available.
|
||||
|
||||
# -----------NewClassCodeGeneration -------------
|
||||
NewClassCodeGeneration.createType.task=Creating type....
|
||||
NewClassCodeGeneration.createFile.task=Creating
|
||||
NewClassCodeGeneration.stub.constructor.name=Constructor
|
||||
NewClassCodeGeneration.stub.destructor.name=Destructor
|
||||
NewClassCodeGeneration.includeGuard.suffix=_H
|
|
@ -0,0 +1,150 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceStatus;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.ui.dialogs.ContainerGenerator;
|
||||
|
||||
public class NewSourceFileGenerator {
|
||||
|
||||
private static final String HEADER_EXT = ".h"; //$NON-NLS-1$
|
||||
private static final String SOURCE_EXT = ".cpp"; //$NON-NLS-1$
|
||||
private static boolean fUseIncludeGuard = true;
|
||||
private static final String fLineDelimiter = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
public static String getLineDelimiter() {
|
||||
//TODO line delimiter part of code template prefs?
|
||||
return fLineDelimiter;
|
||||
}
|
||||
|
||||
public static String generateHeaderFileNameFromClass(String className) {
|
||||
//TODO eventually make this a prefs option - filename pattern
|
||||
return className + HEADER_EXT;
|
||||
}
|
||||
|
||||
public static String generateSourceFileNameFromClass(String className) {
|
||||
//TODO eventually make this a prefs option - filename pattern
|
||||
return className + SOURCE_EXT;
|
||||
}
|
||||
|
||||
public static IFile createHeaderFile(IPath filePath, boolean force, IProgressMonitor monitor) throws CoreException {
|
||||
//TODO should use code templates
|
||||
ByteArrayInputStream stream;
|
||||
if (fUseIncludeGuard) {
|
||||
String includeGuardSymbol = generateIncludeGuardSymbol(filePath);
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("#ifndef "); //$NON-NLS-1$
|
||||
buf.append(includeGuardSymbol);
|
||||
buf.append(fLineDelimiter);
|
||||
buf.append("#define "); //$NON-NLS-1$
|
||||
buf.append(includeGuardSymbol);
|
||||
buf.append(fLineDelimiter);
|
||||
buf.append(fLineDelimiter);
|
||||
buf.append("#endif //"); //$NON-NLS-1$
|
||||
buf.append(includeGuardSymbol);
|
||||
buf.append(fLineDelimiter);
|
||||
stream = new ByteArrayInputStream(buf.toString().getBytes());
|
||||
} else {
|
||||
stream = new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
return createNewFile(filePath, stream, force, monitor);
|
||||
}
|
||||
|
||||
private static String generateIncludeGuardSymbol(IPath headerPath) {
|
||||
//TODO eventually make this a prefs option - filename pattern or
|
||||
// unique id/incremental value
|
||||
String name = headerPath.lastSegment();
|
||||
if (name != null) {
|
||||
//convert to upper case and remove invalid characters
|
||||
//eg convert foo.h --> _FOO_H_
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append('_');
|
||||
for (int i = 0; i < name.length(); ++i) {
|
||||
char ch = name.charAt(i);
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
buf.append(Character.toUpperCase(ch));
|
||||
} else if (ch == '.' || ch == '_') {
|
||||
buf.append('_');
|
||||
}
|
||||
}
|
||||
buf.append('_');
|
||||
return buf.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IFile createSourceFile(IPath filePath, boolean useIncludeGuard, boolean force, IProgressMonitor monitor) throws CoreException {
|
||||
//TODO should use code templates
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[0]);
|
||||
return createNewFile(filePath, stream, force, monitor);
|
||||
}
|
||||
|
||||
private static IFile createNewFile(IPath newFilePath, InputStream contents, boolean force, IProgressMonitor monitor) throws CoreException {
|
||||
int totalWork = 100;
|
||||
int createFileWork = totalWork;
|
||||
|
||||
monitor.beginTask(NewClassWizardMessages.getString("NewClassCodeGeneration.createFile.task"), totalWork); //$NON-NLS-1$
|
||||
|
||||
IWorkspaceRoot root = CUIPlugin.getWorkspace().getRoot();
|
||||
IFile newFile = root.getFileForLocation(newFilePath);
|
||||
if (newFile == null)
|
||||
newFile = root.getFile(newFilePath);
|
||||
if (newFile.exists()) {
|
||||
monitor.done();
|
||||
return newFile;
|
||||
}
|
||||
|
||||
if (newFilePath.segmentCount() > 1) {
|
||||
IPath containerPath = newFilePath.removeLastSegments(1);
|
||||
if (root.getContainerForLocation(containerPath) == null) {
|
||||
int containerWork = totalWork / 2;
|
||||
createFileWork = totalWork / 2;
|
||||
ContainerGenerator generator = new ContainerGenerator(containerPath);
|
||||
generator.generateContainer(new SubProgressMonitor(monitor, containerWork));
|
||||
}
|
||||
}
|
||||
|
||||
createFile(newFile, contents, force, new SubProgressMonitor(monitor, createFileWork));
|
||||
monitor.done();
|
||||
|
||||
return newFile;
|
||||
}
|
||||
|
||||
private static void createFile(IFile fileHandle, InputStream contents, boolean force, IProgressMonitor monitor) throws CoreException {
|
||||
if (contents == null)
|
||||
contents = new ByteArrayInputStream(new byte[0]);
|
||||
|
||||
try {
|
||||
fileHandle.create(contents, force, monitor);
|
||||
} catch (CoreException e) {
|
||||
// If the file already existed locally, just refresh to get contents
|
||||
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
|
||||
fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (monitor.isCanceled())
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.wizards;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.wizards.NewElementWizard;
|
||||
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCreationWizardPage;
|
||||
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardMessages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public class NewClassCreationWizard extends NewElementWizard {
|
||||
|
||||
private NewClassCreationWizardPage fPage;
|
||||
|
||||
public NewClassCreationWizard() {
|
||||
super();
|
||||
setDefaultPageImageDescriptor(CPluginImages.DESC_WIZBAN_NEWCLASS);
|
||||
setDialogSettings(CUIPlugin.getDefault().getDialogSettings());
|
||||
setWindowTitle(NewClassWizardMessages.getString("NewClassCreationWizard.title")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Wizard#createPages
|
||||
*/
|
||||
public void addPages() {
|
||||
super.addPages();
|
||||
fPage = new NewClassCreationWizardPage();
|
||||
addPage(fPage);
|
||||
fPage.init(getSelection());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.ui.wizards.NewElementWizard#canRunForked()
|
||||
*/
|
||||
protected boolean canRunForked() {
|
||||
return !fPage.isEnclosingClassSelected();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.internal.ui.wizards.NewElementWizard#finishPage(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
|
||||
fPage.createClass(monitor); // use the full progress monitor
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.wizard.IWizard#performFinish()
|
||||
*/
|
||||
public boolean performFinish() {
|
||||
boolean res = super.performFinish();
|
||||
if (res) {
|
||||
//TODO need prefs option for opening editor
|
||||
boolean openInEditor = true;
|
||||
|
||||
ITranslationUnit bodyTU = fPage.getCreatedSourceTU();
|
||||
if (bodyTU != null) {
|
||||
IResource resource= bodyTU.getResource();
|
||||
selectAndReveal(resource);
|
||||
if (openInEditor) {
|
||||
openResource((IFile) resource);
|
||||
}
|
||||
}
|
||||
ITranslationUnit headerTU = fPage.getCreatedHeaderTU();
|
||||
if (headerTU != null) {
|
||||
IResource resource = headerTU.getResource();
|
||||
selectAndReveal(resource);
|
||||
if (openInEditor) {
|
||||
openResource((IFile) resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue