1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56: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.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
/**
* Info for ICProject.
@ -73,8 +73,8 @@ class ArchiveInfo extends CFileInfo {
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
if (parser != null) {
try {
IFile file = (IFile) getElement().getUnderlyingResource();
IBinaryFile bfile = parser.getBinary(file);
IPath path = getElement().getUnderlyingResource().getLocation();
IBinaryFile bfile = parser.getBinary(path);
if (bfile instanceof IBinaryArchive) {
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.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -167,8 +166,8 @@ class BinaryInfo extends CFileInfo {
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
if (parser != null) {
try {
IFile file = (IFile) getElement().getUnderlyingResource();
IBinaryFile bfile = parser.getBinary(file);
IPath path = getElement().getUnderlyingResource().getLocation();
IBinaryFile bfile = parser.getBinary(path);
if (bfile instanceof IBinaryObject) {
binary = (IBinaryObject) bfile;
}

View file

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

View file

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

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model.parser;
*/
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
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.Elf.Attribute;
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.Path;
import org.eclipse.core.runtime.PlatformObject;
/**
*/
public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinaryObject, IBinaryExecutable, IBinaryShared {
IFile file;
IPath path;
AR.ARHeader header;
long timestamp;
String soname;
@ -38,13 +36,13 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
Attribute attribute;
ArrayList symbols;
public ElfBinaryFile(IFile f) throws IOException {
this(f, null);
public ElfBinaryFile(IPath p) throws IOException {
this(p, null);
}
public ElfBinaryFile(IFile f, AR.ARHeader h) throws IOException {
public ElfBinaryFile(IPath p, AR.ARHeader h) throws IOException {
header = h;
file = f;
path = p;
loadInformation();
hasChanged();
}
@ -52,8 +50,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/
public IFile getFile() {
return file;
public IPath getPath() {
return path;
}
/**
@ -204,15 +202,15 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
public InputStream getContents() {
InputStream stream = null;
// Archive ?
if (file != null && header != null) {
if (path != null && header != null) {
try {
stream = new ByteArrayInputStream(header.getObjectData());
} catch (IOException e) {
}
} else if (file != null && file.exists()) {
} else if (path != null) {
try {
stream = file.getContents();
} catch (CoreException e) {
stream = new FileInputStream(path.toFile());
} catch (IOException e) {
}
}
if (stream == null) {
@ -228,8 +226,8 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
if (header != null) {
return header.getObjectName();
}
if (file != null) {
return file.getName();
if (path != null) {
return path.lastSegment().toString();
}
return "";
}
@ -259,7 +257,7 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
}
boolean hasChanged() {
long modification = file.getModificationStamp();
long modification = path.toFile().lastModified();
boolean changed = modification != timestamp;
timestamp = modification;
return changed;
@ -269,11 +267,7 @@ public class ElfBinaryFile extends PlatformObject implements IBinaryFile, IBinar
// Archive ?
if (header != null) {
return new ElfHelper(header.getElf());
} else if (file != null && file.exists()) {
IPath path = file.getLocation();
if (path == null) {
path = new Path("");
}
} else if (path != null) {
return new ElfHelper(path.toOSString());
}
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.utils.elf.AR;
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)
*/
public IBinaryFile getBinary(IFile file) throws IOException {
public IBinaryFile getBinary(IPath path) throws IOException {
try {
Elf e = new Elf(file.getLocation().toOSString());
Elf e = new Elf(path.toOSString());
e.dispose();
return new ElfBinaryFile(file);
return new ElfBinaryFile(path);
} catch (IOException e) {
}
// Is it an Archive.
AR ar = new AR(file.getLocation().toOSString());
AR ar = new AR(path.toOSString());
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.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
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.IBinaryObject;
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.PlatformObject;
@ -23,12 +23,12 @@ import org.eclipse.core.runtime.PlatformObject;
*/
public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
IFile file;
IPath path;
ArrayList children;
long timestamp;
public PEBinaryArchive(IFile f) {
file = f;
public PEBinaryArchive(IPath p) {
path = p;
children = new ArrayList(5);
}
@ -38,14 +38,13 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
public IBinaryObject[] getObjects() {
if (hasChanged()) {
children.clear();
IPath location = file.getLocation();
if (location != null) {
if (path != null) {
PEArchive ar = null;
try {
ar = new PEArchive(location.toOSString());
ar = new PEArchive(path.toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
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);
}
} catch (IOException e) {
@ -63,8 +62,8 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/
public IFile getFile() {
return file;
public IPath getPath() {
return path;
}
/**
@ -79,17 +78,21 @@ public class PEBinaryArchive extends PlatformObject implements IBinaryArchive {
*/
public InputStream getContents() {
try {
return file.getContents();
} catch (CoreException e) {
return new FileInputStream(path.toFile());
} catch (IOException e) {
}
return new ByteArrayInputStream(new byte[0]);
}
boolean hasChanged() {
long modif = file.getModificationStamp();
boolean changed = modif != timestamp;
timestamp = modif;
return changed;
File file = path.toFile();
if (file != null && file.exists()) {
long modification = file.lastModified();
boolean changed = modification != timestamp;
timestamp = modification;
return changed;
}
return false;
}
/**
* @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.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
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.PEArchive;
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.Path;
import org.eclipse.core.runtime.PlatformObject;
/**
@ -29,18 +28,18 @@ import org.eclipse.core.runtime.PlatformObject;
public class PEBinaryFile extends PlatformObject implements IBinaryFile,
IBinaryObject, IBinaryExecutable, IBinaryShared {
IFile file;
IPath path;
long timestamp;
PE.Attribute attribute;
String objectName;
ArrayList symbols;
public PEBinaryFile(IFile file) throws IOException {
this(file, null);
public PEBinaryFile(IPath p) throws IOException {
this(p, null);
}
public PEBinaryFile(IFile file, String o) throws IOException {
this.file = file;
public PEBinaryFile(IPath p, String o) throws IOException {
path = p;
objectName = o;
loadInformation();
hasChanged();
@ -51,30 +50,28 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
*/
public InputStream getContents() {
InputStream stream = null;
if (file != null && objectName != null) {
IPath location = file.getLocation();
if (location != null) {
PEArchive ar = null;
try {
ar = new PEArchive(file.getLocation().toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader hdr = headers[i];
if (objectName.equals(hdr.getObjectName())) {
stream = new ByteArrayInputStream(hdr.getObjectData());
break;
}
if (path != null && objectName != null) {
PEArchive ar = null;
try {
ar = new PEArchive(path.toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader hdr = headers[i];
if (objectName.equals(hdr.getObjectName())) {
stream = new ByteArrayInputStream(hdr.getObjectData());
break;
}
} catch (IOException e) {
}
} catch (IOException e) {
} finally {
if (ar != null) {
ar.dispose();
}
}
} else if (file != null && file.exists()) {
} else if (path != null) {
try {
stream = file.getContents();
} catch (CoreException e) {
stream = new FileInputStream (path.toFile());
} catch (IOException e) {
}
}
if (stream == null) {
@ -86,8 +83,8 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
/**
* @see org.eclipse.cdt.core.model.IBinaryParser.IBinaryFile#getFile()
*/
public IFile getFile() {
return file;
public IPath getPath() {
return path;
}
/**
@ -149,8 +146,8 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
public String getName() {
if (objectName != null) {
return objectName;
} else if (file != null) {
return file.getName();
} else if (path != null) {
return path.lastSegment().toString();
}
return "";
}
@ -215,35 +212,28 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
}
protected PE getPE() throws IOException {
if (file != null && objectName != null) {
IPath location = file.getLocation();
if (location != null) {
PE pe = null;
PEArchive ar = null;
try {
ar = new PEArchive(file.getLocation().toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader hdr = headers[i];
if (objectName.equals(hdr.getObjectName())) {
pe = hdr.getPE();
break;
}
}
} finally {
if (ar != null) {
ar.dispose();
if (path != null && objectName != null) {
PE pe = null;
PEArchive ar = null;
try {
ar = new PEArchive(path.toOSString());
PEArchive.ARHeader[] headers = ar.getHeaders();
for (int i = 0; i < headers.length; i++) {
PEArchive.ARHeader hdr = headers[i];
if (objectName.equals(hdr.getObjectName())) {
pe = hdr.getPE();
break;
}
}
if (pe != null) {
return pe;
} finally {
if (ar != null) {
ar.dispose();
}
}
} else if (file != null && file.exists()) {
IPath path = file.getLocation();
if (path == null) {
path = new Path("");
if (pe != null) {
return pe;
}
} else if (path != null) {
return new PE(path.toOSString());
}
throw new IOException("No file assiocated with Binary");
@ -299,10 +289,14 @@ public class PEBinaryFile extends PlatformObject implements IBinaryFile,
}
boolean hasChanged() {
long modification = file.getModificationStamp();
boolean changed = modification != timestamp;
timestamp = modification;
return changed;
File file = path.toFile();
if (file != null && file.exists()) {
long modification = file.lastModified();
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.utils.coff.PE;
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)
*/
public IBinaryFile getBinary(IFile file) throws IOException {
public IBinaryFile getBinary(IPath path) throws IOException {
try {
PE pe = new PE(file.getLocation().toOSString());
PE pe = new PE(path.toOSString());
pe.dispose();
return new PEBinaryFile(file);
return new PEBinaryFile(path);
} catch (IOException e) {
}
// Is it an Archive.
PEArchive ar = new PEArchive(file.getLocation().toOSString());
PEArchive ar = new PEArchive(path.toOSString());
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.InputStream;
import org.eclipse.core.resources.IFile;
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 CORE = 0x10;
public IFile getFile();
public IPath getPath();
public int getType();
public InputStream getContents();
}
@ -84,7 +84,7 @@ public interface IBinaryParser {
public int getType();
}
public IBinaryFile getBinary(IFile file) throws IOException;
public IBinaryFile getBinary(IPath path) throws IOException;
public String getFormat();
}