Skip to main content
Jump to: navigation, search

Difference between revisions of "Object Teams Quick-Start"

(Part one of this page)
 
(Part 2 yet without the image)
Line 62: Line 62:
 
callin ends ...</pre></li>
 
callin ends ...</pre></li>
 
</ol>
 
</ol>
 +
=OT/Equinox Hello World Example=
 +
 +
This example shows a simple adaptation of an existing Eclipse plug-in using the aspect binding concept of OT/Equinox.
 +
<ol>
 +
<li>Start the New Project Wizard, select "''Object Teams Plug-in Project''"
 +
<ol>
 +
  <li>Enter project name and select "''Eclipse version 3.x''" (matching your Eclipse version) as target platform, click "Next" </li>
 +
  <li>Uncheck all of the plug-in options and choose not to create an RCP application</li>
 +
  <li>Click "Finish" </li>
 +
</ol>
 +
<li>Configure the plug-in with the Plug-in Manifest Editor
 +
<ol>
 +
  <li>'''Overview''' tab: check "''Activate this plug-in ...''" and "''This plug-in is a singleton''" </li>
 +
  <li>'''Dependencies''' tab: add <code>org.eclipse.ui.workbench</code> and <code>org.objectteams.otequinox</code> as required plug-ins </li>
 +
  <li>'''Extensions''' tab: add <code>org.objectteams.otequinox.aspectBindings</code> extension
 +
  <ol>
 +
    <li>For the '''basePlugin''' entry, enter the plug-in id <code>org.eclipse.ui.workbench</code></li>
 +
    <li>For the '''team''' entry, enter a class name of <code>aspect.MyTeam</code> and set activation to "<code>ALL_THREADS</code>"</li>
 +
    <li>Save </li>
 +
  </ol></li>
 +
</ol>
 +
<li>Create a new '''Team''' class <code>aspect.MyTeam</code> (e.g., using the New Team wizard) with the following content:
 +
<source lang="otj">package aspect;
 +
 +
import base org.eclipse.ui.internal.about.AboutItem;
 +
 +
@SuppressWarnings("restriction")
 +
public team class MyTeam {
 +
    protected class MyRole playedBy AboutItem {
 +
        callin String getText() {
 +
            StringBuffer sb = new StringBuffer();
 +
            sb.append("########\n");
 +
            sb.append("## Test ##\n");
 +
            sb.append("########\n");
 +
            sb.append(base.getText());
 +
            return sb.toString();
 +
        }
 +
        getText <- replace getText;
 +
    }
 +
}</source></li>
 +
<li>Create a run configuration of type "''Eclipse Application''"
 +
<ol>
 +
  <li>On the '''Main''' tab, check "''Enable OT/Equinox''" </li>
 +
  <li>(''optional'') On the Plug-ins tab, switch to "''plug-ins selected below only''", deselect all, manually select the OT aspect plugin you created and click "''Add Required Plug-ins''" </li>
 +
</ol>
 +
<li>Run this configuration. In the started runtime workbench open the ''Help->About Eclipse SDK'' dialog. It should show the additional text from the callin method like this:
 +
</li>
 +
</ol>
 +
  
 
[[Category:Object Teams]]
 
[[Category:Object Teams]]

Revision as of 12:37, 26 February 2010

This step-by-step Quick-Start guide should get you started with Object Teams in less than 15 minutes.

Installation of the OTDT (development environment)

Note that existing releases are still served from www.objectteams.org until we have clearance to upload to eclipse.org

  1. Prerequisites: Eclipse running on a JRE 1.5 or greater
    1. Tip: set -Xmx512m in eclipse.ini
  2. Fire up Eclipse and add our update site
  3. Select "Object Teams Development Tooling", install it and restart
    1. Ensure that Java compiler compliance level is set to 1.5 or greater
    2. Tip: Enable "Java Type Indicator" under Preferences->General->Appearance->Label Decorations

OT/J Hello World Example

Note: throughout this site links like OTJLD §0 refer to matching paragraphs in the OT/J Language Definition.

This most simple example of an OT/J Application demonstrates how easy it is to intercept a (private!) base method and adapt its behavior in a separate role class. The example makes use of role binding (OTJLD §2, replace callin (OTJLD §4), decapsulation (OTJLD §4.6) and unanticipated team activation (OTJLD §5.5).

  1. Start the New Project Wizard, select "Object Teams Project" and proceed as usual
  2. Create a new class base.Main with the following content:
    package base;
    public class Main {
        public static void main(String[] args) {
            sayHello();
        }
        private static void sayHello() {
            System.out.println("Hello World!");
        }
    }
  3. Create a run configuration of type "Java Application"
    1. Select base.Main as the main class
  4. Run this configuration. The console output should look like:
    Hello World!
  5. Create a new Team class aspect.MyTeam (e.g., using the New Team wizard) with the following content:
    package aspect;
     
    import base base.Main;
     
    public team class MyTeam {
        protected class MyRole playedBy Main {
            callin static void sayMore() {
                System.out.println("callin begins ...");
                base.sayMore();
                System.out.println("callin ends ...");
            }
            sayMore <- replace sayHello;
        }
    }
  6. Open the previously created run configuration
    1. On the JRE tab, make sure that "Enable OTRE" is checked (is default for an Object Teams Project)
    2. On the Team Activation tab, add aspect.MyTeam
  7. Run the configuration again. The console output should now look like:
    callin begins ...
    Hello World!
    callin ends ...

OT/Equinox Hello World Example

This example shows a simple adaptation of an existing Eclipse plug-in using the aspect binding concept of OT/Equinox.

  1. Start the New Project Wizard, select "Object Teams Plug-in Project"
    1. Enter project name and select "Eclipse version 3.x" (matching your Eclipse version) as target platform, click "Next"
    2. Uncheck all of the plug-in options and choose not to create an RCP application
    3. Click "Finish"
  2. Configure the plug-in with the Plug-in Manifest Editor
    1. Overview tab: check "Activate this plug-in ..." and "This plug-in is a singleton"
    2. Dependencies tab: add org.eclipse.ui.workbench and org.objectteams.otequinox as required plug-ins
    3. Extensions tab: add org.objectteams.otequinox.aspectBindings extension
      1. For the basePlugin entry, enter the plug-in id org.eclipse.ui.workbench
      2. For the team entry, enter a class name of aspect.MyTeam and set activation to "ALL_THREADS"
      3. Save
  3. Create a new Team class aspect.MyTeam (e.g., using the New Team wizard) with the following content:
    package aspect;
     
    import base org.eclipse.ui.internal.about.AboutItem;
     
    @SuppressWarnings("restriction")
    public team class MyTeam {
        protected class MyRole playedBy AboutItem {
            callin String getText() {
                StringBuffer sb = new StringBuffer();
                sb.append("########\n");
                sb.append("## Test ##\n");
                sb.append("########\n");
                sb.append(base.getText());
                return sb.toString();
            }
            getText <- replace getText;
        }
    }
  4. Create a run configuration of type "Eclipse Application"
    1. On the Main tab, check "Enable OT/Equinox"
    2. (optional) On the Plug-ins tab, switch to "plug-ins selected below only", deselect all, manually select the OT aspect plugin you created and click "Add Required Plug-ins"
  5. Run this configuration. In the started runtime workbench open the Help->About Eclipse SDK dialog. It should show the additional text from the callin method like this:

Back to the top