return label;
}
- public static String createHandleIdentifier(File sourceFile, int line,int column) {
+ public static String createHandleIdentifier(File sourceFile, int line,int column,int offset) {
StringBuffer sb = new StringBuffer();
sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile));
sb.append(ID_DELIM);
sb.append(line);
sb.append(ID_DELIM);
sb.append(column);
+ sb.append(ID_DELIM);
+ sb.append(offset);
return sb.toString();
}
sb.append(sourceLocation.getLine());
sb.append(ID_DELIM);
sb.append(sourceLocation.getColumn());
+ sb.append(ID_DELIM);
+ sb.append(sourceLocation.getOffset());
return sb.toString();
}
*/
int getColumn();
+ /**
+ * @return offset into file
+ */
+ int getOffset();
+
/** @return getLine()..MAX_LINE */
int getEndLine();
private final int startLine;
private final int column;
private final int endLine;
+ private int offset;
private final String context;
private boolean noColumn;
if (!noColumn) {
sb.append(":" + column);
}
+ if (offset>=0) {
+ sb.append("::"+offset);
+ }
return sb.toString();
}
+
+ // XXX Ctors for this type should know about an offset, rather than
+ // it being set through these methods - but there are just too many
+ // ctors at the moment! It needs sorting out.
+ public int getOffset() { return offset;}
+ public void setOffset(int i) { offset=i;}
}
String sourceHandle = ProgramElement.createHandleIdentifier(
munger.getSourceLocation().getSourceFile(),
munger.getSourceLocation().getLine(),
- munger.getSourceLocation().getColumn());
+ munger.getSourceLocation().getColumn(),
+ munger.getSourceLocation().getOffset());
String targetHandle = ProgramElement.createHandleIdentifier(
onType.getSourceLocation().getSourceFile(),
onType.getSourceLocation().getLine(),
- onType.getSourceLocation().getColumn());
+ onType.getSourceLocation().getColumn(),
+ onType.getSourceLocation().getOffset());
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
return result;
}
+ public int getOffset() {
+ return startPos;
+ }
+
public int getStartPos() {
return startPos;
}
if (getColumn() != 0) {
sb.append(":" + getColumn());
}
+ if (getOffset()>=0) { sb.append("::").append(getOffset()); }
return sb.toString();
}
}
// AMC - use the source start and end from the compilation unit decl
int startLine = getStartLine(unit);
int endLine = getEndLine(unit);
- ISourceLocation sourceLocation
+ SourceLocation sourceLocation
= new SourceLocation(file, startLine, endLine);
+ sourceLocation.setOffset(unit.sourceStart);
cuNode = new ProgramElement(
new String(file.getName()),
IProgramElement.Kind.FILE_JAVA,
// AMC - different strategies based on node kind
int startLine = getStartLine(node);
int endLine = getEndLine(node);
- ISourceLocation loc = null;
+ SourceLocation loc = null;
if ( startLine <= endLine ) {
// found a valid end line for this node...
- loc = new SourceLocation(new File(fileName), startLine, endLine);
+ loc = new SourceLocation(new File(fileName), startLine, endLine);
+ loc.setOffset(node.sourceStart);
} else {
loc = new SourceLocation(new File(fileName), startLine);
+ loc.setOffset(node.sourceStart);
}
return loc;
}
public String getLocationContext() {
return null;
}
+
+ public int getOffset() {
+ return -1;
+ }
/** @return String : {context\n}file:line:column */
public String toString() {
assertTrue(rhs != null);
assertTrue(lhs.getLine() == rhs.getLine());
assertTrue(lhs.getColumn() == rhs.getColumn());
+ assertTrue(lhs.getOffset() == rhs.getOffset());
assertTrue(lhs.getEndLine() == rhs.getEndLine());
// XXX need to compare files, permitting null == NONE
}
String sourceHandle = ProgramElement.createHandleIdentifier(
checker.getSourceLocation().getSourceFile(),
checker.getSourceLocation().getLine(),
- checker.getSourceLocation().getColumn());
+ checker.getSourceLocation().getColumn(),
+ checker.getSourceLocation().getOffset());
String targetHandle = ProgramElement.createHandleIdentifier(
shadow.getSourceLocation().getSourceFile(),
shadow.getSourceLocation().getLine(),
- shadow.getSourceLocation().getColumn());
+ shadow.getSourceLocation().getColumn(),
+ shadow.getSourceLocation().getOffset());
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
sourceHandle = ProgramElement.createHandleIdentifier(
munger.getSourceLocation().getSourceFile(),
munger.getSourceLocation().getLine(),
- munger.getSourceLocation().getColumn());
+ munger.getSourceLocation().getColumn(),
+ munger.getSourceLocation().getOffset());
} else {
sourceHandle = ProgramElement.createHandleIdentifier(
originatingAspect.getSourceLocation().getSourceFile(),
originatingAspect.getSourceLocation().getLine(),
- originatingAspect.getSourceLocation().getColumn());
+ originatingAspect.getSourceLocation().getColumn(),
+ originatingAspect.getSourceLocation().getOffset());
}
if (originatingAspect.getSourceLocation() != null) {
String targetHandle = ProgramElement.createHandleIdentifier(
onType.getSourceLocation().getSourceFile(),
onType.getSourceLocation().getLine(),
- onType.getSourceLocation().getColumn());
+ onType.getSourceLocation().getColumn(),
+ onType.getSourceLocation().getOffset());
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
public void addDeclareParentsRelationship(ISourceLocation decp,ResolvedTypeX targetType, List newParents) {
- String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn());
+ String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset());
IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
String targetHandle = ProgramElement.createHandleIdentifier(
targetType.getSourceLocation().getSourceFile(),
targetType.getSourceLocation().getLine(),
- targetType.getSourceLocation().getColumn());
+ targetType.getSourceLocation().getColumn(),
+ targetType.getSourceLocation().getOffset());
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
ISourceLocation sl = shadow.getSourceLocation();
+// XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
+ SourceLocation peLoc = new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(),sl.getLine());
+ peLoc.setOffset(sl.getOffset());
IProgramElement peNode = new ProgramElement(
shadow.toString(),
IProgramElement.Kind.CODE,
- //XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
- new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()),
+ peLoc,
0,
"",
new ArrayList());
protected static ISourceLocation readSourceLocation(DataInputStream s) throws IOException {
if (!persistSourceLocation) return null;
- ISourceLocation ret = null;
+ SourceLocation ret = null;
ObjectInputStream ois = null;
try {
// This logic copes with the location missing from the attribute - an EOFException will
if (validLocation.booleanValue()) {
File f = (File) ois.readObject();
Integer ii = (Integer)ois.readObject();
+ Integer offset = (Integer)ois.readObject();
ret = new SourceLocation(f,ii.intValue());
+ ret.setOffset(offset.intValue());
}
} catch (EOFException eof) {
return null; // This exception occurs if processing an 'old style' file where the
if (location !=null) {
oos.writeObject(location.getSourceFile());
oos.writeObject(new Integer(location.getLine()));
+ oos.writeObject(new Integer(location.getOffset()));
}
oos.flush();
oos.close();
handle = ProgramElement.createHandleIdentifier(
sl.getSourceFile(),
sl.getLine(),
- sl.getColumn());
+ sl.getColumn(),
+ sl.getOffset());
}
}
return handle;