Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Recoskie2008-04-04 17:48:27 +0000
committerChris Recoskie2008-04-04 17:48:27 +0000
commit504602213a5ed701fc2fb8ebf31bfa7def5a563b (patch)
tree3abcc3cf5944c57b76af5542fa9dbb30acf210db /core/org.eclipse.cdt.core/model/org
parentaf3f69afb9ed7804041fdb5d405c411ac22cfd4e (diff)
downloadorg.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.tar.gz
org.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.tar.xz
org.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.zip
Various changes for EFS
- Fixed many NPEs in the build system that occurred when IProject.getLocation() returned null - Created new IStorage implementation (EFSFileStorage) for the editor which can handle EFS resources - added some utility methods for handling EFS resources
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java15
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java41
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java68
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java7
4 files changed, 125 insertions, 6 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
index 58358b12c8a..95235d43d86 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 QNX Software Systems and others.
+ * Copyright (c) 2000, 2008 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
@@ -8,10 +8,13 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * IBM Corporation - EFS support
*******************************************************************************/
package org.eclipse.cdt.core.model;
+import java.net.URI;
+
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
@@ -75,11 +78,19 @@ public class CoreModel {
}
/**
- * Creates a translation form and IPath. Returns null if not found.
+ * Creates a translation from an IPath. Returns null if not found.
*/
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) {
return manager.createTranslationUnitFrom(cproject, path);
}
+
+ /**
+ * Creates a translation from a location URI. Returns null if not found.
+ * @since 5.0
+ */
+ public ITranslationUnit createTranslationUnitFrom(ICProject cproject, URI locationURI) {
+ return manager.createTranslationUnitFrom(cproject, locationURI);
+ }
/**
* Returns the C model element corresponding to the given handle identifier
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
index ac6f94f231f..faf9a64ac4c 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2007 QNX Software Systems and others.
+ * Copyright (c) 2002, 2008 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
@@ -8,10 +8,12 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * IBM Corporation - EFS support
*******************************************************************************/
package org.eclipse.cdt.core.model;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -573,6 +575,43 @@ public class CoreModelUtil {
return null;
}
+
+ /**
+ * Searches for a translation unit within the cprojects. For external files the ones
+ * from the given project are preferred.
+ * @since 5.0
+ */
+ public static ITranslationUnit findTranslationUnitForLocation(URI locationURI, ICProject preferredProject) throws CModelException {
+ IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(locationURI);
+ if (files.length > 0) {
+ for (int i = 0; i < files.length; i++) {
+ IFile file = files[i];
+ ITranslationUnit tu= findTranslationUnit(file);
+ if (tu != null) {
+ return tu;
+ }
+ }
+ }
+ else {
+ CoreModel coreModel = CoreModel.getDefault();
+ ITranslationUnit tu= null;
+ if (preferredProject != null) {
+ tu= coreModel.createTranslationUnitFrom(preferredProject, locationURI);
+ }
+ if (tu == null) {
+ ICProject[] projects= coreModel.getCModel().getCProjects();
+ for (int i = 0; i < projects.length && tu == null; i++) {
+ ICProject project = projects[i];
+ if (!project.equals(preferredProject)) {
+ tu= coreModel.createTranslationUnitFrom(project, locationURI);
+ }
+ }
+ }
+ return tu;
+ }
+ return null;
+ }
+
/**
* Returns the translation unit for the location given or <code>null</code>.
* @throws CModelException
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
index d7434be9f94..01c9cac9578 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
@@ -11,6 +11,7 @@
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
* Warren Paul (Nokia)
+ * IBM Corporation (EFS Support)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@@ -18,6 +19,7 @@ package org.eclipse.cdt.internal.core.model;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -53,6 +55,9 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.LocalProjectScope;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -429,6 +434,69 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
return null;
}
+
+ /**
+ * Creates a translation unit in the given project for the given location.
+ *
+ * @param cproject
+ * @param locationURI
+ * @return ITranslationUnit
+ */
+ public ITranslationUnit createTranslationUnitFrom(ICProject cproject, URI locationURI) {
+ if (locationURI == null || cproject == null) {
+ return null;
+ }
+
+ if(!locationURI.isAbsolute()) {
+ throw new IllegalArgumentException();
+ }
+
+ final IProject project= cproject.getProject();
+
+ IFileStore fileStore = null;
+ try {
+ fileStore = EFS.getStore(locationURI);
+ } catch (CoreException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ return null;
+ }
+
+ final String contentTypeId = CoreModel.getRegistedContentTypeId(project, fileStore.getName());
+
+ if (! Util.isNonZeroLengthFile(locationURI)) {
+ return null;
+ }
+
+ try {
+ IIncludeReference[] includeReferences = cproject.getIncludeReferences();
+ for (int i = 0; i < includeReferences.length; i++) {
+
+
+ // crecoskie
+ // TODO FIXME: include entries don't handle URIs yet
+ if (includeReferences[i].isOnIncludeEntry(URIUtil.toPath(locationURI))) {
+ String headerContentTypeId= contentTypeId;
+ if (headerContentTypeId == null) {
+ headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER;
+ }
+
+ return new ExternalTranslationUnit(includeReferences[i], locationURI, headerContentTypeId);
+ }
+ }
+ } catch (CModelException e) {
+ }
+
+ // if the file exists and it has a known C/C++ file extension then just create
+ // an external translation unit for it.
+ IFileInfo info = fileStore.fetchInfo();
+
+ if (contentTypeId != null && info != null && info.exists()) {
+ return new ExternalTranslationUnit(cproject, locationURI, contentTypeId);
+ }
+
+ return null;
+ }
public void releaseCElement(ICElement celement) {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
index f01a9401a82..482215c16d0 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
@@ -9,6 +9,7 @@
* Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
+ * IBM Corporation - EFS support
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@@ -441,10 +442,10 @@ public class Util implements ICLogConstants {
public static boolean isNonZeroLengthFile(IPath path) {
return isNonZeroLengthFile(URIUtil.toURI(path));
}
-
+
/**
- * Return true if the file is not a directory and has length > 0
- * @param path
+ * Return true if the file referred to by the URI is not a directory and has length > 0
+ * @param uri
* @return
*/
public static boolean isNonZeroLengthFile(URI uri) {

Back to the top