@@ -0,0 +1,18 @@ | |||
class C { | |||
static int static_c = 0; | |||
int c = 0; | |||
} | |||
aspect A { | |||
static int static_a = 0; | |||
int a = 0; | |||
private void C.itdFromA() { | |||
c = 1; // ok | |||
static_c = 1; // not ok - use C.static_c; | |||
static_a = 1; // ok | |||
a = 1; // not ok | |||
} | |||
} |
@@ -0,0 +1,56 @@ | |||
/* According to the documentation, the scope rules for | |||
intertype method declarations are interpreted | |||
from the originating aspect. The only exceptions | |||
(I thought) are the use of "this" and "super" which refer to | |||
the target type. | |||
According to that interpretation, the program below is type correct, but | |||
ajc generates two error messages, shown in comments | |||
at the relevant lines. Note that it's ok to access private static | |||
fields of the aspect, but not to use private classes of the aspect. | |||
If this is a feature and not a bug, what are the | |||
precise scope rules for intertype method declarations? | |||
*/ | |||
aspect Aspect { | |||
private static int y = 5; | |||
private class A { int x = 3; } | |||
private static class A2 {} | |||
private static void B.happy() { | |||
System.out.println(y); // happy accessing private field y | |||
} | |||
private static void B.foo(A z) { | |||
System.out.println(z.x); | |||
} | |||
private static void B.foo2(A2 z) { | |||
System.out.println(z); | |||
} | |||
public void B.bar() { | |||
B.foo(new A()); // CE L37 : no enclosing instance | |||
} | |||
public void B.bar2() { | |||
B.foo2(new A2()); | |||
} | |||
} | |||
class B { | |||
} | |||
class IT { | |||
public static void main(String[] args) { | |||
new B().bar(); | |||
} | |||
} |
@@ -1,18 +1,8 @@ | |||
/* | |||
Intertype field initialisers should be resolved in the aspect | |||
(lexical scope), for consistency with intertype method and | |||
constructor bodies. | |||
The program below compiles without warning, however, binding z | |||
to the z field of the target class. | |||
*/ | |||
aspect Aspect { | |||
public int A.x = z; // CE L14 error: z not visible. | |||
public int A.x = z; // okay, z is visible. | |||
} | |||
class A { |
@@ -10,7 +10,9 @@ | |||
package org.aspectj.systemtest.ajc121; | |||
import java.io.File; | |||
import junit.framework.Test; | |||
import org.aspectj.testing.XMLBasedAjcTestCase; | |||
public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@@ -148,15 +150,15 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
runTest("ITDs on inner classes should be static context"); | |||
} | |||
// public void test028_itdsAndInitializers() { | |||
// runTest("resolution of IT field inits"); | |||
// } | |||
public void test028_itdsAndInitializers() { | |||
runTest("resolution of IT field inits"); | |||
} | |||
public void test029_falseInvalidAbsoluteTypeName() { | |||
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"); | |||
} | |||
@@ -175,5 +177,10 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
public void test033_stringConcatForDEOWErrorCase() { | |||
runTest("Compile time declarations (warning and error) do not accept string concatenation (with +) (2)"); | |||
} | |||
public void test034_scopeForITDS_pr61768() { | |||
runTest("scope for inter-type methods"); | |||
} | |||
} | |||
@@ -224,14 +224,13 @@ | |||
</compile> | |||
</ajc-test> | |||
<!-- | |||
<ajc-test dir="bugs/oxford" pr="62475" | |||
<!-- should NOT raise error, despite Oxford expectations to the contrary --> | |||
<ajc-test dir="bugs/oxford" pr="62475" | |||
title="resolution of IT field inits"> | |||
<compile files="PR62475.java"> | |||
<message kind="error" line="14" /> | |||
</compile> | |||
</ajc-test> | |||
--> | |||
<ajc-test | |||
dir="bugs/invalidAbsoluteTypeName" | |||
@@ -242,8 +241,8 @@ | |||
</compile> | |||
<run class="False_InvalidAbsoluteTypeName"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs/PR68991" pr="68991" | |||
<ajc-test dir="bugs/PR68991" pr="68991" | |||
title="intertype initialisers should match field set pointcuts"> | |||
<compile files="Simple.java"/> | |||
<run class="Simple"/> | |||
@@ -274,4 +273,10 @@ | |||
<message kind="error" line="22"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="bugs/oxford" pr="61768" | |||
title="scope for inter-type methods"> | |||
<compile files="PR61768.java"> | |||
<message kind="error" line="37" text="No enclosing instance of type Aspect is accessible"/> | |||
</compile> | |||
</ajc-test> |