mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2004-09-09 Chris Wiebe
limit base class selection to referenced projects * src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java * src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
This commit is contained in:
parent
4dcc350233
commit
f3b030d85d
4 changed files with 104 additions and 32 deletions
|
@ -108,7 +108,13 @@ public class PathUtil {
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
IScannerInfo info = provider.getScannerInformation(project);
|
IScannerInfo info = provider.getScannerInformation(project);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
String[] includePaths = info.getIncludePaths();
|
return makeRelativePathToIncludes(fullPath, info.getIncludePaths());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IPath makeRelativePathToIncludes(IPath fullPath, String[] includePaths) {
|
||||||
IPath relativePath = null;
|
IPath relativePath = null;
|
||||||
int mostSegments = 0;
|
int mostSegments = 0;
|
||||||
for (int i = 0; i < includePaths.length; ++i) {
|
for (int i = 0; i < includePaths.length; ++i) {
|
||||||
|
@ -121,12 +127,8 @@ public class PathUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (relativePath != null)
|
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IProject getEnclosingProject(IPath fullPath) {
|
public static IProject getEnclosingProject(IPath fullPath) {
|
||||||
IWorkspaceRoot root = getWorkspaceRoot();
|
IWorkspaceRoot root = getWorkspaceRoot();
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
2004-09-09 Chris Wiebe
|
||||||
|
|
||||||
|
limit base class selection to referenced projects
|
||||||
|
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
|
||||||
|
|
||||||
2004-09-08 Alain Magloire
|
2004-09-08 Alain Magloire
|
||||||
|
|
||||||
Fix For PR 73459
|
Fix For PR 73459
|
||||||
|
|
|
@ -12,10 +12,12 @@ package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CConventions;
|
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.AllTypesCache;
|
||||||
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
||||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||||
|
@ -32,6 +34,8 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
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.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||||
|
@ -133,7 +137,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
private NewClassCodeGenerator fCodeGenerator = null;
|
private NewClassCodeGenerator fCodeGenerator = null;
|
||||||
|
|
||||||
//TODO this should be a prefs option
|
//TODO this should be a prefs option
|
||||||
private boolean fWarnIfBaseClassNotInPath = false;
|
private boolean fErrorIfBaseClassNotInPath = true;
|
||||||
|
|
||||||
public NewClassCreationWizardPage() {
|
public NewClassCreationWizardPage() {
|
||||||
super(PAGE_NAME);
|
super(PAGE_NAME);
|
||||||
|
@ -1220,27 +1224,59 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
*/
|
*/
|
||||||
protected IStatus baseClassesChanged() {
|
protected IStatus baseClassesChanged() {
|
||||||
StatusInfo status = new StatusInfo();
|
StatusInfo status = new StatusInfo();
|
||||||
IProject project = getCurrentProject();
|
if (fErrorIfBaseClassNotInPath) {
|
||||||
if (project != null) {
|
IPath folderPath = getSourceFolderFullPath();
|
||||||
if (fWarnIfBaseClassNotInPath) {
|
if (folderPath != null) {
|
||||||
// make sure all classes belong to the project
|
// make sure all classes belong to the project
|
||||||
IBaseClassInfo[] baseClasses = getBaseClasses();
|
IBaseClassInfo[] baseClasses = getBaseClasses();
|
||||||
|
if (baseClasses != null && baseClasses.length > 0) {
|
||||||
|
// filter out classes not reachable from current source folder
|
||||||
|
IProject project = PathUtil.getEnclosingProject(folderPath);
|
||||||
|
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();
|
||||||
for (int i = 0; i < baseClasses.length; ++i) {
|
for (int i = 0; i < baseClasses.length; ++i) {
|
||||||
ITypeInfo baseType = baseClasses[i].getType();
|
ITypeInfo baseType = baseClasses[i].getType();
|
||||||
IProject baseProject = baseType.getEnclosingProject();
|
if (!isTypeReachable(baseType, project, includePaths)) {
|
||||||
if (baseProject == null || !baseProject.equals(project)) {
|
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.BaseClassNotExistsInProject", baseType.getQualifiedTypeName().toString())); //$NON-NLS-1$
|
||||||
ITypeReference ref = baseType.getResolvedReference();
|
|
||||||
if (ref == null || PathUtil.makeRelativePathToProjectIncludes(ref.getLocation(), project) == null) {
|
|
||||||
status.setWarning(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.warning.BaseClassNotExistsInProject", baseType.getQualifiedTypeName().toString())); //$NON-NLS-1$
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTypeReachable(ITypeInfo type, IProject project, String[] includePaths) {
|
||||||
|
IProject baseProject = type.getEnclosingProject();
|
||||||
|
if (baseProject != null) {
|
||||||
|
if (baseProject.equals(project)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
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.getLocation().isPrefixOf(includePath))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is a hook which gets called after the method stubs
|
* This method is a hook which gets called after the method stubs
|
||||||
* input field has changed. This default implementation updates
|
* input field has changed. This default implementation updates
|
||||||
|
@ -2074,12 +2110,10 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int[] CLASS_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT };
|
|
||||||
|
|
||||||
void chooseBaseClasses() {
|
void chooseBaseClasses() {
|
||||||
prepareTypeCache();
|
prepareTypeCache();
|
||||||
|
|
||||||
ITypeInfo[] elements = AllTypesCache.getTypes(new TypeSearchScope(true), CLASS_TYPES);
|
ITypeInfo[] elements = getAllReachableTypes();
|
||||||
if (elements == null || elements.length == 0) {
|
if (elements == null || elements.length == 0) {
|
||||||
String title = NewClassWizardMessages.getString("NewClassCreationWizardPage.getClasses.noclasses.title"); //$NON-NLS-1$
|
String title = NewClassWizardMessages.getString("NewClassCreationWizardPage.getClasses.noclasses.title"); //$NON-NLS-1$
|
||||||
String message = NewClassWizardMessages.getString("NewClassCreationWizardPage.getClasses.noclasses.message"); //$NON-NLS-1$
|
String message = NewClassWizardMessages.getString("NewClassCreationWizardPage.getClasses.noclasses.message"); //$NON-NLS-1$
|
||||||
|
@ -2102,6 +2136,36 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final int[] CLASS_TYPES = { ICElement.C_CLASS, ICElement.C_STRUCT };
|
||||||
|
|
||||||
|
private ITypeInfo[] getAllReachableTypes() {
|
||||||
|
ITypeInfo[] elements = AllTypesCache.getTypes(new TypeSearchScope(true), CLASS_TYPES);
|
||||||
|
if (elements != null && elements.length > 0) {
|
||||||
|
// filter out classes not reachable from current source folder
|
||||||
|
IPath folderPath = getSourceFolderFullPath();
|
||||||
|
if (folderPath != null) {
|
||||||
|
IProject project = PathUtil.getEnclosingProject(folderPath);
|
||||||
|
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, project, includePaths)) {
|
||||||
|
filteredTypes.add(baseType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ITypeInfo[]) filteredTypes.toArray(new ITypeInfo[filteredTypes.size()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
IPath chooseHeaderFile() {
|
IPath chooseHeaderFile() {
|
||||||
SourceFileSelectionDialog dialog = new SourceFileSelectionDialog(getShell());
|
SourceFileSelectionDialog dialog = new SourceFileSelectionDialog(getShell());
|
||||||
dialog.setTitle(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseHeaderFileDialog.title")); //$NON-NLS-1$
|
dialog.setTitle(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseHeaderFileDialog.title")); //$NON-NLS-1$
|
||||||
|
|
|
@ -71,7 +71,7 @@ NewClassCreationWizardPage.warning.ClassNameDiscouraged=Class name is discourage
|
||||||
|
|
||||||
NewClassCreationWizardPage.baseClasses.label=&Base Classes:
|
NewClassCreationWizardPage.baseClasses.label=&Base Classes:
|
||||||
NewClassCreationWizardPage.error.InvalidBaseClassName=Base class name is not valid. {0}.
|
NewClassCreationWizardPage.error.InvalidBaseClassName=Base class name is not valid. {0}.
|
||||||
NewClassCreationWizardPage.warning.BaseClassNotExistsInProject=Base class ''{0}'' not in include paths for current project.
|
NewClassCreationWizardPage.error.BaseClassNotExistsInProject=Base class ''{0}'' not in include paths for current project.
|
||||||
|
|
||||||
NewClassCreationWizardPage.methodStubs.label=Method &Stubs:
|
NewClassCreationWizardPage.methodStubs.label=Method &Stubs:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue