From d43a39103f476d95cade6b87b604ee4578de25b3 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 11 Aug 2004 13:18:24 +0000 Subject: [PATCH] Tests and fix for Bugzilla Bug 54421 Compile time declarations (warning and error) do not accept string concatenation (with +) --- tests/bugs/decwStrings.java | 49 +++++++++++++++++++ tests/bugs/decwStringsErroneous.java | 29 +++++++++++ .../systemtest/ajc121/Ajc121Tests.java | 12 ++++- .../systemtest/ajc121/ajc121-tests.xml | 24 ++++++++- .../weaver/patterns/PatternParser.java | 28 ++++++++++- 5 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 tests/bugs/decwStrings.java create mode 100644 tests/bugs/decwStringsErroneous.java diff --git a/tests/bugs/decwStrings.java b/tests/bugs/decwStrings.java new file mode 100644 index 000000000..ef392a669 --- /dev/null +++ b/tests/bugs/decwStrings.java @@ -0,0 +1,49 @@ +class WarningSample { + + public void method() {} + public void anotherMethod() { + this.method(); + } + + } + + aspect WarningAspect { + + pointcut illegalCall(): call(* WarningSample.method()) + && within(WarningSample); + + // the same thing happens with declare error + declare warning: illegalCall() : "Hey, don't " + + "do that, that is not nice. You should do something else"; + + public void e1() {} + declare warning: execution(* e1(..)): "hello " + /* comment */ "world"; + + public void e2() {} + declare warning: execution(* e2(..)): "hello " /* comment */ + "world"; + + public void e3() {} + declare warning: execution(* e3(..)): "hello " + // commenthere + // comment here too + "world"; + + public void e4() {} + declare warning: execution(* e4()): "hello " //xxx + + "world"; + + public void e5() {} + declare warning: execution(* e5()): "hello " //xxx + /* here */ + + "world"; + + public void e6() {} + declare warning: execution(* e6()): "abc" + + "def" + // def was here + "ghijklmnopqrstuv" /* silly +place +for a +comment */ + +/* oops */ + "wxyz"; + } + diff --git a/tests/bugs/decwStringsErroneous.java b/tests/bugs/decwStringsErroneous.java new file mode 100644 index 000000000..11664ac98 --- /dev/null +++ b/tests/bugs/decwStringsErroneous.java @@ -0,0 +1,29 @@ +class WarningSample { + + public void method() {} + public void anotherMethod() { + this.method(); + } + + } + + aspect WarningAspect { + + pointcut illegalCall(): call(* WarningSample.method()) + && within(WarningSample); + + // the same thing happens with declare error + declare warning: illegalCall() : "Hey, don't " + + "do that, that is not nice. You should do something else"; + + public void e1() {} + declare warning: execution(* e1(..)): "hello " + /* comment */ "world" + + public void e2() {} + declare warning: execution(* e2(..)): "hello " /* comment + "world"; + + public void e3() {} + declare warning: execution(* e3(..)): "hello " + // commenthere + + } + diff --git a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java index 039dffa0e..805397df1 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java @@ -139,7 +139,8 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void test025_proceedInAround3() { runTest("proceed used as method name in around advice (3)"); } - public void test026_bindingThisAndTargetToTheSameFormal() { + + public void test026_bindingThisAndTargetToTheSameFormal() { runTest("ajc crashes when compiling the following program (binding this() and target())"); } @@ -155,7 +156,7 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("Valid but inaccessible type names should not be flagged by XLint:invalidAbsoluteTypeName"); } - public void test030_privateITDinitialisersBeingMatched() { + public void test030_privateITDinitialisersBeingMatched() { runTest("intertype initialisers should match field set pointcuts"); } @@ -166,6 +167,13 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { assertTrue("Expected output '"+exp+"' but got "+getLastRunResult().getStdErr(), getLastRunResult().getStdErr().equals(exp)); } + + public void test032_stringConcatForDEOW() { + runTest("Compile time declarations (warning and error) do not accept string concatenation (with +)"); + } + public void test033_stringConcatForDEOWErrorCase() { + runTest("Compile time declarations (warning and error) do not accept string concatenation (with +) (2)"); + } } diff --git a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml index dc59c31c1..e1c6c5481 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml @@ -203,7 +203,6 @@ - @@ -254,4 +253,25 @@ title="intertype initialisers should match field set pointcuts (oxford testcase)"> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java index 89a168fef..062f17b21 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java +++ b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java @@ -150,7 +150,7 @@ public class PatternParser { private Declare parseErrorOrWarning(boolean isError) { Pointcut pointcut = parsePointcut(); eat(":"); - String message = parseStringLiteral(); + String message = parsePossibleStringSequence(true); return new DeclareErrorOrWarning(isError, pointcut, message); } @@ -736,6 +736,32 @@ public class PatternParser { } } + public String parsePossibleStringSequence(boolean shouldEnd) { + StringBuffer result = new StringBuffer(); + + IToken token = tokenSource.next(); + if (token.getLiteralKind()==null) { + throw new ParserException("string",token); + } + while (token.getLiteralKind().equals("string")) { + result.append(token.getString()); + boolean plus = maybeEat("+"); + if (!plus) break; + token = tokenSource.next(); + if (token.getLiteralKind()==null) { + throw new ParserException("string",token); + } + } + eatIdentifier(";"); + IToken t = tokenSource.next(); + if (shouldEnd && t!=IToken.EOF) { + throw new ParserException(";",token); + } + + return result.toString(); + + } + public String parseStringLiteral() { IToken token = tokenSource.next(); String literalKind = token.getLiteralKind(); -- 2.39.5