From bc304ce15ec3625077d59499de97decd44dfc899 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 2 Mar 2004 21:08:38 +0000 Subject: [PATCH] Make it possible to set more then one IBinaryParser per file. --- core/org.eclipse.cdt.core/ChangeLog | 9 +++ .../internal/core/model/CModelManager.java | 67 ++++++++++++------- .../cdt/internal/core/model/CProject.java | 35 +++++----- .../src/org/eclipse/cdt/core/CCorePlugin.java | 31 +++++++-- 4 files changed, 97 insertions(+), 45 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 7381d87717d..93b78c0f91f 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,12 @@ +2004-03-02 Alain Magloire + + Work to make it possible to set more the one binaryParser + per project. Note that the UI is not yet enabled. + + * model/org/eclipse/cdt/internal/core/model/CModelManager.java + * model/org/eclipse/cdt/internal/core/model/CProject.java + * src/org/eclipse/cdt/core/CCorePlugin.java + 2004-03-01 Andrew Niefer externalize strings : Bug 53123 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 6a21cfeb9bd..6c2f99fd720 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 @@ -387,38 +387,59 @@ public class CModelManager implements IResourceChangeListener { removeInfo(celement); } - public IBinaryParser getBinaryParser(IProject project) { + public IBinaryParser[] getBinaryParser(IProject project) { try { - IBinaryParser parser = (IBinaryParser)binaryParsersMap.get(project); - if (parser == null) { - parser = CCorePlugin.getDefault().getBinaryParser(project); + IBinaryParser[] parsers = (IBinaryParser[])binaryParsersMap.get(project); + if (parsers == null) { + parsers = CCorePlugin.getDefault().getBinaryParser(project); } - if (parser != null) { - binaryParsersMap.put(project, parser); - return parser; + if (parsers != null) { + binaryParsersMap.put(project, parsers); + return parsers; } } catch (CoreException e) { } - return new NullBinaryParser(); + return new IBinaryParser[] {new NullBinaryParser()}; } public IBinaryFile createBinaryFile(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - InputStream is = file.getContents(); - byte[] bytes = new byte[parser.getHintBufferSize()]; - int count = is.read(bytes); - is.close(); - if (count > 0 && count < bytes.length) { - byte[] array = new byte[count]; - System.arraycopy(bytes, 0, array, 0, count); - bytes = array; + IBinaryParser[] parsers = getBinaryParser(file.getProject()); + int hints = 0; + for (int i = 0; i < parsers.length; i++) { + IBinaryParser parser = parsers[i]; + if (parser.getHintBufferSize() > hints) { + hints = parser.getHintBufferSize(); + } + } + byte[] bytes = new byte[hints]; + if (hints > 0) { + try { + InputStream is = file.getContents(); + int count = is.read(bytes); + is.close(); + if (count > 0 && count < bytes.length) { + byte[] array = new byte[count]; + System.arraycopy(bytes, 0, array, 0, count); + bytes = array; + } + } catch (CoreException e) { + return null; + } catch (IOException e) { + return null; + } + } + + IPath location = file.getLocation(); + + for (int i = 0; i < parsers.length; i++) { + try { + IBinaryFile bin = parsers[i].getBinary(bytes, location); + if (bin != null) { + return bin; + } + } catch (IOException e) { + // } - IPath location = file.getLocation(); - return parser.getBinary(bytes, location); - } catch (IOException e) { - } catch (CoreException e) { - //e.printStackTrace(); } return null; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index 4ac3c8260af..53bffeed28c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -92,16 +92,16 @@ public class CProject extends CContainer implements ICProject { public ILibraryReference[] getLibraryReferences() throws CModelException { ArrayList list = new ArrayList(5); - IBinaryParser binParser = null; + IBinaryParser[] binParsers = null; try { - binParser = CCorePlugin.getDefault().getBinaryParser(getProject()); + binParsers = CCorePlugin.getDefault().getBinaryParser(getProject()); } catch (CoreException e) { } IPathEntry[] entries = getResolvedPathEntries(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) { ILibraryEntry entry = (ILibraryEntry) entries[i]; - ILibraryReference lib = getLibraryReference(this, binParser, entry); + ILibraryReference lib = getLibraryReference(this, binParsers, entry); if (lib != null) { list.add(lib); } @@ -110,24 +110,29 @@ public class CProject extends CContainer implements ICProject { return (ILibraryReference[]) list.toArray(new ILibraryReference[0]); } - public static ILibraryReference getLibraryReference(ICProject cproject, IBinaryParser binParser, ILibraryEntry entry) { - if (binParser == null) { + public static ILibraryReference getLibraryReference(ICProject cproject, IBinaryParser[] binParsers, ILibraryEntry entry) { + if (binParsers == null) { try { - binParser = CCorePlugin.getDefault().getBinaryParser(cproject.getProject()); + binParsers = CCorePlugin.getDefault().getBinaryParser(cproject.getProject()); } catch (CoreException e) { } } ILibraryReference lib = null; - if (binParser != null) { - IBinaryFile bin; - try { - bin = binParser.getBinary(entry.getPath()); - if (bin.getType() == IBinaryFile.ARCHIVE) { - lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); - } else { - lib = new LibraryReferenceShared(cproject, entry, bin); + if (binParsers != null) { + for (int i = 0; i < binParsers.length; i++) { + IBinaryFile bin; + try { + bin = binParsers[i].getBinary(entry.getPath()); + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { + lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); + } else { + lib = new LibraryReferenceShared(cproject, entry, bin); + } + break; + } + } catch (IOException e1) { } - } catch (IOException e1) { } } if (lib == null) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 97bb8b66c59..8dad4e4790c 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -471,21 +471,38 @@ public class CCorePlugin extends Plugin { return getConsole(null); } - public IBinaryParser getBinaryParser(IProject project) throws CoreException { - IBinaryParser parser = null; + public IBinaryParser[] getBinaryParser(IProject project) throws CoreException { + IBinaryParser parsers[] = null; if (project != null) { try { ICDescriptor cdesc = (ICDescriptor) getCProjectDescription(project); ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true); - if (cextensions.length > 0) - parser = (IBinaryParser) cextensions[0].createExtension(); + if (cextensions.length > 0) { + ArrayList list = new ArrayList(cextensions.length); + for (int i = 0; i < cextensions.length; i++) { + IBinaryParser parser = null; + try { + parser = (IBinaryParser) cextensions[i].createExtension(); + } catch (ClassCastException e) { + // + } + if (parser != null) { + list.add(parser); + } + } + parsers = new IBinaryParser[list.size()]; + list.toArray(parsers); + } } catch (CoreException e) { } } - if (parser == null) { - parser = getDefaultBinaryParser(); + if (parsers == null) { + IBinaryParser parser = getDefaultBinaryParser(); + if (parser != null) { + parsers = new IBinaryParser[] {parser}; + } } - return parser; + return parsers; } public IBinaryParser getDefaultBinaryParser() throws CoreException {