]> source.dussan.org Git - aspectj.git/commitdiff
266420: rogue unused private warning
authoraclement <aclement>
Fri, 27 Feb 2009 19:59:36 +0000 (19:59 +0000)
committeraclement <aclement>
Fri, 27 Feb 2009 19:59:36 +0000 (19:59 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/PrivilegedHandler.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java

index 84f7d37b053181a06b06d7ccf0c6150a0e966698..1e4e3c355e6077eb7a2643aaf34dd0b22595d9fd 100644 (file)
@@ -10,7 +10,6 @@
  *     PARC     initial implementation 
  * ******************************************************************/
 
-
 package org.aspectj.ajdt.internal.compiler.lookup;
 
 import java.util.Collection;
@@ -37,8 +36,6 @@ import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 
-
-
 public class PrivilegedHandler implements IPrivilegedHandler {
        private AspectDeclaration inAspect;
        private Map accessors = new HashMap();
@@ -47,52 +44,61 @@ public class PrivilegedHandler implements IPrivilegedHandler {
                this.inAspect = inAspect;
        }
 
-       public FieldBinding getPrivilegedAccessField(FieldBinding baseField, ASTNode location) {        
-               if (baseField instanceof ParameterizedFieldBinding) { 
-                       baseField = ((ParameterizedFieldBinding)baseField).originalField;
+       public boolean definesPrivilegedAccessToField(FieldBinding field) {
+               if (field instanceof ParameterizedFieldBinding) {
+                       field = ((ParameterizedFieldBinding) field).originalField;
+               }
+               ResolvedMember key = inAspect.factory.makeResolvedMember(field);
+               return (accessors.containsKey(key));
+       }
+
+       public FieldBinding getPrivilegedAccessField(FieldBinding baseField, ASTNode location) {
+               if (baseField instanceof ParameterizedFieldBinding) {
+                       baseField = ((ParameterizedFieldBinding) baseField).originalField;
                }
                ResolvedMember key = inAspect.factory.makeResolvedMember(baseField);
-               if (accessors.containsKey(key)) return (FieldBinding)accessors.get(key);
+               if (accessors.containsKey(key))
+                       return (FieldBinding) accessors.get(key);
                FieldBinding ret = new PrivilegedFieldBinding(inAspect, baseField);
                checkWeaveAccess(key.getDeclaringType(), location);
-               if (!baseField.alwaysNeedsAccessMethod(true)) accessors.put(key, ret);
+               if (!baseField.alwaysNeedsAccessMethod(true))
+                       accessors.put(key, ret);
                return ret;
        }
 
        public MethodBinding getPrivilegedAccessMethod(MethodBinding baseMethod, ASTNode location) {
-               if (baseMethod.alwaysNeedsAccessMethod()) return baseMethod;
-               
+               if (baseMethod.alwaysNeedsAccessMethod())
+                       return baseMethod;
+
                ResolvedMember key = null;
-               
+
                if (baseMethod instanceof ParameterizedMethodBinding) {
-                       key = inAspect.factory.makeResolvedMember(((ParameterizedMethodBinding)baseMethod).original());
+                       key = inAspect.factory.makeResolvedMember(((ParameterizedMethodBinding) baseMethod).original());
                } else {
                        key = inAspect.factory.makeResolvedMember(baseMethod);
                }
-               if (accessors.containsKey(key)) return (MethodBinding)accessors.get(key);
-               
+               if (accessors.containsKey(key))
+                       return (MethodBinding) accessors.get(key);
+
                MethodBinding ret;
                if (baseMethod.isConstructor()) {
                        ret = new MethodBinding(baseMethod, baseMethod.declaringClass);
-                       ret.modifiers = AstUtil.makePublic(ret.modifiers); 
+                       ret.modifiers = AstUtil.makePublic(ret.modifiers);
                        baseMethod.modifiers = ret.modifiers;
                } else {
-                       ret = inAspect.factory.makeMethodBinding(
-                       AjcMemberMaker.privilegedAccessMethodForMethod(inAspect.typeX, key)
-                       );
+                       ret = inAspect.factory.makeMethodBinding(AjcMemberMaker.privilegedAccessMethodForMethod(inAspect.typeX, key));
                }
                checkWeaveAccess(key.getDeclaringType(), location);
-               //System.err.println(ret);
-               //Thread.dumpStack();
+               // System.err.println(ret);
+               // Thread.dumpStack();
                accessors.put(key, ret);
                return ret;
        }
-       
+
        public void notePrivilegedTypeAccess(ReferenceBinding type, ASTNode location) {
-               ResolvedMember key =
-                       new ResolvedMemberImpl(Member.STATIC_INITIALIZATION,
-                               inAspect.factory.fromEclipse(type), 0, ResolvedType.VOID, "", UnresolvedType.NONE);
-               
+               ResolvedMember key = new ResolvedMemberImpl(Member.STATIC_INITIALIZATION, inAspect.factory.fromEclipse(type), 0,
+                               ResolvedType.VOID, "", UnresolvedType.NONE);
+
                checkWeaveAccess(key.getDeclaringType(), location);
                accessors.put(key, key);
        }
@@ -104,22 +110,20 @@ public class PrivilegedHandler implements IPrivilegedHandler {
                        if (!world.resolve(typeX).isExposedToWeaver()) {
                                ISourceLocation loc = null;
                                if (location != null) {
-                                       loc = new EclipseSourceLocation(inAspect.compilationResult, 
-                                                       location.sourceStart, location.sourceEnd);
+                                       loc = new EclipseSourceLocation(inAspect.compilationResult, location.sourceStart, location.sourceEnd);
                                }
-                               check.signal(typeX.getName() + " (needed for privileged access)",
-                                                       loc);
+                               check.signal(typeX.getName() + " (needed for privileged access)", loc);
                        }
                }
        }
-       
+
        public ResolvedMember[] getMembers() {
                Collection m = accessors.keySet();
                int len = m.size();
                ResolvedMember[] ret = new ResolvedMember[len];
                int index = 0;
-               for (Iterator i = m.iterator(); i.hasNext(); ) {
-                       ret[index++] = (ResolvedMember)i.next();
+               for (Iterator i = m.iterator(); i.hasNext();) {
+                       ret[index++] = (ResolvedMember) i.next();
                }
                return ret;
        }
index e7e6310a4d1156ca1e1fcceaff9f4688ac2afc6b..144327df779209d77f780bb29309738ed3cc79bf 100644 (file)
@@ -15,8 +15,10 @@ package org.aspectj.ajdt.internal.compiler.problem;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.Modifier;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
@@ -36,12 +38,14 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.IPrivilegedHandler;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
@@ -438,6 +442,39 @@ public class AjProblemReporter extends ProblemReporter {
                super.unusedPrivateType(typeDecl);
        }
 
+       // Don't warn if there is an ITD method/ctor from a privileged aspect
+       public void unusedPrivateField(FieldDeclaration fieldDecl) {
+               if (fieldDecl.binding != null && fieldDecl.binding.declaringClass != null) {
+                       ReferenceBinding type = fieldDecl.binding.declaringClass;
+
+                       ResolvedType weaverType = null;
+                       if (!type.isAnonymousType()) {
+                               weaverType = factory.fromEclipse(type);
+                       } else {
+                               weaverType = factory.fromEclipse(type.superclass());
+                       }
+                       Set checked = new HashSet();
+                       for (Iterator i = weaverType.getInterTypeMungersIncludingSupers().iterator(); i.hasNext();) {
+                               ConcreteTypeMunger m = (ConcreteTypeMunger) i.next();
+                               ResolvedType theAspect = m.getAspectType();
+                               if (!checked.contains(theAspect)) {
+                                       TypeBinding tb = factory.makeTypeBinding(m.getAspectType());
+                                       // Let's check the privilegedHandler from that aspect
+                                       if (tb instanceof SourceTypeBinding) { // BinaryTypeBinding is also a SourceTypeBinding ;)
+                                               IPrivilegedHandler privilegedHandler = ((SourceTypeBinding) tb).privilegedHandler;
+                                               if (privilegedHandler != null) {
+                                                       if (privilegedHandler.definesPrivilegedAccessToField(fieldDecl.binding)) {
+                                                               return;
+                                                       }
+                                               }
+                                       }
+                                       checked.add(theAspect);
+                               }
+                       }
+               }
+               super.unusedPrivateField(fieldDecl);
+       }
+
        public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
                // don't output unused warnings for pointcuts...
                if (!(methodDecl instanceof PointcutDeclaration))