@Override
public ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause) {
- suppressLintWarnings(world);
+ if (!world.areAllLintIgnored()) {
+ suppressLintWarnings(world);
+ }
ShadowMunger ret = super.concretize(fromType, world, clause);
- clearLintSuppressions(world, this.suppressedLintKinds);
+ if (!world.areAllLintIgnored()) {
+ clearLintSuppressions(world, this.suppressedLintKinds);
+ }
IfFinder ifinder = new IfFinder();
ret.getPointcut().accept(ifinder, null);
boolean hasGuardTest = ifinder.hasIf && getKind() != AdviceKind.Around;
@Override
public boolean match(Shadow shadow, World world) {
- suppressLintWarnings(world);
- boolean ret = super.match(shadow, world);
- clearLintSuppressions(world, this.suppressedLintKinds);
- return ret;
+ if (world.areAllLintIgnored()) {
+ return super.match(shadow, world);
+ } else {
+ suppressLintWarnings(world);
+ boolean ret = super.match(shadow, world);
+ clearLintSuppressions(world, this.suppressedLintKinds);
+ return ret;
+ }
}
@Override
}
World world = shadow.getIWorld();
- suppressLintWarnings(world);
+ if (!world.areAllLintIgnored()) {
+ suppressLintWarnings(world);
+ }
runtimeTest = getPointcut().findResidue(shadow, exposedState);
- clearLintSuppressions(world, this.suppressedLintKinds);
+ if (!world.areAllLintIgnored()) {
+ clearLintSuppressions(world, this.suppressedLintKinds);
+ }
// these initializations won't be performed by findResidue, but need to be
// so that the joinpoint is primed for weaving
private void unpackAjAttributes(World world) {
associatedShadowMunger = null;
- List<AjAttribute> as = Utility.readAjAttributes(getDeclaringType().getClassName(), method.getAttributes(),
- getSourceContext(world), world, bcelObjectType.getWeaverVersionAttribute());
+ ResolvedType resolvedDeclaringType = getDeclaringType().resolve(world);
+ List<AjAttribute> as = Utility.readAjAttributes(resolvedDeclaringType.getClassName(), method.getAttributes(),
+ resolvedDeclaringType.getSourceContext(), world, bcelObjectType.getWeaverVersionAttribute());
processAttributes(world, as);
- as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut,
- getSourceContext(world), world.getMessageHandler());
+ as = AtAjAttributes.readAj5MethodAttributes(method, this, resolvedDeclaringType, preResolvedPointcut, resolvedDeclaringType
+ .getSourceContext(), world.getMessageHandler());
processAttributes(world, as);
}
public class BcelObjectType extends AbstractReferenceTypeDelegate {
public JavaClass javaClass;
+ private boolean artificial; // Was the BcelObject built from an artificial set of bytes? Or from the real ondisk stuff?
private LazyClassGen lazyClassGen = null; // set lazily if it's an aspect
private int modifiers;
* that's a bigger piece of work. XXX
*/
- BcelObjectType(ReferenceType resolvedTypeX, JavaClass javaClass, boolean exposedToWeaver) {
+ BcelObjectType(ReferenceType resolvedTypeX, JavaClass javaClass, boolean artificial, boolean exposedToWeaver) {
super(resolvedTypeX, exposedToWeaver);
this.javaClass = javaClass;
+ this.artificial = artificial;
initializeFromJavaclass();
// ATAJ: set the delegate right now for @AJ pointcut, else it is done
}
// repeat initialization
- public void setJavaClass(JavaClass newclass) {
+ public void setJavaClass(JavaClass newclass, boolean artificial) {
this.javaClass = newclass;
+ this.artificial = artificial;
resetState();
initializeFromJavaclass();
}
return javaClass;
}
+ public boolean isArtificial() {
+ return artificial;
+ }
+
public void resetState() {
if (javaClass == null) {
// we might store the classname and allow reloading?
fields[i].evictWeavingState();
}
javaClass = null;
+
+ this.artificial = true;
// setSourceContext(SourceContextImpl.UNKNOWN_SOURCE_CONTEXT); //
// bit naughty
// interfaces=null; // force reinit - may get us the right
public boolean copySourceContext() {
return false;
}
+
+ public void setExposedToWeaver(boolean b) {
+ exposedToWeaver = b;
+ }
}
if (wsi != null && wsi.isReweavable()) {
BcelObjectType classType = getClassType(type.getName());
JavaClass wovenJavaClass = classType.getJavaClass();
- JavaClass unwovenJavaClass = Utility.makeJavaClass(wovenJavaClass.getFileName(), wsi
- .getUnwovenClassFileData(wovenJavaClass.getBytes()));
+ byte[] bytes = wsi.getUnwovenClassFileData(wovenJavaClass.getBytes());
+ JavaClass unwovenJavaClass = Utility.makeJavaClass(wovenJavaClass.getFileName(), bytes);
world.storeClass(unwovenJavaClass);
- classType.setJavaClass(unwovenJavaClass);
+ classType.setJavaClass(unwovenJavaClass, true);
// classType.setJavaClass(Utility.makeJavaClass(classType.
// getJavaClass().getFileName(),
// wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes(
}
// FIXME ASC performance? of this alternative soln.
+ int size = (int) entry.getSize();
ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName());
JavaClass jc = parser.parse();
inStream.closeEntry();
- ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
+ ResolvedType type = world.addSourceObjectType(jc, false).getResolvedTypeX();
type.setBinaryPath(inFile.getAbsolutePath());
if (type.isAspect()) {
addedAspects.add(type);
private void addIfAspect(byte[] bytes, String name, List<ResolvedType> toList, File dir) throws IOException {
ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), name);
JavaClass jc = parser.parse();
- ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
+ ResolvedType type = world.addSourceObjectType(jc, false).getResolvedTypeX();
String typeName = type.getName().replace('.', File.separatorChar);
int end = name.lastIndexOf(typeName + ".class");
String binaryPath = null;
// classFile)) {
// // throw new RuntimeException(classFile.getClassName());
// }
- ReferenceType type = world.addSourceObjectType(classFile.getJavaClass()).getResolvedTypeX();
+ ReferenceType type = world.addSourceObjectType(classFile.getJavaClass(), false).getResolvedTypeX();
if (fromInpath) {
type.setBinaryPath(classFile.getFilename());
}
ResolvedType superclassType = resolvedTypeToWeave.getSuperclass();
String superclassTypename = (superclassType == null ? null : superclassType.getName());
- if (superclassType != null && !superclassType.isTypeHierarchyComplete() && superclassType.isExposedToWeaver()) { // typesForWeaving.contains(superclassTypename)) // {
+ if (superclassType != null && !superclassType.isTypeHierarchyComplete() && superclassType.isExposedToWeaver()) { // typesForWeaving.contains(superclassTypename))
+ // // {
weaveParentsFor(typesForWeaving, superclassTypename, superclassType);
}
// ().getFileName(), wsi.getUnwovenClassFileData()));
// new: reweavable default with clever diff
if (!world.isOverWeaving()) {
- classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi
- .getUnwovenClassFileData(classType.getJavaClass().getBytes())));
+
+ byte[] bytes = wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes());
+ classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), bytes), true);
// } else {
// System.out.println("overweaving " + className);
}
return null;
}
ReferenceType resolvedClassType = classType.getResolvedTypeX();
-
+
if (world.isXmlConfigured() && world.getXmlConfiguration().excludesType(resolvedClassType)) {
if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
world.getMessageHandler().handleMessage(
MessageUtil.info("Type '" + resolvedClassType.getName()
+ "' not woven due to exclusion via XML weaver exclude section"));
-
+
}
if (dump) {
dumpUnchanged(classFile);
}
return null;
}
-
+
List<ShadowMunger> shadowMungers = fastMatch(shadowMungerList, resolvedClassType);
List<ConcreteTypeMunger> typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
-
+
resolvedClassType.checkInterTypeMungers();
-
+
// Decide if we need to do actual weaving for this class
boolean mightNeedToWeave = shadowMungers.size() > 0 || typeMungers.size() > 0 || classType.isAspect()
|| world.getDeclareAnnotationOnMethods().size() > 0 || world.getDeclareAnnotationOnFields().size() > 0;
-
+
// May need bridge methods if on 1.5 and something in our hierarchy is
// affected by ITDs
boolean mightNeedBridgeMethods = world.isInJava5Mode() && !classType.isInterface()
&& resolvedClassType.getInterTypeMungersIncludingSupers().size() > 0;
-
+
LazyClassGen clazz = null;
if (mightNeedToWeave || mightNeedBridgeMethods) {
clazz = classType.getLazyClassGen();
// clazz.getWeaverState());
try {
boolean isChanged = false;
-
+
if (mightNeedToWeave) {
isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList,
inReweavableMode);
}
-
+
if (mightNeedBridgeMethods) {
isChanged = BcelClassWeaver.calculateAnyRequiredBridgeMethods(world, clazz) || isChanged;
}
-
+
if (isChanged) {
if (dump) {
dump(classFile, clazz);
* world.getModelAsAsmManager(); if (asm != null) { IHierarchy model = asm.getHierarchy(); if (!classType.isAspect()) {
*
* String pkgname = classType.getResolvedTypeX().getPackageName(); String tname =
- * classType.getResolvedTypeX().getSimpleBaseName(); IProgramElement typeElement = model.findElementForType(pkgname, tname);
- * if (typeElement != null) { Set deleted = new HashSet();
+ * classType.getResolvedTypeX().getSimpleBaseName(); IProgramElement typeElement = model.findElementForType(pkgname,
+ * tname); if (typeElement != null) { Set deleted = new HashSet();
* deleted.add(asm.getCanonicalFilePath(typeElement.getSourceLocation().getSourceFile()));
*
- * model.updateHandleMap(deleted); IProgramElement parent = typeElement.getParent(); // parent may have children: PACKAGE
- * DECL, IMPORT-REFEFERENCE, TYPE_DECL if (parent != null) { typeElement.getParent().removeChild(typeElement); //
- * System.out.println("Removing " + classType.getResolvedTypeX().getName() + "? " // + ); } } } }
+ * model.updateHandleMap(deleted); IProgramElement parent = typeElement.getParent(); // parent may have children:
+ * PACKAGE DECL, IMPORT-REFEFERENCE, TYPE_DECL if (parent != null) { typeElement.getParent().removeChild(typeElement);
+ * // System.out.println("Removing " + classType.getResolvedTypeX().getName() + "? " // + ); } } } }
*/
- if (dump) {
+ if (dump) {
dumpUnchanged(classFile);
return clazz;
} else {
if (jc == null) {
return null;
} else {
- return buildBcelDelegate(ty, jc, false);
+ return buildBcelDelegate(ty, jc, false, false);
}
}
- public BcelObjectType buildBcelDelegate(ReferenceType type, JavaClass jc, boolean exposedToWeaver) {
- BcelObjectType ret = new BcelObjectType(type, jc, exposedToWeaver);
+ public BcelObjectType buildBcelDelegate(ReferenceType type, JavaClass jc, boolean artificial, boolean exposedToWeaver) {
+ BcelObjectType ret = new BcelObjectType(type, jc, artificial, exposedToWeaver);
return ret;
}
}
}
- public BcelObjectType addSourceObjectType(JavaClass jc) {
+ // public BcelObjectType addSourceObjectType(JavaClass jc) {
+ // return addSourceObjectType(jc.getClassName(), jc, -1);
+ // }
+
+ public BcelObjectType addSourceObjectType(JavaClass jc, boolean artificial) {
+ return addSourceObjectType(jc.getClassName(), jc, artificial);
+ }
+
+ public BcelObjectType addSourceObjectType(String classname, JavaClass jc, boolean artificial) {
BcelObjectType ret = null;
+ if (!jc.getClassName().equals(classname)) {
+ throw new RuntimeException(jc.getClassName() + "!=" + classname);
+ }
String signature = UnresolvedType.forName(jc.getClassName()).getSignature();
- Object fromTheMap = typeMap.get(signature);
+ ResolvedType fromTheMap = typeMap.get(signature);
+
+ if (fromTheMap != null && !(fromTheMap instanceof ReferenceType)) {
+ // what on earth is it then? See pr 112243
+ StringBuffer exceptionText = new StringBuffer();
+ exceptionText.append("Found invalid (not a ReferenceType) entry in the type map. ");
+ exceptionText.append("Signature=[" + signature + "] Found=[" + fromTheMap + "] Class=[" + fromTheMap.getClass() + "]");
+ throw new BCException(exceptionText.toString());
+ }
+
+ ReferenceType nameTypeX = (ReferenceType) fromTheMap;
+
+ if (nameTypeX == null) {
+ if (jc.isGeneric() && isInJava5Mode()) {
+ nameTypeX = ReferenceType.fromTypeX(UnresolvedType.forRawTypeName(jc.getClassName()), this);
+ ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
+ ReferenceType genericRefType = new ReferenceType(UnresolvedType.forGenericTypeSignature(signature, ret
+ .getDeclaredGenericSignature()), this);
+ nameTypeX.setDelegate(ret);
+ genericRefType.setDelegate(ret);
+ nameTypeX.setGenericType(genericRefType);
+ typeMap.put(signature, nameTypeX);
+ } else {
+ nameTypeX = new ReferenceType(signature, this);
+ ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
+ typeMap.put(signature, nameTypeX);
+ }
+ } else {
+ ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
+ }
+ return ret;
+ }
+
+ public BcelObjectType addSourceObjectType(String classname, byte[] bytes, boolean artificial) {
+ BcelObjectType ret = null;
+ String signature = UnresolvedType.forName(classname).getSignature();
+
+ ResolvedType fromTheMap = typeMap.get(signature);
if (fromTheMap != null && !(fromTheMap instanceof ReferenceType)) {
// what on earth is it then? See pr 112243
ReferenceType nameTypeX = (ReferenceType) fromTheMap;
if (nameTypeX == null) {
+ JavaClass jc = Utility.makeJavaClass(classname, bytes);
if (jc.isGeneric() && isInJava5Mode()) {
nameTypeX = ReferenceType.fromTypeX(UnresolvedType.forRawTypeName(jc.getClassName()), this);
- ret = buildBcelDelegate(nameTypeX, jc, true);
+ ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
ReferenceType genericRefType = new ReferenceType(UnresolvedType.forGenericTypeSignature(signature, ret
.getDeclaredGenericSignature()), this);
nameTypeX.setDelegate(ret);
typeMap.put(signature, nameTypeX);
} else {
nameTypeX = new ReferenceType(signature, this);
- ret = buildBcelDelegate(nameTypeX, jc, true);
+ ret = buildBcelDelegate(nameTypeX, jc, artificial, true);
typeMap.put(signature, nameTypeX);
}
} else {
- ret = buildBcelDelegate(nameTypeX, jc, true);
+ Object o = nameTypeX.getDelegate();
+ if (!(o instanceof BcelObjectType)) {
+ throw new IllegalStateException("For " + classname + " should be BcelObjectType, but is " + o.getClass());
+ }
+ ret = (BcelObjectType) o;
+ // byte[] bs = ret.javaClass.getBytes();
+ // if (bs.length != bytes.length) {
+ // throw new RuntimeException("Shit");
+ // }
+ if (ret.isArtificial()) {
+ // System.out.println("Rebuilding " + nameTypeX.getName());
+ ret = buildBcelDelegate(nameTypeX, Utility.makeJavaClass(classname, bytes), artificial, true);
+ } else {
+ ret.setExposedToWeaver(true);
+ }
}
return ret;
}
}
}
+ public TypeMap getTypeMap() {
+ return typeMap;
+ }
+
}
import org.aspectj.weaver.bcel.BcelWeaver;
import org.aspectj.weaver.bcel.BcelWorld;
import org.aspectj.weaver.bcel.UnwovenClassFile;
-import org.aspectj.weaver.bcel.Utility;
// OPTIMIZE add guards for all the debug/info/etc
/**
private boolean abortOnError = false;
protected GeneratedClassHandler generatedClassHandler;
protected Map generatedClasses = new HashMap(); /* String -> UnwovenClassFile */
- protected BcelObjectType delegateForCurrentClass; // lazily initialized, should be used to prevent parsing bytecode multiple
+ public BcelObjectType delegateForCurrentClass; // lazily initialized, should be used to prevent parsing bytecode multiple
// times
private boolean haveWarnedOnJavax = false;
return bytes;
}
+ boolean debugOn = !messageHandler.isIgnoring(Message.DEBUG);
+
try {
delegateForCurrentClass = null;
name = name.replace('/', '.');
// a valid aspectOf()/hasAspect() generated in them. However - if they are excluded
// (via include/exclude in aop.xml) they really should only get aspectOf()/hasAspect()
// and not be included in the full set of aspects being applied by 'this' weaver
- debug("weaving '" + name + "'");
- bytes = getWovenBytes(name, bytes);
- } else if (shouldWeaveAnnotationStyleAspect(name, bytes)) {
- if (mustWeave) {
- if (bcelWorld.getLint().mustWeaveXmlDefinedAspects.isEnabled()) {
- bcelWorld.getLint().mustWeaveXmlDefinedAspects.signal(name, null);
- }
+ if (debugOn) {
+ debug("weaving '" + name + "'");
}
- // an @AspectJ aspect needs to be at least munged by the aspectOf munger
- debug("weaving '" + name + "'");
- bytes = getAtAspectJAspectBytes(name, bytes);
- } else {
+ bytes = getWovenBytes(name, bytes);
+ // temporarily out - searching for @Aspect annotated types is a slow thing to do - we should
+ // expect the user to name them if they want them woven - just like code style
+ // } else if (shouldWeaveAnnotationStyleAspect(name, bytes)) {
+ // if (mustWeave) {
+ // if (bcelWorld.getLint().mustWeaveXmlDefinedAspects.isEnabled()) {
+ // bcelWorld.getLint().mustWeaveXmlDefinedAspects.signal(name, null);
+ // }
+ // }
+ // // an @AspectJ aspect needs to be at least munged by the aspectOf munger
+ // if (debugOn) {
+ // debug("weaving '" + name + "'");
+ // }
+ // bytes = getAtAspectJAspectBytes(name, bytes);
+ } else if (debugOn) {
debug("not weaving '" + name + "'");
}
- } else {
+ } else if (debugOn) {
debug("cannot weave '" + name + "'");
}
} finally {
}
private boolean shouldWeaveName(String name) {
- if ((weavingSpecialTypes & INITIALIZED) == 0) {
- weavingSpecialTypes |= INITIALIZED;
- // initialize it
- Properties p = weaver.getWorld().getExtraConfiguration();
- if (p != null) {
- boolean b = p.getProperty(World.xsetWEAVE_JAVA_PACKAGES, "false").equalsIgnoreCase("true");
- if (b) {
- weavingSpecialTypes |= WEAVE_JAVA_PACKAGE;
- }
- b = p.getProperty(World.xsetWEAVE_JAVAX_PACKAGES, "false").equalsIgnoreCase("true");
- if (b) {
- weavingSpecialTypes |= WEAVE_JAVAX_PACKAGE;
+ if ("osj".indexOf(name.charAt(0)) != -1) {
+ if ((weavingSpecialTypes & INITIALIZED) == 0) {
+ weavingSpecialTypes |= INITIALIZED;
+ // initialize it
+ Properties p = weaver.getWorld().getExtraConfiguration();
+ if (p != null) {
+ boolean b = p.getProperty(World.xsetWEAVE_JAVA_PACKAGES, "false").equalsIgnoreCase("true");
+ if (b) {
+ weavingSpecialTypes |= WEAVE_JAVA_PACKAGE;
+ }
+ b = p.getProperty(World.xsetWEAVE_JAVAX_PACKAGES, "false").equalsIgnoreCase("true");
+ if (b) {
+ weavingSpecialTypes |= WEAVE_JAVAX_PACKAGE;
+ }
}
}
- }
- if (name.startsWith("org.aspectj.")) {
- return false;
- }
- if (name.startsWith("sun.reflect.")) {// JDK reflect
- return false;
- }
- if (name.startsWith("javax.")) {
- if ((weavingSpecialTypes & WEAVE_JAVAX_PACKAGE) != 0) {
- return true;
- } else {
- if (!haveWarnedOnJavax) {
- haveWarnedOnJavax = true;
- warn("javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified");
- }
+ if (name.startsWith("org.aspectj.")) {
return false;
}
- }
- if (name.startsWith("java.")) {
- if ((weavingSpecialTypes & WEAVE_JAVA_PACKAGE) != 0) {
- return true;
- } else {
+ if (name.startsWith("sun.reflect.")) {// JDK reflect
return false;
}
+ if (name.startsWith("javax.")) {
+ if ((weavingSpecialTypes & WEAVE_JAVAX_PACKAGE) != 0) {
+ return true;
+ } else {
+ if (!haveWarnedOnJavax) {
+ haveWarnedOnJavax = true;
+ warn("javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified");
+ }
+ return false;
+ }
+ }
+ if (name.startsWith("java.")) {
+ if ((weavingSpecialTypes & WEAVE_JAVA_PACKAGE) != 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
// boolean should = !(name.startsWith("org.aspectj.")
// || (name.startsWith("java.") && (weavingSpecialTypes & WEAVE_JAVA_PACKAGE) == 0)
protected void ensureDelegateInitialized(String name, byte[] bytes) {
if (delegateForCurrentClass == null) {
- delegateForCurrentClass = ((BcelWorld) weaver.getWorld()).addSourceObjectType(Utility.makeJavaClass(name, bytes));
+ BcelWorld world = (BcelWorld) weaver.getWorld();
+ delegateForCurrentClass = world.addSourceObjectType(name, bytes, false);
}
}