blob: 00183a8e2721ae645c6f80d4f872a088cc1d9f66 (
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* *******************************************************************
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
* 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:
* PARC initial implementation
* ******************************************************************/
package org.aspectj.weaver.patterns;
import java.util.Arrays;
import org.aspectj.weaver.Member;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.ast.Expr;
import org.aspectj.weaver.ast.Var;
public class ExposedState {
public static final boolean[] NO_ERRONEOUS_VARS = new boolean[0];
public Var[] vars;
private boolean[] erroneousVars;
private Expr aspectInstance;
private UnresolvedType[] expectedVarTypes; // enables us to check that binding is occurring with the *right* types
private ResolvedType concreteAspect;
public ExposedState(int size) {
super();
if (size == 0) {
vars = Var.NONE;
erroneousVars = NO_ERRONEOUS_VARS;
} else {
vars = new Var[size];
erroneousVars = new boolean[size];
}
}
public ExposedState(Member signature) {
// XXX there maybe something about target for non-static sigs
this(signature.getParameterTypes().length);
expectedVarTypes = new UnresolvedType[signature.getParameterTypes().length];
if (expectedVarTypes.length > 0) {
for (int i = 0; i < signature.getParameterTypes().length; i++) {
expectedVarTypes[i] = signature.getParameterTypes()[i];
}
}
}
public boolean isFullySetUp() {
for (Var var : vars) {
if (var == null)
return false;
}
return true;
}
public void set(int i, Var var) {
// check the type is OK if we can... these are the same rules as in matchesInstanceOf() processing
if (expectedVarTypes != null) {
ResolvedType expected = expectedVarTypes[i].resolve(var.getType().getWorld());
if (!expected.equals(ResolvedType.OBJECT)) {
if (!expected.isAssignableFrom(var.getType())) {
if (!var.getType().isCoerceableFrom(expected)) {
// throw new
// BCException("Expected type "+expectedVarTypes[i]+" in slot "+i+" but attempt to put "+var.getType()+" into it");
return;
}
}
}
}
vars[i] = var;
}
public Var get(int i) {
return vars[i];
}
public int size() {
return vars.length;
}
public Expr getAspectInstance() {
return aspectInstance;
}
public void setAspectInstance(Expr aspectInstance) {
this.aspectInstance = aspectInstance;
}
public String toString() {
return "ExposedState(#Vars=" + vars.length + ",Vars=" + Arrays.asList(vars) + ",AspectInstance=" + aspectInstance + ")";
}
// Set to true if we have reported an error message against it,
// prevents us blowing up in later code gen.
public void setErroneousVar(int formalIndex) {
erroneousVars[formalIndex] = true;
}
public boolean isErroneousVar(int formalIndex) {
return erroneousVars[formalIndex];
}
public void setConcreteAspect(ResolvedType concreteAspect) {
this.concreteAspect = concreteAspect;
}
public ResolvedType getConcreteAspect() {
return this.concreteAspect;
}
}
|