ajc reports error when encountering static declaration of nested classestags/v1_1_0_RC1
@@ -5585,5 +5585,19 @@ | |||
<message kind="error" line="22"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="bugs" pr="33635" | |||
title="Negation of if pointcut does not work"> | |||
<compile files="NotIf.java"/> | |||
<run class="NotIf"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs" pr="32463" | |||
title="ajc reports error when encountering static declaration of nested classes"> | |||
<compile files="WeaveLocal.java"/> | |||
<run class="WeaveLocal"/> | |||
</ajc-test> | |||
</suite> |
@@ -0,0 +1,37 @@ | |||
// for Bug#: 32463 | |||
import org.aspectj.testing.Tester; | |||
public class WeaveLocal | |||
{ | |||
// Commenting out the static declaration makes everything work OK | |||
static | |||
{ | |||
class StaticNestedClass | |||
{ | |||
} | |||
} | |||
public static void main(String[] args) | |||
{ | |||
System.out.println(new WeaveLocal().handleOrder("test")); | |||
} | |||
private String handleOrder(String t) | |||
{ | |||
return t; | |||
} | |||
} | |||
aspect A { | |||
pointcut withinTest(): within(WeaveLocal); | |||
pointcut callToHandleOrder() : (withinTest() && | |||
call(* handleOrder(..))); | |||
Object around(): callToHandleOrder() { | |||
return "DUMMY inserted by ASPECT" ; | |||
} | |||
} |
@@ -1,12 +1,7 @@ | |||
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"> | |||
<suite> | |||
<ajc-test dir="bugs" pr="33635" | |||
title="Negation of if pointcut does not work"> | |||
<compile files="NotIf.java"/> | |||
<run class="NotIf"/> | |||
</ajc-test> | |||
<!-- | |||
@@ -268,16 +268,9 @@ public class NameMangler { | |||
// ---- | |||
private static TypeX getOutermostType(TypeX type) { | |||
TypeX outerType = type.getDeclaringType(); | |||
if (outerType == null) return type; | |||
return getOutermostType(outerType); | |||
} | |||
private static String makeVisibilityName(int modifiers, TypeX aspectType) { | |||
if (Modifier.isPrivate(modifiers)) { | |||
return getOutermostType(aspectType).getNameAsIdentifier(); | |||
return aspectType.getOutermostType().getNameAsIdentifier(); | |||
} else if (Modifier.isProtected(modifiers)) { | |||
throw new RuntimeException("protected inter-types not allowed"); | |||
} else if (Modifier.isPublic(modifiers)) { |
@@ -792,11 +792,29 @@ public abstract class ResolvedTypeX extends TypeX { | |||
return interTypeMungers; | |||
} | |||
private static ResolvedTypeX getOutermostType(ResolvedTypeX t) { | |||
TypeX dec = t.getDeclaringType(); | |||
if (dec == null) return t; | |||
return getOutermostType(dec.resolve(t.getWorld())); | |||
} | |||
/** | |||
* Returns a ResolvedTypeX object representing the declaring type of this type, or | |||
* null if this type does not represent a non-package-level-type. | |||
* | |||
* <strong>Warning</strong>: This is guaranteed to work for all member types. | |||
* For anonymous/local types, the only guarantee is given in JLS 13.1, where | |||
* it guarantees that if you call getDeclaringType() repeatedly, you will eventually | |||
* get the top-level class, but it does not say anything about classes in between. | |||
* | |||
* @return the declaring TypeX object, or null. | |||
*/ | |||
public ResolvedTypeX getDeclaringType() { | |||
if (isArray()) return null; | |||
String name = getName(); | |||
int lastDollar = name.lastIndexOf('$'); | |||
while (lastDollar != -1) { | |||
ResolvedTypeX ret = world.resolve(TypeX.forName(name.substring(0, lastDollar)), true); | |||
if (ret != ResolvedTypeX.MISSING) return ret; | |||
lastDollar = name.lastIndexOf('$', lastDollar-1); | |||
} | |||
return null; | |||
} | |||
public static boolean isVisible(int modifiers, ResolvedTypeX targetType, ResolvedTypeX fromType) { | |||
//System.err.println("mod: " + modifiers + ", " + targetType + " and " + fromType); | |||
@@ -804,7 +822,7 @@ public abstract class ResolvedTypeX extends TypeX { | |||
if (Modifier.isPublic(modifiers)) { | |||
return true; | |||
} else if (Modifier.isPrivate(modifiers)) { | |||
return getOutermostType(targetType).equals(getOutermostType(fromType)); | |||
return targetType.getOutermostType().equals(fromType.getOutermostType()); | |||
} else if (Modifier.isProtected(modifiers)) { | |||
return samePackage(targetType, fromType) || targetType.isAssignableFrom(fromType); | |||
} else { // package-visible |
@@ -249,26 +249,23 @@ public class TypeX { | |||
public final boolean isArray() { | |||
return signature.startsWith("["); | |||
} | |||
/** | |||
* Returns a TypeX object representing the declaring type of this type, or | |||
* null if this type does not represent a non-package-level-type. | |||
* Returns a TypeX object representing the effective outermost enclosing type | |||
* for a name type. For all other types, this will return the type itself. | |||
* | |||
* <strong>Warning</strong>: This is guaranteed to work for all member types. | |||
* For anonymous/local types, the only guarantee is given in JLS 13.1, where | |||
* it guarantees that if you call getDeclaringType() repeatedly, you will eventually | |||
* get the top-level class, but it does not say anything about classes in between. | |||
* | |||
* @return the declaring TypeX object, or null. | |||
* The only guarantee is given in JLS 13.1 where code generated according to | |||
* those rules will have type names that can be split apart in this way. | |||
* @return the outermost enclosing TypeX object or this. | |||
*/ | |||
public TypeX getDeclaringType() { | |||
if (isArray()) return null; | |||
String name = getName(); | |||
int lastDollar = name.lastIndexOf('$'); | |||
if (lastDollar != -1) { | |||
return TypeX.forName(name.substring(0, lastDollar)); | |||
public TypeX getOutermostType() { | |||
if (isArray() || isPrimitive()) return this; | |||
String sig = getSignature(); | |||
int dollar = sig.indexOf('$'); | |||
if (dollar != -1) { | |||
return TypeX.forSignature(sig.substring(0, dollar) + ';'); | |||
} else { | |||
return null; | |||
return this; | |||
} | |||
} | |||
@@ -34,13 +34,14 @@ public class WithinPointcut extends Pointcut { | |||
} | |||
public FuzzyBoolean match(Shadow shadow) { | |||
TypeX enclosingType = shadow.getEnclosingType(); | |||
ResolvedTypeX enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType()); | |||
//System.err.println("enclosingType: " + enclosingType); | |||
// if (shadow.getKind() == Shadow.FieldSet) { | |||
// System.err.println("within?" + type + " matches " + enclosingType + " on " + shadow); | |||
// } | |||
while (enclosingType != null) { | |||
if (type.matchesStatically(shadow.getIWorld().resolve(enclosingType))) { | |||
if (type.matchesStatically(enclosingType)) { | |||
return FuzzyBoolean.YES; | |||
} | |||
enclosingType = enclosingType.getDeclaringType(); |
@@ -58,8 +58,8 @@ public class TypeXTestCase extends TestCase { | |||
TypeX t = TypeX.forName("java.util.Map$Entry"); | |||
assertEquals(t.getName(), "java.util.Map$Entry"); | |||
assertEquals(t.getSignature(), "Ljava/util/Map$Entry;"); | |||
assertEquals(t.getDeclaringType(), TypeX.forName("java.util.Map")); | |||
assertNull(TypeX.forName("java.util.Map").getDeclaringType()); | |||
assertEquals(t.getOutermostType(), TypeX.forName("java.util.Map")); | |||
assertEquals(TypeX.forName("java.util.Map").getOutermostType(), TypeX.forName("java.util.Map")); | |||
} | |||
private void isPrimitiveTest(TypeX[] types, boolean[] isPrimitives) { |