1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added new methods to CoreModel and IncludeEntry

This commit is contained in:
Alain Magloire 2004-04-19 05:46:43 +00:00
parent ce956c49b8
commit 981f445bb4
6 changed files with 68 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2004-04-18 Alain Magloire
Added a new method in CoreModel to get ITranslationUnit
for external headers, implementation in CModelManager.
Changes to IIncludReference and implementations.
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/core/model/IInludeEntry.java
* model/org/eclipse/cdt/core/model/IIncludeReference.java
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
* model/org/eclipse/cdt/internal/core/model/IncludeReference.java
2004-04-16 Hoda Amer 2004-04-16 Hoda Amer
Reveresed a change in IParent caused by my previous patch. Reveresed a change in IParent caused by my previous patch.

View file

@ -41,6 +41,13 @@ public class CoreModel {
return manager.create(path); return manager.create(path);
} }
/**
* Creates a translation form and IPath. Returns null if not found.
*/
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) {
return manager.createTranslationUnitFrom(cproject, path);
}
/** /**
* Creates an ICElement form and IFile. Returns null if not found. * Creates an ICElement form and IFile. Returns null if not found.
*/ */

View file

@ -40,4 +40,9 @@ public interface IIncludeEntry extends IPathEntry {
*/ */
IPath[] getExclusionPatterns(); IPath[] getExclusionPatterns();
/**
* Returns a char based representation of the exclusions patterns full path.
*/
public char[][] fullExclusionPatternChars();
} }

View file

@ -30,4 +30,13 @@ public interface IIncludeReference extends IParent, ICElement {
* @return * @return
*/ */
IPath getAffectedPath(); IPath getAffectedPath();
/**
* Return true if the path is on the include path Entry
*
* @param path
* @return
*/
boolean isOnIncludeEntry(IPath path);
} }

View file

@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,8 +35,10 @@ import org.eclipse.cdt.core.model.ICElementDelta;
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;
import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
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.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -368,6 +371,26 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
return celement; return celement;
} }
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) {
if (path == null || cproject == null) {
return null;
}
File file = path.toFile();
if (file == null || !file.isFile()) {
return null;
}
try {
IIncludeReference[] includeReferences = cproject.getIncludeReferences();
for (int i = 0; i < includeReferences.length; i++) {
if (includeReferences[i].isOnIncludeEntry(path)) {
return new ExternalTranslationUnit(includeReferences[i], path);
}
}
} catch (CModelException e) {
}
return null;
}
public void releaseCElement(ICElement celement) { public void releaseCElement(ICElement celement) {
// Guard. // Guard.

View file

@ -16,6 +16,7 @@ import java.util.ArrayList;
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.CoreModelUtil;
import org.eclipse.cdt.core.model.ICElement; 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.IIncludeEntry; import org.eclipse.cdt.core.model.IIncludeEntry;
@ -118,4 +119,15 @@ public class IncludeReference extends Openable implements IIncludeReference {
return true; return true;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IIncludeReference#isOnIncludeEntry(org.eclipse.core.runtime.IPath)
*/
public boolean isOnIncludeEntry(IPath path) {
if (fIncludeEntry.getIncludePath().isPrefixOf(path)
&& !CoreModelUtil.isExcluded(path, fIncludeEntry.fullExclusionPatternChars())) {
return true;
}
return false;
}
} }