close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 2 and Version 3 of JCopManual


Ignore:
Timestamp:
01/12/2011 04:37:56 PM (9 years ago)
Author:
malte.appeltauer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • JCopManual

    v2 v3  
    120120
    121121{{{jcop}}} accepts Java bytecode files with the {{{class}}} extension.
     122
     123== Compiler API ==
     124The compiler can be executed programatically by invoking the compile method of jcop.compiler.JCopCompiler
     125in the jcop.jar archive. All compiler arguments — including the name of the class to be
     126compiled — must be passed to the String[] argument of this compile method. Note that
     127key-value pairs are to separate elements of this string array. For example, the following
     128command...
     129
     130  {{{
     131  jcopc  -sourcepath  D:\example\src  -d  D:\example\bin  MyClass
     132  }}}
     133
     134... can be executed calling:
     135  {{{
     136  String[]  args  =
     137    new  String[]  {"-sourcepath",  "D:\example\src",  "-d",  "D:\example\bin",  "MyClass"};
     138  jcop.compiler.JCopCompiler.compile(args);
     139  }}}
     140
     141== Restrictions and Limitations ==
     142
     143=== Restrictions to Plain Java Programs ===
     144In general, JCop is a superset of Java, thus any Java programs should be compilable and
     145executable using JCop. However, the following limitations need to be considered for plain
     146Java source code.
     147
     148==== Primitives and Boxing in Java 5 ====
     149The underlying JastAddJ compiler is not able to perform type boxing in combination
     150with generics. The following listing describes such an scenario.
     151
     152  {{{
     153  Vector<Byte>  bytecode  =  new  Vector<Byte>();
     154  for(byte  bc  :  bytecode)  //  this  will  compile  but  not  run
     155    ...
     156  }}}
     157
     158The above code will compile, however, launching will cause a bytecode verification
     159error similar to the following:
     160
     161  {{{
     162  Exception  in  thread  "main"  java.lang.VerifyError:
     163  (class:  Test,  method:  <init>  signature:  ()V)
     164  Register  2  contains  wrong  type
     165  Could  not  find  the  main  class:  Test.    Program  will  exit.
     166  }}}
     167
     168As a workaround, we suggest to consistently use class types instead of primitives in
     169such cases.
     170
     171  {{{
     172  Vector<Byte>  bytecode  =  new  Vector<Byte>();for(Byte  bc  :  bytecode)
     173  ... 
     174  }}}
     175
     176==== Reserved Keywords ====
     177In addition to Java’s keywords, the following keywords are introduced by JCop and
     178cannot be used as identifiers. This might require identifier renaming in existing Java
     179programs.
     180
     181{{{after, before, call, context, layer, on, proceed, subject, with, without, when, ".." }}}
     182
     183
     184
     185=== Limitations of the JCop Compiler ===
     186
     187==== Default Package ====
     188Layer declarations in classes of the default package are not supported, thus those
     189classes must contain a package declaration. However, layer import and (de-)activation
     190statements can be used in the default package.
     191
     192==== Nested Class Support ====
     193Layers cannot be declared and activated within nested and anonymous classes, yet.
     194
     195  {{{
     196  public  class  MyClass  {
     197    class  MyInnerClass  {
     198      void  m()  {  ...  }
     199      layer  MyLayer{  ...  }  //  this  won’t  work
     200    }
     201    void  myMethod()  {
     202      new  MyNestedClass()  {
     203      layer  MyLayer  {  ...  }  //  this  won’t  work
     204    }
     205  }
     206  }}}
     207
     208==== Context Object Methods ====
     209Due to implementation details, context objects must not contain methods of the
     210folloing signature:
     211 * {{{void initLayers()}}}
     212 * {{{boolean isActiveFor(String)}}}
     213 * {{{String jcop_name()}}}
     214{{{jcop}}} accepts Java bytecode files with the {{{class}}} extension.