mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +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
|
2004-03-01 Andrew Niefer
|
||||||
externalize strings : Bug 53123
|
externalize strings : Bug 53123
|
||||||
|
|
||||||
|
|
|
@ -387,38 +387,59 @@ public class CModelManager implements IResourceChangeListener {
|
||||||
removeInfo(celement);
|
removeInfo(celement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinaryParser getBinaryParser(IProject project) {
|
public IBinaryParser[] getBinaryParser(IProject project) {
|
||||||
try {
|
try {
|
||||||
IBinaryParser parser = (IBinaryParser)binaryParsersMap.get(project);
|
IBinaryParser[] parsers = (IBinaryParser[])binaryParsersMap.get(project);
|
||||||
if (parser == null) {
|
if (parsers == null) {
|
||||||
parser = CCorePlugin.getDefault().getBinaryParser(project);
|
parsers = CCorePlugin.getDefault().getBinaryParser(project);
|
||||||
}
|
}
|
||||||
if (parser != null) {
|
if (parsers != null) {
|
||||||
binaryParsersMap.put(project, parser);
|
binaryParsersMap.put(project, parsers);
|
||||||
return parser;
|
return parsers;
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
return new NullBinaryParser();
|
return new IBinaryParser[] {new NullBinaryParser()};
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinaryFile createBinaryFile(IFile file) {
|
public IBinaryFile createBinaryFile(IFile file) {
|
||||||
try {
|
IBinaryParser[] parsers = getBinaryParser(file.getProject());
|
||||||
IBinaryParser parser = getBinaryParser(file.getProject());
|
int hints = 0;
|
||||||
InputStream is = file.getContents();
|
for (int i = 0; i < parsers.length; i++) {
|
||||||
byte[] bytes = new byte[parser.getHintBufferSize()];
|
IBinaryParser parser = parsers[i];
|
||||||
int count = is.read(bytes);
|
if (parser.getHintBufferSize() > hints) {
|
||||||
is.close();
|
hints = parser.getHintBufferSize();
|
||||||
if (count > 0 && count < bytes.length) {
|
}
|
||||||
byte[] array = new byte[count];
|
}
|
||||||
System.arraycopy(bytes, 0, array, 0, count);
|
byte[] bytes = new byte[hints];
|
||||||
bytes = array;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,16 +92,16 @@ public class CProject extends CContainer implements ICProject {
|
||||||
|
|
||||||
public ILibraryReference[] getLibraryReferences() throws CModelException {
|
public ILibraryReference[] getLibraryReferences() throws CModelException {
|
||||||
ArrayList list = new ArrayList(5);
|
ArrayList list = new ArrayList(5);
|
||||||
IBinaryParser binParser = null;
|
IBinaryParser[] binParsers = null;
|
||||||
try {
|
try {
|
||||||
binParser = CCorePlugin.getDefault().getBinaryParser(getProject());
|
binParsers = CCorePlugin.getDefault().getBinaryParser(getProject());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
IPathEntry[] entries = getResolvedPathEntries();
|
IPathEntry[] entries = getResolvedPathEntries();
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
|
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
|
||||||
ILibraryEntry entry = (ILibraryEntry) entries[i];
|
ILibraryEntry entry = (ILibraryEntry) entries[i];
|
||||||
ILibraryReference lib = getLibraryReference(this, binParser, entry);
|
ILibraryReference lib = getLibraryReference(this, binParsers, entry);
|
||||||
if (lib != null) {
|
if (lib != null) {
|
||||||
list.add(lib);
|
list.add(lib);
|
||||||
}
|
}
|
||||||
|
@ -110,24 +110,29 @@ public class CProject extends CContainer implements ICProject {
|
||||||
return (ILibraryReference[]) list.toArray(new ILibraryReference[0]);
|
return (ILibraryReference[]) list.toArray(new ILibraryReference[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ILibraryReference getLibraryReference(ICProject cproject, IBinaryParser binParser, ILibraryEntry entry) {
|
public static ILibraryReference getLibraryReference(ICProject cproject, IBinaryParser[] binParsers, ILibraryEntry entry) {
|
||||||
if (binParser == null) {
|
if (binParsers == null) {
|
||||||
try {
|
try {
|
||||||
binParser = CCorePlugin.getDefault().getBinaryParser(cproject.getProject());
|
binParsers = CCorePlugin.getDefault().getBinaryParser(cproject.getProject());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ILibraryReference lib = null;
|
ILibraryReference lib = null;
|
||||||
if (binParser != null) {
|
if (binParsers != null) {
|
||||||
IBinaryFile bin;
|
for (int i = 0; i < binParsers.length; i++) {
|
||||||
try {
|
IBinaryFile bin;
|
||||||
bin = binParser.getBinary(entry.getPath());
|
try {
|
||||||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
bin = binParsers[i].getBinary(entry.getPath());
|
||||||
lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin);
|
if (bin != null) {
|
||||||
} else {
|
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||||
lib = new LibraryReferenceShared(cproject, entry, bin);
|
lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin);
|
||||||
|
} else {
|
||||||
|
lib = new LibraryReferenceShared(cproject, entry, bin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
} catch (IOException e1) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lib == null) {
|
if (lib == null) {
|
||||||
|
|
|
@ -471,21 +471,38 @@ public class CCorePlugin extends Plugin {
|
||||||
return getConsole(null);
|
return getConsole(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinaryParser getBinaryParser(IProject project) throws CoreException {
|
public IBinaryParser[] getBinaryParser(IProject project) throws CoreException {
|
||||||
IBinaryParser parser = null;
|
IBinaryParser parsers[] = null;
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
try {
|
try {
|
||||||
ICDescriptor cdesc = (ICDescriptor) getCProjectDescription(project);
|
ICDescriptor cdesc = (ICDescriptor) getCProjectDescription(project);
|
||||||
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
|
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
|
||||||
if (cextensions.length > 0)
|
if (cextensions.length > 0) {
|
||||||
parser = (IBinaryParser) cextensions[0].createExtension();
|
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) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parser == null) {
|
if (parsers == null) {
|
||||||
parser = getDefaultBinaryParser();
|
IBinaryParser parser = getDefaultBinaryParser();
|
||||||
|
if (parser != null) {
|
||||||
|
parsers = new IBinaryParser[] {parser};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parser;
|
return parsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinaryParser getDefaultBinaryParser() throws CoreException {
|
public IBinaryParser getDefaultBinaryParser() throws CoreException {
|
||||||
|
|
Loading…
Add table
Reference in a new issue