From: aclement Date: Wed, 4 Aug 2010 19:26:16 +0000 (+0000) Subject: 278496: type demotion, complete! X-Git-Tag: V1_6_10RC1~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=52598b935aa710833c8376d2838f7ec272ee75d3;p=aspectj.git 278496: type demotion, complete! --- diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/IncrementalCompilationTests.java b/tests/src/org/aspectj/systemtest/incremental/tools/IncrementalCompilationTests.java index fe719f275..9cf58112d 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/IncrementalCompilationTests.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/IncrementalCompilationTests.java @@ -10,10 +10,20 @@ *******************************************************************/ package org.aspectj.systemtest.incremental.tools; -import junit.framework.Assert; +import java.util.Set; +import org.aspectj.ajde.core.internal.AjdeCoreBuildManager; +import org.aspectj.ajdt.internal.core.builder.AjBuildManager; import org.aspectj.asm.IProgramElement; import org.aspectj.asm.internal.AspectJElementHierarchy; +import org.aspectj.weaver.AnnotationAJ; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ReferenceTypeDelegate; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.World.TypeMap; /** * Incremental compilation tests. MultiProjectIncrementalTests was getting unwieldy - started this new test class for 1.6.10. @@ -210,8 +220,8 @@ public class IncrementalCompilationTests extends AbstractMultiProjectIncremental AspectJElementHierarchy model = (AspectJElementHierarchy) getModelFor(p).getHierarchy(); // Node for "Code.java" should not be there: - IProgramElement ipe = model.findElementForHandleOrCreate("=PR278496_1;",fields[2].getGenericReturnType().getSignature()); + assertEquals("Ljava/util/List;",fields[3].getSignature()); + assertEquals("Pjava/util/List;",fields[3].getGenericReturnType().getSignature()); + } + + public void testWorldDemotion_278496_6() throws Exception { + String p = "PR278496_6"; + initialiseProject(p); + configureNonStandardCompileOptions(p, "-Xset:typeDemotion=true"); + build(p); + checkWasFullBuild(); + alter(p,"inc1"); + build(p); + checkWasntFullBuild(); + AjdeCoreBuildManager buildManager = getCompilerForProjectWithName(p).getBuildManager(); + AjBuildManager ajBuildManager = buildManager.getAjBuildManager(); + World w = ajBuildManager.getWorld(); + ReferenceTypeDelegate delegate = null; + delegate = w.resolveToReferenceType("com.Meths").getDelegate(); + // assertTrue(delegate instanceof CompactTypeStructureDelegate); + ResolvedMember[] methods = delegate.getDeclaredMethods(); + assertEquals("void com.Meths.()",methods[0].toString()); + assertEquals("void com.Meths.m()",methods[1].toString()); + assertEquals("java.util.List com.Meths.n(int, long, java.util.List)",methods[2].toString()); + + + System.out.println(stringify(methods[0].getAnnotations())); + System.out.println(stringify(methods[1].getAnnotations())); + System.out.println(stringify(methods[2].getAnnotations())); + assertEquals("[Anno[Lcom/Anno; rVis]]", stringify(methods[1].getAnnotations())); + // assertNotNull(fields[2].getAnnotationOfType(UnresolvedType.forSignature("Lcom/Anno;"))); + // assertNull(fields[2].getAnnotationOfType(UnresolvedType.forSignature("Lcom/Anno2;"))); + // assertTrue(fields[2].hasAnnotation(UnresolvedType.forSignature("Lcom/Anno;"))); + // assertFalse(fields[2].hasAnnotation(UnresolvedType.forSignature("Ljava/lang/String;"))); + // assertEquals(0,fields[1].getAnnotations().length); + // assertEquals("[com.Anno2 com.Anno]",stringify(fields[3].getAnnotationTypes())); + // assertEquals("[]",stringify(fields[1].getAnnotationTypes())); + // assertEquals("[Anno[Lcom/Anno2; rVis a=(int)42] Anno[Lcom/Anno; rVis]]",stringify(fields[3].getAnnotations())); + // assertEquals("[]",stringify(fields[1].getAnnotations())); + // + // assertEquals("I",fields[0].getSignature()); + // assertEquals("Ljava/lang/String;",fields[1].getSignature()); + // assertEquals("Ljava/util/List;",fields[2].getSignature()); + // assertEquals("Pjava/util/List;",fields[2].getGenericReturnType().getSignature()); + // assertEquals("Ljava/util/List;",fields[3].getSignature()); + // assertEquals("Pjava/util/List;",fields[3].getGenericReturnType().getSignature()); + } + + // public void testWorldDemotion_278496_7() throws Exception { + // boolean demotion = true; + // AjdeInteractionTestbed.VERBOSE=true; + // String p = "PR278496_7"; + // TypeMap.useExpendableMap=false; + // initialiseProject(p); + // if (demotion) { + // configureNonStandardCompileOptions(p, "-Xset:typeDemotion=true,typeDemotionDebug=true"); + // } + // build(p); + // checkWasFullBuild(); + // assertNoErrors(p); + // alter(p,"inc1"); + // build(p); + // checkWasntFullBuild(); + // assertNoErrors(p); + // + // AjdeCoreBuildManager buildManager = getCompilerForProjectWithName(p).getBuildManager(); + // AjBuildManager ajBuildManager = buildManager.getAjBuildManager(); + // World w = ajBuildManager.getWorld(); + // } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + TypeMap.useExpendableMap=true; + } + + public void testWorldDemotion_278496_4() throws Exception { + String p = "PR278496_4"; + // Setting this ensures types are forced out when demoted - we are not at the mercy of weak reference GC + TypeMap.useExpendableMap=false; + initialiseProject(p); + configureNonStandardCompileOptions(p, "-Xset:typeDemotion=true,typeDemotionDebug=true"); + build(p); + checkWasFullBuild(); + alter(p,"inc1"); + build(p); + checkWasntFullBuild(); + + AjdeCoreBuildManager buildManager = getCompilerForProjectWithName(p).getBuildManager(); + AjBuildManager ajBuildManager = buildManager.getAjBuildManager(); + World w = ajBuildManager.getWorld(); + + // Confirm demoted: + assertNotInTypeMap(w,"Lcom/foo/Bar;"); + + ReferenceType rt =null; + ReferenceTypeDelegate delegate = null; + rt = w.resolveToReferenceType("com.foo.Bar"); + delegate = rt.getDelegate(); + // Should have been demoted to a CTSD + assertEquals(0,delegate.getAnnotations().length); + assertEquals(0,delegate.getAnnotationTypes().length); + assertEquals(0,delegate.getDeclaredInterfaces().length); + assertEquals("java.lang.Object",delegate.getSuperclass().toString()); + assertNull(delegate.getRetentionPolicy()); + assertFalse(delegate.isInterface()); + assertTrue(delegate.isClass()); + assertFalse(delegate.isEnum()); + // assertFalse(rtd.isWeavable()); + // try { + // assertTrue(delegate.hasBeenWoven()); + // fail("expected exception"); + // } catch (IllegalStateException ise) { + // // success + // } + + // Confirm demoted: + assertNull(w.getTypeMap().get("Lcom/foo/Color;")); + rt = w.resolveToReferenceType("com.foo.Color"); + delegate = rt.getDelegate(); + assertFalse(delegate.isInterface()); + assertTrue(delegate.isEnum()); + + // Aspects are never demoted and so never have a per clause, declares or type mungers + assertNull(delegate.getPerClause()); + assertEquals(0,delegate.getDeclares().size()); + assertEquals(0,delegate.getTypeMungers().size()); + assertFalse(delegate.isAspect()); + assertEquals(0,delegate.getPrivilegedAccesses().size()); + assertEquals(0,delegate.getDeclaredPointcuts().length); + assertFalse(delegate.isAnnotationStyleAspect()); + assertFalse(delegate.isAnnotationWithRuntimeRetention()); + + // Confirm demoted: + assertNull(w.getTypeMap().get("Lcom/foo/Extender;")); + rt = w.resolveToReferenceType("com.foo.Extender"); + delegate = rt.getDelegate(); + assertEquals("[com.foo.Marker]",stringify(delegate.getDeclaredInterfaces())); + assertEquals("com.foo.Super",delegate.getSuperclass().toString()); + + // this has one fixed annotation that is a well known one + // Confirm demoted: + ResolvedType annoType = w.getTypeMap().get("Lcom/foo/Anno;"); + assertNull(annoType); + rt = w.resolveToReferenceType("com.foo.Anno"); + delegate = rt.getDelegate(); + assertEquals("[Anno[Ljava/lang/annotation/Retention; rVis value=E(Ljava/lang/annotation/RetentionPolicy; RUNTIME)]]",stringify(delegate.getAnnotations())); + assertEquals("[java.lang.annotation.Retention]",stringify(delegate.getAnnotationTypes())); + assertTrue(delegate.isAnnotationWithRuntimeRetention()); + assertEquals("RUNTIME",delegate.getRetentionPolicy()); + + // this has a bunch of well known ones + rt = w.resolveToReferenceType("com.foo.Anno2"); + delegate = rt.getDelegate(); + assertEquals("[Anno[Ljava/lang/Deprecated; rVis] Anno[Ljava/lang/annotation/Inherited; rVis] Anno[Ljava/lang/annotation/Retention; rVis value=E(Ljava/lang/annotation/RetentionPolicy; CLASS)]]", + stringify(delegate.getAnnotations())); + assertEquals("[java.lang.Deprecated java.lang.annotation.Inherited java.lang.annotation.Retention]",stringify(delegate.getAnnotationTypes())); + assertFalse(delegate.isAnnotationWithRuntimeRetention()); + assertEquals("CLASS",delegate.getRetentionPolicy()); + assertTrue(delegate.hasAnnotation(UnresolvedType.forSignature("Ljava/lang/annotation/Inherited;"))); + assertTrue(delegate.hasAnnotation(UnresolvedType.forSignature("Ljava/lang/annotation/Retention;"))); + assertFalse(delegate.hasAnnotation(UnresolvedType.forSignature("Lcom/foo/Anno;"))); + + // this has a well known one and a non-well known one + rt = w.resolveToReferenceType("com.foo.Anno3"); + delegate = rt.getDelegate(); + System.out.println(stringify(delegate.getAnnotations())); + assertEquals("[Anno[Lcom/foo/Anno; rVis] Anno[Ljava/lang/annotation/Retention; rVis value=E(Ljava/lang/annotation/RetentionPolicy; SOURCE)]]",stringify(delegate.getAnnotations())); + assertEquals("[com.foo.Anno java.lang.annotation.Retention]",stringify(delegate.getAnnotationTypes())); + assertFalse(delegate.isAnnotationWithRuntimeRetention()); + assertEquals("SOURCE",delegate.getRetentionPolicy()); + + // this has two non-well known ones + rt = w.resolveToReferenceType("com.foo.Anno4"); + delegate = rt.getDelegate(); + assertEquals("[Anno[Lcom/foo/Anno2; rInvis] Anno[Lcom/foo/Anno; rVis]]",stringify(delegate.getAnnotations())); + assertEquals("[com.foo.Anno2 com.foo.Anno]",stringify(delegate.getAnnotationTypes())); + assertFalse(delegate.isAnnotationWithRuntimeRetention()); + assertNull(delegate.getRetentionPolicy()); + assertTrue(delegate.hasAnnotation(UnresolvedType.forSignature("Lcom/foo/Anno;"))); + + + rt = w.resolveToReferenceType("com.foo.Colored"); + delegate = rt.getDelegate(); + AnnotationAJ annotation = delegate.getAnnotations()[0]; // should be ColorAnno(c=Color.G) + assertTrue(annotation.hasNamedValue("c")); + assertFalse(annotation.hasNamedValue("value")); + assertTrue(annotation.hasNameValuePair("c","Lcom/foo/Color;G")); + assertFalse(annotation.hasNameValuePair("c","Lcom/foo/Color;B")); + assertFalse(annotation.hasNameValuePair("d","xxx")); + assertNull(annotation.getStringFormOfValue("d")); + assertEquals("Lcom/foo/Color;G",annotation.getStringFormOfValue("c")); + assertEquals(0,annotation.getTargets().size()); + assertTrue(delegate.isCacheable()); + + assertFalse(delegate.isExposedToWeaver()); + + // assertEquals(w.resolve(UnresolvedType.forSignature("Lcom/foo/Colored;")),delegate.getResolvedTypeX()); + + assertEquals("com/foo/Colored.java",delegate.getSourcefilename()); + + // Anno5 has an @Target annotation + rt = w.resolveToReferenceType("com.foo.Anno5"); + delegate = rt.getDelegate(); + annotation = delegate.getAnnotations()[0]; // should be @Target(TYPE,FIELD) + Set ss = annotation.getTargets(); + assertEquals(2,ss.size()); + assertTrue(ss.contains("FIELD")); + assertTrue(ss.contains("TYPE")); + // AnnotationTargetKind[] kinds = delegate.getAnnotationTargetKinds(); + // assertEquals("FIELD",kinds[0].getName()); + // assertEquals("TYPE",kinds[1].getName()); + + rt = w.resolveToReferenceType("com.foo.Inners$Inner"); + delegate = rt.getDelegate(); + assertTrue(delegate.isNested()); + assertEquals("com.foo.Inners",delegate.getOuterClass().getName()); + + rt = w.resolveToReferenceType("com.foo.Inners$1"); + delegate = rt.getDelegate(); + assertTrue(delegate.isAnonymous()); + assertTrue(delegate.isNested()); + + // delegate = w.resolveToReferenceType("com.foo.Anno6").getDelegate(); + // kinds = delegate.getAnnotationTargetKinds(); + // assertEquals(6,kinds.length); + // String s = stringify(kinds); + // assertTrue(s.contains("ANNOTATION_TYPE")); + // assertTrue(s.contains("LOCAL_VARIABLE")); + // assertTrue(s.contains("METHOD")); + // assertTrue(s.contains("PARAMETER")); + // assertTrue(s.contains("PACKAGE")); + // assertTrue(s.contains("CONSTRUCTOR")); + + delegate = w.resolveToReferenceType("com.foo.Marker").getDelegate(); + assertTrue(delegate.isInterface()); + + } + + private void assertNotInTypeMap(World w, String string) { + assertNull(w.getTypeMap().get(string)); + } + + private String stringify(Object[] arr) { + StringBuilder s = new StringBuilder(); + for (int i=0;i