Jump to: navigation, search

Difference between revisions of "Type inference for APDT"

(Participants)
(Abstract)
 
(23 intermediate revisions by 2 users not shown)
Line 9: Line 9:
  
 
The type inference could be also used to improve APDT UI by providing aspect type information in the editor.
 
The type inference could be also used to improve APDT UI by providing aspect type information in the editor.
 +
 +
'''Update: the last release of APDT takes advantage of this work, please check it out at [http://apdt.googlecode.com]'''
  
 
== Participants ==
 
== Participants ==
Line 15: Line 17:
 
* Mentor: Michael Spector
 
* Mentor: Michael Spector
  
== Source Location ==
+
== Getting the source ==
 +
 
 +
The source is available on [https://apdt.googlecode.com/svn/trunk/ APDT SVN repository].
 +
APDT contains many eclipse plugins and the runtime library for PHP.
 +
{| class="wikitable"
 +
|-
 +
! Project
 +
! Description
 +
|-
 +
| PHPAspect
 +
| Runtime support for PHPAspect: joinpoint dispatcher, aspect reflection API.
 +
|-
 +
| PHPAspectTest
 +
| Test for PHPAspect runtime library.
 +
|-
 +
| PHPAspectTest
 +
| Test for PHPAspect runtime library.
 +
|-
 +
| org.phpaspect.apdt
 +
| APDT main plugin.
 +
|-
 +
| org.phpaspect.apdt.core
 +
| Core plugin.
 +
|-
 +
| org.phpaspect.apdt.debug.core
 +
| PHPAspect core launcher.
 +
|-
 +
| org.phpaspect.apdt.debug.ui
 +
| PHPAspect UI launcher.
 +
|-
 +
| org.phpaspect.apdt.feature
 +
| APDT feature.
 +
|-
 +
| org.phpaspect.apdt.help
 +
| APDT help (empty for now).
 +
|-
 +
| org.phpaspect.apdt.sdk-feature
 +
| APDT SDK feature.
 +
|-
 +
| org.phpaspect.apdt.ui
 +
| APDT UI features.
 +
|-
 +
| org.phpaspect.apdt.updatesite
 +
| APDT Update site.
 +
|-
 +
| org.phpaspect.apdt.documentation
 +
| PHPAspect documentation
 +
|-
 +
| org.phpaspect.weaver
 +
| PHPAspect weaver
 +
|-
 +
| org.phpaspect.weaver.test
 +
| PHPAspect weaver test cases
 +
|}
 +
 
 +
== Release ==
 +
APDT depends on PDT 2.0 extension points and APIs.
 +
The release will be made the same day than PDT 2.0 release.
 +
APDT is a great showcase for people who wants to contribute PDT 2.0 extension points and use PDT 2.0 API.
 +
 
 +
== Hello World ==
 +
Let's consider a simple piece of PHP code:
 +
<source lang="php">
 +
<?php
 +
class Foo{
 +
  public function fuebar(){
 +
    return true;
 +
  }
 +
}
 +
 
 +
class Bar{
 +
  public function fuebar(){
 +
    return true;
 +
  }
 +
}
 +
 
 +
$foo = new Foo();
 +
$bar = new Bar();
 +
$foo->fuebar();
 +
$bar->fuebar();
 +
$unknown->fuebar();
 +
?>
 +
</source>
 +
And the following joinpoint (all method invocation of the ''fuebar()'' method in an instance of ''Foo''):
 +
<source lang="java">call(Foo->fuebar())</source>
 +
Before this summer, when you were writing a such joinpoint, PHPAspect was testing the type of ''$foo'', ''$bar'' and ''$unknown'' to check if the joinpoint has been matched and then execute the associated code-advince.
 +
By using DLTK/PDT type inference engine, APDT knows that ''$foo'' is an instance of Foo therefore the joinpoint has been statically matched. ''$bar'' isn't an instance of Foo, this node in the PHP Program is left unchanged. The type of ''$unknown'' is unknown, APDT adds a runtime assertion: the type of $unknown is tested at runtime to check for code-advice execution.
 +
The weaved source code is the following:
 +
<source lang="php">
 +
$foo = new Foo();
 +
$bar = new Bar();
 +
PHPAspect_dispatch(array(2,),new JoinPointImpl(JoinPoint::METHOD_EXECUTION,$foo,new ReflectionMethod($foo,'fuebar'),array(),__FILE__,__LINE__),array(2=>true,));
 +
$bar->fuebar();
 +
PHPAspect_dispatch(array(2,),new JoinPointImpl(JoinPoint::METHOD_EXECUTION,$unknown,new ReflectionMethod($unknown,'fuebar'),array(),__FILE__,__LINE__),
 +
  array(2=>(PHPAspect_match($unknown,'Foo')),));
 +
</source>
 +
Above, the call of ''$foo->fueaber()'' is matched, ''$bar->fuebar()'' is unchanged and ''$unknown->fuebar()'' has the runtime assertion '''''PHPAspect_match($unknown,'Foo')'''''.
 +
== Which JoinPoints are using DLTK/PDT Type inference ? ==
 +
The following joinpoints are taking advantage of APDT type inference:
 +
* Method invocation
 +
* Static method invocation
 +
* Object instance creation.
 +
* Object destruction.
 +
* Executing Object.
 +
* Target Object.
 +
* Declaring Type.
  
__ please enter __
+
== APDT PHP Runtime support ==
 +
=== Aspects are first class entities during the execution ===
 +
At compile-time, APDT generates generate a class for each aspect.
 +
These classes are singleton an implements the Aspect interface.
 +
Code advices are method specialized using annotations. For runtime support of annotations, PHPAspect uses [http://code.google.com/p/addendum/ addendum].
 +
<source lang="php">
 +
class Logging implements Aspect{
  
== Features ==
+
private static $instance = null;
 +
 +
private function __construct(){}
 +
 +
public static function getInstance(){
 +
if(self::$instance == null){
 +
self::$instance = new Logging();
 +
}
 +
return self::$instance;
 +
}
  
* Improved code completion in the APDT editor.
+
      /**
* Quick assist markers in the APDT editor, like AJDT provides (semantic analysis).
+
* @After
 +
* @Id(10)
 +
*/
 +
public function codeAdvice1(JoinPoint $thisJoinPoint){
 +
printf("%s->%s()\n",
 +
$thisJoinPoint->getTarget()->getDeclaringClass()->getName(),
 +
$thisJoinPoint->getTarget()->getName());
 +
}
 +
}
 +
</source>
  
 
== Community Proposals ==
 
== Community Proposals ==

Latest revision as of 19:23, 24 May 2009

Abstract

The Aspect PHP Development Tools (APDT) project provides Eclipse platform based tool support for AOSD with PHPAspect. Our goal is to deliver a user experience that is consistent with the PHP Development Tools (PDT) when working with PHPAspect projects and resources. This plugin provides an integration layer between the PHPAspect weaver, runtime and Eclipse/PDT extension points.

Due to the highly dynamic nature of PHP, most of PHPAspect joinpoints can't be determined statically: PHPAspect weaves hooks in the source code in order to perform type checking at runtime. When a project is woven, a significant amount of hooks can be inserted in the source even though it be can statically analyzed that none of these hooks will trigger a code-advice: this is where type inference comes in.

APDT and PDT have both an integration layer with DLTK which as an experimental type inference framework used to improve code analysis on dynamic languages.

The type inference could be also used to improve APDT UI by providing aspect type information in the editor.

Update: the last release of APDT takes advantage of this work, please check it out at [1]

Participants

  • Student: William Candillon
  • Mentor: Michael Spector

Getting the source

The source is available on APDT SVN repository. APDT contains many eclipse plugins and the runtime library for PHP.

Project Description
PHPAspect Runtime support for PHPAspect: joinpoint dispatcher, aspect reflection API.
PHPAspectTest Test for PHPAspect runtime library.
PHPAspectTest Test for PHPAspect runtime library.
org.phpaspect.apdt APDT main plugin.
org.phpaspect.apdt.core Core plugin.
org.phpaspect.apdt.debug.core PHPAspect core launcher.
org.phpaspect.apdt.debug.ui PHPAspect UI launcher.
org.phpaspect.apdt.feature APDT feature.
org.phpaspect.apdt.help APDT help (empty for now).
org.phpaspect.apdt.sdk-feature APDT SDK feature.
org.phpaspect.apdt.ui APDT UI features.
org.phpaspect.apdt.updatesite APDT Update site.
org.phpaspect.apdt.documentation PHPAspect documentation
org.phpaspect.weaver PHPAspect weaver
org.phpaspect.weaver.test PHPAspect weaver test cases

Release

APDT depends on PDT 2.0 extension points and APIs. The release will be made the same day than PDT 2.0 release. APDT is a great showcase for people who wants to contribute PDT 2.0 extension points and use PDT 2.0 API.

Hello World

Let's consider a simple piece of PHP code:

<?php
class Foo{
  public function fuebar(){
    return true;
  }
}
 
class Bar{
  public function fuebar(){
    return true;
  }
}
 
$foo = new Foo();
$bar = new Bar();
$foo->fuebar();
$bar->fuebar();
$unknown->fuebar();
?>

And the following joinpoint (all method invocation of the fuebar() method in an instance of Foo):

call(Foo->fuebar())

Before this summer, when you were writing a such joinpoint, PHPAspect was testing the type of $foo, $bar and $unknown to check if the joinpoint has been matched and then execute the associated code-advince. By using DLTK/PDT type inference engine, APDT knows that $foo is an instance of Foo therefore the joinpoint has been statically matched. $bar isn't an instance of Foo, this node in the PHP Program is left unchanged. The type of $unknown is unknown, APDT adds a runtime assertion: the type of $unknown is tested at runtime to check for code-advice execution. The weaved source code is the following:

$foo = new Foo();
$bar = new Bar();
PHPAspect_dispatch(array(2,),new JoinPointImpl(JoinPoint::METHOD_EXECUTION,$foo,new ReflectionMethod($foo,'fuebar'),array(),__FILE__,__LINE__),array(2=>true,));
$bar->fuebar();
PHPAspect_dispatch(array(2,),new JoinPointImpl(JoinPoint::METHOD_EXECUTION,$unknown,new ReflectionMethod($unknown,'fuebar'),array(),__FILE__,__LINE__),
  array(2=>(PHPAspect_match($unknown,'Foo')),));

Above, the call of $foo->fueaber() is matched, $bar->fuebar() is unchanged and $unknown->fuebar() has the runtime assertion PHPAspect_match($unknown,'Foo').

Which JoinPoints are using DLTK/PDT Type inference ?

The following joinpoints are taking advantage of APDT type inference:

  • Method invocation
  • Static method invocation
  • Object instance creation.
  • Object destruction.
  • Executing Object.
  • Target Object.
  • Declaring Type.

APDT PHP Runtime support

Aspects are first class entities during the execution

At compile-time, APDT generates generate a class for each aspect. These classes are singleton an implements the Aspect interface. Code advices are method specialized using annotations. For runtime support of annotations, PHPAspect uses addendum.

class Logging implements Aspect{
 
	private static $instance = null;
 
	private function __construct(){}
 
	public static function getInstance(){
		if(self::$instance == null){
			self::$instance = new Logging();	
		}
		return self::$instance;
	}
 
      /**
	 * @After
	 * @Id(10)
	 */
	public function codeAdvice1(JoinPoint $thisJoinPoint){
		printf("%s->%s()\n",
			$thisJoinPoint->getTarget()->getDeclaringClass()->getName(),
			$thisJoinPoint->getTarget()->getName());
	}
}

Community Proposals

Links

APDT Website

An overview of APDT

PHPAspect Website