1
/* *******************************************************************
2
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
4
* This program and the accompanying materials are made available
5
* under the terms of the Eclipse Public License v1.0
6
* which accompanies this distribution and is available at
7
* http://www.eclipse.org/legal/epl-v10.html
10
* PARC initial implementation
11
* ******************************************************************/
13
package org.aspectj.weaver.patterns;
15
import org.aspectj.bridge.IMessage;
16
import org.aspectj.weaver.BCException;
17
import org.aspectj.weaver.UnresolvedType;
19
public class Bindings {
20
public static final Bindings NONE = new Bindings(0);
22
private BindingPattern[] bindings;
24
public Bindings(BindingPattern[] bindings) {
25
this.bindings = bindings;
28
public Bindings(int count) {
29
this(new BindingPattern[count]);
32
public void register(BindingPattern binding, IScope scope) {
33
int index = binding.getFormalIndex();
34
BindingPattern existingBinding = bindings[index];
35
if (existingBinding != null) {
36
scope.message(IMessage.ERROR, existingBinding, binding, "multiple bindings" + index + ", " + binding);
38
bindings[index] = binding;
41
public void mergeIn(Bindings other, IScope scope) {
42
for (int i = 0, len = other.bindings.length; i < len; i++) {
43
if (other.bindings[i] != null) {
44
register(other.bindings[i], scope);
50
* signals an error if one has a binding and other doesn't
52
public void checkEquals(Bindings other, IScope scope) {
53
BindingPattern[] b1 = this.bindings;
54
BindingPattern[] b2 = other.bindings;
56
if (len != b2.length) {
57
throw new BCException("INSANE");
60
for (int i = 0; i < len; i++) {
61
if (b1[i] == null && b2[i] != null) {
62
scope.message(IMessage.ERROR, b2[i], "inconsistent binding");
63
b1[i] = b2[i]; // done just to produce fewer error messages
64
} else if (b2[i] == null && b1[i] != null) {
65
scope.message(IMessage.ERROR, b1[i], "inconsistent binding");
66
b2[i] = b1[i]; // done just to produce fewer error messages
71
public String toString() {
72
StringBuffer buf = new StringBuffer("Bindings(");
73
for (int i = 0, len = bindings.length; i < len; i++) {
76
buf.append(bindings[i]);
79
return buf.toString();
82
public int[] getUsedFormals() {
83
// System.out.println("used: " + this);
84
int[] ret = new int[bindings.length];
86
for (int i = 0, len = bindings.length; i < len; i++) {
87
if (bindings[i] != null) {
91
int[] newRet = new int[index];
92
System.arraycopy(ret, 0, newRet, 0, index);
93
// System.out.println("ret: " + index);
97
public UnresolvedType[] getUsedFormalTypes() {
98
UnresolvedType[] ret = new UnresolvedType[bindings.length];
100
for (int i = 0, len = bindings.length; i < len; i++) {
101
if (bindings[i] != null) {
102
ret[index++] = ((BindingTypePattern) bindings[i]).getExactType();
105
UnresolvedType[] newRet = new UnresolvedType[index];
106
System.arraycopy(ret, 0, newRet, 0, index);
107
// System.out.println("ret: " + index);
111
public Bindings copy() {
112
// int len = bindings.length;
113
// boolean[] a = new boolean[len];
114
// System.arraycopy(bindings, 0, a, 0, len);
115
return new Bindings((BindingPattern[]) bindings.clone());
118
public void checkAllBound(IScope scope) {
119
for (int i = 0, len = bindings.length; i < len; i++) {
120
if (bindings[i] == null) {
121
// ATAJ: avoid warnings for implicit bindings
122
if (scope.getFormal(i) instanceof FormalBinding.ImplicitFormalBinding) {
123
bindings[i] = new BindingTypePattern(scope.getFormal(i), false);
125
scope.message(IMessage.ERROR, scope.getFormal(i), "formal unbound in pointcut ");
133
return bindings.length;