mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Update the necessary classes to use the new
ResolverModel.
This commit is contained in:
parent
895266aebe
commit
40f9982534
15 changed files with 61 additions and 137 deletions
|
@ -112,17 +112,17 @@ public class CModelTests extends TestCase {
|
|||
testProject=CProjectHelper.createCProject("naturetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
assertTrue("hasCNature works", CoreModel.getDefault().hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature", !(CoreModel.getDefault().hasCCNature(testProject.getProject())));
|
||||
assertTrue("hasCNature works", CoreModel.hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature", !(CoreModel.hasCCNature(testProject.getProject())));
|
||||
|
||||
|
||||
CCProjectNature.addCCNature(testProject.getProject(), monitor);
|
||||
assertTrue("hasCCNature works", (CoreModel.getDefault().hasCCNature(testProject.getProject())));
|
||||
assertTrue("hasCCNature works", (CoreModel.hasCCNature(testProject.getProject())));
|
||||
|
||||
CCProjectNature.removeCCNature(testProject.getProject(), monitor);
|
||||
CCProjectNature.removeCNature(testProject.getProject(), monitor);
|
||||
assertTrue("hasCNature works without cnature", !CoreModel.getDefault().hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature or cnature", !(CoreModel.getDefault().hasCCNature(testProject.getProject())));
|
||||
assertTrue("hasCNature works without cnature", !CoreModel.hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature or cnature", !(CoreModel.hasCCNature(testProject.getProject())));
|
||||
try{
|
||||
testProject.getProject().delete(true,true,monitor);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class CModelTests extends TestCase {
|
|||
assertTrue("isSharedLib", !CoreModel.getDefault().isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.getDefault().isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.getDefault().isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.getDefault().isTranslationUnit(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
|
||||
file = testProject.getProject().getFile("exetest.c");
|
||||
|
@ -171,7 +171,7 @@ public class CModelTests extends TestCase {
|
|||
assertTrue("isSharedLib", !CoreModel.getDefault().isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.getDefault().isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.getDefault().isObject(file));
|
||||
assertTrue("isTranslationUnit", CoreModel.getDefault().isTranslationUnit(file));
|
||||
assertTrue("isTranslationUnit", CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("exetest.o");
|
||||
if (!file.exists()) {
|
||||
|
@ -187,7 +187,7 @@ public class CModelTests extends TestCase {
|
|||
assertTrue("isSharedLib", !CoreModel.getDefault().isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.getDefault().isArchive(file));
|
||||
assertTrue("isObject", CoreModel.getDefault().isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.getDefault().isTranslationUnit(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("liblibtest_g.so");
|
||||
if (!file.exists()) {
|
||||
|
@ -203,7 +203,7 @@ public class CModelTests extends TestCase {
|
|||
assertTrue("isSharedLib", CoreModel.getDefault().isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.getDefault().isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.getDefault().isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.getDefault().isTranslationUnit(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("liblibtest_g.a");
|
||||
if (!file.exists()) {
|
||||
|
@ -222,7 +222,7 @@ public class CModelTests extends TestCase {
|
|||
assertTrue("isSharedLib", !CoreModel.getDefault().isSharedLib(file));
|
||||
assertTrue("isArchive", CoreModel.getDefault().isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.getDefault().isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.getDefault().isTranslationUnit(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
|
||||
|
||||
|
@ -237,9 +237,9 @@ public class CModelTests extends TestCase {
|
|||
* Some simple tests for isValidTranslationUnitName
|
||||
*/
|
||||
public void testIsValidTranslationUnitName() throws CoreException {
|
||||
assertTrue("Invalid C file", !CoreModel.getDefault().isValidTranslationUnitName("notcfile"));
|
||||
assertTrue("Invalid C file", !CoreModel.getDefault().isValidTranslationUnitName("not.c.file"));
|
||||
assertTrue("Invalid C file", !CoreModel.getDefault().isValidTranslationUnitName("not.ca"));
|
||||
assertTrue("Valid C file", CoreModel.getDefault().isValidTranslationUnitName("areal.c"));
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName(null, "notcfile"));
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName(null, "not.c.file"));
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName(null, "not.ca"));
|
||||
assertTrue("Valid C file", CoreModel.isValidTranslationUnitName(null, "areal.c"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2004-05-25 Alain Magloire
|
||||
Update the necessary classes to use the new
|
||||
ResolverModel.
|
||||
|
||||
2004-05-25 Alain Magloire
|
||||
|
||||
Major Patch from Sam Robb
|
||||
|
|
|
@ -3,14 +3,11 @@ package org.eclipse.cdt.core.model;
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved.
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
|
||||
import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
|
||||
import org.eclipse.cdt.core.resources.IPathEntryStore;
|
||||
import org.eclipse.cdt.internal.core.model.BatchOperation;
|
||||
import org.eclipse.cdt.internal.core.model.CModel;
|
||||
|
@ -170,84 +167,27 @@ public class CoreModel {
|
|||
/**
|
||||
* Return true if name is a valid name for a translation unit.
|
||||
*/
|
||||
public static boolean isValidTranslationUnitName(String name) {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileType type = resolver.getFileType(name);
|
||||
public static boolean isValidTranslationUnitName(IProject project, String name) {
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
|
||||
return type.isTranslationUnit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if name is a valid name for a translation unit.
|
||||
*/
|
||||
public static boolean isValidHeaderUnitName(String name) {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileType type = resolver.getFileType(name);
|
||||
public static boolean isValidHeaderUnitName(IProject project, String name) {
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
|
||||
return type.isHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if name is a valid name for a translation unit.
|
||||
*/
|
||||
public static boolean isValidSourceUnitName(String name) {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileType type = resolver.getFileType(name);
|
||||
public static boolean isValidSourceUnitName(IProject project, String name) {
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
|
||||
return type.isSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of headers extensions.
|
||||
*/
|
||||
public static String[] getHeaderExtensions() {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileTypeAssociation[] associations = resolver.getFileTypeAssociations();
|
||||
ArrayList list = new ArrayList(associations.length);
|
||||
for (int i = 0; i < associations.length; i++) {
|
||||
ICFileType type = associations[i].getType();
|
||||
if (type.isHeader()) {
|
||||
list.add(associations[i].getPattern());
|
||||
}
|
||||
}
|
||||
String[] exts = new String[list.size()];
|
||||
list.toArray(exts);
|
||||
return exts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of source extensions.
|
||||
*/
|
||||
public static String[] getSourceExtensions() {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileTypeAssociation[] associations = resolver.getFileTypeAssociations();
|
||||
ArrayList list = new ArrayList(associations.length);
|
||||
for (int i = 0; i < associations.length; i++) {
|
||||
ICFileType type = associations[i].getType();
|
||||
if (type.isSource()) {
|
||||
list.add(associations[i].getPattern());
|
||||
}
|
||||
}
|
||||
String[] exts = new String[list.size()];
|
||||
list.toArray(exts);
|
||||
return exts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of headers and sources extensions
|
||||
*/
|
||||
public static String[] getTranslationUnitExtensions() {
|
||||
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||
ICFileTypeAssociation[] associations = resolver.getFileTypeAssociations();
|
||||
ArrayList list = new ArrayList(associations.length);
|
||||
for (int i = 0; i < associations.length; i++) {
|
||||
ICFileType type = associations[i].getType();
|
||||
if (type.isTranslationUnit()) {
|
||||
list.add(associations[i].getPattern());
|
||||
}
|
||||
}
|
||||
String[] exts = new String[list.size()];
|
||||
list.toArray(exts);
|
||||
return exts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if project has C nature.
|
||||
*/
|
||||
|
|
|
@ -80,7 +80,8 @@ public class CContainerInfo extends OpenableInfo {
|
|||
}
|
||||
case IResource.FILE: {
|
||||
String filename = member.getName();
|
||||
if (CoreModel.isValidTranslationUnitName(filename) && root.isOnSourceEntry(member)) {
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) &&
|
||||
root.isOnSourceEntry(member)) {
|
||||
continue;
|
||||
} else {
|
||||
if (root.isOnSourceEntry(member)) {
|
||||
|
|
|
@ -135,7 +135,13 @@ public class CModelBuilder {
|
|||
}
|
||||
|
||||
// pick the language
|
||||
ParserLanguage language = hasCppNature ? ParserLanguage.CPP : ParserLanguage.C;
|
||||
ParserLanguage language;
|
||||
if (hasCppNature) {
|
||||
language = ParserLanguage.CPP;
|
||||
} else {
|
||||
// for C project try to guess.
|
||||
language = translationUnit.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C;
|
||||
}
|
||||
|
||||
// create the parser
|
||||
IParser parser = null;
|
||||
|
|
|
@ -266,6 +266,14 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
if (cproject == null) {
|
||||
cproject = create(file.getProject());
|
||||
}
|
||||
/////////////////////////////////////////////////
|
||||
// FIXME-alain: Quick hack 'til we fix the CDescriptor
|
||||
// This should/must be remove
|
||||
// ".cdtproject" is a special file for CProjects.
|
||||
/////////////////////////////////////////////////
|
||||
if (file.getName().equals(".cdtproject")) { // $NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
boolean checkIfBinary = false;
|
||||
ICElement celement = null;
|
||||
try {
|
||||
|
@ -284,7 +292,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
cfolder = cfolder.getCContainer(segments[j]);
|
||||
}
|
||||
|
||||
if (CoreModel.isValidTranslationUnitName(fileName)) {
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) {
|
||||
celement = cfolder.getTranslationUnit(fileName);
|
||||
} else if (cproject.isOnOutputEntry(file)) {
|
||||
IBinaryFile bin = createBinaryFile(file);
|
||||
|
|
|
@ -106,7 +106,7 @@ class CProjectInfo extends OpenableInfo {
|
|||
case IResource.FILE: {
|
||||
String filename = member.getName();
|
||||
if (srcIsProject) {
|
||||
if (CoreModel.isValidTranslationUnitName(filename)
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename)
|
||||
&& !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
|
||||
continue;
|
||||
} else if (!CoreModelUtil.isExcluded(member, exclusionPatterns)) {
|
||||
|
|
|
@ -607,7 +607,7 @@ public class DeltaProcessor {
|
|||
|
||||
String filename = resource.getName();
|
||||
|
||||
if (CoreModel.isValidHeaderUnitName(filename)) {
|
||||
if (CoreModel.isValidHeaderUnitName(resource.getProject(), filename)) {
|
||||
indexManager.updateDependencies(resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,8 @@ public class IncludeReference extends Openable implements IIncludeReference {
|
|||
ICElement celement = null;
|
||||
if (child.isDirectory()) {
|
||||
celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath()));
|
||||
} else if (CoreModel.isValidTranslationUnitName(names[i]) && child.isFile()) {
|
||||
} else if (CoreModel.isValidTranslationUnitName(getCProject().getProject(), names[i]) &&
|
||||
child.isFile()) {
|
||||
celement = new ExternalTranslationUnit(this, path.append(names[i]));
|
||||
}
|
||||
if (celement != null) {
|
||||
|
|
|
@ -102,8 +102,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
}
|
||||
|
||||
public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException {
|
||||
boolean markers = cproject.getProject().getWorkspace().isTreeLocked();
|
||||
return getResolvedPathEntries(cproject, !markers);
|
||||
//boolean markers = cproject.getProject().getWorkspace().isTreeLocked();
|
||||
//return getResolvedPathEntries(cproject, !markers);
|
||||
return getResolvedPathEntries(cproject, false);
|
||||
}
|
||||
|
||||
public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException {
|
||||
|
|
|
@ -532,14 +532,16 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit()
|
||||
*/
|
||||
public boolean isHeaderUnit() {
|
||||
return CoreModel.isValidHeaderUnitName(getPath().lastSegment());
|
||||
IProject project = getCProject().getProject();
|
||||
return CoreModel.isValidHeaderUnitName(project, getPath().lastSegment());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit()
|
||||
*/
|
||||
public boolean isSourceUnit() {
|
||||
return CoreModel.isValidSourceUnitName(getPath().lastSegment());
|
||||
IProject project = getCProject().getProject();
|
||||
return CoreModel.isValidSourceUnitName(project, getPath().lastSegment());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -662,22 +662,6 @@ public class CCorePlugin extends Plugin {
|
|||
return new DefaultPathEntryStore(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file type object corresponding to the provided
|
||||
* file name, using the workspace resolver.
|
||||
*
|
||||
* If no file type object exists, a default file type object is
|
||||
* returned.
|
||||
*
|
||||
* @param fileName Name of the file to resolve type info for.
|
||||
*
|
||||
* @return File type object for the provided file name, in the
|
||||
* context of the workspace
|
||||
*/
|
||||
public ICFileType getFileType(String fileName) {
|
||||
return getFileTypeResolver().getFileType(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file type object corresponding to the provided
|
||||
* file name.
|
||||
|
@ -695,17 +679,6 @@ public class CCorePlugin extends Plugin {
|
|||
return getFileTypeResolver(project).getFileType(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file type resolver for the workspace.
|
||||
*
|
||||
* @param project Project to get file type resolver for.
|
||||
*
|
||||
* @return File type resolver for the project.
|
||||
*/
|
||||
public ICFileTypeResolver getFileTypeResolver() {
|
||||
return getResolverModel().getResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file type resolver for the specified project.
|
||||
* Specifying a null project returns the file type resolver
|
||||
|
|
|
@ -109,7 +109,7 @@ public class TypeInfoLabelProvider extends LabelProvider {
|
|||
ITypeReference ref = typeRef.getResolvedReference();
|
||||
if (ref != null) {
|
||||
path = ref.getPath();
|
||||
if (CoreModel.isValidHeaderUnitName(path.lastSegment())) {
|
||||
if (CoreModel.isValidHeaderUnitName(typeRef.getEnclosingProject(), path.lastSegment())) {
|
||||
return HEADER_ICON;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class UndoManager implements IUndoManager {
|
|||
IResource resource= delta.getResource();
|
||||
if (resource.getType() == IResource.FILE && delta.getKind() == IResourceDelta.CHANGED &&
|
||||
(delta.getFlags() & IResourceDelta.CONTENT) != 0) {
|
||||
if(CoreModel.getDefault().isValidTranslationUnitName(resource.getName())) {
|
||||
if(CoreModel.isValidTranslationUnitName(resource.getProject(), resource.getName())) {
|
||||
ITranslationUnit unit= (ITranslationUnit)CoreModel.getDefault().create((IFile)resource);
|
||||
if (unit != null && unit.exists()) {
|
||||
flush();
|
||||
|
|
|
@ -112,24 +112,12 @@ public class CElementSorter extends ViewerSorter {
|
|||
} else if (element instanceof ICContainer) {
|
||||
return CCONTAINERS;
|
||||
} else if (element instanceof ITranslationUnit) {
|
||||
IResource res = null;
|
||||
res = ((ITranslationUnit)element).getUnderlyingResource();
|
||||
if (res != null) {
|
||||
String ext = res.getFileExtension();
|
||||
if (ext != null) {
|
||||
String[] headers = CoreModel.getDefault().getHeaderExtensions();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
if (ext.equals(headers[i])) {
|
||||
return TRANSLATIONUNIT_HEADERS;
|
||||
}
|
||||
}
|
||||
String[] sources = CoreModel.getDefault().getSourceExtensions();
|
||||
for (int i = 0; i < sources.length; i++) {
|
||||
if (ext.equals(sources[i])) {
|
||||
return TRANSLATIONUNIT_SOURCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
ITranslationUnit tu = (ITranslationUnit)element;
|
||||
if (CoreModel.isValidHeaderUnitName(tu.getCProject().getProject(), tu.getElementName())) {
|
||||
return TRANSLATIONUNIT_HEADERS;
|
||||
}
|
||||
if (CoreModel.isValidSourceUnitName(tu.getCProject().getProject(), tu.getElementName())) {
|
||||
return TRANSLATIONUNIT_SOURCE;
|
||||
}
|
||||
return TRANSLATIONUNITS;
|
||||
} else if (element instanceof IInclude) {
|
||||
|
|
Loading…
Add table
Reference in a new issue