Skip to content

Commit

Permalink
rename class JointPoint to JoinPoint (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewadams authored and mgechev committed Oct 9, 2018
1 parent 144a255 commit fe0588c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
15 changes: 14 additions & 1 deletion lib/src/core/join_point.ts
Expand Up @@ -5,7 +5,7 @@ export interface Precondition {
assert(data: any): boolean;
}

export abstract class JointPoint {
export abstract class JoinPoint {
constructor(public precondition: Precondition) {}

public abstract match(descriptor: Function): string[];
Expand Down Expand Up @@ -57,3 +57,16 @@ export abstract class JointPoint {
return metadata;
}
}

/**
* Kept for backward compability only.
* Use {@link JoinPoint} instead.
*
* @deprecated renamed to JoinPoint
* @see JoinPoint
*/
export abstract class JointPoint extends JoinPoint {
constructor(public precondition: Precondition) {
super(precondition)
}
}
4 changes: 2 additions & 2 deletions lib/src/core/pointcut.ts
@@ -1,8 +1,8 @@
import { JointPoint } from './join_point';
import { JoinPoint } from './join_point';
import { Advice } from './advice';

export class Pointcut {
public joinPoints: JointPoint[];
public joinPoints: JoinPoint[];
public advice: Advice;
private _applications = new Set<Function>();

Expand Down
23 changes: 18 additions & 5 deletions lib/src/join_points/accessor_use.ts
@@ -1,4 +1,4 @@
import { JointPoint, Precondition } from '../core/join_point';
import { JoinPoint, Precondition } from '../core/join_point';
import { Advice } from '../core/advice';
import { Pointcut } from '../core/pointcut';
import { AspectRegistry, Targets, Aspect } from '../core/aspect';
Expand All @@ -7,8 +7,8 @@ import { MemberPrecondition } from './preconditions';

export type AccessorType = 'get' | 'set';

export class AccessorJointPoint extends JointPoint {
constructor(precondition: Precondition, private type: AccessorType) {
export class AccessorJoinPoint extends JoinPoint {
constructor(precondition: Precondition, protected type: AccessorType) {
super(precondition);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ export function makeFieldGetAdviceDecorator(constr: new (...args: any[]) => Advi
return function(...selectors: MemberSelector[]): MethodDecorator {
return function<T>(target: Object, prop: string | symbol, descriptor: TypedPropertyDescriptor<T>) {
const joinpoints = selectors.map(selector => {
return new AccessorJointPoint(new MemberPrecondition(selector), 'get');
return new AccessorJoinPoint(new MemberPrecondition(selector), 'get');
});
const pointcut = new Pointcut();
pointcut.advice = <Advice>new constr(target, descriptor.value);
Expand All @@ -71,7 +71,7 @@ export function makeFieldSetAdviceDecorator(constr: new (...args: any[]) => Advi
return function(...selectors: MemberSelector[]): MethodDecorator {
return function<T>(target: Object, prop: string | symbol, descriptor: TypedPropertyDescriptor<T>) {
const joinpoints = selectors.map(selector => {
return new AccessorJointPoint(new MemberPrecondition(selector), 'set');
return new AccessorJoinPoint(new MemberPrecondition(selector), 'set');
});
const pointcut = new Pointcut();
pointcut.advice = <Advice>new constr(target, descriptor.value);
Expand All @@ -85,3 +85,16 @@ export function makeFieldSetAdviceDecorator(constr: new (...args: any[]) => Advi
};
};
}

/**
* Kept for backward compability only.
* Use {@link AccessorJoinPoint} instead.
*
* @deprecated renamed to AccessorJoinPoint
* @see AccessorJoinPoint
*/
export abstract class AccessorJointPoint extends AccessorJoinPoint {
constructor(precondition: Precondition, protected type: AccessorType) {
super(precondition, type);
}
}
19 changes: 16 additions & 3 deletions lib/src/join_points/method_call.ts
@@ -1,4 +1,4 @@
import { Precondition, JointPoint } from '../core/join_point';
import { Precondition, JoinPoint } from '../core/join_point';
import { Advice } from '../core/advice';
import { Pointcut } from '../core/pointcut';
import { AspectRegistry, Targets, Aspect } from '../core/aspect';
Expand All @@ -7,7 +7,7 @@ import { MethodPrecondition } from './preconditions';

const BLACK_LIST = ['constructor'];

export class MethodCallJointPoint extends JointPoint {
export class MethodCallJoinPoint extends JoinPoint {
public getTarget(fn: Function): any {
return fn.prototype;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ export function makeMethodCallAdviceDecorator(constr: any) {
return function(...selectors: MethodSelector[]): MethodDecorator {
return function<T>(target: Object, prop: symbol | string, descriptor: TypedPropertyDescriptor<T>) {
let joinpoints = selectors.map(selector => {
return new MethodCallJointPoint(new MethodPrecondition(selector));
return new MethodCallJoinPoint(new MethodPrecondition(selector));
});
let pointcut = new Pointcut();
pointcut.advice = <Advice>new constr(target, descriptor.value);
Expand All @@ -66,3 +66,16 @@ export function makeMethodCallAdviceDecorator(constr: any) {
};
};
}

/**
* Kept for backward compability only.
* Use {@link MethodCallJoinPoint} instead.
*
* @deprecated renamed to MethodCallJoinPoint
* @see MethodCallJoinPoint
*/
export abstract class MethodCallJointPoint extends MethodCallJoinPoint {
constructor(precondition: Precondition) {
super(precondition)
}
}
19 changes: 16 additions & 3 deletions lib/src/join_points/static_method.ts
@@ -1,11 +1,11 @@
import { Precondition, JointPoint } from '../core/join_point';
import { Precondition, JoinPoint } from '../core/join_point';
import { Advice } from '../core/advice';
import { Pointcut } from '../core/pointcut';
import { AspectRegistry, Targets, Aspect } from '../core/aspect';
import { MethodSelector } from './selectors';
import { MethodPrecondition } from './preconditions';

export class StaticMethodJointPoint extends JointPoint {
export class StaticMethodJoinPoint extends JoinPoint {
constructor(precondition: Precondition) {
super(precondition);
}
Expand Down Expand Up @@ -44,7 +44,7 @@ export function makeStaticMethodAdviceDecorator(constr: any) {
return function(...selectors: MethodSelector[]): MethodDecorator {
return function<T>(target: Object, prop: symbol | string, descriptor: TypedPropertyDescriptor<T>) {
let joinpoints = selectors.map(selector => {
return new StaticMethodJointPoint(new MethodPrecondition(selector));
return new StaticMethodJoinPoint(new MethodPrecondition(selector));
});
let pointcut = new Pointcut();
pointcut.advice = <Advice>new constr(target, descriptor.value);
Expand All @@ -58,3 +58,16 @@ export function makeStaticMethodAdviceDecorator(constr: any) {
};
};
}

/**
* Kept for backward compability only.
* Use {@link StaticMethodJoinPoint} instead.
*
* @deprecated renamed to StaticMethodJoinPoint
* @see StaticMethodJoinPoint
*/
export abstract class StaticMethodJointPoint extends StaticMethodJoinPoint {
constructor(precondition: Precondition) {
super(precondition)
}
}
8 changes: 4 additions & 4 deletions test/core/pointcut.spec.ts
@@ -1,8 +1,8 @@
import { Pointcut, Precondition, JointPoint, Advice } from '../../lib/src/core';
import { Pointcut, Precondition, JoinPoint, Advice } from '../../lib/src/core';

import { expect } from 'chai';

class SimpleJP extends JointPoint {
class SimpleJP extends JoinPoint {
match(descriptor: Object): string[] {
if (this.precondition.assert(descriptor)) {
return ['1'];
Expand All @@ -25,8 +25,8 @@ class SimplePrecondition implements Precondition {
// TODO(mgechev) refactor with spies
describe('Pointcut', () => {
let pc: Pointcut;
let jp1: JointPoint;
let jp2: JointPoint;
let jp1: JoinPoint;
let jp2: JoinPoint;
beforeEach(() => {
pc = new Pointcut();
jp1 = new SimpleJP(new SimplePrecondition());
Expand Down

0 comments on commit fe0588c

Please sign in to comment.