]> source.dussan.org Git - aspectj.git/commitdiff
add offset in MethodDeclarationAttribute for @AJ in AJDT
authoravasseur <avasseur>
Tue, 5 Jul 2005 11:46:21 +0000 (11:46 +0000)
committeravasseur <avasseur>
Tue, 5 Jul 2005 11:46:21 +0000 (11:46 +0000)
13 files changed:
bridge/src/org/aspectj/bridge/SourceLocation.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjConstructorDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjMethodDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java
tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java
weaver/src/org/aspectj/weaver/AjAttribute.java
weaver/src/org/aspectj/weaver/ISourceContext.java
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/BcelSourceContext.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java

index fecf9041a4a2992ece27672ee0ec6c24770383d7..73b63f940c994e5411da62d36bb207e0ad6b65f0 100644 (file)
@@ -155,4 +155,5 @@ public class SourceLocation implements ISourceLocation, java.io.Serializable {
     public void setOffset(int i) { offset=i;}
 
 
+
 }
index 504631c9c6a9ef8d9a04e149249e48849221f925..13212dfdd01750ab0b9e2c3a60819d11b8d9b2a6 100644 (file)
@@ -53,6 +53,6 @@ public class AjConstructorDeclaration extends ConstructorDeclaration {
                }
                
                extraAttributeList.add(
-                               new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine)));
+                               new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
        }
 }
index ae91da8949de37f1f71fbb971acae54894d8a793..21e009f67fab8f150534d0b20f2e698a47325d16 100644 (file)
@@ -69,6 +69,6 @@ public class AjMethodDeclaration extends MethodDeclaration {
                }
                
                extraAttributeList.add(
-                               new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine)));
+                               new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
        }
 }
index b3fc473b4a837879842bb885a67543ce17c7f827..8cdaa333bc39acc3dbed6edb4331e714291795ae 100644 (file)
@@ -50,18 +50,22 @@ public class EclipseSourceContext implements ISourceContext {
                return new EclipseSourceLocation(result, position.getStart(), position.getEnd());
        }
 
-    public ISourceLocation makeSourceLocation(int line) {
+    public ISourceLocation makeSourceLocation(int line, int offset) {
                SourceLocation sl = new SourceLocation(getSourceFile(), line);
 
-        // compute the offset
-        //TODO AV - should we do it lazily?
-        int[] offsets = result.lineSeparatorPositions;
-        int likelyOffset = 0;
-        if (line > 0 && line < offsets.length) {
-            //1st char of given line is next char after previous end of line
-            likelyOffset = offsets[line-1];
+        if (offset > 0) {
+            sl.setOffset(offset);
+        } else {
+            // compute the offset
+            //TODO AV - should we do it lazily?
+            int[] offsets = result.lineSeparatorPositions;
+            int likelyOffset = 0;
+            if (line > 0 && line < offsets.length) {
+                //1st char of given line is next char after previous end of line
+                likelyOffset = offsets[line-1];//FIXME may be need -2
+            }
+            sl.setOffset(likelyOffset);
         }
-        sl.setOffset(likelyOffset);
         return sl;
        }
 
index eda07cb53819b70618ad665b35146229b21a14dc..7cec3892b59a748ccdfbdbe79a2214b1a4ad4f3d 100644 (file)
@@ -41,11 +41,11 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase {
 
     public void testSingletonAspectBindings() {
         //Note AV: uncomment setReporting to get it in modules/tests folder
-        //org.aspectj.asm.AsmManager.setReporting("debug.txt",true,true,true,true);
+        org.aspectj.asm.AsmManager.setReporting("debug.txt",true,true,true,true);
         runTest("singletonAspectBindings");
         // same stuff with AJ
         //org.aspectj.asm.AsmManager.setReporting("debug-aj.txt",true,true,true,true);
-        runTest("singletonAspectBindings2");
+        //runTest("singletonAspectBindings2");
 
     }
 
index 8bb1f6a9c623c8f9e5fc97c2d51789c509aa3629..bc0628a3e81b2475c89d5a775bbefbcc31f44a0b 100644 (file)
@@ -314,23 +314,35 @@ public abstract class AjAttribute {
                }
                
                private int lineNumber;
-               
-               public MethodDeclarationLineNumberAttribute(int line) {
+
+        // AV: added in 1.5 M3 thus handling cases where we don't have that information
+        private int offset;
+
+               public MethodDeclarationLineNumberAttribute(int line, int offset) {
                        this.lineNumber = line;
+            this.offset = offset;
                }
                
                public int getLineNumber() { return lineNumber; }
-               
+
+        public int getOffset() { return offset; }
+
                public void write(DataOutputStream s) throws IOException {
                        s.writeInt(lineNumber);
+            s.writeInt(offset);
                }
                
                public static MethodDeclarationLineNumberAttribute read(VersionedDataInputStream s) throws IOException {
-                       return new MethodDeclarationLineNumberAttribute(s.readInt());
+            int line = s.readInt();
+            int offset = 0;
+            if (s.available()>0) {
+                offset = s.readInt();
+            }
+                       return new MethodDeclarationLineNumberAttribute(line, offset);
                }
 
                public String toString() {
-                       return AttributeName + ": " + lineNumber;
+                       return AttributeName + ": " + lineNumber + ":" + offset;
                }
        }
        
index d0c91a27b0f113362086e20a0f67b25ca47c86ea..70c7031d83bf77f54a9ad5864c1fa5b117bc7afe 100644 (file)
@@ -17,6 +17,6 @@ import org.aspectj.bridge.ISourceLocation;
 
 public interface ISourceContext {
        public ISourceLocation makeSourceLocation(IHasPosition position);
-       public ISourceLocation makeSourceLocation(int line);
+       public ISourceLocation makeSourceLocation(int line, int offset);
        public int getOffset();
 }
index e45259a38edae80c9e0a4bd68126ab6002cb25b0..499bc04b692b31d451840689938bef34fb5ae1ba 100644 (file)
@@ -552,7 +552,7 @@ public class AtAjAttributes {
                 }
                 setIgnoreUnboundBindingNames(pc, bindings);
 
-                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber());
+                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber(), struct.bMethod.getDeclarationOffset());
                 struct.ajAttributes.add(
                         new AjAttribute.AdviceAttribute(
                                 AdviceKind.Before,
@@ -607,7 +607,7 @@ public class AtAjAttributes {
                 }
                 setIgnoreUnboundBindingNames(pc, bindings);
 
-                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber());
+                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber(), struct.bMethod.getDeclarationOffset());
                 struct.ajAttributes.add(
                         new AjAttribute.AdviceAttribute(
                                 AdviceKind.After,
@@ -692,7 +692,7 @@ public class AtAjAttributes {
             }
             setIgnoreUnboundBindingNames(pc, bindings);
 
-            ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber());
+            ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber(), struct.bMethod.getDeclarationOffset());
             struct.ajAttributes.add(
                     new AjAttribute.AdviceAttribute(
                             AdviceKind.AfterReturning,
@@ -776,7 +776,7 @@ public class AtAjAttributes {
             }
             setIgnoreUnboundBindingNames(pc, bindings);
 
-            ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber());
+            ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber(), struct.bMethod.getDeclarationOffset());
             struct.ajAttributes.add(
                     new AjAttribute.AdviceAttribute(
                             AdviceKind.AfterThrowing,
@@ -830,7 +830,7 @@ public class AtAjAttributes {
                 }
                 setIgnoreUnboundBindingNames(pc, bindings);
 
-                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber());
+                ISourceLocation sl = struct.context.makeSourceLocation(struct.bMethod.getDeclarationLineNumber(), struct.bMethod.getDeclarationOffset());
                 struct.ajAttributes.add(
                         new AjAttribute.AdviceAttribute(
                                 AdviceKind.Around,
index e4dff0586118fe2129a098f67b43eae941b04f3b..376ee1e145162b22ab1535796b1c5e17a4887720 100644 (file)
@@ -151,13 +151,21 @@ final class BcelMethod extends ResolvedMember {
                        return -1;
                }
        }
-    
+
+    public int getDeclarationOffset() {
+        if (declarationLineNumber != null) {
+            return declarationLineNumber.getOffset();
+        } else {
+            return -1;
+        }
+    }
+
     public ISourceLocation getSourceLocation() {
       ISourceLocation ret = super.getSourceLocation(); 
       if ((ret == null || ret.getLine()==0) && hasDeclarationLineNumberInfo()) {
         // lets see if we can do better
         ISourceContext isc = getSourceContext();
-        if (isc !=null) ret = isc.makeSourceLocation(getDeclarationLineNumber());
+        if (isc !=null) ret = isc.makeSourceLocation(getDeclarationLineNumber(), getDeclarationOffset());
         else            ret = new SourceLocation(null,getDeclarationLineNumber());
       }
       return ret;
index 3a3cdc2f06709b86fec0f4ced4310c182fd34fea..21f3d766a940527151c1de83959d4084751a2016 100644 (file)
@@ -394,7 +394,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        }
 
        public ISourceLocation getSourceLocation() {
-               return getResolvedTypeX().getSourceContext().makeSourceLocation(0); //FIXME ??? we can do better than this
+               return getResolvedTypeX().getSourceContext().makeSourceLocation(0, 0); //FIXME ??? we can do better than this
        }
        
        public AjAttribute.WeaverVersionInfo getWeaverVersionAttribute() {
index 16fa420a252b1d60db1f2189d771f889473c4611..e0db5e9cda9c9e062f36df2142bb3ec9048b59e1 100644 (file)
@@ -3020,7 +3020,7 @@ public class BcelShadow extends Shadow {
                        if (getKind()==Shadow.StaticInitialization && getEnclosingClass().getType().getSourceLocation().getOffset()!=0)
                                return getEnclosingClass().getType().getSourceLocation();
                        else 
-                           return getEnclosingClass().getType().getSourceContext().makeSourceLocation(sourceLine);
+                           return getEnclosingClass().getType().getSourceContext().makeSourceLocation(sourceLine, 0);
                }
        }
 
index 2bd26e0668a1bc5e643e38dbe69ba8851a0a9876..d4a47c80bd0615b1bde2c51341e35949d4eacec9 100644 (file)
@@ -86,16 +86,20 @@ public class BcelSourceContext implements ISourceContext {
                }
        }
        
-       public ISourceLocation makeSourceLocation(int line) {
+       public ISourceLocation makeSourceLocation(int line, int offset) {
         if (line < 0) line = 0;
                SourceLocation sl = new SourceLocation(getSourceFile(), line);
-        if (lineBreaks != null) {
-            int likelyOffset = 0;
-            if (line > 0 && line < lineBreaks.length) {
-                //1st char of given line is next char after previous end of line
-                likelyOffset = lineBreaks[line-1] + 1;
+        if (offset > 0) {
+            sl.setOffset(offset);
+        } else {
+            if (lineBreaks != null) {
+                int likelyOffset = 0;
+                if (line > 0 && line < lineBreaks.length) {
+                    //1st char of given line is next char after previous end of line
+                    likelyOffset = lineBreaks[line-1] + 1;
+                }
+                sl.setOffset(likelyOffset);
             }
-            sl.setOffset(likelyOffset);
         }
         return sl;
        }
index bebc5aa84c8a4ae1b7803ff2f134c6431a59ae12..f914b74acbbc7e7454f77f22e9528bbb69c21fbd 100644 (file)
@@ -120,12 +120,12 @@ public class IfPointcut extends Pointcut {
        
        public void write(DataOutputStream s) throws IOException {
                s.writeByte(Pointcut.IF);
-               testMethod.write(s);//TODO Adrian, do something if this one happens to be null for @style if() from JDT stuff
+               testMethod.write(s);//FIXME Adrian, do something if this one happens to be null for @style if() from JDT stuff
                s.writeByte(extraParameterFlags);
                writeLocation(s);
        }
        public static Pointcut read(VersionedDataInputStream s, ISourceContext context) throws IOException {
-        //TODO Adrian, read may failt if testMethod happens to be null for @style if() from JDT stuff
+        //FIXME Adrian, read may failt if testMethod happens to be null for @style if() from JDT stuff
                IfPointcut ret = new IfPointcut(ResolvedMember.readResolvedMember(s, context), s.readByte());
                ret.readLocation(context, s);
                return ret;