Enabling assertions and also demonstrating that fields can be moved up to one level in the class hierarchy
authorJaroslav Tulach <jtulach@netbeans.org>
Fri, 29 Aug 2008 15:08:04 +0200
changeset 27734370a93db6b
parent 276 b4404001f0e2
child 278 c15f77497f6a
Enabling assertions and also demonstrating that fields can be moved up to one level in the class hierarchy
samples/insertsuperclass/build.xml
samples/insertsuperclass/nbproject/project.xml
samples/insertsuperclass/src-api1.0/api/HelloFieldClass.java
samples/insertsuperclass/src-api2.0/api/HelloFieldClass.java
samples/insertsuperclass/src-api2.0/api/SimpleHelloFieldClass.java
samples/insertsuperclass/src-impl/impl/Main.java
     1.1 --- a/samples/insertsuperclass/build.xml	Sun Aug 24 13:39:55 2008 +0200
     1.2 +++ b/samples/insertsuperclass/build.xml	Fri Aug 29 15:08:04 2008 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4      <target name="clean">
     1.5          <delete dir="build"/>
     1.6      </target>
     1.7 -    <target name="test"/>
     1.8 +    <target name="test" depends="run"/>
     1.9      
    1.10      <target name="compile" depends="build"/>
    1.11      <target name="build">
    1.12 @@ -37,8 +37,9 @@
    1.13      <target name="-run-one">
    1.14          <fail message="You need to specify API version number" unless="version"/>
    1.15          <java classpath="build/${version}/classes:build/impl/classes" classname="impl.Main"
    1.16 -            failonerror="true"
    1.17 -        />
    1.18 +            failonerror="true">
    1.19 +            <jvmarg value="-ea"/>
    1.20 +        </java>
    1.21      </target>
    1.22      
    1.23      <target name="-build-one">
    1.24 @@ -51,6 +52,7 @@
    1.25              destdir="build/${version}/classes" 
    1.26              source="1.5" target="1.5"
    1.27              classpath="${cp}"
    1.28 +            debug="true"
    1.29          />
    1.30      </target>
    1.31  </project>
     2.1 --- a/samples/insertsuperclass/nbproject/project.xml	Sun Aug 24 13:39:55 2008 +0200
     2.2 +++ b/samples/insertsuperclass/nbproject/project.xml	Fri Aug 29 15:08:04 2008 +0200
     2.3 @@ -22,9 +22,15 @@
     2.4                      <encoding>UTF-8</encoding>
     2.5                  </source-folder>
     2.6                  <source-folder>
     2.7 -                    <label>impl</label>
     2.8 +                    <label>src-api2.0</label>
     2.9                      <type>java</type>
    2.10 -                    <location>impl</location>
    2.11 +                    <location>src-api2.0</location>
    2.12 +                    <encoding>UTF-8</encoding>
    2.13 +                </source-folder>
    2.14 +                <source-folder>
    2.15 +                    <label>src-impl</label>
    2.16 +                    <type>java</type>
    2.17 +                    <location>src-impl</location>
    2.18                      <encoding>UTF-8</encoding>
    2.19                  </source-folder>
    2.20              </folders>
    2.21 @@ -53,8 +59,12 @@
    2.22                          <location>src-api1.0</location>
    2.23                      </source-folder>
    2.24                      <source-folder style="packages">
    2.25 -                        <label>impl</label>
    2.26 -                        <location>impl</location>
    2.27 +                        <label>src-api2.0</label>
    2.28 +                        <location>src-api2.0</location>
    2.29 +                    </source-folder>
    2.30 +                    <source-folder style="packages">
    2.31 +                        <label>src-impl</label>
    2.32 +                        <location>src-impl</location>
    2.33                      </source-folder>
    2.34                      <source-file>
    2.35                          <location>build.xml</location>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/samples/insertsuperclass/src-api1.0/api/HelloFieldClass.java	Fri Aug 29 15:08:04 2008 +0200
     3.3 @@ -0,0 +1,7 @@
     3.4 +package api;
     3.5 +
     3.6 +public class HelloFieldClass {
     3.7 +// BEGIN: design.insert.field.superclass
     3.8 +    public String field = "Hello";
     3.9 +// END: design.insert.field.superclass
    3.10 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/samples/insertsuperclass/src-api2.0/api/HelloFieldClass.java	Fri Aug 29 15:08:04 2008 +0200
     4.3 @@ -0,0 +1,6 @@
     4.4 +package api;
     4.5 +
     4.6 +// BEGIN: design.insert.field.superclass2
     4.7 +public class HelloFieldClass extends SimpleHelloFieldClass {
     4.8 +}
     4.9 +// END: design.insert.field.superclass2
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/samples/insertsuperclass/src-api2.0/api/SimpleHelloFieldClass.java	Fri Aug 29 15:08:04 2008 +0200
     5.3 @@ -0,0 +1,7 @@
     5.4 +package api;
     5.5 +
     5.6 +// BEGIN: design.insert.field.superclass1
     5.7 +public abstract class SimpleHelloFieldClass {
     5.8 +    public String field = "Hello";
     5.9 +// FINISH: design.insert.field.superclass1
    5.10 +}
     6.1 --- a/samples/insertsuperclass/src-impl/impl/Main.java	Sun Aug 24 13:39:55 2008 +0200
     6.2 +++ b/samples/insertsuperclass/src-impl/impl/Main.java	Fri Aug 29 15:08:04 2008 +0200
     6.3 @@ -2,6 +2,7 @@
     6.4  package impl;
     6.5  
     6.6  import api.HelloClass;
     6.7 +import api.HelloFieldClass;
     6.8  import api.HelloInterface;
     6.9  
    6.10  /**
    6.11 @@ -10,15 +11,24 @@
    6.12   */
    6.13  public class Main {
    6.14      public static void main(String[] args) throws Exception {
    6.15 +        boolean assertionsOn = false;
    6.16 +        assert assertionsOn = true;
    6.17 +        if (!assertionsOn) {
    6.18 +            throw new IllegalStateException("Enable assertions!");
    6.19 +        }
    6.20 +        
    6.21          HelloClass clazz = new ImplClass();
    6.22          assert "Hello Unknown!".equals(clazz.sayHello());
    6.23          assert "Hello Jaroslav!".equals(clazz.sayHelloTo("Jaroslav"));
    6.24 +        System.err.println("Who defines sayHello(): " + clazz.getClass().getSuperclass().getMethod("sayHello"));
    6.25  
    6.26          HelloInterface iface = new ImplInterface();
    6.27          assert "Hello Unknown!".equals(iface.sayHello());
    6.28          assert "Hello Jaroslav!".equals(iface.sayHelloTo("Jaroslav"));
    6.29 +        System.err.println("Who defines sayHello(): " + iface.getClass().getInterfaces()[0].getMethod("sayHello"));
    6.30          
    6.31 -        System.err.println("Who defines sayHello(): " + clazz.getClass().getSuperclass().getMethod("sayHello"));
    6.32 -        System.err.println("Who defines sayHello(): " + iface.getClass().getInterfaces()[0].getMethod("sayHello"));
    6.33 +        HelloFieldClass fieldClass = new HelloFieldClass();
    6.34 +        assert "Hello".equals(fieldClass.field);
    6.35 +        System.err.println("Who defines field: " + fieldClass.getClass().getField("field"));
    6.36      }
    6.37  }