Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Experiment No.

: 6

Aim: Create a java application with fields in AspectJ.


Theory:
In this experiment, some classes that participate in many illustrated examples of AspectJ are:
• Box, FigureElement, Group, Line, Point, ShapeFigureElement, SlotFulPoint.

The sources of these classes are from:


https://github.com/eclipse/org.aspectj/tree/master/docs/teaching/exercises/figures

Steps:
1. The package figures we have already installed in our Eclipse IDE for previous experiment,
and here also we are going to use Point.java class for our experiment.

2. Create FieldInAspectJTest.java class file and FieldInAspectJ.aj aspect file for


demonstrating the experiment work.
3. Now, Start working on code to run java application with fields in AspectJ.

4. Run the Aspect/Java Application file.

5. Now, output of the java application is visible in output console.


Code:

FieldInAspectJ.aj File
package com.aop.gbu;
import java.io.PrintStream;
public aspect FieldInAspectJ {
// Field in AspectJ.
PrintStream logStream = System.err;
pointcut move() : call(* figures.Point.move(int,int)) && within(FieldInAspectJTest);
before () : move() {
logStream.println("Before Point move");
}
}

FieldInAspectJTest.java file
package com.aop.gbu;
import figures.Point;
public class FieldInAspectJTest {
public static void main(String[] args) {
Point point = new Point(10, 200);
System.err.println("---- (1) ----");
System.err.println("---- (2) ----");
point.move(10, 10);
System.err.println("---- (3) ----");
}
}

Output:

You might also like