~ubuntu-branches/ubuntu/natty/aspectj/natty

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/patterns/Bindings.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-10-04 16:37:23 UTC
  • mfrom: (1.1.3 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091004163723-ck4y7j7fhjxskkie
Tags: 1.6.6+dfsg-1
* New upstream release.
  - Update 02_use_gjdoc.diff patch
* Update my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* *******************************************************************
 
2
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 
3
 * All rights reserved. 
 
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 
 
8
 *  
 
9
 * Contributors: 
 
10
 *     PARC     initial implementation 
 
11
 * ******************************************************************/
 
12
 
 
13
package org.aspectj.weaver.patterns;
 
14
 
 
15
import org.aspectj.bridge.IMessage;
 
16
import org.aspectj.weaver.BCException;
 
17
import org.aspectj.weaver.UnresolvedType;
 
18
 
 
19
public class Bindings {
 
20
        public static final Bindings NONE = new Bindings(0);
 
21
 
 
22
        private BindingPattern[] bindings;
 
23
 
 
24
        public Bindings(BindingPattern[] bindings) {
 
25
                this.bindings = bindings;
 
26
        }
 
27
 
 
28
        public Bindings(int count) {
 
29
                this(new BindingPattern[count]);
 
30
        }
 
31
 
 
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);
 
37
                }
 
38
                bindings[index] = binding;
 
39
        }
 
40
 
 
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);
 
45
                        }
 
46
                }
 
47
        }
 
48
 
 
49
        /**
 
50
         * signals an error if one has a binding and other doesn't
 
51
         */
 
52
        public void checkEquals(Bindings other, IScope scope) {
 
53
                BindingPattern[] b1 = this.bindings;
 
54
                BindingPattern[] b2 = other.bindings;
 
55
                int len = b1.length;
 
56
                if (len != b2.length) {
 
57
                        throw new BCException("INSANE");
 
58
                }
 
59
 
 
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
 
67
                        }
 
68
                }
 
69
        }
 
70
 
 
71
        public String toString() {
 
72
                StringBuffer buf = new StringBuffer("Bindings(");
 
73
                for (int i = 0, len = bindings.length; i < len; i++) {
 
74
                        if (i > 0)
 
75
                                buf.append(", ");
 
76
                        buf.append(bindings[i]);
 
77
                }
 
78
                buf.append(")");
 
79
                return buf.toString();
 
80
        }
 
81
 
 
82
        public int[] getUsedFormals() {
 
83
                // System.out.println("used: " + this);
 
84
                int[] ret = new int[bindings.length];
 
85
                int index = 0;
 
86
                for (int i = 0, len = bindings.length; i < len; i++) {
 
87
                        if (bindings[i] != null) {
 
88
                                ret[index++] = i;
 
89
                        }
 
90
                }
 
91
                int[] newRet = new int[index];
 
92
                System.arraycopy(ret, 0, newRet, 0, index);
 
93
                // System.out.println("ret: " + index);
 
94
                return newRet;
 
95
        }
 
96
 
 
97
        public UnresolvedType[] getUsedFormalTypes() {
 
98
                UnresolvedType[] ret = new UnresolvedType[bindings.length];
 
99
                int index = 0;
 
100
                for (int i = 0, len = bindings.length; i < len; i++) {
 
101
                        if (bindings[i] != null) {
 
102
                                ret[index++] = ((BindingTypePattern) bindings[i]).getExactType();
 
103
                        }
 
104
                }
 
105
                UnresolvedType[] newRet = new UnresolvedType[index];
 
106
                System.arraycopy(ret, 0, newRet, 0, index);
 
107
                // System.out.println("ret: " + index);
 
108
                return newRet;
 
109
        }
 
110
 
 
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());
 
116
        }
 
117
 
 
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);
 
124
                                } else {
 
125
                                        scope.message(IMessage.ERROR, scope.getFormal(i), "formal unbound in pointcut ");
 
126
                                }
 
127
                        }
 
128
                }
 
129
 
 
130
        }
 
131
 
 
132
        public int size() {
 
133
                return bindings.length;
 
134
        }
 
135
 
 
136
}