Index: src/org/aspectj/weaver/bcel/BcelWeaver.java =================================================================== RCS file: /cvsroot/tools/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java,v --- src/org/aspectj/weaver/bcel/BcelWeaver.java 29 Nov 2008 20:46:42 -0000 1.125 +++ src/org/aspectj/weaver/bcel/BcelWeaver.java 20 Jan 2009 18:22:40 -0000 @@ -63,6 +63,7 @@ import org.aspectj.weaver.IClassFileProvider; import org.aspectj.weaver.IUnwovenClassFile; import org.aspectj.weaver.IWeaveRequestor; +import org.aspectj.weaver.MatchHolder; import org.aspectj.weaver.NewParentTypeMunger; import org.aspectj.weaver.ReferenceType; import org.aspectj.weaver.ReferenceTypeDelegate; @@ -518,6 +519,36 @@ // because continuing with // inconsistent pointcuts could lead to problems typeMungerList = xcutSet.getTypeMungers(); + + Map/*UnresolvedType>MatchHolder*/ duplicatorAvoidanceMap = new HashMap(); + for (Iterator iterator = typeMungerList.iterator(); iterator.hasNext();) { + ConcreteTypeMunger typeMunger = (ConcreteTypeMunger) iterator.next(); + UnresolvedType onTypeU = typeMunger.getSignature().getDeclaringType(); + ResolvedType onType = world.resolve(onTypeU); +// System.out.println("Matches check for "+this+" on "+matchType+" decltype="+onType); + if (onType.isRawType()) { + onType = onType.getGenericType(); + } + MatchHolder mHolder = (MatchHolder)duplicatorAvoidanceMap.get(onType); + if (mHolder == null) { + mHolder = new MatchHolder(onType); + duplicatorAvoidanceMap.put(onType,mHolder); + } + typeMunger.setAvoider(mHolder); +// Integer i = (Integer)counter.get(typeMunger.getSignature().getDeclaringType()); +// if (i!=null) { +// i = new Integer(i.intValue()+1); +// counter.put(typeMunger.getSignature().getDeclaringType(),i); +// } else { +// counter.put(typeMunger.getSignature().getDeclaringType(),new Integer(1)); +// } + } +// Set s = counter.keySet(); +// for (Iterator iterator = s.iterator(); iterator.hasNext();) { +// Object object = (Object) iterator.next(); +// System.out.println("K:"+object+" v:"+counter.get(object)); +// } + lateTypeMungerList = xcutSet.getLateTypeMungers(); declareParentsList = xcutSet.getDeclareParents(); Index: src/org/aspectj/weaver/ConcreteTypeMunger.java =================================================================== RCS file: /cvsroot/tools/org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/ConcreteTypeMunger.java,v --- src/org/aspectj/weaver/ConcreteTypeMunger.java 5 Jan 2009 22:02:29 -0000 1.2 +++ src/org/aspectj/weaver/ConcreteTypeMunger.java 20 Jan 2009 18:22:42 -0000 @@ -150,4 +150,8 @@ public boolean shouldOverwrite() { return true; } + + public void setAvoider(MatchHolder holder) { + if (munger!=null) munger.setAvoider(holder); + } } Index: src/org/aspectj/weaver/ResolvedTypeMunger.java =================================================================== RCS file: /cvsroot/tools/org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java,v --- src/org/aspectj/weaver/ResolvedTypeMunger.java 6 Jan 2009 23:53:58 -0000 1.2 +++ src/org/aspectj/weaver/ResolvedTypeMunger.java 20 Jan 2009 18:22:42 -0000 @@ -57,6 +57,7 @@ private Set /* resolvedMembers */superMethodsCalled = Collections.EMPTY_SET; private ISourceLocation location; // Lost during serialize/deserialize ! + private MatchHolder avoider; public ResolvedTypeMunger(Kind kind, ResolvedMember signature) { this.kind = kind; @@ -99,34 +100,44 @@ // ConcreteTypeMunger munger = world.concreteTypeMunger(this, aspectType); // return munger; // } - + + public boolean matches(ResolvedType matchType, ResolvedType aspectType) { - ResolvedType onType = matchType.getWorld().resolve(signature.getDeclaringType()); - if (onType.isRawType()) - onType = onType.getGenericType(); - // System.err.println("matching: " + this + " to " + matchType + " onType = " + onType); - if (matchType.equals(onType)) { - if (!onType.isExposedToWeaver()) { - // if the onType is an interface, and it already has the member we are about - // to munge, then this is ok... - boolean ok = (onType.isInterface() && (onType.lookupMemberWithSupersAndITDs(getSignature()) != null)); - - if (!ok && onType.getWeaverState() == null) { - if (matchType.getWorld().getLint().typeNotExposedToWeaver.isEnabled()) { - matchType.getWorld().getLint().typeNotExposedToWeaver.signal(matchType.getName(), signature - .getSourceLocation()); + Boolean b = (avoider==null?null:avoider.matches(matchType)); + if (b==null) { + ResolvedType onType = matchType.getWorld().resolve(signature.getDeclaringType()); + // System.out.println("Matches check for "+this+" on "+matchType+" decltype="+onType); + if (onType.isRawType()) { + onType = onType.getGenericType(); + } + // System.err.println("matching: " + this + " to " + matchType + " onType = " + onType); + if (matchType.equals(onType)) { + if (!onType.isExposedToWeaver()) { + // if the onType is an interface, and it already has the member we are about + // to munge, then this is ok... + boolean ok = (onType.isInterface() && (onType.lookupMemberWithSupersAndITDs(getSignature()) != null)); + + if (!ok && onType.getWeaverState() == null) { + if (matchType.getWorld().getLint().typeNotExposedToWeaver.isEnabled()) { + matchType.getWorld().getLint().typeNotExposedToWeaver.signal(matchType.getName(), signature + .getSourceLocation()); + } } } + b = Boolean.TRUE; + } else { + + if (onType.isInterface()) { + b = Boolean.valueOf(matchType.isTopmostImplementor(onType)); + } else { + b = Boolean.FALSE; + } + } + if (avoider!=null) { + avoider.record(matchType,b); } - return true; - } - // System.err.println("NO MATCH DIRECT"); - - if (onType.isInterface()) { - return matchType.isTopmostImplementor(onType); - } else { - return false; } + return b.booleanValue(); } // ---- @@ -449,4 +460,8 @@ throw new BCException("Dont call parameterizeWith() on a type munger of this kind: " + this.getClass()); } + public void setAvoider(MatchHolder holder) { + this.avoider = holder; + } + } Index: src/org/aspectj/weaver/MatchHolder.java =================================================================== RCS file: src/org/aspectj/weaver/MatchHolder.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/aspectj/weaver/MatchHolder.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,34 @@ +/* ******************************************************************* + * Copyright (c) 2009 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.weaver; + +import java.util.HashMap; +import java.util.Map; + +public class MatchHolder { + + private ResolvedType forType; + private Map/*matchType,boolean*/ matches = new HashMap(); + + public MatchHolder(ResolvedType forType) { + this.forType = forType; + } + + public Boolean matches(ResolvedType matchType) { + return (Boolean)matches.get(matchType); + } + + public void record(ResolvedType matchType, Boolean b) { + matches.put(matchType,b); + } + +}