1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Moving the work from Sam Robb part of PR 52864, this

is is only the Core part, UI is still pending.
This commit is contained in:
Alain Magloire 2004-04-23 18:27:04 +00:00
parent 63bc5b00d2
commit be4fd43913
12 changed files with 227 additions and 182 deletions

View file

@ -1,3 +1,19 @@
2004-04-23 Alain Magloire
Moving the work from Sam Robb part of PR 52864, this
is is only the Core part, UI is still pending.
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/core/model/ITranslationUnit.java
* model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
* model/org/eclipse/cdt/internal/core/model/CContainer.java
* model/org/eclipse/cdt/internal/core/model/CModel.java
* model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
* model/org/eclipse/cdt/internal/core/model/CModelInfo.java
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
* model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
2004-04-21 Alain Magloire
Added support for Base Reference Attribute in the PathEntry

View file

@ -3,7 +3,14 @@ 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.internal.core.model.BatchOperation;
import org.eclipse.cdt.internal.core.model.CModel;
import org.eclipse.cdt.internal.core.model.CModelManager;
@ -53,7 +60,6 @@ public class CoreModel {
*/
public ICElement create(IFile file) {
return manager.create(file, null);
}
/**
@ -104,91 +110,171 @@ public class CoreModel {
* Return true if IFile is a shared library, i.e. libxx.so
*/
public boolean isSharedLib(IFile file) {
return manager.isSharedLib(file);
ICElement celement = create(file);
if (celement instanceof IBinary) {
return ((IBinary)celement).isSharedLib();
}
return false;
}
/**
* Return true if IFile is a an object(ELF), i.e. *.o
*/
public boolean isObject(IFile file) {
return manager.isObject(file);
ICElement celement = create(file);
if (celement instanceof IBinary) {
return ((IBinary)celement).isObject();
}
return false;
}
/**
* Return true if IFile is an ELF executable
*/
public boolean isExecutable(IFile file) {
return manager.isExecutable(file);
ICElement celement = create(file);
if (celement instanceof IBinary) {
return ((IBinary)celement).isExecutable();
}
return false;
}
/**
* Return true if IFile is an ELF.
*/
public boolean isBinary(IFile file) {
return manager.isBinary(file);
ICElement celement = create(file);
return (celement instanceof IBinary);
}
/**
* Return true if IFile is an Achive, *.a
*/
public boolean isArchive(IFile file) {
return manager.isArchive(file);
ICElement celement = create(file);
return(celement instanceof IArchive);
}
/**
* Return true if IFile is a TranslationUnit.
*/
public boolean isTranslationUnit(IFile file) {
return manager.isTranslationUnit(file);
public static boolean isTranslationUnit(IFile file) {
if (file != null) {
ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
return type.isTranslationUnit();
}
return false;
}
/**
* Return true if name is a valid name for a translation unit.
*/
public boolean isValidTranslationUnitName(String name) {
return manager.isValidTranslationUnitName(name);
public static boolean isValidTranslationUnitName(String name) {
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
ICFileType type = resolver.getFileType(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);
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);
return type.isSource();
}
/**
* Return the list of headers extensions.
*/
public String[] getHeaderExtensions() {
return manager.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 String[] getSourceExtensions() {
return manager.getSourceExtensions();
}
/**
* Returns the list of assembly file extensions.
*/
public String[] getAssemblyExtensions() {
return manager.getAssemblyExtensions();
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 String[] getTranslationUnitExtensions() {
return manager.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.
*/
public boolean hasCNature(IProject project) {
return manager.hasCNature(project);
public static boolean hasCNature(IProject project) {
boolean ok = false;
try {
ok = (project.isOpen() && project.hasNature(CProjectNature.C_NATURE_ID));
} catch (CoreException e) {
//throws exception if the project is not open.
//System.out.println (e);
//e.printStackTrace();
}
return ok;
}
/**
* Return true if project has C++ nature.
*/
public boolean hasCCNature(IProject project) {
return manager.hasCCNature(project);
public static boolean hasCCNature(IProject project) {
boolean ok = false;
try {
ok = (project.isOpen() && project.hasNature(CCProjectNature.CC_NATURE_ID));
} catch (CoreException e) {
//throws exception if the project is not open.
//System.out.println (e);
//e.printStackTrace();
}
return ok;
}
/**

View file

@ -203,6 +203,39 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* exception occurs while accessing its corresponding resource
*/
IUsing[] getUsings() throws CModelException;
/**
* True if its a header.
* @return boolean
*/
boolean isHeaderUnit();
/**
* True it is a source file.
* @return boolean
*/
boolean isSourceUnit();
/**
* True if the code is C
* @return
*/
boolean isCLanguage();
/**
* True if the code is C++
*
* @return
*/
boolean isCXXLanguage();
/**
* True if assembly
*
* @return
*/
boolean isASMLanguage();
/**
* Returns a new working copy for the Translation Unit.
* @return IWorkingCopy
@ -219,7 +252,8 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* Checks if this is a working copy.
* @return boolean
*/
boolean isWorkingCopy();
boolean isWorkingCopy();
/**
* parse()
* returns a map of all new elements and their element info

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
@ -105,7 +106,7 @@ public class BinaryRunner {
CModelManager factory = CModelManager.getDefault();
// Attempt to speed things up by rejecting up front
// Things we know should not be Binary files.
if (!factory.isTranslationUnit(file)) {
if (!CoreModel.isTranslationUnit(file)) {
IBinaryFile bin = factory.createBinaryFile(file);
if (bin != null) {
// Create the file will add it to the {Archive,Binary}Containery.

View file

@ -11,6 +11,7 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
@ -226,7 +227,7 @@ public class CContainer extends Openable implements ICContainer {
case IResource.FILE :
{
IFile file = (IFile) resource;
if (factory.isTranslationUnit(file)) {
if (CoreModel.isTranslationUnit(file)) {
celement = new TranslationUnit(this, file);
} else if (cproject.isOnOutputEntry(file)) {
IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);

View file

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
@ -207,7 +208,7 @@ public class CModel extends Openable implements ICModel {
IProject[] projects = root.getProjects();
for (int i = 0, max = projects.length; i < max; i++) {
IProject project = projects[i];
if (factory.hasCNature(project) || factory.hasCCNature(project)) {
if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) {
ICProject cproject = new CProject(this, project);
info.addChild(cproject);
}

View file

@ -89,7 +89,7 @@ public class CModelBuilder {
// check the project's nature
if( currentProject != null )
{
hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
hasCppNature = CoreModel.hasCCNature(currentProject);
}
// get the code to parse
try{

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@ -33,7 +34,7 @@ public class CModelInfo extends OpenableInfo {
int index = 0;
for (int i = 0; i < length; i++) {
IProject project = projects[i];
if (!(mgr.hasCNature(project) || mgr.hasCCNature(project))) {
if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
if (nonCProjects == null) {
nonCProjects = new Object[length];
}

View file

@ -26,9 +26,8 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
@ -156,7 +155,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
*/
public ICModel getCModel(IWorkspaceRoot root) {
return getCModel();
//return create(root);
}
public CModel getCModel() {
@ -269,7 +267,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
cfolder = cfolder.getCContainer(segments[j]);
}
if (isValidTranslationUnitName(fileName)) {
if (CoreModel.isValidTranslationUnitName(fileName)) {
celement = cfolder.getTranslationUnit(fileName);
} else if (cproject.isOnOutputEntry(file)) {
IBinaryFile bin = createBinaryFile(file);
@ -558,123 +556,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
}
public boolean isSharedLib(IFile file) {
ICElement celement = create(file, null);
if (celement instanceof IBinary) {
return ((IBinary)celement).isSharedLib();
}
return false;
}
public boolean isObject(IFile file) {
ICElement celement = create(file, null);
if (celement instanceof IBinary) {
return ((IBinary)celement).isObject();
}
return false;
}
public boolean isExecutable(IFile file) {
ICElement celement = create(file, null);
if (celement instanceof IBinary) {
return ((IBinary)celement).isExecutable();
}
return false;
}
public boolean isBinary(IFile file) {
ICElement celement = create(file, null);
return (celement instanceof IBinary);
}
public boolean isArchive(IFile file) {
ICElement celement = create(file, null);
return(celement instanceof IArchive);
}
public boolean isTranslationUnit(IFile file) {
return file != null && isValidTranslationUnitName(file.getName());
}
public boolean isSourceUnit(IFile file) {
return file != null && isValidSourceUnitName(file.getName());
}
public boolean isHeaderUnit(IFile file) {
return file != null && isValidHeaderUnitName(file.getName());
}
public boolean isAssemblyUnit(IFile file) {
return file != null && isValidAssemblyUnitName(file.getName());
}
public boolean isValidTranslationUnitName(String name){
if (name == null) {
return false;
}
int index = name.lastIndexOf('.');
if (index == -1) {
return false;
}
String ext = name.substring(index + 1);
String[] cexts = getTranslationUnitExtensions();
for (int i = 0; i < cexts.length; i++) {
if (ext.equals(cexts[i]))
return true;
}
return false;
}
public boolean isValidSourceUnitName(String name){
if (name == null) {
return false;
}
int index = name.lastIndexOf('.');
if (index == -1) {
return false;
}
String ext = name.substring(index + 1);
String[] cexts = getSourceExtensions();
for (int i = 0; i < cexts.length; i++) {
if (ext.equals(cexts[i]))
return true;
}
return false;
}
public boolean isValidHeaderUnitName(String name){
if (name == null) {
return false;
}
int index = name.lastIndexOf('.');
if (index == -1) {
return false;
}
String ext = name.substring(index + 1);
String[] cexts = getHeaderExtensions();
for (int i = 0; i < cexts.length; i++) {
if (ext.equals(cexts[i]))
return true;
}
return false;
}
public boolean isValidAssemblyUnitName(String name){
if (name == null) {
return false;
}
int index = name.lastIndexOf('.');
if (index == -1) {
return false;
}
String ext = name.substring(index + 1);
String[] cexts = getAssemblyExtensions();
for (int i = 0; i < cexts.length; i++) {
if (ext.equals(cexts[i]))
return true;
}
return false;
}
/*
public String[] getHeaderExtensions() {
return headerExtensions;
@ -698,33 +580,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
System.arraycopy(asm, 0, cexts, sources.length + headers.length, asm.length);
return cexts;
}
/* Only project with C nature and Open. */
public boolean hasCNature (IProject p) {
boolean ok = false;
try {
ok = (p.isOpen() && p.hasNature(CProjectNature.C_NATURE_ID));
} catch (CoreException e) {
//throws exception if the project is not open.
//System.out.println (e);
//e.printStackTrace();
}
return ok;
}
/* Only project with C++ nature and Open. */
public boolean hasCCNature (IProject p) {
boolean ok = false;
try {
ok = (p.isOpen() && p.hasNature(CCProjectNature.CC_NATURE_ID));
} catch (CoreException e) {
//throws exception if the project is not open.
//System.out.println (e);
//e.printStackTrace();
}
return ok;
}
*/
public BinaryRunner getBinaryRunner(ICProject project) {
BinaryRunner runner = null;
synchronized(binaryRunners) {

View file

@ -63,7 +63,7 @@ public class DeltaProcessor {
// Check for C nature or if the was a CNature
if (!(resource instanceof IWorkspaceRoot)) {
IProject project = resource.getProject();
if (!(manager.hasCNature(project) || manager.hasCCNature(project))) {
if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
shouldProcess = false;
CModel root = manager.getCModel();
CModelInfo rootInfo = (CModelInfo)manager.peekAtInfo(root);
@ -384,7 +384,7 @@ public class DeltaProcessor {
// ensure the project has a C nature (if open)
IProject project = resource.getProject();
if (project.isOpen()) {
return CoreModel.getDefault().hasCNature(project);
return CoreModel.hasCNature(project);
}
return false;
}

View file

@ -229,7 +229,7 @@ public class PathEntryManager implements ICDescriptorListener {
public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException {
CModelManager factory = CModelManager.getDefault();
if (!(factory.hasCNature(cproject.getProject()) || factory.hasCCNature(cproject.getProject()))) {
if (!(CoreModel.hasCNature(cproject.getProject()) || CoreModel.hasCCNature(cproject.getProject()))) {
return NO_PATHENTRIES;
}
ArrayList pathEntries = new ArrayList();
@ -884,7 +884,7 @@ public class PathEntryManager implements ICDescriptorListener {
if (cdesc != null) {
CModelManager manager = CModelManager.getDefault();
IProject project = cdesc.getProject();
if (manager.hasCNature(project) || manager.hasCCNature(project)) {
if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) {
ICProject cproject = manager.create(project);
try {
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);

View file

@ -11,7 +11,10 @@ import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IInclude;
@ -23,6 +26,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IUsing;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -510,5 +514,49 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit()
*/
public boolean isHeaderUnit() {
return CoreModel.isValidHeaderUnitName(getPath().lastSegment());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit()
*/
public boolean isSourceUnit() {
return CoreModel.isValidSourceUnitName(getPath().lastSegment());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCLanguage()
*/
public boolean isCLanguage() {
IProject project = getCProject().getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
String lid = type.getLanguageId();
return lid != null && lid.equals(ICFileTypeConstants.LANG_C);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCXXLanguage()
*/
public boolean isCXXLanguage() {
IProject project = getCProject().getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
String lid = type.getLanguageId();
return lid != null && lid.equals(ICFileTypeConstants.LANG_CXX);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isASMLanguage()
*/
public boolean isASMLanguage() {
IProject project = getCProject().getProject();
ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
String lid = type.getLanguageId();
return lid != null && lid.equals(ICFileTypeConstants.LANG_ASM);
}
}