mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Make it possible to set more then one IBinaryParser
per file.
This commit is contained in:
parent
e9ce7d57a8
commit
bc304ce15e
4 changed files with 97 additions and 45 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -387,26 +387,34 @@ 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) {
|
||||
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 {
|
||||
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) {
|
||||
|
@ -414,11 +422,24 @@ public class CModelManager implements IResourceChangeListener {
|
|||
System.arraycopy(bytes, 0, array, 0, count);
|
||||
bytes = array;
|
||||
}
|
||||
IPath location = file.getLocation();
|
||||
return parser.getBinary(bytes, location);
|
||||
} catch (IOException e) {
|
||||
} catch (CoreException e) {
|
||||
//e.printStackTrace();
|
||||
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) {
|
||||
//
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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,26 +110,31 @@ 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) {
|
||||
if (binParsers != null) {
|
||||
for (int i = 0; i < binParsers.length; i++) {
|
||||
IBinaryFile bin;
|
||||
try {
|
||||
bin = binParser.getBinary(entry.getPath());
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lib == null) {
|
||||
lib = new LibraryReference(cproject, entry);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue