]> source.dussan.org Git - aspectj.git/commitdiff
propogating information needed for decent Xlint warnings when privileged
authorjhugunin <jhugunin>
Wed, 8 Jan 2003 02:16:12 +0000 (02:16 +0000)
committerjhugunin <jhugunin>
Wed, 8 Jan 2003 02:16:12 +0000 (02:16 +0000)
access is made to a type not exposed to the weaver

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java
org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/IPrivilegedHandler.java
org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
weaver/src/org/aspectj/weaver/Lint.java

index 411ae4df5dc7ff2594b157afc8d6210306d01594..473e247c22c59e9d432d78e0acc8e145254c881e 100644 (file)
@@ -41,7 +41,7 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter {
                        FieldBinding fieldBinding = (FieldBinding)ref.binding;
                        makePublic(fieldBinding.declaringClass);
                        if (isPublic(fieldBinding)) return;
-                       ref.binding = handler.getPrivilegedAccessField(fieldBinding);
+                       ref.binding = handler.getPrivilegedAccessField(fieldBinding, ref);
                }
        }
 
@@ -50,7 +50,7 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter {
                        FieldBinding fieldBinding = (FieldBinding)ref.binding;
                        makePublic(fieldBinding.declaringClass);
                        if (isPublic(fieldBinding)) return;
-                       ref.binding = handler.getPrivilegedAccessField(fieldBinding);
+                       ref.binding = handler.getPrivilegedAccessField(fieldBinding, ref);
                }
        }
 
@@ -59,7 +59,7 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter {
                        FieldBinding fieldBinding = (FieldBinding)ref.binding;
                        makePublic(fieldBinding.declaringClass);
                        if (isPublic(fieldBinding)) return;
-                       ref.binding = handler.getPrivilegedAccessField(fieldBinding);
+                       ref.binding = handler.getPrivilegedAccessField(fieldBinding, ref);
                }
        }
        public void endVisit(MessageSend send, BlockScope scope) {
@@ -67,13 +67,13 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter {
                if (send.binding == null) return;
                if (isPublic(send.binding)) return;
                makePublic(send.binding.declaringClass);
-               send.binding = send.codegenBinding = handler.getPrivilegedAccessMethod(send.binding);
+               send.binding = send.codegenBinding = handler.getPrivilegedAccessMethod(send.binding, send);
        }
        public void endVisit(AllocationExpression send, BlockScope scope) {
                if (send.binding == null) return;
                if (isPublic(send.binding)) return;
                makePublic(send.binding.declaringClass);
-               send.binding = handler.getPrivilegedAccessMethod(send.binding);
+               send.binding = handler.getPrivilegedAccessMethod(send.binding, send);
        }       
        public void endVisit(
                QualifiedTypeReference ref,
@@ -104,7 +104,7 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter {
        private void makePublic(TypeBinding binding) {
                if (binding instanceof ReferenceBinding) {
                        ReferenceBinding rb = (ReferenceBinding)binding;
-                       if (!rb.isPublic()) handler.notePrivilegedTypeAccess(rb);
+                       if (!rb.isPublic()) handler.notePrivilegedTypeAccess(rb, null); //???
                } else if (binding instanceof ArrayBinding) {
                        makePublic( ((ArrayBinding)binding).leafComponentType );
                } else {
index ecf773c76cacd169a4587aec030c4aa9ca2ca2d3..d2c02fd0217106020398c571dbd2267690a5f1d7 100644 (file)
@@ -16,7 +16,9 @@ package org.aspectj.ajdt.internal.compiler.lookup;
 import java.util.*;
 
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
+import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.weaver.*;
+import org.eclipse.jdt.internal.compiler.ast.AstNode;
 import org.eclipse.jdt.internal.compiler.lookup.*;
 
 
@@ -29,15 +31,16 @@ public class PrivilegedHandler implements IPrivilegedHandler {
                this.inAspect = inAspect;
        }
 
-       public FieldBinding getPrivilegedAccessField(FieldBinding baseField) {
+       public FieldBinding getPrivilegedAccessField(FieldBinding baseField, AstNode location) {
                ResolvedMember key = inAspect.world.makeResolvedMember(baseField);
                if (accessors.containsKey(key)) return (FieldBinding)accessors.get(key);
                FieldBinding ret = new PrivilegedFieldBinding(inAspect, baseField);
+               checkWeaveAccess(key.getDeclaringType(), location);
                accessors.put(key, ret);
                return ret;
        }
 
-       public MethodBinding getPrivilegedAccessMethod(MethodBinding baseMethod) {
+       public MethodBinding getPrivilegedAccessMethod(MethodBinding baseMethod, AstNode location) {
                ResolvedMember key = inAspect.world.makeResolvedMember(baseMethod);
                if (accessors.containsKey(key)) return (MethodBinding)accessors.get(key);
                
@@ -49,18 +52,37 @@ public class PrivilegedHandler implements IPrivilegedHandler {
                        AjcMemberMaker.privilegedAccessMethodForMethod(inAspect.typeX, key)
                        );
                }
-               
+               checkWeaveAccess(key.getDeclaringType(), location);
                //new PrivilegedMethodBinding(inAspect, baseMethod);
                accessors.put(key, ret);
                return ret;
        }
        
-       public void notePrivilegedTypeAccess(ReferenceBinding type) {
+       public void notePrivilegedTypeAccess(ReferenceBinding type, AstNode location) {
                ResolvedMember key =
                        new ResolvedMember(Member.STATIC_INITIALIZATION,
                                inAspect.world.fromEclipse(type), 0, ResolvedTypeX.VOID, "", TypeX.NONE);
+               
+               checkWeaveAccess(key.getDeclaringType(), location);
                accessors.put(key, key);
        }
+
+       private void checkWeaveAccess(TypeX typeX, AstNode location) {
+               World world = inAspect.world;
+               Lint.Kind check = world.getLint().typeNotExposedToWeaver;
+               if (check.isEnabled()) {
+                       if (!world.resolve(typeX).isExposedToWeaver()) {
+                               ISourceLocation loc = null;
+                               if (location != null) {
+                                       loc = new EclipseSourceLocation(inAspect.compilationResult, 
+                                                       location.sourceStart, location.sourceEnd);
+                               }
+                               check.signal(typeX.getName() + " (needed for privileged access)",
+                                                       loc);
+                       }
+               }
+       }
+
        
        public ResolvedMember[] getMembers() {
                Collection m = accessors.keySet();
index c32fa6cce8128df3045dca4a9ccc6eb7b02d3945..6be97d13886aa3e87f68c58e56e4bdc202c599bc 100644 (file)
@@ -932,7 +932,7 @@ public class BlockScope extends Scope {
                        if (methodBinding.canBeSeenBy(invocationSite, this)) {
                                return methodBinding;
                        } else if (handler != null) {
-                               return handler.getPrivilegedAccessMethod(methodBinding);
+                               return handler.getPrivilegedAccessMethod(methodBinding, (AstNode)invocationSite);
                        }
                }
 
index 05488ee2dae658c65b768c4bffdbe21d6254315e..b2921080a49680d5768d2c6817e47ec516b671f7 100644 (file)
@@ -11,6 +11,8 @@
 
 package org.eclipse.jdt.internal.compiler.lookup;
 
+import org.eclipse.jdt.internal.compiler.ast.AstNode;
+
 
 /**
  * This interface is used by SourceTypeBinding to provide a delegated lookup
@@ -20,8 +22,8 @@ package org.eclipse.jdt.internal.compiler.lookup;
  */
 public interface IPrivilegedHandler {
        
-       FieldBinding getPrivilegedAccessField(FieldBinding baseField);
+       FieldBinding getPrivilegedAccessField(FieldBinding baseField, AstNode location);
        
-       MethodBinding getPrivilegedAccessMethod(MethodBinding baseMethod);
-       void notePrivilegedTypeAccess(ReferenceBinding type);
+       MethodBinding getPrivilegedAccessMethod(MethodBinding baseMethod, AstNode location);
+       void notePrivilegedTypeAccess(ReferenceBinding type, AstNode location);
 }
index 75a7662ae1d2acaf0b24717edf98bf92bc22df82..cc0ca8531c0b15332119ff802fdc932826cfdc4a 100644 (file)
@@ -70,7 +70,7 @@ public final boolean canBeSeenBy(ReferenceBinding receiverType, SourceTypeBindin
        //System.err.println("trying to see: " + new String(sourceName));
 
        if (Scope.findPrivilegedHandler(invocationType) != null) {
-               Scope.findPrivilegedHandler(invocationType).notePrivilegedTypeAccess(this);
+               Scope.findPrivilegedHandler(invocationType).notePrivilegedTypeAccess(this, null);
                return true;
        }
        return false;
@@ -155,7 +155,7 @@ public final boolean canBeSeenBy(Scope scope) {
 
        if (Scope.findPrivilegedHandler(invocationType) != null) {
                //System.err.println("    is privileged!");
-               Scope.findPrivilegedHandler(invocationType).notePrivilegedTypeAccess(this);
+               Scope.findPrivilegedHandler(invocationType).notePrivilegedTypeAccess(this, null);
                return true;
        }
        return false;
index a277b224007521b90bcdad48c972aa5b81a450e2..da9ff51ce145715e91c4c47ea66ecf781d1711ca 100644 (file)
@@ -11,6 +11,7 @@
  ******************************************************************************/
 package org.eclipse.jdt.internal.compiler.lookup;
 
+import org.eclipse.jdt.internal.compiler.ast.AstNode;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
@@ -184,7 +185,7 @@ public abstract class Scope
                                IPrivilegedHandler handler = findPrivilegedHandler(invocationType());
                                if (handler != null) {
                                        //???System.err.println("privileged access: ");
-                                       return invocationType().privilegedHandler.getPrivilegedAccessMethod(exactMethod);
+                                       return invocationType().privilegedHandler.getPrivilegedAccessMethod(exactMethod, (AstNode)invocationSite);
                                }
                        }
                }
index bfac0b42856af37584f1119faf59b8807e4c9511..a4106b4781008b572e9a01d20d2d8e40dedc7676 100644 (file)
@@ -16,6 +16,7 @@ import java.util.*;
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Argument;
 import org.eclipse.jdt.internal.compiler.ast.AssertStatement;
+import org.eclipse.jdt.internal.compiler.ast.AstNode;
 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
@@ -512,7 +513,7 @@ public FieldBinding getField(char[] fieldName, InvocationSite site, Scope scope)
                        !ret.canBeSeenBy(this, site, scope))
                {
                        //System.err.println("privileged access: " + new String(fieldName));
-                       return handler.getPrivilegedAccessField(ret);
+                       return handler.getPrivilegedAccessField(ret, (AstNode)site);
                }
        }
        return ret;
index ce8850754d0eaba40c6a1d7b487ded8eeee1498b..527dfa0feea5e817e57649d53fa33b2b40213481 100644 (file)
@@ -36,8 +36,7 @@ public class Lint {
        
        public final Kind typeNotExposedToWeaver = 
                new Kind("typeNotExposedToWeaver", "this affected type is not exposed to the weaver: {0}");
-       
-       
+               
        public Lint(World world) {
                this.world = world;
        }