From 1575a175b511eadbae03fc760b0cd20edde6ae4e Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 10 Dec 2004 15:40:59 +0000 Subject: [PATCH] Support for 'offset' in source locations - enabling AJDT improvements. Not perfect - really the whole ISourceLocation thing needs sorting out ... --- .../aspectj/asm/internal/ProgramElement.java | 6 ++++- .../org/aspectj/bridge/ISourceLocation.java | 5 ++++ .../org/aspectj/bridge/SourceLocation.java | 10 +++++++ .../AsmInterTypeRelationshipProvider.java | 6 +++-- .../lookup/EclipseSourceLocation.java | 5 ++++ .../core/builder/AsmHierarchyBuilder.java | 9 ++++--- .../testing/xml/SoftSourceLocation.java | 4 +++ .../testing/harness/bridge/AjcSpecTest.java | 1 + .../weaver/AsmRelationshipProvider.java | 26 ++++++++++++------- .../aspectj/weaver/ResolvedTypeMunger.java | 5 +++- .../src/org/aspectj/weaver/ShadowMunger.java | 3 ++- 11 files changed, 63 insertions(+), 17 deletions(-) diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 3965c21d0..6bfe85115 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -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(); } diff --git a/bridge/src/org/aspectj/bridge/ISourceLocation.java b/bridge/src/org/aspectj/bridge/ISourceLocation.java index f43a2f54c..ba6d61ee3 100644 --- a/bridge/src/org/aspectj/bridge/ISourceLocation.java +++ b/bridge/src/org/aspectj/bridge/ISourceLocation.java @@ -53,6 +53,11 @@ public interface ISourceLocation { */ int getColumn(); + /** + * @return offset into file + */ + int getOffset(); + /** @return getLine()..MAX_LINE */ int getEndLine(); diff --git a/bridge/src/org/aspectj/bridge/SourceLocation.java b/bridge/src/org/aspectj/bridge/SourceLocation.java index 259fc2067..fecf9041a 100644 --- a/bridge/src/org/aspectj/bridge/SourceLocation.java +++ b/bridge/src/org/aspectj/bridge/SourceLocation.java @@ -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;} } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java index ad43d9ee9..523fea5a6 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java @@ -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) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java index 65df2f306..6b395c6e0 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java @@ -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(); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java index 8687cf957..04a44d059 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java @@ -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; } diff --git a/testing/src/org/aspectj/testing/xml/SoftSourceLocation.java b/testing/src/org/aspectj/testing/xml/SoftSourceLocation.java index 022342aa2..0d5f36744 100644 --- a/testing/src/org/aspectj/testing/xml/SoftSourceLocation.java +++ b/testing/src/org/aspectj/testing/xml/SoftSourceLocation.java @@ -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() { diff --git a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java index f48000d18..6ac4b039c 100644 --- a/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java +++ b/testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java @@ -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 } diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java index d851d59ec..efa3482f9 100644 --- a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java +++ b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java @@ -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()); diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java index dedd32ef7..f28e87535 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java @@ -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(); diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java index 57c629ff2..36218cdb2 100644 --- a/weaver/src/org/aspectj/weaver/ShadowMunger.java +++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java @@ -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; -- 2.39.5