From f6034581d8540124494806a7c6b3ad37ead2b6c3 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 9 May 2005 11:08:28 +0000 Subject: [PATCH] tests and fixes for 93345 and static imports. From Andrew Huff. --- tests/bugs150/PR93345.aj | 12 +++++++ tests/java5/staticImports/StaticImport.aj | 9 +++++ .../systemtest/ajc150/AllTestsAspectJ150.java | 1 + .../systemtest/ajc150/StaticImports.java | 33 +++++++++++++++++++ .../systemtest/ajc150/SuppressedWarnings.java | 5 ++- .../org/aspectj/systemtest/ajc150/ajc150.xml | 10 ++++++ .../org/aspectj/weaver/bcel/BcelWeaver.java | 19 ++++++----- 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 tests/bugs150/PR93345.aj create mode 100644 tests/java5/staticImports/StaticImport.aj create mode 100644 tests/src/org/aspectj/systemtest/ajc150/StaticImports.java diff --git a/tests/bugs150/PR93345.aj b/tests/bugs150/PR93345.aj new file mode 100644 index 000000000..4950aa6e9 --- /dev/null +++ b/tests/bugs150/PR93345.aj @@ -0,0 +1,12 @@ +// "XLint warning for advice not applied with cflow(execution)" + +class AClass { +} + +aspect AnAspect { + pointcut a() : cflow( execution(* *(..)) ); + + before() : a() { + System.out.println("before a"); + } +} \ No newline at end of file diff --git a/tests/java5/staticImports/StaticImport.aj b/tests/java5/staticImports/StaticImport.aj new file mode 100644 index 000000000..3d82bcbeb --- /dev/null +++ b/tests/java5/staticImports/StaticImport.aj @@ -0,0 +1,9 @@ +// "import static java.lang.System.out" + +import static java.lang.System.out; + +public class StaticImport{ + public static void main(String [] args){ + out.println("hello world"); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java index c71386e41..004eb0a0d 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java @@ -34,6 +34,7 @@ public class AllTestsAspectJ150 { suite.addTest(AnnotationsBinaryWeaving.suite()); suite.addTest(AnnotationPointcutsTests.suite()); suite.addTestSuite(VarargsTests.class); + suite.addTestSuite(StaticImports.class); suite.addTest(AnnotationRuntimeTests.suite()); suite.addTestSuite(PerTypeWithinTests.class); diff --git a/tests/src/org/aspectj/systemtest/ajc150/StaticImports.java b/tests/src/org/aspectj/systemtest/ajc150/StaticImports.java new file mode 100644 index 000000000..a6de381fe --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc150/StaticImports.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Andrew Huff - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class StaticImports extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(StaticImports.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } + + public void testImportStaticSystemDotOut() { + runTest("import static java.lang.System.out"); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/SuppressedWarnings.java b/tests/src/org/aspectj/systemtest/ajc150/SuppressedWarnings.java index 8f1e7d295..db407560c 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/SuppressedWarnings.java +++ b/tests/src/org/aspectj/systemtest/ajc150/SuppressedWarnings.java @@ -42,5 +42,8 @@ public class SuppressedWarnings extends XMLBasedAjcTestCase { public void testSuppression2() { runTest("suppressing non-matching advice warnings when multiple source files involved"); } - + + public void testSuppressionWithCflow_pr93345() { + runTest("XLint warning for advice not applied with cflow(execution)"); + } } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 15afabbfe..283217815 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -5,6 +5,10 @@ + + + + @@ -1054,6 +1058,12 @@ + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 028b229b0..b32ebc0c7 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -995,6 +995,7 @@ public class BcelWeaver implements IWeaver { deletedTypenames = new ArrayList(); + // FIXME asc Should be factored out into Xlint code and done automatically for all xlint messages, ideally. // if a piece of advice hasn't matched anywhere and we are in -1.5 mode, put out a warning if (world.behaveInJava5Way && world.getLint().adviceDidNotMatch.isEnabled()) { @@ -1003,15 +1004,15 @@ public class BcelWeaver implements IWeaver { ShadowMunger element = (ShadowMunger) iter.next(); if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers BcelAdvice ba = (BcelAdvice)element; - if (!ba.hasMatchedSomething()) { - BcelMethod meth = (BcelMethod)ba.getSignature(); - if (meth!=null) { - AnnotationX[] anns = (AnnotationX[])meth.getAnnotations(); - // Check if they want to suppress the warning on this piece of advice - if (!Utility.isSuppressing(anns,"adviceDidNotMatch")) { - world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation()); - } - } + if (!ba.hasMatchedSomething()) { + // Because we implement some features of AJ itself by creating our own kind of mungers, you sometimes + // find that ba.getSignature() is not a BcelMethod - for example it might be a cflow entry munger. + if (ba.getSignature()!=null) { + if (!(ba.getSignature() instanceof BcelMethod) + || !Utility.isSuppressing((AnnotationX[])ba.getSignature().getAnnotations(),"adviceDidNotMatch")) { + world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation()); + } + } } } } -- 2.39.5