1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Put the Type Cache back and reactivate the code that uses it, i.e., Open Type and the New Class Wizard. The info still returns null but I'll you should be able to compile.

This commit is contained in:
Doug Schaefer 2006-04-19 19:20:05 +00:00
parent 093466adab
commit b9ae5fbbe8
14 changed files with 944 additions and 82 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="model"/>
<classpathentry kind="src" path="browser"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="utils"/>
<classpathentry kind="src" path="parser"/>

View file

@ -7,6 +7,7 @@ Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.browser,
org.eclipse.cdt.core.dom,
org.eclipse.cdt.core.dom.ast,
org.eclipse.cdt.core.dom.ast.c,
@ -24,6 +25,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.parser.util,
org.eclipse.cdt.core.resources,
org.eclipse.cdt.internal.core,
org.eclipse.cdt.internal.core.browser.util,
org.eclipse.cdt.internal.core.dom,
org.eclipse.cdt.internal.core.dom.parser,
org.eclipse.cdt.internal.core.dom.parser.c,
@ -45,6 +47,9 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.pdom.dom,
org.eclipse.cdt.internal.core.pdom.dom.c,
org.eclipse.cdt.internal.core.pdom.dom.cpp,
org.eclipse.cdt.internal.core.pdom.indexer.ctags,
org.eclipse.cdt.internal.core.pdom.indexer.fast,
org.eclipse.cdt.internal.core.pdom.indexer.nulli,
org.eclipse.cdt.internal.core.util,
org.eclipse.cdt.internal.errorparsers,
org.eclipse.cdt.internal.formatter,

View file

@ -0,0 +1,188 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.browser;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
/**
* @author Doug Schaefer
*
*/
public class PDOMTypeInfo implements ITypeInfo {
public void addDerivedReference(ITypeReference location) {
// TODO Auto-generated method stub
}
public void addReference(ITypeReference location) {
// TODO Auto-generated method stub
}
public boolean canSubstituteFor(ITypeInfo info) {
// TODO Auto-generated method stub
return false;
}
public boolean encloses(ITypeInfo info) {
// TODO Auto-generated method stub
return false;
}
public boolean exists() {
// TODO Auto-generated method stub
return false;
}
public int getCElementType() {
// TODO Auto-generated method stub
return 0;
}
public ITypeReference[] getDerivedReferences() {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo[] getEnclosedTypes() {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo[] getEnclosedTypes(int[] kinds) {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo getEnclosingNamespace(boolean includeGlobalNamespace) {
// TODO Auto-generated method stub
return null;
}
public ICProject getEnclosingProject() {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo getEnclosingType() {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo getEnclosingType(int[] kinds) {
// TODO Auto-generated method stub
return null;
}
public String getName() {
// TODO Auto-generated method stub
return null;
}
public IQualifiedTypeName getQualifiedTypeName() {
// TODO Auto-generated method stub
return null;
}
public ITypeReference[] getReferences() {
// TODO Auto-generated method stub
return null;
}
public ITypeReference getResolvedReference() {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo[] getSubTypes() {
// TODO Auto-generated method stub
return null;
}
public ASTAccessVisibility getSuperTypeAccess(ITypeInfo subType) {
// TODO Auto-generated method stub
return null;
}
public ITypeInfo[] getSuperTypes() {
// TODO Auto-generated method stub
return null;
}
public boolean hasEnclosedTypes() {
// TODO Auto-generated method stub
return false;
}
public boolean hasSubTypes() {
// TODO Auto-generated method stub
return false;
}
public boolean hasSuperTypes() {
// TODO Auto-generated method stub
return false;
}
public boolean isClass() {
// TODO Auto-generated method stub
return false;
}
public boolean isEnclosed(ITypeInfo info) {
// TODO Auto-generated method stub
return false;
}
public boolean isEnclosed(ITypeSearchScope scope) {
// TODO Auto-generated method stub
return false;
}
public boolean isEnclosedType() {
// TODO Auto-generated method stub
return false;
}
public boolean isEnclosingType() {
// TODO Auto-generated method stub
return false;
}
public boolean isReferenced(ITypeSearchScope scope) {
// TODO Auto-generated method stub
return false;
}
public boolean isUndefinedType() {
// TODO Auto-generated method stub
return false;
}
public void setCElementType(int type) {
// TODO Auto-generated method stub
}
public int compareTo(Object arg0) {
// TODO Auto-generated method stub
return 0;
}
}

View file

@ -10,12 +10,28 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.browser.opentype;
import org.eclipse.cdt.core.browser.AllTypesCache;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.ITextEditor;
public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
@ -29,12 +45,96 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
ITypeInfo[] elements = AllTypesCache.getAllTypes();
if (elements.length == 0) {
String title = OpenTypeMessages.getString("OpenTypeAction.notypes.title"); //$NON-NLS-1$
String message = OpenTypeMessages.getString("OpenTypeAction.notypes.message"); //$NON-NLS-1$
MessageDialog.openInformation(getShell(), title, message);
return;
}
OpenTypeDialog dialog = new OpenTypeDialog(getShell());
dialog.setElements(elements);
int result = dialog.open();
if (result != IDialogConstants.OK_ID)
return;
ITypeInfo info = (ITypeInfo) dialog.getFirstResult();
if (info == null)
return;
ITypeReference location = info.getResolvedReference();
if (location == null) {
// could not resolve location
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorTypeNotFound", info.getQualifiedTypeName().toString()); //$NON-NLS-1$
MessageDialog.openError(getShell(), title, message);
} else if (!openTypeInEditor(location)) {
// error opening editor
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorOpenEditor", location.getPath().toString()); //$NON-NLS-1$
MessageDialog.openError(getShell(), title, message);
}
}
protected Shell getShell() {
return CUIPlugin.getActiveWorkbenchShell();
}
/**
* Opens an editor and displays the selected type.
*
* @param info Type to display.
* @return true if succesfully displayed.
*/
private boolean openTypeInEditor(ITypeReference location) {
ITranslationUnit unit = location.getTranslationUnit();
IEditorPart editorPart = null;
try {
if (unit != null)
editorPart = EditorUtility.openInEditor(unit);
if (editorPart == null) {
// open as external file
IPath path = location.getLocation();
if (path != null) {
IStorage storage = new FileStorage(path);
editorPart = EditorUtility.openInEditor(storage);
}
}
// highlight the type in the editor
if (editorPart != null && editorPart instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) editorPart;
if( location.isLineNumber() )
{
IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
try
{
int startOffset = document.getLineOffset(location.getOffset()-1);
int length=document.getLineLength(location.getOffset()-1);
editor.selectAndReveal(startOffset, length);
return true;
}
catch( BadLocationException ble )
{
return false;
}
}
editor.selectAndReveal(location.getOffset(), location.getLength());
return true;
}
} catch (CModelException ex) {
ex.printStackTrace();
return false;
} catch (PartInitException ex) {
ex.printStackTrace();
return false;
}
return false;
}
/*
* (non-Javadoc)
*

View file

@ -0,0 +1,154 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software Systems - adapted for use in CDT
*******************************************************************************/
package org.eclipse.cdt.ui.browser.typeinfo;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeInfo;
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.ICProject;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
public class TypeInfoLabelProvider extends LabelProvider {
public static final int SHOW_TYPE_ONLY= 0x01;
public static final int SHOW_ENCLOSING_TYPE_ONLY= 0x02;
public static final int SHOW_FULLY_QUALIFIED= 0x04;
public static final int SHOW_PATH= 0x08;
private static final Image HEADER_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TUNIT_HEADER);
private static final Image SOURCE_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TUNIT);
private static final Image NAMESPACE_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_NAMESPACE);
private static final Image TEMPLATE_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TEMPLATE);
private static final Image CLASS_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_CLASS);
private static final Image STRUCT_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_STRUCT);
private static final Image TYPEDEF_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_TYPEDEF);
private static final Image UNION_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_UNION);
private static final Image ENUM_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_ENUMERATION);
private static final Image UNKNOWN_TYPE_ICON= CPluginImages.get(CPluginImages.IMG_OBJS_UNKNOWN_TYPE);
private int fFlags;
public TypeInfoLabelProvider(int flags) {
fFlags= flags;
}
private boolean isSet(int flag) {
return (fFlags & flag) != 0;
}
/* non java-doc
* @see ILabelProvider#getText
*/
public String getText(Object element) {
if (! (element instanceof ITypeInfo))
return super.getText(element);
ITypeInfo typeRef= (ITypeInfo) element;
IQualifiedTypeName qualifiedName = typeRef.getQualifiedTypeName();
StringBuffer buf= new StringBuffer();
if (isSet(SHOW_TYPE_ONLY)) {
String name= typeRef.getName();
if (name != null && name.length() > 0)
buf.append(name);
} else if (isSet(SHOW_ENCLOSING_TYPE_ONLY)) {
IQualifiedTypeName parentName= qualifiedName.getEnclosingTypeName();
if (parentName != null) {
buf.append(parentName.getFullyQualifiedName());
} else {
buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.globalScope")); //$NON-NLS-1$
}
} else if (isSet(SHOW_FULLY_QUALIFIED)) {
buf.append(qualifiedName.getFullyQualifiedName());
}
if (isSet(SHOW_PATH)) {
IPath path = null;
ITypeReference ref = typeRef.getResolvedReference();
if (ref != null) {
path = ref.getPath();
} else {
ICProject project = typeRef.getEnclosingProject();
if (project != null) {
path = project.getProject().getFullPath();
}
}
if (path != null) {
buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$
buf.append(path.toString());
}
}
return buf.toString();
}
/* non java-doc
* @see ILabelProvider#getImage
*/
public Image getImage(Object element) {
if (!(element instanceof ITypeInfo))
return super.getImage(element);
ITypeInfo typeRef= (ITypeInfo) element;
if (isSet(SHOW_ENCLOSING_TYPE_ONLY)) {
ITypeInfo parentInfo = typeRef.getEnclosingType();
if (parentInfo != null) {
return getTypeIcon(parentInfo.getCElementType());
}
IPath path = null;
ITypeReference ref = typeRef.getResolvedReference();
if (ref != null) {
path = ref.getPath();
if (CoreModel.isValidHeaderUnitName(typeRef.getEnclosingProject().getProject(), path.lastSegment())) {
return HEADER_ICON;
}
}
return SOURCE_ICON;
}
return getTypeIcon(typeRef.getCElementType());
}
public static Image getTypeIcon(int type)
{
switch (type)
{
case ICElement.C_NAMESPACE:
return NAMESPACE_ICON;
case ICElement.C_TEMPLATE_CLASS:
return TEMPLATE_ICON;
case ICElement.C_CLASS:
return CLASS_ICON;
case ICElement.C_STRUCT:
return STRUCT_ICON;
case ICElement.C_UNION:
return UNION_ICON;
case ICElement.C_ENUMERATION:
return ENUM_ICON;
case ICElement.C_TYPEDEF:
return TYPEDEF_ICON;
default:
return UNKNOWN_TYPE_ICON;
}
}
}

View file

@ -11,13 +11,17 @@
*******************************************************************************/
package org.eclipse.cdt.ui.browser.typeinfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.util.QualifiedTypeName;
import org.eclipse.cdt.internal.ui.util.StringMatcher;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.dialogs.IDialogSettings;
@ -117,7 +121,46 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
* @see FilteredList.FilterMatcher#match(Object)
*/
public boolean match(Object element) {
return false;
if (!(element instanceof ITypeInfo))
return false;
ITypeInfo info = (ITypeInfo) element;
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
if (fVisibleTypes != null && !fVisibleTypes.contains(new Integer(info.getCElementType())))
return false;
if (!fShowLowLevelTypes && qualifiedName.isLowLevel())
return false;
if (fSegmentMatchers.length == 1 && !fMatchGlobalNamespace)
return fNameMatcher.match(qualifiedName.getName());
return matchQualifiedName(info);
}
private boolean matchQualifiedName(ITypeInfo info) {
IQualifiedTypeName qualifiedName = info.getQualifiedTypeName();
if (fSegmentMatchers.length != qualifiedName.segmentCount())
return false;
if (fMatchGlobalNamespace) {
// must match global namespace (eg ::foo)
if (info.getRootNamespace(false) != null)
return false;
}
boolean matchFound = true;
int max = Math.min(fSegmentMatchers.length, qualifiedName.segmentCount());
for (int i = 0; i < max; ++i) {
StringMatcher matcher = fSegmentMatchers[i];
String name = qualifiedName.segment(i);
if (name == null || !matcher.match(name)) {
matchFound = false;
break;
}
}
return matchFound;
}
private static String adjustPattern(String pattern) {
@ -160,6 +203,9 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
private static final String SETTINGS_SHOW_UNIONS = "show_unions"; //$NON-NLS-1$
private static final String SETTINGS_SHOW_LOWLEVEL = "show_lowlevel"; //$NON-NLS-1$
private static final TypeInfoLabelProvider fElementRenderer = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY);
private static final TypeInfoLabelProvider fQualifierRenderer = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_ENCLOSING_TYPE_ONLY + TypeInfoLabelProvider.SHOW_PATH);
static final TypeFilterMatcher fFilterMatcher = new TypeFilterMatcher();
private static final StringComparator fStringComparator = new StringComparator();
@ -180,7 +226,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
* @param parent the parent shell.
*/
public TypeSelectionDialog(Shell parent) {
super(parent, null, null);//fElementRenderer, fQualifierRenderer);
super(parent, fElementRenderer, fQualifierRenderer);
setMatchEmptyString(false);
setUpperListLabel(TypeInfoMessages.getString("TypeSelectionDialog.upperLabel")); //$NON-NLS-1$
setLowerListLabel(TypeInfoMessages.getString("TypeSelectionDialog.lowerLabel")); //$NON-NLS-1$
@ -295,7 +341,7 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
default:
return;
}
Image icon = null; //TypeInfoLabelProvider.getTypeIcon(type);
Image icon = TypeInfoLabelProvider.getTypeIcon(type);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout= new GridLayout(2, false);
@ -524,5 +570,12 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
* @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
*/
protected void computeResult() {
ITypeInfo selection = (ITypeInfo) getLowerSelectedElement();
if (selection == null)
return;
List result = new ArrayList(1);
result.add(selection);
setResult(result);
}
}

View file

@ -10,19 +10,26 @@
*******************************************************************************/
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(ASTAccessVisibility access, boolean isVirtual) {
public BaseClassInfo(ITypeInfo type, ASTAccessVisibility access, boolean isVirtual) {
fType = type;
fAccess = access;
fIsVirtual = isVirtual;
}
public ITypeInfo getType() {
return fType;
}
public ASTAccessVisibility getAccess() {
return fAccess;
}

View file

@ -11,6 +11,7 @@
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;
@ -36,6 +37,8 @@ public final class BaseClassesLabelProvider implements ITableLabelProvider {
return ACCESS_PUBLIC;
}
private static TypeInfoLabelProvider fTypeInfoLabelProvider = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED);
/*
* @see ITableLabelProvider#getColumnImage(Object, int)
*/
@ -44,7 +47,7 @@ public final class BaseClassesLabelProvider implements ITableLabelProvider {
return null;
IBaseClassInfo info = (IBaseClassInfo) element;
return null; //fTypeInfoLabelProvider.getImage(info.getType());
return fTypeInfoLabelProvider.getImage(info.getType());
}
/*
@ -55,7 +58,7 @@ public final class BaseClassesLabelProvider implements ITableLabelProvider {
switch (columnIndex) {
case 0:
return null; //fTypeInfoLabelProvider.getText(info.getType());
return fTypeInfoLabelProvider.getText(info.getType());
case 1:
return getAccessText(info.getAccess());
case 2:

View file

@ -10,10 +10,12 @@
*******************************************************************************/
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();

View file

@ -11,13 +11,19 @@
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.browser.ITypeInfo;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogConstants;
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 {
@ -28,6 +34,7 @@ public class NewBaseClassSelectionDialog extends TypeSelectionDialog {
private List fTypeListeners;
public interface ITypeSelectionListener {
void typeAdded(ITypeInfo baseClass);
}
public NewBaseClassSelectionDialog(Shell parent) {
@ -51,6 +58,19 @@ public class NewBaseClassSelectionDialog extends TypeSelectionDialog {
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
*/
@ -78,6 +98,61 @@ public class NewBaseClassSelectionDialog extends TypeSelectionDialog {
}
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.classalreadyadded.info", qualifiedName); //$NON-NLS-1$
updateStatus(new StatusInfo(IStatus.INFO, message));
} else {
String qualifiedName = type.getQualifiedTypeName().getFullyQualifiedName();
String message = NewClassWizardMessages.getFormattedString("NewBaseClassSelectionDialog.addingclass.info", qualifiedName); //$NON-NLS-1$
updateStatus(new StatusInfo(IStatus.INFO, message));
boolean canAdd = true;
if (verifyBaseClasses()) {
IProgressService service = PlatformUI.getWorkbench().getProgressService();
NewClassWizardUtil.resolveClassLocation(type, service);
canAdd = (type.getResolvedReference() != null);
}
// // 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 (canAdd) {
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));
}
}
}
}
/**

View file

@ -15,6 +15,10 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
@ -24,15 +28,12 @@ import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.util.IQualifiedTypeName;
import org.eclipse.cdt.core.model.util.QualifiedTypeName;
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.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@ -385,22 +386,22 @@ public class NewClassCodeGenerator {
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);
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);
}
}
}
@ -521,10 +522,10 @@ public class NewClassCodeGenerator {
if (cProject.getPath().segment(0).equals(folderToAdd.segment(0)))
continue;
IProject includeProject = PathUtil.getEnclosingProject(folderToAdd);
ICProject includeProject = PathUtil.getEnclosingProject(folderToAdd);
// make sure that the include is made the same way that build properties for projects makes them, so .contains below is a valid check
IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, null, includeProject.getLocation(), true);
IIncludeEntry entry = CoreModel.newIncludeEntry(addToResourcePath, null, includeProject.getProject().getLocation(), true);
if (!checkEntryList.contains(entry)) // if the path already exists in the #includes then don't add it
pathEntryList.add(entry);
@ -623,20 +624,20 @@ public class NewClassCodeGenerator {
private List getBaseClassPaths(boolean verifyLocation) throws CodeGeneratorException {
List list = new ArrayList();
for (int i = 0; i < fBaseClasses.length; ++i) {
// IBaseClassInfo baseClass = fBaseClasses[i];
// ITypeReference ref = baseClass.getType().getResolvedReference();
// IPath baseClassLocation = null;
// if (ref != null) {
// baseClassLocation = ref.getLocation();
// }
//
// if (baseClassLocation == null) {
// if (verifyLocation) {
// throw new CodeGeneratorException("Could not find base class " + baseClass.toString()); //$NON-NLS-1$
// }
// } else if (!list.contains(baseClassLocation)) {
// list.add(baseClassLocation);
// }
IBaseClassInfo baseClass = fBaseClasses[i];
ITypeReference ref = baseClass.getType().getResolvedReference();
IPath baseClassLocation = null;
if (ref != null) {
baseClassLocation = ref.getLocation();
}
if (baseClassLocation == null) {
if (verifyLocation) {
throw new CodeGeneratorException("Could not find base class " + baseClass.toString()); //$NON-NLS-1$
}
} else if (!list.contains(baseClassLocation)) {
list.add(baseClassLocation);
}
}
return list;
}

View file

@ -10,22 +10,35 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.AllTypesCache;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.TypeSearchScope;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@ -252,5 +265,82 @@ public class NewClassWizardUtil {
public static IWorkspaceRoot getWorkspaceRoot() {
return ResourcesPlugin.getWorkspace().getRoot();
}
/**
* Resolve the location of the given class.
*
* @param type the class to resolve
* @param context the runnable context
* @return the class location, or <code>null</code> if not found
*/
public static ITypeReference resolveClassLocation(ITypeInfo type, IRunnableContext context) {
return type.getResolvedReference();
}
private static final int[] CLASS_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT };
/**
* Returns all classes/structs which are accessible from the include
* paths of the given project.
*
* @param project the given project
* @return array of classes/structs
*/
public static ITypeInfo[] getReachableClasses(ICProject cProject) {
ITypeInfo[] elements = AllTypesCache.getTypes(new TypeSearchScope(true), CLASS_TYPES);
if (elements != null && elements.length > 0) {
if (cProject != null) {
IProject project = cProject.getProject();
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
if (provider != null) {
//TODO get the scanner info for the actual source folder
IScannerInfo info = provider.getScannerInformation(project);
if (info != null) {
String[] includePaths = info.getIncludePaths();
List filteredTypes = new ArrayList();
for (int i = 0; i < elements.length; ++i) {
ITypeInfo baseType = elements[i];
if (isTypeReachable(baseType, cProject, includePaths)) {
filteredTypes.add(baseType);
}
}
return (ITypeInfo[]) filteredTypes.toArray(new ITypeInfo[filteredTypes.size()]);
}
}
}
}
return elements;
}
/**
* Checks whether the given type can be found in the given project or the
* given include paths.
*
* @param type the type
* @param project the project
* @param includePaths the include paths
* @return <code>true</code> if the given type is found
*/
public static boolean isTypeReachable(ITypeInfo type, ICProject project, String[] includePaths) {
ICProject baseProject = type.getEnclosingProject();
if (baseProject != null) {
if (baseProject.equals(project)) {
return true;
}
ITypeReference ref = type.getResolvedReference();
for (int i = 0; i < includePaths.length; ++i) {
IPath includePath = new Path(includePaths[i]);
if (ref != null) {
if (includePath.isPrefixOf(ref.getLocation()))
return true;
} else {
// we don't have the real location, so just check the project path
if (baseProject.getProject().getLocation().isPrefixOf(includePath))
return true;
}
}
}
return false;
}
}

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.wizards.classwizard;
import java.util.ArrayList;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
@ -30,7 +31,6 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CElementSorter;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;

View file

@ -10,37 +10,48 @@
*******************************************************************************/
package org.eclipse.cdt.ui.wizards;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CConventions;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.AllTypesCache;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeSearchScope;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.browser.TypeSearchScope;
import org.eclipse.cdt.core.browser.TypeUtil;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.util.IQualifiedTypeName;
import org.eclipse.cdt.core.model.util.QualifiedTypeName;
import org.eclipse.cdt.core.model.util.TypeUtil;
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.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.cdt.internal.ui.util.SWTUtil;
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog;
import org.eclipse.cdt.internal.ui.wizards.classwizard.BaseClassInfo;
import org.eclipse.cdt.internal.ui.wizards.classwizard.BaseClassesListDialogField;
import org.eclipse.cdt.internal.ui.wizards.classwizard.ConstructorMethodStub;
import org.eclipse.cdt.internal.ui.wizards.classwizard.DestructorMethodStub;
import org.eclipse.cdt.internal.ui.wizards.classwizard.IBaseClassInfo;
import org.eclipse.cdt.internal.ui.wizards.classwizard.IMethodStub;
import org.eclipse.cdt.internal.ui.wizards.classwizard.MethodStubsListDialogField;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NamespaceSelectionDialog;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewBaseClassSelectionDialog;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCodeGenerator;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardMessages;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardPrefs;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardUtil;
import org.eclipse.cdt.internal.ui.wizards.classwizard.SourceFileSelectionDialog;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardUtil;
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewBaseClassSelectionDialog.ITypeSelectionListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter;
@ -52,7 +63,6 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -63,6 +73,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
@ -562,7 +574,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
*
* @return the current project
*/
protected IProject getCurrentProject() {
protected ICProject getCurrentProject() {
IPath folderPath = getSourceFolderFullPath();
if (folderPath != null) {
return PathUtil.getEnclosingProject(folderPath);
@ -677,25 +689,25 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
* @param access the access visibility (public/private/protected)
* @param isVirtual <code>true</code> if the inheritance is virtual
*/
// protected void addBaseClass(ITypeInfo newBaseClass, ASTAccessVisibility access, boolean isVirtual) {
// // check if already exists
// List baseClasses = fBaseClassesDialogField.getElements();
// if (baseClasses != null) {
// for (Iterator i = baseClasses.iterator(); i.hasNext(); ) {
// BaseClassInfo info = (BaseClassInfo) i.next();
// if (info.getType().equals(newBaseClass)) {
// // already added
// return;
// }
// }
// }
//
// if (verifyBaseClasses()) {
// NewClassWizardUtil.resolveClassLocation(newBaseClass, getContainer());
// }
//
// fBaseClassesDialogField.addBaseClass(new BaseClassInfo(newBaseClass, access, isVirtual));
// }
protected void addBaseClass(ITypeInfo newBaseClass, ASTAccessVisibility access, boolean isVirtual) {
// check if already exists
List baseClasses = fBaseClassesDialogField.getElements();
if (baseClasses != null) {
for (Iterator i = baseClasses.iterator(); i.hasNext(); ) {
BaseClassInfo info = (BaseClassInfo) i.next();
if (info.getType().equals(newBaseClass)) {
// already added
return;
}
}
}
if (verifyBaseClasses()) {
NewClassWizardUtil.resolveClassLocation(newBaseClass, getContainer());
}
fBaseClassesDialogField.addBaseClass(new BaseClassInfo(newBaseClass, access, isVirtual));
}
/**
* Returns the selection state of the file group checkbox.
@ -963,6 +975,34 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
*/
private final class NamespaceFieldAdapter implements IStringButtonAdapter, IDialogFieldListener {
public void changeControlPressed(DialogField field) {
ITypeInfo ns = chooseNamespace();
if (ns != null) {
int changedFields = NAMESPACE_ID|CLASS_NAME_ID;
IPath oldFolderPath = getSourceFolderFullPath();
if (oldFolderPath == null) {
IPath headerPath = getHeaderFileFullPath();
IPath sourcePath = getSourceFileFullPath();
IPath newFolderPath = updateSourceFolderFromPath(ns.getEnclosingProject().getProject().getFullPath());
if (newFolderPath != null) {
changedFields |= SOURCE_FOLDER_ID | HEADER_FILE_ID | SOURCE_FILE_ID;
// adjust the relative paths
if (oldFolderPath != null && oldFolderPath.matchingFirstSegments(newFolderPath) == 0) {
if (headerPath != null) {
headerPath = newFolderPath.append(headerPath.lastSegment());
}
if (sourcePath != null) {
sourcePath = newFolderPath.append(sourcePath.lastSegment());
}
}
setSourceFolderFullPath(newFolderPath, false);
// adjust the relative paths
setHeaderFileFullPath(headerPath, false);
setSourceFileFullPath(sourcePath, false);
}
}
setNamespaceText(ns.getQualifiedTypeName().toString(), false);
handleFieldChanged(changedFields);
}
}
public void dialogFieldChanged(DialogField field) {
@ -982,9 +1022,36 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
if (folder != null) {
return folder.getPath();
}
IProject proj = PathUtil.getEnclosingProject(filePath);
ICProject proj = PathUtil.getEnclosingProject(filePath);
if (proj != null)
return proj.getFullPath();
return proj.getProject().getFullPath();
return null;
}
private ITypeInfo chooseNamespace() {
ITypeSearchScope scope;
ICProject project = getCurrentProject();
if (project != null) {
scope = new TypeSearchScope(project);
} else {
scope = new TypeSearchScope(true);
}
ITypeInfo[] elements = AllTypesCache.getNamespaces(scope, false);
if (elements == null || elements.length == 0) {
String title = NewClassWizardMessages.getString("NewClassCreationWizardPage.getTypes.noNamespaces.title"); //$NON-NLS-1$
String message = NewClassWizardMessages.getString("NewClassCreationWizardPage.getTypes.noNamespaces.message"); //$NON-NLS-1$
MessageDialog.openInformation(getShell(), title, message);
return null;
}
NamespaceSelectionDialog dialog = new NamespaceSelectionDialog(getShell());
dialog.setElements(elements);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
return (ITypeInfo) dialog.getFirstResult();
}
return null;
}
@ -1021,6 +1088,27 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
private void chooseBaseClasses() {
ITypeInfo[] elements = NewClassWizardUtil.getReachableClasses(getCurrentProject());
if (elements == null || elements.length == 0) {
String title = NewClassWizardMessages.getString("NewClassCreationWizardPage.getTypes.noClasses.title"); //$NON-NLS-1$
String message = NewClassWizardMessages.getString("NewClassCreationWizardPage.getTypes.noClasses.message"); //$NON-NLS-1$
MessageDialog.openInformation(getShell(), title, message);
return;
}
List oldContents = fBaseClassesDialogField.getElements();
NewBaseClassSelectionDialog dialog = new NewBaseClassSelectionDialog(getShell());
dialog.addListener(new ITypeSelectionListener() {
public void typeAdded(ITypeInfo newBaseClass) {
addBaseClass(newBaseClass, ASTAccessVisibility.PUBLIC, false);
}
});
dialog.setElements(elements);
int result = dialog.open();
if (result != IDialogConstants.OK_ID) {
// restore the old contents
fBaseClassesDialogField.setElements(oldContents);
}
}
/**
@ -1114,9 +1202,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
SourceFileSelectionDialog dialog = new SourceFileSelectionDialog(getShell());
dialog.setTitle(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseHeaderFileDialog.title")); //$NON-NLS-1$
ICElement input = CoreModel.create(NewClassWizardUtil.getWorkspaceRoot());
IProject project = getCurrentProject();
ICProject project = getCurrentProject();
if (project != null)
input = CoreModel.getDefault().create(project);
input = project;
dialog.setInput(input);
IPath filePath = getHeaderFileFullPath();
@ -1141,9 +1229,9 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
SourceFileSelectionDialog dialog = new SourceFileSelectionDialog(getShell());
dialog.setTitle(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseSourceFileDialog.title")); //$NON-NLS-1$
ICElement input = CoreModel.create(NewClassWizardUtil.getWorkspaceRoot());
IProject project = getCurrentProject();
ICProject project = getCurrentProject();
if (project != null)
input = CoreModel.getDefault().create(project);
input = project;
dialog.setInput(input);
IPath filePath = getSourceFileFullPath();
@ -1392,14 +1480,62 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
IQualifiedTypeName typeName = new QualifiedTypeName(namespace);
IProject project = getCurrentProject();
ICProject project = getCurrentProject();
if (project != null) {
if (typeName.isQualified()) {
// make sure enclosing namespace exists
ITypeInfo parentNamespace = AllTypesCache.getType(project, ICElement.C_NAMESPACE, typeName.getEnclosingTypeName());
if (parentNamespace == null) {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.EnclosingNamespaceNotExists")); //$NON-NLS-1$
return status;
}
}
ITypeInfo[] types = AllTypesCache.getTypes(project, typeName, false, true);
if (types.length > 0) {
// look for namespace
boolean foundNamespace = false;
boolean exactMatch = false;
for (int i = 0; i < types.length; ++i) {
ITypeInfo currType = types[i];
if (currType.getCElementType() == ICElement.C_NAMESPACE) {
foundNamespace = true;
exactMatch = currType.getQualifiedTypeName().equals(typeName);
if (exactMatch) {
// found a matching namespace
break;
}
}
}
if (foundNamespace) {
if (exactMatch) {
// we're good to go
status.setOK();
} else {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.NamespaceExistsDifferentCase")); //$NON-NLS-1$
}
return status;
}
// look for other types
exactMatch = false;
for (int i = 0; i < types.length; ++i) {
ITypeInfo currType = types[i];
if (currType.getCElementType() != ICElement.C_NAMESPACE) {
exactMatch = currType.getQualifiedTypeName().equals(typeName);
if (exactMatch) {
// found a matching type
break;
}
}
}
if (exactMatch) {
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.TypeMatchingNamespaceExists")); //$NON-NLS-1$
} else {
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.TypeMatchingNamespaceExistsDifferentCase")); //$NON-NLS-1$
}
} else {
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.NamespaceNotExists")); //$NON-NLS-1$
}
}
val = CConventions.validateNamespaceName(typeName.lastSegment());
@ -1442,7 +1578,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
// continue checking
}
IProject project = getCurrentProject();
ICProject project = getCurrentProject();
if (project != null) {
IQualifiedTypeName fullyQualifiedName = typeName;
if (isNamespaceSelected()) {
@ -1452,8 +1588,51 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
}
ITypeInfo[] types = AllTypesCache.getTypes(project, fullyQualifiedName, false, true);
if (types.length > 0) {
// look for class
boolean foundClass = false;
boolean exactMatch = false;
for (int i = 0; i < types.length; ++i) {
ITypeInfo currType = types[i];
if (currType.getCElementType() == ICElement.C_CLASS
|| currType.getCElementType() == ICElement.C_STRUCT) {
foundClass = true;
exactMatch = currType.getQualifiedTypeName().equals(fullyQualifiedName);
if (exactMatch) {
// found a matching class
break;
}
}
}
if (foundClass) {
if (exactMatch) {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.ClassNameExists")); //$NON-NLS-1$
} else {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.ClassNameExistsDifferentCase")); //$NON-NLS-1$
}
return status;
}
// look for other types
exactMatch = false;
for (int i = 0; i < types.length; ++i) {
ITypeInfo currType = types[i];
if (currType.getCElementType() != ICElement.C_CLASS
&& currType.getCElementType() != ICElement.C_STRUCT) {
exactMatch = currType.getQualifiedTypeName().equals(fullyQualifiedName);
if (exactMatch) {
// found a matching type
break;
}
}
}
if (exactMatch) {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.TypeMatchingClassExists")); //$NON-NLS-1$
} else {
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.TypeMatchingClassExistsDifferentCase")); //$NON-NLS-1$
}
return status;
}
}
return status;
}
@ -1467,7 +1646,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
protected IStatus baseClassesChanged() {
if (verifyBaseClasses()) {
IPath folder = getSourceFolderFullPath();
IProject project = getCurrentProject();
ICProject project = getCurrentProject();
if (project != null) {
IBaseClassInfo[] baseClasses = getBaseClasses();
// make sure all classes belong to the project
@ -1494,17 +1673,21 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
*
* @return the status of the validation
*/
protected IStatus baseClassesChanged(IProject project, IPath sourceFolder, IBaseClassInfo[] baseClasses) {
protected IStatus baseClassesChanged(ICProject project, IPath sourceFolder, IBaseClassInfo[] baseClasses) {
MultiStatus status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project.getProject());
if (provider != null) {
//TODO get the scanner info for the actual source folder
IScannerInfo info = provider.getScannerInformation(project);
IScannerInfo info = provider.getScannerInformation(project.getProject());
if (info != null) {
String[] includePaths = info.getIncludePaths();
for (int i = 0; i < baseClasses.length; ++i) {
IBaseClassInfo baseClass = baseClasses[i];
ITypeInfo baseType = baseClass.getType();
StatusInfo baseClassStatus = new StatusInfo();
if (!NewClassWizardUtil.isTypeReachable(baseType, project, includePaths)) {
baseClassStatus.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.BaseClassNotExistsInProject", baseType.getQualifiedTypeName().toString())); //$NON-NLS-1$
}
status.add(baseClassStatus);
}
}
@ -1588,7 +1771,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
if (!fileExists) {
IStatus val = CConventions.validateHeaderFileName(getCurrentProject(), path.lastSegment());
IStatus val = CConventions.validateHeaderFileName(getCurrentProject().getProject(), path.lastSegment());
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.InvalidHeaderFileName", val.getMessage())); //$NON-NLS-1$
return status;
@ -1655,7 +1838,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
}
if (!fileExists) {
IStatus val = CConventions.validateSourceFileName(getCurrentProject(), path.lastSegment());
IStatus val = CConventions.validateSourceFileName(getCurrentProject().getProject(), path.lastSegment());
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.InvalidSourceFileName", val.getMessage())); //$NON-NLS-1$
return status;