mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +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:
parent
63bc5b00d2
commit
be4fd43913
12 changed files with 227 additions and 182 deletions
|
@ -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
|
2004-04-21 Alain Magloire
|
||||||
|
|
||||||
Added support for Base Reference Attribute in the PathEntry
|
Added support for Base Reference Attribute in the PathEntry
|
||||||
|
|
|
@ -3,7 +3,14 @@ package org.eclipse.cdt.core.model;
|
||||||
/*
|
/*
|
||||||
* (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved.
|
* (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.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.BatchOperation;
|
||||||
import org.eclipse.cdt.internal.core.model.CModel;
|
import org.eclipse.cdt.internal.core.model.CModel;
|
||||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
@ -53,7 +60,6 @@ public class CoreModel {
|
||||||
*/
|
*/
|
||||||
public ICElement create(IFile file) {
|
public ICElement create(IFile file) {
|
||||||
return manager.create(file, null);
|
return manager.create(file, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,91 +110,171 @@ public class CoreModel {
|
||||||
* Return true if IFile is a shared library, i.e. libxx.so
|
* Return true if IFile is a shared library, i.e. libxx.so
|
||||||
*/
|
*/
|
||||||
public boolean isSharedLib(IFile file) {
|
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
|
* Return true if IFile is a an object(ELF), i.e. *.o
|
||||||
*/
|
*/
|
||||||
public boolean isObject(IFile file) {
|
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
|
* Return true if IFile is an ELF executable
|
||||||
*/
|
*/
|
||||||
public boolean isExecutable(IFile file) {
|
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.
|
* Return true if IFile is an ELF.
|
||||||
*/
|
*/
|
||||||
public boolean isBinary(IFile file) {
|
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
|
* Return true if IFile is an Achive, *.a
|
||||||
*/
|
*/
|
||||||
public boolean isArchive(IFile file) {
|
public boolean isArchive(IFile file) {
|
||||||
return manager.isArchive(file);
|
ICElement celement = create(file);
|
||||||
|
return(celement instanceof IArchive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if IFile is a TranslationUnit.
|
* Return true if IFile is a TranslationUnit.
|
||||||
*/
|
*/
|
||||||
public boolean isTranslationUnit(IFile file) {
|
public static boolean isTranslationUnit(IFile file) {
|
||||||
return manager.isTranslationUnit(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.
|
* Return true if name is a valid name for a translation unit.
|
||||||
*/
|
*/
|
||||||
public boolean isValidTranslationUnitName(String name) {
|
public static boolean isValidTranslationUnitName(String name) {
|
||||||
return manager.isValidTranslationUnitName(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.
|
* Return the list of headers extensions.
|
||||||
*/
|
*/
|
||||||
public String[] getHeaderExtensions() {
|
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.
|
* Returns the list of source extensions.
|
||||||
*/
|
*/
|
||||||
public String[] getSourceExtensions() {
|
public String[] getSourceExtensions() {
|
||||||
return manager.getSourceExtensions();
|
ICFileTypeResolver resolver = CCorePlugin.getDefault().getFileTypeResolver();
|
||||||
}
|
ICFileTypeAssociation[] associations = resolver.getFileTypeAssociations();
|
||||||
|
ArrayList list = new ArrayList(associations.length);
|
||||||
/**
|
for (int i = 0; i < associations.length; i++) {
|
||||||
* Returns the list of assembly file extensions.
|
ICFileType type = associations[i].getType();
|
||||||
*/
|
if (type.isSource()) {
|
||||||
public String[] getAssemblyExtensions() {
|
list.add(associations[i].getPattern());
|
||||||
return manager.getAssemblyExtensions();
|
}
|
||||||
|
}
|
||||||
|
String[] exts = new String[list.size()];
|
||||||
|
list.toArray(exts);
|
||||||
|
return exts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of headers and sources extensions
|
* Returns the list of headers and sources extensions
|
||||||
*/
|
*/
|
||||||
public String[] getTranslationUnitExtensions() {
|
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.
|
* Return true if project has C nature.
|
||||||
*/
|
*/
|
||||||
public boolean hasCNature(IProject project) {
|
public static boolean hasCNature(IProject project) {
|
||||||
return manager.hasCNature(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.
|
* Return true if project has C++ nature.
|
||||||
*/
|
*/
|
||||||
public boolean hasCCNature(IProject project) {
|
public static boolean hasCCNature(IProject project) {
|
||||||
return manager.hasCCNature(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -203,6 +203,39 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
* exception occurs while accessing its corresponding resource
|
* exception occurs while accessing its corresponding resource
|
||||||
*/
|
*/
|
||||||
IUsing[] getUsings() throws CModelException;
|
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.
|
* Returns a new working copy for the Translation Unit.
|
||||||
* @return IWorkingCopy
|
* @return IWorkingCopy
|
||||||
|
@ -219,7 +252,8 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
* Checks if this is a working copy.
|
* Checks if this is a working copy.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean isWorkingCopy();
|
boolean isWorkingCopy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse()
|
* parse()
|
||||||
* returns a map of all new elements and their element info
|
* returns a map of all new elements and their element info
|
||||||
|
|
|
@ -7,6 +7,7 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
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.ElementChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICModel;
|
import org.eclipse.cdt.core.model.ICModel;
|
||||||
|
@ -105,7 +106,7 @@ public class BinaryRunner {
|
||||||
CModelManager factory = CModelManager.getDefault();
|
CModelManager factory = CModelManager.getDefault();
|
||||||
// Attempt to speed things up by rejecting up front
|
// Attempt to speed things up by rejecting up front
|
||||||
// Things we know should not be Binary files.
|
// Things we know should not be Binary files.
|
||||||
if (!factory.isTranslationUnit(file)) {
|
if (!CoreModel.isTranslationUnit(file)) {
|
||||||
IBinaryFile bin = factory.createBinaryFile(file);
|
IBinaryFile bin = factory.createBinaryFile(file);
|
||||||
if (bin != null) {
|
if (bin != null) {
|
||||||
// Create the file will add it to the {Archive,Binary}Containery.
|
// Create the file will add it to the {Archive,Binary}Containery.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
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.IArchive;
|
||||||
import org.eclipse.cdt.core.model.IBinary;
|
import org.eclipse.cdt.core.model.IBinary;
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
|
@ -226,7 +227,7 @@ public class CContainer extends Openable implements ICContainer {
|
||||||
case IResource.FILE :
|
case IResource.FILE :
|
||||||
{
|
{
|
||||||
IFile file = (IFile) resource;
|
IFile file = (IFile) resource;
|
||||||
if (factory.isTranslationUnit(file)) {
|
if (CoreModel.isTranslationUnit(file)) {
|
||||||
celement = new TranslationUnit(this, file);
|
celement = new TranslationUnit(this, file);
|
||||||
} else if (cproject.isOnOutputEntry(file)) {
|
} else if (cproject.isOnOutputEntry(file)) {
|
||||||
IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);
|
IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICModel;
|
import org.eclipse.cdt.core.model.ICModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -207,7 +208,7 @@ public class CModel extends Openable implements ICModel {
|
||||||
IProject[] projects = root.getProjects();
|
IProject[] projects = root.getProjects();
|
||||||
for (int i = 0, max = projects.length; i < max; i++) {
|
for (int i = 0, max = projects.length; i < max; i++) {
|
||||||
IProject project = projects[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);
|
ICProject cproject = new CProject(this, project);
|
||||||
info.addChild(cproject);
|
info.addChild(cproject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class CModelBuilder {
|
||||||
// check the project's nature
|
// check the project's nature
|
||||||
if( currentProject != null )
|
if( currentProject != null )
|
||||||
{
|
{
|
||||||
hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
|
hasCppNature = CoreModel.hasCCNature(currentProject);
|
||||||
}
|
}
|
||||||
// get the code to parse
|
// get the code to parse
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.eclipse.cdt.internal.core.model;
|
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.IProject;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ public class CModelInfo extends OpenableInfo {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
IProject project = projects[i];
|
IProject project = projects[i];
|
||||||
if (!(mgr.hasCNature(project) || mgr.hasCCNature(project))) {
|
if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
|
||||||
if (nonCProjects == null) {
|
if (nonCProjects == null) {
|
||||||
nonCProjects = new Object[length];
|
nonCProjects = new Object[length];
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,8 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
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.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.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||||
|
@ -156,7 +155,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
||||||
*/
|
*/
|
||||||
public ICModel getCModel(IWorkspaceRoot root) {
|
public ICModel getCModel(IWorkspaceRoot root) {
|
||||||
return getCModel();
|
return getCModel();
|
||||||
//return create(root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CModel getCModel() {
|
public CModel getCModel() {
|
||||||
|
@ -269,7 +267,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
||||||
cfolder = cfolder.getCContainer(segments[j]);
|
cfolder = cfolder.getCContainer(segments[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidTranslationUnitName(fileName)) {
|
if (CoreModel.isValidTranslationUnitName(fileName)) {
|
||||||
celement = cfolder.getTranslationUnit(fileName);
|
celement = cfolder.getTranslationUnit(fileName);
|
||||||
} else if (cproject.isOnOutputEntry(file)) {
|
} else if (cproject.isOnOutputEntry(file)) {
|
||||||
IBinaryFile bin = createBinaryFile(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() {
|
public String[] getHeaderExtensions() {
|
||||||
return headerExtensions;
|
return headerExtensions;
|
||||||
|
@ -698,33 +580,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
||||||
System.arraycopy(asm, 0, cexts, sources.length + headers.length, asm.length);
|
System.arraycopy(asm, 0, cexts, sources.length + headers.length, asm.length);
|
||||||
return cexts;
|
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) {
|
public BinaryRunner getBinaryRunner(ICProject project) {
|
||||||
BinaryRunner runner = null;
|
BinaryRunner runner = null;
|
||||||
synchronized(binaryRunners) {
|
synchronized(binaryRunners) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class DeltaProcessor {
|
||||||
// Check for C nature or if the was a CNature
|
// Check for C nature or if the was a CNature
|
||||||
if (!(resource instanceof IWorkspaceRoot)) {
|
if (!(resource instanceof IWorkspaceRoot)) {
|
||||||
IProject project = resource.getProject();
|
IProject project = resource.getProject();
|
||||||
if (!(manager.hasCNature(project) || manager.hasCCNature(project))) {
|
if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
|
||||||
shouldProcess = false;
|
shouldProcess = false;
|
||||||
CModel root = manager.getCModel();
|
CModel root = manager.getCModel();
|
||||||
CModelInfo rootInfo = (CModelInfo)manager.peekAtInfo(root);
|
CModelInfo rootInfo = (CModelInfo)manager.peekAtInfo(root);
|
||||||
|
@ -384,7 +384,7 @@ public class DeltaProcessor {
|
||||||
// ensure the project has a C nature (if open)
|
// ensure the project has a C nature (if open)
|
||||||
IProject project = resource.getProject();
|
IProject project = resource.getProject();
|
||||||
if (project.isOpen()) {
|
if (project.isOpen()) {
|
||||||
return CoreModel.getDefault().hasCNature(project);
|
return CoreModel.hasCNature(project);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ public class PathEntryManager implements ICDescriptorListener {
|
||||||
|
|
||||||
public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException {
|
public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException {
|
||||||
CModelManager factory = CModelManager.getDefault();
|
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;
|
return NO_PATHENTRIES;
|
||||||
}
|
}
|
||||||
ArrayList pathEntries = new ArrayList();
|
ArrayList pathEntries = new ArrayList();
|
||||||
|
@ -884,7 +884,7 @@ public class PathEntryManager implements ICDescriptorListener {
|
||||||
if (cdesc != null) {
|
if (cdesc != null) {
|
||||||
CModelManager manager = CModelManager.getDefault();
|
CModelManager manager = CModelManager.getDefault();
|
||||||
IProject project = cdesc.getProject();
|
IProject project = cdesc.getProject();
|
||||||
if (manager.hasCNature(project) || manager.hasCCNature(project)) {
|
if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) {
|
||||||
ICProject cproject = manager.create(project);
|
ICProject cproject = manager.create(project);
|
||||||
try {
|
try {
|
||||||
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
|
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
|
||||||
|
|
|
@ -11,7 +11,10 @@ import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.IBuffer;
|
import org.eclipse.cdt.core.model.IBuffer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IInclude;
|
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.IUsing;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue