]> source.dussan.org Git - aspectj.git/commitdiff
fixing Bug 31724
authorjhugunin <jhugunin>
Tue, 11 Mar 2003 23:46:51 +0000 (23:46 +0000)
committerjhugunin <jhugunin>
Tue, 11 Mar 2003 23:46:51 +0000 (23:46 +0000)
   declare warning/error emitted without context
and generally providing better error context information

15 files changed:
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseShadow.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java
tests/ajcTests.xml
tests/ajcTestsFailing.xml
tests/jimTests.xml
tests/new/declare/DeclareWarningEmpty.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/ISourceContext.java
weaver/src/org/aspectj/weaver/Position.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/ResolvedTypeX.java
weaver/src/org/aspectj/weaver/Shadow.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/testsrc/org/aspectj/weaver/TestShadow.java

index 01ed6dcc2a9cfcd27e09157a2749c16a465f8067..2e0630f6c554d2f256f70e4cddb0720864b9f560 100644 (file)
@@ -18,6 +18,7 @@ import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
+import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
 import org.aspectj.weaver.Member;
 import org.aspectj.weaver.Shadow;
@@ -65,7 +66,7 @@ public class EclipseShadow extends Shadow {
                return world.fromBinding(enclosingMethod.binding.declaringClass);
        }
        
-       public SourceLocation getSourceLocation() {
+       public ISourceLocation getSourceLocation() {
                //XXX need to fill this in ASAP
                return null;
        }
index dbb985ab00da8a9767b9a0df6369d877a56241a8..abee60abfdd94189690a4f720de86a28b2846d1b 100644 (file)
@@ -16,6 +16,7 @@ package org.aspectj.ajdt.internal.compiler.lookup;
 import java.util.*;
 
 import org.aspectj.ajdt.internal.compiler.ast.*;
+import org.aspectj.ajdt.internal.core.builder.EclipseSourceContext;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.weaver.*;
@@ -54,6 +55,10 @@ public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
                this.factory = factory;
                this.binding = binding;
                this.declaration = declaration;
+               
+               resolvedTypeX.setSourceContext(new EclipseSourceContext(declaration.compilationResult));
+               resolvedTypeX.setStartPos(declaration.sourceStart);
+               resolvedTypeX.setEndPos(declaration.sourceEnd);
        }
 
 
@@ -195,10 +200,10 @@ public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
 //             return crosscuttingMembers;
 //     }
 
-       public ISourceLocation getSourceLocation() {
-               TypeDeclaration dec = binding.scope.referenceContext;
-               return new EclipseSourceLocation(dec.compilationResult, dec.sourceStart, dec.sourceEnd);
-       }
+//     public ISourceLocation getSourceLocation() {
+//             TypeDeclaration dec = binding.scope.referenceContext;
+//             return new EclipseSourceLocation(dec.compilationResult, dec.sourceStart, dec.sourceEnd);
+//     }
 
        public boolean isInterface() {
                return binding.isInterface();
index f54ebc1a1955a2fd2d34c0af15fe389e7ff2f7c4..fd107e77a64e3157aaf7b22f536684896afbf6af 100644 (file)
 
 package org.aspectj.ajdt.internal.core.builder;
 
+import java.io.File;
+
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.SourceLocation;
 import org.aspectj.weaver.IHasPosition;
 import org.aspectj.weaver.ISourceContext;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
@@ -29,9 +32,16 @@ public class EclipseSourceContext implements ISourceContext {
                this.result = result;
        }
        
+       private File getSourceFile() {
+               return new File(new String(result.fileName));
+       }
 
        public ISourceLocation makeSourceLocation(IHasPosition position) {
                return new EclipseSourceLocation(result, position.getStart(), position.getEnd());
        }
 
+       public ISourceLocation makeSourceLocation(int line) {
+               return new SourceLocation(getSourceFile(), line);
+       }
+
 }
index 321afe3d936e231f3e2c51ef2f28270443fd2e4c..a2e0b3c6ef57ef933fa9ee521429226aca4acf7f 100644 (file)
                <message kind="error" line="25"/>
         </compile>
     </ajc-test>
+    
+    <ajc-test dir="new/declare" pr="31724"
+            title="omnibus declare warning context with no initializer/constructor">
+        <compile files="DeclareWarningEmpty.java">
+            <message kind="warning" line="3"/>
+        </compile>
+    </ajc-test>
+    
+
+    <ajc-test dir="new/declare" pr="31724"
+            title="omnibus declare warning context">
+        <compile files="DeclareWarning.java">
+            <message kind="warning" line="5"/>
+            <message kind="warning" line="12"/>
+            <message kind="warning" line="13"/>
+            <message kind="warning" line="14"/>
+            <message kind="warning" line="15"/>
+            <message kind="warning" line="16"/>
+            <message kind="warning" line="17"/>
+            <message kind="warning" line="18"/>
+            <message kind="warning" line="21"/>
+            <message kind="warning" line="22"/>
+            <message kind="warning" line="23"/>
+            <message kind="warning" line="33"/>
+            <message kind="warning" line="36"/>
+            <message kind="warning" line="39"/>
+            <message kind="warning" line="74"/>
+        </compile>
+    </ajc-test>
 </suite>
index 051196a60faf58493fbd16efa09a7b5faa4a4c78..b7fadc1465b4171cb8bae7d815cb7a0979c77122 100644 (file)
         </compile>
     </ajc-test>
 
-    <ajc-test dir="new/declare" pr="31724"
-            title="omnibus declare warning context"
-          comment="XXX untested: no source context shown">
-        <compile files="DeclareWarning.java">
-            <message kind="warning" line="5"/>
-            <message kind="warning" line="12"/>
-            <message kind="warning" line="13"/>
-            <message kind="warning" line="14"/>
-            <message kind="warning" line="15"/>
-            <message kind="warning" line="16"/>
-            <message kind="warning" line="17"/>
-            <message kind="warning" line="18"/>
-            <message kind="warning" line="21"/>
-            <message kind="warning" line="22"/>
-            <message kind="warning" line="23"/>
-            <message kind="warning" line="33"/>
-            <message kind="warning" line="36"/>
-            <message kind="warning" line="39"/>
-            <message kind="warning" line="74"/>
-        </compile>
-    </ajc-test>
-
     <ajc-test dir="errors"  keywords="error"
                title="class extending abstract aspect">
         <compile files="ClassExtendingAbstractAspectCE.java">
index 17db88e593c9e8d2eeeba06bc81424c1054faa1c..53a3a9ef1d2f5f755cba2b8e2999ace5228bec53 100644 (file)
@@ -1,26 +1,6 @@
 <!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
 <suite>
-    <ajc-test dir="new/declare" pr="31724"
-            title="omnibus declare warning context"
-          comment="XXX untested: no source context shown">
-        <compile files="DeclareWarning.java">
-            <message kind="warning" line="5"/>
-            <message kind="warning" line="12"/>
-            <message kind="warning" line="13"/>
-            <message kind="warning" line="14"/>
-            <message kind="warning" line="15"/>
-            <message kind="warning" line="16"/>
-            <message kind="warning" line="17"/>
-            <message kind="warning" line="18"/>
-            <message kind="warning" line="21"/>
-            <message kind="warning" line="22"/>
-            <message kind="warning" line="23"/>
-            <message kind="warning" line="33"/>
-            <message kind="warning" line="36"/>
-            <message kind="warning" line="39"/>
-            <message kind="warning" line="74"/>
-        </compile>
-    </ajc-test>
+
 
     <!--
     
diff --git a/tests/new/declare/DeclareWarningEmpty.java b/tests/new/declare/DeclareWarningEmpty.java
new file mode 100644 (file)
index 0000000..b310022
--- /dev/null
@@ -0,0 +1,16 @@
+
+/** @testcase PR#31724 omnibus declare-warning test using default initializers/constructors*/
+public class DeclareWarningEmpty {  // CE 3        
+
+
+
+
+
+}
+
+aspect A {
+    declare warning: staticinitialization(DeclareWarningEmpty)   
+        : "staticinitialization(DeclareWarningEmpty)";
+    declare warning: initialization(DeclareWarningEmpty.new(..))   
+        : "initialization(DeclareWarningEmpty)";
+}
index 8b591a47975a8849bccb54ebd0b7fc60141a8a34..16cb3c8bcb7db34f05e80214a50253822188bbf9 100644 (file)
@@ -17,4 +17,5 @@ import org.aspectj.bridge.ISourceLocation;
 
 public interface ISourceContext {
        public ISourceLocation makeSourceLocation(IHasPosition position);
+       public ISourceLocation makeSourceLocation(int line);
 }
diff --git a/weaver/src/org/aspectj/weaver/Position.java b/weaver/src/org/aspectj/weaver/Position.java
new file mode 100644 (file)
index 0000000..5e5c5c5
--- /dev/null
@@ -0,0 +1,32 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     PARC     initial implementation 
+ * ******************************************************************/
+
+
+package org.aspectj.weaver;
+
+public class Position implements IHasPosition {
+       private int start, end;
+       
+       public Position(int start, int end) {
+               this.start = start;
+               this.end = end;
+       }
+
+       public int getEnd() {
+               return end;
+       }
+
+       public int getStart() {
+               return start;
+       }
+
+}
index 6249a9b213492d153e1a1ed11e74a17d4042200f..9de2348ea7669d9b7552c6b038f9134e9dffa400 100644 (file)
@@ -499,6 +499,9 @@ public abstract class ResolvedTypeX extends TypeX {
     
     public static class Name extends ResolvedTypeX {
        private ConcreteName delegate = null;
+       private ISourceContext sourceContext = null;
+       private int startPos = 0;
+       private int endPos = 0;
 
                //??? should set delegate before any use
         public Name(String signature, World world) {
@@ -556,10 +559,13 @@ public abstract class ResolvedTypeX extends TypeX {
         }
 
                public ISourceContext getSourceContext() {
-                       return delegate.getSourceContext();
+                       return sourceContext;
                }
                
-               public ISourceLocation getSourceLocation() { return delegate.getSourceLocation(); }
+               public ISourceLocation getSourceLocation() {
+                       if (sourceContext == null) return null;
+                       return sourceContext.makeSourceLocation(new Position(startPos, endPos));
+               }
 
                public boolean isExposedToWeaver() {
                        return delegate.isExposedToWeaver();  //??? where does this belong
@@ -608,10 +614,30 @@ public abstract class ResolvedTypeX extends TypeX {
                public void setDelegate(ConcreteName delegate) {
                        this.delegate = delegate;
                }
+               public int getEndPos() {
+                       return endPos;
+               }
+
+               public int getStartPos() {
+                       return startPos;
+               }
+
+               public void setEndPos(int endPos) {
+                       this.endPos = endPos;
+               }
+
+               public void setSourceContext(ISourceContext sourceContext) {
+                       this.sourceContext = sourceContext;
+               }
+
+               public void setStartPos(int startPos) {
+                       this.startPos = startPos;
+               }
+
     }
     
     public static abstract class ConcreteName {
-       protected ISourceContext sourceContext;
+       //protected ISourceContext sourceContext;
        protected boolean exposedToWeaver;
        ResolvedTypeX.Name resolvedTypeX;
        
@@ -648,13 +674,13 @@ public abstract class ResolvedTypeX extends TypeX {
 
                public abstract ResolvedTypeX getSuperclass();
 
-               public abstract ISourceLocation getSourceLocation();
+//             public abstract ISourceLocation getSourceLocation();
 
                public abstract boolean isWovenBy(ResolvedTypeX aspectType);
 
-               public ISourceContext getSourceContext() {
-                       return sourceContext;
-               }
+//             public ISourceContext getSourceContext() {
+//                     return sourceContext;
+//             }
 
                public boolean isExposedToWeaver() {
                        return exposedToWeaver;
index dd36e0edaafbbdc98415ba29e47fe43cfcef2aca..9a3f7908205498736a9c192581ecd019400cfe6a 100644 (file)
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.aspectj.bridge.*;
 import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.SourceLocation;
 import org.aspectj.lang.JoinPoint;
@@ -315,7 +316,7 @@ public abstract class Shadow {
                return null; //XXX
        }
        
-       public abstract SourceLocation getSourceLocation();
+       public abstract ISourceLocation getSourceLocation();
 
        // ---- utility
     
index 05d7248b160b8fe558a680e28a38eda5b5a70c21..5cd46b71d40a0170ebcc889b790de6e0322cc2ee 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.bcel.classfile.Field;
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.classfile.Method;
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.weaver.*;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ResolvedMember;
@@ -76,7 +77,9 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
         super(resolvedTypeX, exposedToWeaver);
         this.javaClass = javaClass;
         
-        sourceContext = new BcelSourceContext(this);
+        if (resolvedTypeX.getSourceContext() == null) {
+               resolvedTypeX.setSourceContext(new BcelSourceContext(this));
+        }
         
         // this should only ever be java.lang.Object which is 
         // the only class in Java-1.4 with no superclasses
@@ -155,7 +158,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
                List pointcuts = new ArrayList();
                typeMungers = new ArrayList();
                declares = new ArrayList();
-               List l = BcelAttributes.readAjAttributes(javaClass.getAttributes(), getSourceContext());
+               List l = BcelAttributes.readAjAttributes(javaClass.getAttributes(), getResolvedTypeX().getSourceContext());
                for (Iterator iter = l.iterator(); iter.hasNext();) {
                        AjAttribute a = (AjAttribute) iter.next();
                        //System.err.println("unpacking: " + this + " and " + a);
@@ -172,7 +175,9 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
                        } else if (a instanceof AjAttribute.PrivilegedAttribute) {
                                privilegedAccess = ((AjAttribute.PrivilegedAttribute)a).getAccessedMembers();
                        } else if (a instanceof AjAttribute.SourceContextAttribute) {
-                               ((BcelSourceContext)sourceContext).addAttributeInfo((AjAttribute.SourceContextAttribute)a);
+                               if (getResolvedTypeX().getSourceContext() instanceof BcelSourceContext) {
+                                       ((BcelSourceContext)getResolvedTypeX().getSourceContext()).addAttributeInfo((AjAttribute.SourceContextAttribute)a);
+                               }
                        } else {
                                throw new BCException("bad attribute " + a);
                        }
@@ -257,7 +262,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName {
        }
 
        public ISourceLocation getSourceLocation() {
-               return null; //FIXME, we can do much better than this
+               return getResolvedTypeX().getSourceContext().makeSourceLocation(0); //FIXME, we can do better than this
        }
 } 
     
index 9a9efd7986d50252f64ca092d0312aa9f5dca6d0..f0b0742d8f52065b25462230b8ac22c90bd4faaf 100644 (file)
@@ -42,6 +42,7 @@ import org.apache.bcel.generic.ReturnInstruction;
 import org.apache.bcel.generic.SWAP;
 import org.apache.bcel.generic.TargetLostException;
 import org.apache.bcel.generic.Type;
+import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
 import org.aspectj.weaver.AdviceKind;
 import org.aspectj.weaver.AjcMemberMaker;
@@ -294,7 +295,13 @@ public class BcelShadow extends Shadow {
        }
        
     public int getSourceLine() {
-       if (range == null) return 0;
+       if (range == null) {
+               if (getEnclosingMethod().hasBody()) {
+                       return Utility.getSourceLine(getEnclosingMethod().getBody().getStart());
+               } else {
+                       return 0;
+               }
+       }
        int ret = Utility.getSourceLine(range.getStart());
        if (ret < 0) return 0;
        return ret;
@@ -1867,24 +1874,15 @@ public class BcelShadow extends Shadow {
         return getEnclosingClass().getFactory();
     }
     
-       public SourceLocation getSourceLocation() {
-               // AMC - a temporary "fudge" to give as much information as possible about the identity of the
-               // source file this source location points to.
-               String internalClassName = getEnclosingClass().getInternalClassName();
-               String fileName = getEnclosingClass().getFileName();
-               String extension = fileName.substring( fileName.lastIndexOf("."), fileName.length());
-               String filePrefix = fileName.substring( 0, fileName.lastIndexOf("."));
-               // internal class name is e.g. figures/Point, we don't know whether the file was
-               // .aj or .java so we put it together with the file extension of the enclosing class
-               // BUT... sometimes internalClassName is a different class (an aspect), so we only use it if it 
-               // matches the file name.
-               String mostAccurateFileNameGuess;
-               if ( internalClassName.endsWith(filePrefix)) {
-                       mostAccurateFileNameGuess = internalClassName + extension;
+       public ISourceLocation getSourceLocation() {
+               int sourceLine = getSourceLine();
+               if (sourceLine == 0) {
+//                     Thread.currentThread().dumpStack();
+//                     System.err.println(this + ": " + range);
+                       return getEnclosingClass().getType().getSourceLocation();
                } else {
-                       mostAccurateFileNameGuess = fileName;
+                       return getEnclosingClass().getType().getSourceContext().makeSourceLocation(sourceLine);
                }
-               return new SourceLocation(new File(mostAccurateFileNameGuess), getSourceLine());
        }
 
        public Shadow getEnclosingShadow() {
index 157a207406e60a77f77f5f7997cc2e3fa324c12b..72a7939e14d305b69c33d95f77e720639c81164c 100644 (file)
@@ -31,22 +31,52 @@ public class BcelSourceContext implements ISourceContext {
                this.inObject = inObject;
        }
        
-
-       public ISourceLocation makeSourceLocation(IHasPosition position) {
+       private File getSourceFile() {
+               //XXX make this work better borrowing code from below
                String fileName = sourceFileName;
                if (fileName == null) inObject.getJavaClass().getFileName();
                if (fileName == null) fileName = inObject.getResolvedTypeX().getName() + ".class";
                
+               return new File(fileName);
+       }
+               
+               /*
+               // AMC - a temporary "fudge" to give as much information as possible about the identity of the
+               // source file this source location points to.
+               String internalClassName = getEnclosingClass().getInternalClassName();
+               String fileName = getEnclosingClass().getFileName();
+               String extension = fileName.substring( fileName.lastIndexOf("."), fileName.length());
+               String filePrefix = fileName.substring( 0, fileName.lastIndexOf("."));
+               // internal class name is e.g. figures/Point, we don't know whether the file was
+               // .aj or .java so we put it together with the file extension of the enclosing class
+               // BUT... sometimes internalClassName is a different class (an aspect), so we only use it if it 
+               // matches the file name.
+               String mostAccurateFileNameGuess;
+               if ( internalClassName.endsWith(filePrefix)) {
+                       mostAccurateFileNameGuess = internalClassName + extension;
+               } else {
+                       mostAccurateFileNameGuess = fileName;
+               }
+               return new SourceLocation(new File(mostAccurateFileNameGuess), getSourceLine());
+               */
+
+
+
+       public ISourceLocation makeSourceLocation(IHasPosition position) {
+               
+               
                if (lineBreaks != null) {
                        int line = Arrays.binarySearch(lineBreaks, position.getStart());
                        if (line < 0) line = -line;
-                       return new SourceLocation(new File(fileName), line); //??? have more info
+                       return new SourceLocation(getSourceFile(), line); //??? have more info
                } else {
-                       return new SourceLocation(new File(fileName), 0);
+                       return new SourceLocation(getSourceFile(), 0);
                }
        }
        
-       
+       public ISourceLocation makeSourceLocation(int line) {
+               return new SourceLocation(getSourceFile(), line);
+       }
 
        public void addAttributeInfo(SourceContextAttribute sourceContextAttribute) {
                this.sourceFileName = sourceContextAttribute.getSourceFileName();
index 0a91cf1e38241ac689936f8a09222753ffcbaa98..534eca0a51451ecce422aecae9d2540c5f79fc61 100644 (file)
@@ -14,6 +14,7 @@
 package org.aspectj.weaver;
 
 import org.aspectj.weaver.ast.Var;
+import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
 
 public class TestShadow extends Shadow {
@@ -62,7 +63,7 @@ public class TestShadow extends Shadow {
                throw new RuntimeException("unimplemented");
        }
 
-       public SourceLocation getSourceLocation() {
+       public ISourceLocation getSourceLocation() {
                throw new RuntimeException("unimplemented");
        }