diff options
author | jhugunin <jhugunin> | 2003-01-08 02:16:12 +0000 |
---|---|---|
committer | jhugunin <jhugunin> | 2003-01-08 02:16:12 +0000 |
commit | 8995a3a369a70a5d6122faee1f1783777c83b2ac (patch) | |
tree | 8affef726ed2cbf962186be42eaecbf292a9b538 /org.aspectj.ajdt.core | |
parent | 91d9045736aa5705ad0289c0209474bac205aab7 (diff) | |
download | aspectj-8995a3a369a70a5d6122faee1f1783777c83b2ac.tar.gz aspectj-8995a3a369a70a5d6122faee1f1783777c83b2ac.zip |
propogating information needed for decent Xlint warnings when privileged
access is made to a type not exposed to the weaver
Diffstat (limited to 'org.aspectj.ajdt.core')
2 files changed, 32 insertions, 10 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java index 411ae4df5..473e247c2 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java @@ -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 { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java index ecf773c76..d2c02fd02 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java @@ -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(); |