aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/main/java/org/aspectj/weaver/PoliceExtensionUse.java
blob: 348d5dc7f5baa5e05b2e944315f9c755fcd0a5a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
 * Copyright (c) 2006 IBM
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *    Andy Clement - initial API and implementation
 *******************************************************************************/
package org.aspectj.weaver;

import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.weaver.patterns.AbstractPatternNodeVisitor;
import org.aspectj.weaver.patterns.AndPointcut;
import org.aspectj.weaver.patterns.KindedPointcut;
import org.aspectj.weaver.patterns.NotPointcut;
import org.aspectj.weaver.patterns.OrPointcut;
import org.aspectj.weaver.patterns.Pointcut;

/**
 * Walks a pointcut and determines if the synchronization related designators have been used: lock() or unlock()
 */
public class PoliceExtensionUse extends AbstractPatternNodeVisitor {

	private boolean synchronizationDesignatorEncountered;
	private World world;
	private Pointcut p;

	public PoliceExtensionUse(World w, Pointcut p) {
		this.world = w;
		this.p = p;
		this.synchronizationDesignatorEncountered = false;
	}

	public boolean synchronizationDesignatorEncountered() {
		return synchronizationDesignatorEncountered;
	}

	public Object visit(KindedPointcut node, Object data) {
		if (world == null)
			return super.visit(node, data); // error scenario can sometimes lead to this LazyClassGen.toLongString()
		if (node.getKind() == Shadow.SynchronizationLock || node.getKind() == Shadow.SynchronizationUnlock)
			synchronizationDesignatorEncountered = true;
		// Check it!
		if (!world.isJoinpointSynchronizationEnabled()) {
			if (node.getKind() == Shadow.SynchronizationLock) {
				IMessage m = MessageUtil.warn(
						"lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization", p
								.getSourceLocation());
				world.getMessageHandler().handleMessage(m);
			} else if (node.getKind() == Shadow.SynchronizationUnlock) {
				IMessage m = MessageUtil.warn(
						"unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization", p
								.getSourceLocation());
				world.getMessageHandler().handleMessage(m);
			}
		}
		return super.visit(node, data);
	}

	public Object visit(AndPointcut node, Object data) {
		node.getLeft().accept(this, data);
		node.getRight().accept(this, data);
		return node;
	}

	public Object visit(NotPointcut node, Object data) {
		node.getNegatedPointcut().accept(this, data);
		return node;
	}

	public Object visit(OrPointcut node, Object data) {
		node.getLeft().accept(this, data);
		node.getRight().accept(this, data);
		return node;
	}

}