1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Share some code.

This commit is contained in:
Alain Magloire 2005-03-30 17:22:42 +00:00
parent 585cbe890c
commit 0826b3421e

View file

@ -174,72 +174,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
public IIncludeFileEntry[] getIncludeFileEntries(ITranslationUnit cunit) throws CModelException { public IIncludeFileEntry[] getIncludeFileEntries(ITranslationUnit cunit) throws CModelException {
ArrayList includeFileList = new ArrayList(); List list = getPathEntries(cunit, IPathEntry.CDT_INCLUDE_FILE);
ICProject cproject = cunit.getCProject(); IIncludeFileEntry[] incFiles = (IIncludeFileEntry[]) list.toArray(new IIncludeFileEntry[list.size()]);
IPath resPath = cunit.getPath(); return incFiles;
// Do this first so the containers get inialized.
ArrayList resolvedListEntries = getResolvedPathEntries(cproject, false);
for (int i = 0; i < resolvedListEntries.size(); ++i) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE_FILE) {
includeFileList.add(entry);
}
}
IPathEntryContainer[] containers = getPathEntryContainers(cproject);
for (int i = 0; i < containers.length; ++i) {
if (containers[i] instanceof IPathEntryContainerExtension) {
IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i];
IIncludeFileEntry[] incs = (IIncludeFileEntry[])extension.getPathEntries(resPath, IPathEntry.CDT_INCLUDE_FILE);
includeFileList.addAll(Arrays.asList(incs));
}
}
IIncludeFileEntry[] includeFiles = (IIncludeFileEntry[]) includeFileList.toArray(new IIncludeFileEntry[includeFileList.size()]);
// Clear the list since we are reusing it.
includeFileList.clear();
// We need to reorder the include/macros:
// includes with the closest match to the resource will come first
// /project/src/file.c --> /usr/local/include
// /project --> /usr/include
//
// /usr/local/include must come first.
//
int count = resPath.segmentCount();
for (int i = 0; i < count; i++) {
IPath newPath = resPath.removeLastSegments(i);
for (int j = 0; j < includeFiles.length; j++) {
IPath otherPath = includeFiles[j].getPath();
if (newPath.equals(otherPath)) {
includeFileList.add(includeFiles[j]);
}
}
}
// Since the include that comes from a project contribution are not
// tied to a resource they are added last.
for (int i = 0; i < resolvedListEntries.size(); i++) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
if (entry != null && entry.getEntryKind() == IPathEntry.CDT_PROJECT) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(entry.getPath());
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);
if (refCProject != null) {
IPathEntry[] projEntries = refCProject.getResolvedPathEntries();
for (int j = 0; j < projEntries.length; j++) {
IPathEntry projEntry = projEntries[j];
if (projEntry.isExported()) {
if (projEntry.getEntryKind() == IPathEntry.CDT_INCLUDE_FILE) {
IIncludeFileEntry includeFile = (IIncludeFileEntry)projEntry;
includeFileList.add(includeFile);
}
}
}
}
}
}
}
return (IIncludeFileEntry[])includeFileList.toArray(new IIncludeFileEntry[includeFileList.size()]);
} }
public IIncludeEntry[] getIncludeEntries(IPath resPath) throws CModelException { public IIncludeEntry[] getIncludeEntries(IPath resPath) throws CModelException {
@ -251,72 +188,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
public IIncludeEntry[] getIncludeEntries(ITranslationUnit cunit) throws CModelException { public IIncludeEntry[] getIncludeEntries(ITranslationUnit cunit) throws CModelException {
ArrayList includeList = new ArrayList(); List list = getPathEntries(cunit, IPathEntry.CDT_INCLUDE);
ICProject cproject = cunit.getCProject(); IIncludeEntry[] includes = (IIncludeEntry[]) list.toArray(new IIncludeEntry[list.size()]);
IPath resPath = cunit.getPath(); return includes;
// Do this first so the containers get inialized.
ArrayList resolvedListEntries = getResolvedPathEntries(cproject, false);
for (int i = 0; i < resolvedListEntries.size(); ++i) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE) {
includeList.add(entry);
}
}
IPathEntryContainer[] containers = getPathEntryContainers(cproject);
for (int i = 0; i < containers.length; ++i) {
if (containers[i] instanceof IPathEntryContainerExtension) {
IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i];
IIncludeEntry[] incs = (IIncludeEntry[]) extension.getPathEntries(resPath, IPathEntry.CDT_INCLUDE_FILE);
includeList.addAll(Arrays.asList(incs));
}
}
IIncludeEntry[] includes = (IIncludeEntry[]) includeList.toArray(new IIncludeEntry[includeList.size()]);
// Clear the list since we are reusing it.
includeList.clear();
// We need to reorder the include/macros:
// includes with the closest match to the resource will come first
// /project/src/file.c --> /usr/local/include
// /project --> /usr/include
//
// /usr/local/include must come first.
//
int count = resPath.segmentCount();
for (int i = 0; i < count; i++) {
IPath newPath = resPath.removeLastSegments(i);
for (int j = 0; j < includes.length; j++) {
IPath otherPath = includes[j].getPath();
if (newPath.equals(otherPath)) {
includeList.add(includes[j]);
}
}
}
// Since the include that comes from a project contribution are not
// tied to a resource they are added last.
for (int i = 0; i < resolvedListEntries.size(); i++) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
if (entry != null && entry.getEntryKind() == IPathEntry.CDT_PROJECT) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(entry.getPath());
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);
if (refCProject != null) {
IPathEntry[] projEntries = refCProject.getResolvedPathEntries();
for (int j = 0; j < projEntries.length; j++) {
IPathEntry projEntry = projEntries[j];
if (projEntry.isExported()) {
if (projEntry.getEntryKind() == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry)projEntry;
includeList.add(include);
}
}
}
}
}
}
}
return (IIncludeEntry[])includeList.toArray(new IIncludeEntry[includeList.size()]);
} }
public IMacroEntry[] getMacroEntries(IPath resPath) throws CModelException { public IMacroEntry[] getMacroEntries(IPath resPath) throws CModelException {
@ -327,7 +201,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return NO_MACRO_ENTRIES; return NO_MACRO_ENTRIES;
} }
public IMacroEntry[] getMacroEntries(ITranslationUnit cunit) throws CModelException { private IMacroEntry[] getMacroEntries(ITranslationUnit cunit) throws CModelException {
ArrayList macroList = new ArrayList(); ArrayList macroList = new ArrayList();
ICProject cproject = cunit.getCProject(); ICProject cproject = cunit.getCProject();
IPath resPath = cunit.getPath(); IPath resPath = cunit.getPath();
@ -410,48 +284,55 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
public IMacroFileEntry[] getMacroFileEntries(ITranslationUnit cunit) throws CModelException { public IMacroFileEntry[] getMacroFileEntries(ITranslationUnit cunit) throws CModelException {
ArrayList macroFileList = new ArrayList(); List list = getPathEntries(cunit, IPathEntry.CDT_MACRO_FILE);
IMacroFileEntry[] macFiles = (IMacroFileEntry[]) list.toArray(new IMacroFileEntry[list.size()]);
return macFiles;
}
private List getPathEntries(ITranslationUnit cunit, int type) throws CModelException {
ArrayList entryList = new ArrayList();
ICProject cproject = cunit.getCProject(); ICProject cproject = cunit.getCProject();
IPath resPath = cunit.getPath(); IPath resPath = cunit.getPath();
// Do this first so the containers get inialized. // Do this first so the containers get inialized.
ArrayList resolvedListEntries = getResolvedPathEntries(cproject, false); ArrayList resolvedListEntries = getResolvedPathEntries(cproject, false);
for (int i = 0; i < resolvedListEntries.size(); ++i) { for (int i = 0; i < resolvedListEntries.size(); ++i) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i); IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
if (entry.getEntryKind() == IPathEntry.CDT_MACRO_FILE) { if ((entry.getEntryKind() & type) != 0) {
macroFileList.add(entry); entryList.add(entry);
} }
} }
IPathEntryContainer[] containers = getPathEntryContainers(cproject); IPathEntryContainer[] containers = getPathEntryContainers(cproject);
for (int i = 0; i < containers.length; ++i) { for (int i = 0; i < containers.length; ++i) {
if (containers[i] instanceof IPathEntryContainerExtension) { if (containers[i] instanceof IPathEntryContainerExtension) {
IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i]; IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i];
IMacroFileEntry[] macFiles = (IMacroFileEntry[])extension.getPathEntries(resPath, IPathEntry.CDT_MACRO_FILE); IPathEntry[] incs = extension.getPathEntries(resPath, type);
macroFileList.addAll(Arrays.asList(macFiles)); entryList.addAll(Arrays.asList(incs));
} }
} }
IMacroFileEntry[] macroFiles = (IMacroFileEntry[]) macroFileList.toArray(new IMacroFileEntry[macroFileList.size()]); IPathEntry[] entries = (IPathEntry[]) entryList.toArray(new IPathEntry[entryList.size()]);
macroFileList.clear(); // Clear the list since we are reusing it.
entryList.clear();
// We need to reorder the macro files: // We need to reorder the include/macros:
// with the closest match to the resource coming first // includes with the closest match to the resource will come first
// /project/src/file.c --> /usr/local/include/macrofile // /project/src/file.c --> /usr/local/include
// /project --> /usr/include/macrofile // /project --> /usr/include
// //
// /usr/local/include/macrofile must come first. // /usr/local/include must come first.
// //
int count = resPath.segmentCount(); int count = resPath.segmentCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
IPath newPath = resPath.removeLastSegments(i); IPath newPath = resPath.removeLastSegments(i);
for (int j = 0; j < macroFiles.length; j++) { for (int j = 0; j < entries.length; j++) {
IPath otherPath = macroFiles[j].getPath(); IPath otherPath = entries[j].getPath();
if (newPath.equals(otherPath)) { if (newPath.equals(otherPath)) {
macroFileList.add(macroFiles[j]); entryList.add(entries[j]);
} }
} }
} }
// Since the macroFile that comes from a project contribution are not // Since the include that comes from a project contribution are not
// tied to a resource they are added last. // tied to a resource they are added last.
for (int i = 0; i < resolvedListEntries.size(); i++) { for (int i = 0; i < resolvedListEntries.size(); i++) {
IPathEntry entry = (IPathEntry)resolvedListEntries.get(i); IPathEntry entry = (IPathEntry)resolvedListEntries.get(i);
@ -464,9 +345,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
for (int j = 0; j < projEntries.length; j++) { for (int j = 0; j < projEntries.length; j++) {
IPathEntry projEntry = projEntries[j]; IPathEntry projEntry = projEntries[j];
if (projEntry.isExported()) { if (projEntry.isExported()) {
if (projEntry.getEntryKind() == IPathEntry.CDT_MACRO_FILE) { if ((projEntry.getEntryKind() & type) != 0) {
IMacroFileEntry macroFile = (IMacroFileEntry)projEntry; entryList.add(projEntry);
macroFileList.add(macroFile);
} }
} }
} }
@ -474,7 +354,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
} }
return (IMacroFileEntry[])macroFileList.toArray(NO_MACRO_FILE_ENTRIES); return entryList;
} }
/** /**