--- /dev/null
+package de.rohith;
+public class HelloWorld {
+
+ public static void main(String[] args) {
+ PrinterWorld p = new PrinterWorld();
+ p.print();
+ Integer i = p.returnInt();
+ Integer[] intArray = p.returnArrayWithCloning();
+ Integer[] array2 = p.returnArrayWithoutCloning();
+ }
+}
--- /dev/null
+package de.rohith;
+import java.lang.Object;
+
+public aspect HelloWorldAspect {
+
+ private int callDepth = -1;
+
+ public HelloWorldAspect() {
+ }
+
+ pointcut hello(): !within(HelloWorldAspect);
+
+ pointcut method(): execution(public (*[]) de..*(..));
+
+ pointcut cloning(): call(* java.lang.Object.clone());
+
+ declare warning: method() && hello(): "*[] returning method called" ;
+
+ Object[] around(): cflow(method()) && cloning() && hello() {
+ print("", thisEnclosingJoinPointStaticPart);
+ Object[] ret = proceed();
+ return (Object[])ret.clone();
+ }
+
+ private void print(String prefix, Object message) {
+ for (int i = 0, spaces = callDepth * 2; i < spaces; i++) {
+ System.out.print(" ");
+ }
+ System.out.println(prefix + message);
+ }
+}
--- /dev/null
+package de.rohith;
+public class PrinterWorld {
+ private Integer[] intArray = new Integer[2];
+ public PrinterWorld() {
+
+ }
+ public void print() {
+ System.out.println("Hello World!");
+ }
+
+ public Integer returnInt() {
+ return new Integer(3);
+ }
+
+ public Integer[] returnArrayWithCloning() {
+ for (int i = 0; i < intArray.length; i++) {
+ intArray[i] = new Integer(i++);
+ }
+ return (Integer[])intArray.clone();
+ }
+
+ public Integer[] returnArrayWithoutCloning() {
+ return intArray;
+ }
+}
runTest("The introduction on interface causes the interface implementation class error (4)");
}
+ public void test050_typePatternMatchingWithArrays() {
+ runTest("declare warning warns at wrong points");
+ }
}
</compile>
</ajc-test>
+
+ <ajc-test dir="bugs/pr72531" pr="72531"
+ title="declare warning warns at wrong points">
+ <compile files="de/rohith/HelloWorld.java,de/rohith/HelloWorldAspect.java,de/rohith/PrinterWorld.java">
+ <message kind="warning" line="15" text="*[] returning method called"/>
+ <message kind="warning" line="22" text="*[] returning method called"/>
+ </compile>
+ </ajc-test>
+
\ No newline at end of file
return innerMatchesExactly(targetTypeName);
}
+ if (isStar()) {
+ // we match if the dimensions match
+ int numDimensionsInTargetType = 0;
+ if (dim > 0) {
+ int index;
+ while((index = targetTypeName.indexOf('[')) != -1) {
+ numDimensionsInTargetType++;
+ targetTypeName = targetTypeName.substring(index+1);
+ }
+ if (numDimensionsInTargetType == dim) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
// if our pattern is length 1, then known matches are exact matches
// if it's longer than that, then known matches are prefixes of a sort
if (namePatterns.length == 1) {
boolean allowBinding, boolean requireExactType)
{
if (isStar()) {
- return TypePattern.ANY; //??? loses source location
+ if (dim == 0) { // pr72531
+ return TypePattern.ANY; //??? loses source location
+ }
}
String simpleName = maybeGetSimpleName();
}
+
+ public void testArrayMatch() {
+ world = new BcelWorld();
+ checkMatch("*[][]","java.lang.Object",false);
+ checkMatch("*[]","java.lang.Object[]",true);
+ checkMatch("*[][]","java.lang.Object[][]",true);
+ checkMatch("java.lang.Object[]","java.lang.Object",false);
+ checkMatch("java.lang.Object[]","java.lang.Object[]",true);
+ checkMatch("java.lang.Object[][]","java.lang.Object[][]",true);
+ checkMatch("java.lang.String[]","java.lang.Object",false);
+ checkMatch("java.lang.String[]","java.lang.Object[]",false);
+ checkMatch("java.lang.String[][]","java.lang.Object[][]",false);
+ checkMatch("java.lang.Object+[]","java.lang.String[]",true);
+ }
private void checkIllegalInstanceofMatch(String pattern, String name) {
try {