* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.ajdt.internal.compiler.lookup;
import java.util.Collection;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
-
-
public class PrivilegedHandler implements IPrivilegedHandler {
private AspectDeclaration inAspect;
private Map accessors = new HashMap();
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);
}
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;
}
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;
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;
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))