@@ -447,13 +447,15 @@ public class ProgramElement implements IProgramElement { | |||
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(); | |||
} | |||
@@ -475,6 +477,8 @@ public class ProgramElement implements IProgramElement { | |||
sb.append(sourceLocation.getLine()); | |||
sb.append(ID_DELIM); | |||
sb.append(sourceLocation.getColumn()); | |||
sb.append(ID_DELIM); | |||
sb.append(sourceLocation.getOffset()); | |||
return sb.toString(); | |||
} | |||
@@ -53,6 +53,11 @@ public interface ISourceLocation { | |||
*/ | |||
int getColumn(); | |||
/** | |||
* @return offset into file | |||
*/ | |||
int getOffset(); | |||
/** @return getLine()..MAX_LINE */ | |||
int getEndLine(); | |||
@@ -55,6 +55,7 @@ public class SourceLocation implements ISourceLocation, java.io.Serializable { | |||
private final int startLine; | |||
private final int column; | |||
private final int endLine; | |||
private int offset; | |||
private final String context; | |||
private boolean noColumn; | |||
@@ -141,8 +142,17 @@ public class SourceLocation implements ISourceLocation, java.io.Serializable { | |||
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;} | |||
} |
@@ -50,12 +50,14 @@ public class AsmInterTypeRelationshipProvider { | |||
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) { |
@@ -44,6 +44,10 @@ public class EclipseSourceLocation implements ISourceLocation { | |||
return result; | |||
} | |||
public int getOffset() { | |||
return startPos; | |||
} | |||
public int getStartPos() { | |||
return startPos; | |||
} | |||
@@ -123,6 +127,7 @@ public class EclipseSourceLocation implements ISourceLocation { | |||
if (getColumn() != 0) { | |||
sb.append(":" + getColumn()); | |||
} | |||
if (getOffset()>=0) { sb.append("::").append(getOffset()); } | |||
return sb.toString(); | |||
} | |||
} |
@@ -106,8 +106,9 @@ public class AsmHierarchyBuilder extends ASTVisitor { | |||
// 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, | |||
@@ -716,12 +717,14 @@ public class AsmHierarchyBuilder extends ASTVisitor { | |||
// 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; | |||
} |
@@ -115,6 +115,10 @@ public class SoftSourceLocation implements ISourceLocation { | |||
public String getLocationContext() { | |||
return null; | |||
} | |||
public int getOffset() { | |||
return -1; | |||
} | |||
/** @return String : {context\n}file:line:column */ | |||
public String toString() { |
@@ -333,6 +333,7 @@ public class AjcSpecTest extends TestCase { | |||
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 | |||
} |
@@ -46,12 +46,14 @@ public class AsmRelationshipProvider { | |||
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) { | |||
@@ -78,19 +80,22 @@ public class AsmRelationshipProvider { | |||
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) { | |||
@@ -107,7 +112,7 @@ public class AsmRelationshipProvider { | |||
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); | |||
@@ -115,7 +120,8 @@ public class AsmRelationshipProvider { | |||
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) { | |||
@@ -212,11 +218,13 @@ public class AsmRelationshipProvider { | |||
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()); |
@@ -145,7 +145,7 @@ public abstract class ResolvedTypeMunger { | |||
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 | |||
@@ -155,7 +155,9 @@ public abstract class ResolvedTypeMunger { | |||
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 | |||
@@ -180,6 +182,7 @@ public abstract class ResolvedTypeMunger { | |||
if (location !=null) { | |||
oos.writeObject(location.getSourceFile()); | |||
oos.writeObject(new Integer(location.getLine())); | |||
oos.writeObject(new Integer(location.getOffset())); | |||
} | |||
oos.flush(); | |||
oos.close(); |
@@ -90,7 +90,8 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH | |||
handle = ProgramElement.createHandleIdentifier( | |||
sl.getSourceFile(), | |||
sl.getLine(), | |||
sl.getColumn()); | |||
sl.getColumn(), | |||
sl.getOffset()); | |||
} | |||
} | |||
return handle; |