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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/* *******************************************************************
* 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.io.IOException;
import java.util.Map;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.Advice;
import org.aspectj.weaver.AjcMemberMaker;
import org.aspectj.weaver.CompressingDataOutputStream;
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.PerObjectInterfaceTypeMunger;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.ResolvedTypeMunger;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.VersionedDataInputStream;
import org.aspectj.weaver.World;
import org.aspectj.weaver.ast.Expr;
import org.aspectj.weaver.ast.Test;
import org.aspectj.weaver.ast.Var;
public class PerObject extends PerClause {
private final boolean isThis;
private final Pointcut entry;
private static final int thisKindSet;
private static final int targetKindSet;
static {
int thisFlags = Shadow.ALL_SHADOW_KINDS_BITS;
int targFlags = Shadow.ALL_SHADOW_KINDS_BITS;
for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) {
Shadow.Kind kind = Shadow.SHADOW_KINDS[i];
if (kind.neverHasThis()) {
thisFlags -= kind.bit;
}
if (kind.neverHasTarget()) {
targFlags -= kind.bit;
}
}
thisKindSet = thisFlags;
targetKindSet = targFlags;
}
public PerObject(Pointcut entry, boolean isThis) {
this.entry = entry;
this.isThis = isThis;
}
public Object accept(PatternNodeVisitor visitor, Object data) {
return visitor.visit(this, data);
}
@Override
public Object traverse(PatternNodeVisitor visitor, Object data) {
Object ret = accept(visitor, data);
if (this.entry != null)
this.entry.traverse(visitor, ret);
return ret;
}
public int couldMatchKinds() {
return isThis ? thisKindSet : targetKindSet;
}
// -----
public FuzzyBoolean fastMatch(FastMatchInfo type) {
return FuzzyBoolean.MAYBE;
}
protected FuzzyBoolean matchInternal(Shadow shadow) {
// System.err.println("matches " + this + " ? " + shadow + ", " +
// shadow.hasTarget());
// ??? could probably optimize this better by testing could match
if (isThis) {
return FuzzyBoolean.fromBoolean(shadow.hasThis());
} else {
return FuzzyBoolean.fromBoolean(shadow.hasTarget());
}
}
public void resolveBindings(IScope scope, Bindings bindings) {
// assert bindings == null;
entry.resolve(scope);
}
public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
PerObject ret = new PerObject(entry.parameterizeWith(typeVariableMap, w), isThis);
ret.copyLocationFrom(this);
return ret;
}
private Var getVar(Shadow shadow) {
return isThis ? shadow.getThisVar() : shadow.getTargetVar();
}
protected Test findResidueInternal(Shadow shadow, ExposedState state) {
Expr myInstance = Expr.makeCallExpr(AjcMemberMaker.perObjectAspectOfMethod(inAspect), new Expr[] { getVar(shadow) },
inAspect);
state.setAspectInstance(myInstance);
return Test.makeCall(AjcMemberMaker.perObjectHasAspectMethod(inAspect), new Expr[] { getVar(shadow) });
}
public PerClause concretize(ResolvedType inAspect) {
PerObject ret = new PerObject(entry, isThis);
ret.inAspect = inAspect;
if (inAspect.isAbstract()) {
return ret;
}
World world = inAspect.getWorld();
Pointcut concreteEntry = entry.concretize(inAspect, inAspect, 0, null);
// concreteEntry = new AndPointcut(this, concreteEntry);
// concreteEntry.state = Pointcut.CONCRETE;
inAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makePerObjectEntry(world, concreteEntry, isThis, inAspect));
// FIXME AV - don't use lateMunger here due to test
// "inheritance, around advice and abstract pointcuts"
// see #75442 thread. Issue with weaving order.
ResolvedTypeMunger munger = new PerObjectInterfaceTypeMunger(inAspect, concreteEntry);
inAspect.crosscuttingMembers.addLateTypeMunger(world.getWeavingSupport().concreteTypeMunger(munger, inAspect));
// ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects
if (inAspect.isAnnotationStyleAspect() && !inAspect.isAbstract()) {
inAspect.crosscuttingMembers.addLateTypeMunger(inAspect.getWorld().getWeavingSupport().makePerClauseAspect(inAspect,
getKind()));
}
// ATAJ inline around advice support - don't use a late munger to allow
// around inling for itself
if (inAspect.isAnnotationStyleAspect() && !inAspect.getWorld().isXnoInline()) {
inAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().createAccessForInlineMunger(inAspect));
}
return ret;
}
public void write(CompressingDataOutputStream s) throws IOException {
PEROBJECT.write(s);
entry.write(s);
s.writeBoolean(isThis);
writeLocation(s);
}
public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
PerClause ret = new PerObject(Pointcut.read(s, context), s.readBoolean());
ret.readLocation(context, s);
return ret;
}
public PerClause.Kind getKind() {
return PEROBJECT;
}
public boolean isThis() {
return isThis;
}
public String toString() {
return "per" + (isThis ? "this" : "target") + "(" + entry + ")";
}
public String toDeclarationString() {
return toString();
}
public Pointcut getEntry() {
return entry;
}
public boolean equals(Object other) {
if (!(other instanceof PerObject)) {
return false;
}
PerObject pc = (PerObject) other;
return (pc.isThis && isThis) && ((pc.inAspect == null) ? (inAspect == null) : pc.inAspect.equals(inAspect))
&& ((pc.entry == null) ? (entry == null) : pc.entry.equals(entry));
}
public int hashCode() {
int result = 17;
result = 37 * result + (isThis ? 0 : 1);
result = 37 * result + ((inAspect == null) ? 0 : inAspect.hashCode());
result = 37 * result + ((entry == null) ? 0 : entry.hashCode());
return result;
}
}
|