@@ -84,7 +84,7 @@ import org.aspectj.apache.bcel.generic.annotation.AnnotationGen; | |||
* existing java class (file). | |||
* | |||
* @see JavaClass | |||
* @version $Id: ClassGen.java,v 1.7 2006/03/16 11:01:53 aclement Exp $ | |||
* @version $Id: ClassGen.java,v 1.8 2006/08/22 07:34:50 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* | |||
* Upgraded, Andy Clement 9th Mar 06 - calculates SUID | |||
@@ -567,9 +567,16 @@ public class ClassGen extends AccessFlags implements Cloneable { | |||
classmods|=(isPublic()?Constants.ACC_PUBLIC:0); | |||
classmods|=(isFinal()?Constants.ACC_FINAL:0); | |||
classmods|=(isInterface()?Constants.ACC_INTERFACE:0); | |||
if (isInterface() && isAbstract()) { // remove abstract if we have it but have no methods | |||
if (methods.length>0) classmods|=Constants.ACC_ABSTRACT; | |||
if (isAbstract()) { | |||
// if an interface then abstract is only set if it has methods | |||
if (isInterface()) { | |||
if (methods.length>0) classmods|=Constants.ACC_ABSTRACT; | |||
} else { | |||
classmods|=Constants.ACC_ABSTRACT; | |||
} | |||
} | |||
dos.writeInt(classmods); | |||
// 3. ordered list of interfaces |
@@ -0,0 +1,7 @@ | |||
package com.testware.ejb.common; | |||
import java.io.Serializable; | |||
// ATest: static final long serialVersionUID = -7843094187906014027L; | |||
public abstract class ATest implements Serializable{ | |||
abstract void getid(); | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.testware.ejb.common; | |||
// Test: static final long serialVersionUID = 2486685186022095906L; | |||
public class Test extends ATest { | |||
void getid() { | |||
} | |||
} |
@@ -0,0 +1,57 @@ | |||
import java.io.Serializable; | |||
import java.lang.reflect.Field; | |||
import com.testware.ejb.common.*; | |||
// when in a package, AJ worked out: | |||
//Test SerialVersionUID is 8593816477552447372 | |||
//ATest SerialVersionUID is -5439116922937363745 | |||
// atest serialveruid: -5439116922937363745L | |||
// test serialveruid: 8593816477552447372L | |||
//ATest: static final long serialVersionUID = 9091955077097551023L; | |||
//Test: static final long serialVersionUID = 1583992244946994789L; | |||
//ATest SerialVersionUID is 9091955077097551023 | |||
//Test SerialVersionUID is 1583992244946994789 | |||
// | |||
aspect X { | |||
before(): staticinitialization(*Test) {} | |||
} | |||
public class TwoTypes implements Serializable { | |||
public static void main(String[] args) { | |||
try { | |||
Test c = (Test)Test.class.newInstance(); | |||
Field f = Test.class.getDeclaredField("serialVersionUID"); | |||
f.setAccessible(true); | |||
long l = f.getLong(c); | |||
System.err.println("Test SerialVersionUID is "+l); | |||
// ATest b = (ATest)ATest.class.newInstance(); | |||
f = ATest.class.getDeclaredField("serialVersionUID"); | |||
f.setAccessible(true); | |||
l = f.getLong(Test.class.getSuperclass()); | |||
System.err.println("ATest SerialVersionUID is "+l); | |||
} catch (Exception e) { | |||
System.err.println("Problem: "+e.toString()); | |||
e.printStackTrace(); | |||
} | |||
} | |||
// | |||
// public int anInt; | |||
// | |||
// public static boolean aBoolean = false; | |||
// | |||
// public long foo = 376; | |||
// | |||
// public void m() {} | |||
// public int compareTo(Object o) { return 0;} | |||
// public String m2(boolean b,long l, String s) { return "";} | |||
// | |||
// public static transient short fo2 = 3; | |||
} |
@@ -23,6 +23,8 @@ public class SerialVersionUIDTests extends XMLBasedAjcTestCase { | |||
public void testTheBasicsWithLint() { runTest("basic - lint"); } | |||
public void testHorrible() { runTest("horrible"); } | |||
public void testAbstractClass() { runTest("abstract class");} | |||
// | |||
public static Test suite() { | |||
return XMLBasedAjcTestCase.loadSuite(SerialVersionUIDTests.class); |
@@ -34,4 +34,18 @@ | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="features151/serialveruid" title="abstract class"> | |||
<compile files="TwoTypes.java,Test.java,ATest.java" options="-1.5 -XaddSerialVersionUID -Xlint:warning"> | |||
<message kind="warning" text="calculated SerialVersionUID for type TwoTypes"/> | |||
<message kind="warning" text="calculated SerialVersionUID for type com.testware.ejb.common.Test to be -1674849842374764518L"/> | |||
<message kind="warning" text="calculated SerialVersionUID for type com.testware.ejb.common.ATest to be -7300724421810308152L"/> | |||
</compile> | |||
<run class="TwoTypes"> | |||
<stderr> | |||
<line text="Test SerialVersionUID is -1674849842374764518"/> | |||
<line text="ATest SerialVersionUID is -7300724421810308152"/> | |||
</stderr> | |||
</run> | |||
</ajc-test> | |||
</suite> |