]> source.dussan.org Git - aspectj.git/commitdiff
Support for 'offset' in source locations - enabling AJDT improvements. Not perfect...
authoraclement <aclement>
Fri, 10 Dec 2004 15:40:59 +0000 (15:40 +0000)
committeraclement <aclement>
Fri, 10 Dec 2004 15:40:59 +0000 (15:40 +0000)
asm/src/org/aspectj/asm/internal/ProgramElement.java
bridge/src/org/aspectj/bridge/ISourceLocation.java
bridge/src/org/aspectj/bridge/SourceLocation.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceLocation.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
testing/src/org/aspectj/testing/xml/SoftSourceLocation.java
testing/testsrc/org/aspectj/testing/harness/bridge/AjcSpecTest.java
weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java
weaver/src/org/aspectj/weaver/ShadowMunger.java

index 3965c21d0d44481fb34e5647de36ec907e440de8..6bfe851151276c3cf353caeb879e163ac649fff9 100644 (file)
@@ -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();
        }
        
index f43a2f54c900c0b92fcce6b37c21c69db2543a60..ba6d61ee35b2dc3f3b8bb4241dbdc687d321da06 100644 (file)
@@ -53,6 +53,11 @@ public interface ISourceLocation  {
      */
     int getColumn();    
     
+    /**
+     * @return offset into file
+     */
+    int getOffset();
+    
     /** @return getLine()..MAX_LINE */
     int getEndLine();
     
index 259fc2067bd9a77dc7939a0432158bec032fde36..fecf9041a4a2992ece27672ee0ec6c24770383d7 100644 (file)
@@ -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;}
 
 
 }
index ad43d9ee9691c8ffb4d1b6c854743185c427f7b3..523fea5a6e095f990efeded4343ff443aca27e45 100644 (file)
@@ -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) {
index 65df2f306dbc90b875a541852f7e843206db8bec..6b395c6e0299d7f2f38bf175d212820fe0380e21 100644 (file)
@@ -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();
     }
 }
index 8687cf957cd24184c6147a2f887387b1647bd772..04a44d059424ca602aa9f1df385b343ea2a41e28 100644 (file)
@@ -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;
        }
index 022342aa2c35a89cb06c6bf59149e18846d96c47..0d5f367441151f6f73a89c0d4a89a19d59c2e7d3 100644 (file)
@@ -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() {
index f48000d18241d65421687fa665294765653f7787..6ac4b039c2dc0a73f0d1061bd3441b35835a309b 100644 (file)
@@ -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        
        }
index d851d59ec60df46648406c71b0ee1d7a9fe23e23..efa3482f99008ac666907df87f3135687736e3c3 100644 (file)
@@ -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());
index dedd32ef7301f78c6c4d5054b3b8f84eb8cdc137..f28e8753534df0c47aa08d5bb3e3bf3fbf09f653 100644 (file)
@@ -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();
index 57c629ff2e295386dc168dce4d9514b823004e02..36218cdb21fd9586f4c2da82d7ceb14fe15128ab 100644 (file)
@@ -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;