1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

IBinaryParser interface change the methos:

public IBinaryFile getBinary(IFile)

to

public IBinaryFile getBinary(IPath)
This commit is contained in:
Alain Magloire 2003-02-26 21:38:44 +00:00
parent 6940e686c7
commit add6587020
10 changed files with 124 additions and 136 deletions

View file

@ -13,9 +13,9 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
/** /**
* Info for ICProject. * Info for ICProject.
@ -73,8 +73,8 @@ class ArchiveInfo extends CFileInfo {
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
if (parser != null) { if (parser != null) {
try { try {
IFile file = (IFile) getElement().getUnderlyingResource(); IPath path = getElement().getUnderlyingResource().getLocation();
IBinaryFile bfile = parser.getBinary(file); IBinaryFile bfile = parser.getBinary(path);
if (bfile instanceof IBinaryArchive) { if (bfile instanceof IBinaryArchive) {
archive = (IBinaryArchive) bfile; archive = (IBinaryArchive) bfile;
} }

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
import org.eclipse.cdt.core.IBinaryParser.ISymbol; import org.eclipse.cdt.core.IBinaryParser.ISymbol;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -167,8 +166,8 @@ class BinaryInfo extends CFileInfo {
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project); IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
if (parser != null) { if (parser != null) {
try { try {
IFile file = (IFile) getElement().getUnderlyingResource(); IPath path = getElement().getUnderlyingResource().getLocation();
IBinaryFile bfile = parser.getBinary(file); IBinaryFile bfile = parser.getBinary(path);
if (bfile instanceof IBinaryObject) { if (bfile instanceof IBinaryObject) {
binary = (IBinaryObject) bfile; binary = (IBinaryObject) bfile;
} }

View file

@ -461,7 +461,7 @@ public class CModelManager implements IResourceChangeListener {
public boolean isSharedLib(IFile file) { public boolean isSharedLib(IFile file) {
try { try {
IBinaryParser parser = getBinaryParser(file.getProject()); IBinaryParser parser = getBinaryParser(file.getProject());
IBinaryFile bin = parser.getBinary(file); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.SHARED); return (bin.getType() == IBinaryFile.SHARED);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
@ -472,7 +472,7 @@ public class CModelManager implements IResourceChangeListener {
public boolean isObject(IFile file) { public boolean isObject(IFile file) {
try { try {
IBinaryParser parser = getBinaryParser(file.getProject()); IBinaryParser parser = getBinaryParser(file.getProject());
IBinaryFile bin = parser.getBinary(file); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.OBJECT); return (bin.getType() == IBinaryFile.OBJECT);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
@ -483,7 +483,7 @@ public class CModelManager implements IResourceChangeListener {
public boolean isExecutable(IFile file) { public boolean isExecutable(IFile file) {
try { try {
IBinaryParser parser = getBinaryParser(file.getProject()); IBinaryParser parser = getBinaryParser(file.getProject());
IBinaryFile bin = parser.getBinary(file); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.EXECUTABLE); return (bin.getType() == IBinaryFile.EXECUTABLE);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
@ -494,7 +494,7 @@ public class CModelManager implements IResourceChangeListener {
public boolean isBinary(IFile file) { public boolean isBinary(IFile file) {
try { try {
IBinaryParser parser = getBinaryParser(file.getProject()); IBinaryParser parser = getBinaryParser(file.getProject());
IBinaryFile bin = parser.getBinary(file); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.EXECUTABLE return (bin.getType() == IBinaryFile.EXECUTABLE
|| bin.getType() == IBinaryFile.OBJECT || bin.getType() == IBinaryFile.OBJECT
|| bin.getType() == IBinaryFile.SHARED || bin.getType() == IBinaryFile.SHARED
@ -508,7 +508,7 @@ public class CModelManager implements IResourceChangeListener {
public boolean isArchive(IFile file) { public boolean isArchive(IFile file) {
try { try {
IBinaryParser parser = getBinaryParser(file.getProject()); IBinaryParser parser = getBinaryParser(file.getProject());
IBinaryFile bin = parser.getBinary(file); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.ARCHIVE); return (bin.getType() == IBinaryFile.ARCHIVE);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model.parser;
*/ */
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,8 +15,6 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.utils.elf.AR; import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -23,12 +22,12 @@ import org.eclipse.core.runtime.PlatformObject;
*/ */
public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive { public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
IFile file; IPath path;
ArrayList children; ArrayList children;
long timestamp; long timestamp;
public ElfBinaryArchive(IFile f) { public ElfBinaryArchive(IPath p) {
file = f; path = p;
children = new ArrayList(5); children = new ArrayList(5);
} }
@ -38,14 +37,13 @@ public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
public IBinaryObject[] getObjects() { public IBinaryObject[] getObjects() {
if (hasChanged()) { if (hasChanged()) {
children.clear(); children.clear();
IPath location = file.getLocation(); if (path != null) {
if (location != null) {
AR ar = null; AR ar = null;
try { try {
ar = new AR(location.toOSString()); ar = new AR(path.toOSString());
AR.ARHeader[] headers = ar.getHeaders(); AR.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) { for (int i = 0; i < headers.length; i++) {
IBinaryObject bin = new ElfBinaryFile(file, headers[i]); IBinaryObject bin = new ElfBinaryFile(path, headers[i]);
children.add(bin); children.add(bin);
} }
} catch (IOException e) { } catch (IOException e) {
@ -63,8 +61,8 @@ public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/ */
public IFile getFile() { public IPath getPath() {
return file; return path;
} }
/** /**
@ -79,14 +77,14 @@ public class ElfBinaryArchive extends PlatformObject implements IBinaryArchive {
*/ */
public InputStream getContents() { public InputStream getContents() {
try { try {
return file.getContents(); return new FileInputStream(path.toFile());
} catch (CoreException e) { } catch (IOException e) {
} }
return new ByteArrayInputStream(new byte[0]); return new ByteArrayInputStream(new byte[0]);
} }
boolean hasChanged() { boolean hasChanged() {
long modif = file.getModificationStamp(); long modif = path.toFile().lastModified();
boolean changed = modif != timestamp; boolean changed = modif != timestamp;
timestamp = modif; timestamp = modif;
return changed; return changed;

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model.parser;
*/ */
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,16 +21,13 @@ import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.cdt.utils.elf.ElfHelper; import org.eclipse.cdt.utils.elf.ElfHelper;
import org.eclipse.cdt.utils.elf.Elf.Attribute; import org.eclipse.cdt.utils.elf.Elf.Attribute;
import org.eclipse.cdt.utils.elf.ElfHelper.Sizes; import org.eclipse.cdt.utils.elf.ElfHelper.Sizes;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
*/ */
public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinaryObject, IBinaryExecutable, IBinaryShared { public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinaryObject, IBinaryExecutable, IBinaryShared {
IFile file; IPath path;
AR.ARHeader header; AR.ARHeader header;
long timestamp; long timestamp;
String soname; String soname;
@ -38,13 +36,13 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
Attribute attribute; Attribute attribute;
ArrayList symbols; ArrayList symbols;
public ElfBinaryFile(IFile f) throws IOException { public ElfBinaryFile(IPath p) throws IOException {
this(f, null); this(p, null);
} }
public ElfBinaryFile(IFile f, AR.ARHeader h) throws IOException { public ElfBinaryFile(IPath p, AR.ARHeader h) throws IOException {
header = h; header = h;
file = f; path = p;
loadInformation(); loadInformation();
hasChanged(); hasChanged();
} }
@ -52,8 +50,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/ */
public IFile getFile() { public IPath getPath() {
return file; return path;
} }
/** /**
@ -204,15 +202,15 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
public InputStream getContents() { public InputStream getContents() {
InputStream stream = null; InputStream stream = null;
// Archive ? // Archive ?
if (file != null && header != null) { if (path != null && header != null) {
try { try {
stream = new ByteArrayInputStream(header.getObjectData()); stream = new ByteArrayInputStream(header.getObjectData());
} catch (IOException e) { } catch (IOException e) {
} }
} else if (file != null && file.exists()) { } else if (path != null) {
try { try {
stream = file.getContents(); stream = new FileInputStream(path.toFile());
} catch (CoreException e) { } catch (IOException e) {
} }
} }
if (stream == null) { if (stream == null) {
@ -228,8 +226,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
if (header != null) { if (header != null) {
return header.getObjectName(); return header.getObjectName();
} }
if (file != null) { if (path != null) {
return file.getName(); return path.lastSegment().toString();
} }
return ""; return "";
} }
@ -259,7 +257,7 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
} }
boolean hasChanged() { boolean hasChanged() {
long modification = file.getModificationStamp(); long modification = path.toFile().lastModified();
boolean changed = modification != timestamp; boolean changed = modification != timestamp;
timestamp = modification; timestamp = modification;
return changed; return changed;
@ -269,11 +267,7 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
// Archive ? // Archive ?
if (header != null) { if (header != null) {
return new ElfHelper(header.getElf()); return new ElfHelper(header.getElf());
} else if (file != null && file.exists()) { } else if (path != null) {
IPath path = file.getLocation();
if (path == null) {
path = new Path("");
}
return new ElfHelper(path.toOSString()); return new ElfHelper(path.toOSString());
} }
throw new IOException("No file assiocated with Binary"); throw new IOException("No file assiocated with Binary");

View file

@ -10,7 +10,7 @@ import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.elf.AR; import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf;
import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath;
/** /**
*/ */
@ -19,17 +19,17 @@ public class ElfParser implements IBinaryParser {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath) * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath)
*/ */
public IBinaryFile getBinary(IFile file) throws IOException { public IBinaryFile getBinary(IPath path) throws IOException {
try { try {
Elf e = new Elf(file.getLocation().toOSString()); Elf e = new Elf(path.toOSString());
e.dispose(); e.dispose();
return new ElfBinaryFile(file); return new ElfBinaryFile(path);
} catch (IOException e) { } catch (IOException e) {
} }
// Is it an Archive. // Is it an Archive.
AR ar = new AR(file.getLocation().toOSString()); AR ar = new AR(path.toOSString());
ar.dispose(); ar.dispose();
return new ElfBinaryArchive(file); return new ElfBinaryArchive(path);
} }
/** /**

View file

@ -6,6 +6,8 @@ package org.eclipse.cdt.internal.core.model.parser;
*/ */
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,8 +16,6 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.utils.coff.PEArchive; import org.eclipse.cdt.utils.coff.PEArchive;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
@ -23,12 +23,12 @@ import org.eclipse.core.runtime.PlatformObject;
*/ */
public class PEBinaryArchive extends PlatformObject implements IBinaryArchive { public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
IFile file; IPath path;
ArrayList children; ArrayList children;
long timestamp; long timestamp;
public PEBinaryArchive(IFile f) { public PEBinaryArchive(IPath p) {
file = f; path = p;
children = new ArrayList(5); children = new ArrayList(5);
} }
@ -38,14 +38,13 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
public IBinaryObject[] getObjects() { public IBinaryObject[] getObjects() {
if (hasChanged()) { if (hasChanged()) {
children.clear(); children.clear();
IPath location = file.getLocation(); if (path != null) {
if (location != null) {
PEArchive ar = null; PEArchive ar = null;
try { try {
ar = new PEArchive(location.toOSString()); ar = new PEArchive(path.toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders(); PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) { for (int i = 0; i < headers.length; i++) {
IBinaryObject bin = new PEBinaryFile(file, headers[i].getObjectName()); IBinaryObject bin = new PEBinaryFile(path, headers[i].getObjectName());
children.add(bin); children.add(bin);
} }
} catch (IOException e) { } catch (IOException e) {
@ -63,8 +62,8 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/ */
public IFile getFile() { public IPath getPath() {
return file; return path;
} }
/** /**
@ -79,17 +78,21 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
*/ */
public InputStream getContents() { public InputStream getContents() {
try { try {
return file.getContents(); return new FileInputStream(path.toFile());
} catch (CoreException e) { } catch (IOException e) {
} }
return new ByteArrayInputStream(new byte[0]); return new ByteArrayInputStream(new byte[0]);
} }
boolean hasChanged() { boolean hasChanged() {
long modif = file.getModificationStamp(); File file = path.toFile();
boolean changed = modif != timestamp; if (file != null && file.exists()) {
timestamp = modif; long modification = file.lastModified();
return changed; boolean changed = modification != timestamp;
timestamp = modification;
return changed;
}
return false;
} }
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[]) * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryArchive#add(IBinaryObject[])

View file

@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.core.model.parser;
*/ */
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,10 +20,7 @@ import org.eclipse.cdt.utils.coff.Coff;
import org.eclipse.cdt.utils.coff.PE; import org.eclipse.cdt.utils.coff.PE;
import org.eclipse.cdt.utils.coff.PEArchive; import org.eclipse.cdt.utils.coff.PEArchive;
import org.eclipse.cdt.utils.coff.PE.Attribute; import org.eclipse.cdt.utils.coff.PE.Attribute;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
/** /**
@ -29,18 +28,18 @@ import org.eclipse.core.runtime.PlatformObject;
public class PEBinaryFile extends PlatformObject implements IBinaryFile, public class PEBinaryFile extends PlatformObject implements IBinaryFile,
IBinaryObject, IBinaryExecutable, IBinaryShared { IBinaryObject, IBinaryExecutable, IBinaryShared {
IFile file; IPath path;
long timestamp; long timestamp;
PE.Attribute attribute; PE.Attribute attribute;
String objectName; String objectName;
ArrayList symbols; ArrayList symbols;
public PEBinaryFile(IFile file) throws IOException { public PEBinaryFile(IPath p) throws IOException {
this(file, null); this(p, null);
} }
public PEBinaryFile(IFile file, String o) throws IOException { public PEBinaryFile(IPath p, String o) throws IOException {
this.file = file; path = p;
objectName = o; objectName = o;
loadInformation(); loadInformation();
hasChanged(); hasChanged();
@ -51,30 +50,28 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
*/ */
public InputStream getContents() { public InputStream getContents() {
InputStream stream = null; InputStream stream = null;
if (file != null && objectName != null) { if (path != null && objectName != null) {
IPath location = file.getLocation(); PEArchive ar = null;
if (location != null) { try {
PEArchive ar = null; ar = new PEArchive(path.toOSString());
try { PEArchive.ARHeader[] headers = ar.getHeaders();
ar = new PEArchive(file.getLocation().toOSString()); for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader[] headers = ar.getHeaders(); PEArchive.ARHeader hdr = headers[i];
for (int i = 0; i < headers.length; i++) { if (objectName.equals(hdr.getObjectName())) {
PEArchive.ARHeader hdr = headers[i]; stream = new ByteArrayInputStream(hdr.getObjectData());
if (objectName.equals(hdr.getObjectName())) { break;
stream = new ByteArrayInputStream(hdr.getObjectData());
break;
}
} }
} catch (IOException e) {
} }
} catch (IOException e) {
} finally {
if (ar != null) { if (ar != null) {
ar.dispose(); ar.dispose();
} }
} }
} else if (file != null && file.exists()) { } else if (path != null) {
try { try {
stream = file.getContents(); stream = new FileInputStream (path.toFile());
} catch (CoreException e) { } catch (IOException e) {
} }
} }
if (stream == null) { if (stream == null) {
@ -86,8 +83,8 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile() * @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/ */
public IFile getFile() { public IPath getPath() {
return file; return path;
} }
/** /**
@ -149,8 +146,8 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
public String getName() { public String getName() {
if (objectName != null) { if (objectName != null) {
return objectName; return objectName;
} else if (file != null) { } else if (path != null) {
return file.getName(); return path.lastSegment().toString();
} }
return ""; return "";
} }
@ -215,35 +212,28 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
} }
protected PE getPE() throws IOException { protected PE getPE() throws IOException {
if (file != null && objectName != null) { if (path != null && objectName != null) {
IPath location = file.getLocation(); PE pe = null;
if (location != null) { PEArchive ar = null;
PE pe = null; try {
PEArchive ar = null; ar = new PEArchive(path.toOSString());
try { PEArchive.ARHeader[] headers = ar.getHeaders();
ar = new PEArchive(file.getLocation().toOSString()); for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader[] headers = ar.getHeaders(); PEArchive.ARHeader hdr = headers[i];
for (int i = 0; i < headers.length; i++) { if (objectName.equals(hdr.getObjectName())) {
PEArchive.ARHeader hdr = headers[i]; pe = hdr.getPE();
if (objectName.equals(hdr.getObjectName())) { break;
pe = hdr.getPE();
break;
}
}
} finally {
if (ar != null) {
ar.dispose();
} }
} }
if (pe != null) { } finally {
return pe; if (ar != null) {
ar.dispose();
} }
} }
} else if (file != null && file.exists()) { if (pe != null) {
IPath path = file.getLocation(); return pe;
if (path == null) {
path = new Path("");
} }
} else if (path != null) {
return new PE(path.toOSString()); return new PE(path.toOSString());
} }
throw new IOException("No file assiocated with Binary"); throw new IOException("No file assiocated with Binary");
@ -299,10 +289,14 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
} }
boolean hasChanged() { boolean hasChanged() {
long modification = file.getModificationStamp(); File file = path.toFile();
boolean changed = modification != timestamp; if (file != null && file.exists()) {
timestamp = modification; long modification = file.lastModified();
return changed; boolean changed = modification != timestamp;
timestamp = modification;
return changed;
}
return false;
} }
} }

View file

@ -10,7 +10,7 @@ import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.coff.PE; import org.eclipse.cdt.utils.coff.PE;
import org.eclipse.cdt.utils.coff.PEArchive; import org.eclipse.cdt.utils.coff.PEArchive;
import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath;
/** /**
*/ */
@ -19,17 +19,17 @@ public class PEParser implements IBinaryParser {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IFile) * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IFile)
*/ */
public IBinaryFile getBinary(IFile file) throws IOException { public IBinaryFile getBinary(IPath path) throws IOException {
try { try {
PE pe = new PE(file.getLocation().toOSString()); PE pe = new PE(path.toOSString());
pe.dispose(); pe.dispose();
return new PEBinaryFile(file); return new PEBinaryFile(path);
} catch (IOException e) { } catch (IOException e) {
} }
// Is it an Archive. // Is it an Archive.
PEArchive ar = new PEArchive(file.getLocation().toOSString()); PEArchive ar = new PEArchive(path.toOSString());
ar.dispose(); ar.dispose();
return new PEBinaryArchive(file); return new PEBinaryArchive(path);
} }
/** /**

View file

@ -8,8 +8,8 @@ package org.eclipse.cdt.core;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
/** /**
*/ */
@ -25,7 +25,7 @@ public interface IBinaryParser {
public int ARCHIVE = 0x08; public int ARCHIVE = 0x08;
public int CORE = 0x10; public int CORE = 0x10;
public IFile getFile(); public IPath getPath();
public int getType(); public int getType();
public InputStream getContents(); public InputStream getContents();
} }
@ -84,7 +84,7 @@ public interface IBinaryParser {
public int getType(); public int getType();
} }
public IBinaryFile getBinary(IFile file) throws IOException; public IBinaryFile getBinary(IPath path) throws IOException;
public String getFormat(); public String getFormat();
} }