Skip to content

Commit 4f3e990

Browse files
committed
JoinPointImpl minor structural refactoring
No functionality was changed. Signed-off-by: Alexander Kriegisch <[email protected]>
1 parent 70a4547 commit 4f3e990

File tree

1 file changed

+79
-89
lines changed

1 file changed

+79
-89
lines changed

runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java

Lines changed: 79 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package org.aspectj.runtime.reflect;
1515

16-
import org.aspectj.lang.JoinPoint;
1716
import org.aspectj.lang.ProceedingJoinPoint;
1817
import org.aspectj.lang.Signature;
1918
import org.aspectj.lang.reflect.SourceLocation;
@@ -23,11 +22,11 @@
2322
import java.util.List;
2423

2524
class JoinPointImpl implements ProceedingJoinPoint {
26-
static class StaticPartImpl implements JoinPoint.StaticPart {
25+
static class StaticPartImpl implements StaticPart {
2726
String kind;
2827
Signature signature;
2928
SourceLocation sourceLocation;
30-
private int id;
29+
private final int id;
3130

3231
public StaticPartImpl(int id, String kind, Signature signature, SourceLocation sourceLocation) {
3332
this.kind = kind;
@@ -53,12 +52,7 @@ public SourceLocation getSourceLocation() {
5352
}
5453

5554
String toString(StringMaker sm) {
56-
StringBuilder buf = new StringBuilder();
57-
buf.append(sm.makeKindName(getKind()));
58-
buf.append("(");
59-
buf.append(((SignatureImpl) getSignature()).toString(sm));
60-
buf.append(")");
61-
return buf.toString();
55+
return sm.makeKindName(getKind()) + "(" + ((SignatureImpl) getSignature()).toString(sm) + ")";
6256
}
6357

6458
public final String toString() {
@@ -83,9 +77,9 @@ public EnclosingStaticPartImpl(int count, String kind, Signature signature, Sour
8377
Object _this;
8478
Object target;
8579
Object[] args;
86-
org.aspectj.lang.JoinPoint.StaticPart staticPart;
80+
StaticPart staticPart;
8781

88-
public JoinPointImpl(org.aspectj.lang.JoinPoint.StaticPart staticPart, Object _this, Object target, Object[] args) {
82+
public JoinPointImpl(StaticPart staticPart, Object _this, Object target, Object[] args) {
8983
this.staticPart = staticPart;
9084
this._this = _this;
9185
this.target = target;
@@ -101,15 +95,14 @@ public Object getTarget() {
10195
}
10296

10397
public Object[] getArgs() {
104-
if (args == null) {
98+
if (args == null)
10599
args = new Object[0];
106-
}
107100
Object[] argsCopy = new Object[args.length];
108101
System.arraycopy(args, 0, argsCopy, 0, args.length);
109102
return argsCopy;
110103
}
111104

112-
public org.aspectj.lang.JoinPoint.StaticPart getStaticPart() {
105+
public StaticPart getStaticPart() {
113106
return staticPart;
114107
}
115108

@@ -150,9 +143,8 @@ public final String toLongString() {
150143

151144
public void stack$AroundClosure(AroundClosure arc) {
152145
// If input parameter arc is null this is the 'unlink' call from AroundClosure
153-
if (arcs == null) {
146+
if (arcs == null)
154147
arcs = new ArrayList<>();
155-
}
156148
if (arc == null) {
157149
int newIndex = arcIndex.get() - 1;
158150
if (newIndex > -1)
@@ -169,11 +161,7 @@ public final String toLongString() {
169161
public Object proceed() throws Throwable {
170162
// when called from a before advice, but be a no-op
171163
if (arcs == null) {
172-
if (arc == null) {
173-
return null;
174-
} else {
175-
return arc.run(arc.getState());
176-
}
164+
return arc == null ? null : arc.run(arc.getState());
177165
} else {
178166
final AroundClosure ac = arcs.get(arcIndex.get());
179167
return ac.run(ac.getState());
@@ -184,82 +172,84 @@ public Object proceed(Object[] adviceBindings) throws Throwable {
184172
// when called from a before advice, but be a no-op
185173
AroundClosure ac = arcs == null ? arc : arcs.get(arcIndex.get());
186174

187-
if (ac == null) {
175+
if (ac == null)
188176
return null;
189-
} else {
190-
// Based on the bit flags in the AroundClosure we can determine what to
191-
// expect in the adviceBindings array. We may or may not be expecting
192-
// the first value to be a new this or a new target... (see pr126167)
193-
int flags = ac.getFlags();
194-
boolean unset = (flags & 0x100000) != 0;
195-
boolean thisTargetTheSame = (flags & 0x010000) != 0;
196-
boolean hasThis = (flags & 0x001000) != 0;
197-
boolean bindsThis = (flags & 0x000100) != 0;
198-
boolean hasTarget = (flags & 0x000010) != 0;
199-
boolean bindsTarget = (flags & 0x000001) != 0;
200-
201-
// state is always consistent with caller?,callee?,formals...,jp
202-
Object[] state = ac.getState();
203-
204-
// these next two numbers can differ because some join points have a this and
205-
// target that are the same (eg. call) - and yet you can bind this and target
206-
// separately.
207-
208-
// In the state array, [0] may be this, [1] may be target
209-
210-
int firstArgumentIndexIntoAdviceBindings = 0;
211-
int firstArgumentIndexIntoState = 0;
212-
firstArgumentIndexIntoState += (hasThis ? 1 : 0);
213-
firstArgumentIndexIntoState += (hasTarget && !thisTargetTheSame ? 1 : 0);
214-
if (hasThis) {
215-
if (bindsThis) {
216-
// replace [0] (this)
217-
firstArgumentIndexIntoAdviceBindings = 1;
218-
state[0] = adviceBindings[0];
219-
} else {
220-
// leave state[0] alone, its OK
221-
}
177+
178+
// Based on the bit flags in the AroundClosure we can determine what to
179+
// expect in the adviceBindings array. We may or may not be expecting
180+
// the first value to be a new this or a new target... (see pr126167)
181+
int flags = ac.getFlags();
182+
boolean unset = (flags & 0x100000) != 0;
183+
boolean thisTargetTheSame = (flags & 0x010000) != 0;
184+
boolean hasThis = (flags & 0x001000) != 0;
185+
boolean bindsThis = (flags & 0x000100) != 0;
186+
boolean hasTarget = (flags & 0x000010) != 0;
187+
boolean bindsTarget = (flags & 0x000001) != 0;
188+
189+
// state is always consistent with caller?,callee?,formals...,jp
190+
Object[] state = ac.getState();
191+
192+
// these next two numbers can differ because some join points have a this and
193+
// target that are the same (eg. call) - and yet you can bind this and target
194+
// separately.
195+
196+
// In the state array, [0] may be this, [1] may be target
197+
198+
int firstArgumentIndexIntoAdviceBindings = 0;
199+
int firstArgumentIndexIntoState = 0;
200+
firstArgumentIndexIntoState += (hasThis ? 1 : 0);
201+
firstArgumentIndexIntoState += (hasTarget && !thisTargetTheSame ? 1 : 0);
202+
if (hasThis) {
203+
if (bindsThis) {
204+
// replace [0] (this)
205+
firstArgumentIndexIntoAdviceBindings = 1;
206+
state[0] = adviceBindings[0];
207+
} else {
208+
// leave state[0] alone, its OK
222209
}
223-
if (hasTarget) {
224-
if (bindsTarget) {
225-
if (thisTargetTheSame) {
226-
// this and target are the same so replace state[0]
227-
firstArgumentIndexIntoAdviceBindings = 1 + (bindsThis ? 1 : 0);
228-
state[0] = adviceBindings[(bindsThis ? 1 : 0)];
229-
} else {
230-
// need to replace the target, and it is different to this, whether
231-
// that means replacing state[0] or state[1] depends on whether
232-
// the join point has a this
233-
234-
// This previous variant doesn't seem to cope with only binding target at a joinpoint
235-
// which has both this and target. It forces you to supply this even if you didn't bind
236-
// it.
237-
// firstArgumentIndexIntoAdviceBindings = (hasThis ? 1 : 0) + 1;
238-
// state[hasThis ? 1 : 0] = adviceBindings[hasThis ? 1 : 0];
239-
240-
int targetPositionInAdviceBindings = (hasThis && bindsThis) ? 1 : 0;
241-
firstArgumentIndexIntoAdviceBindings = ((hasThis&&bindsThis)?1:0)+((hasTarget&&bindsTarget&&!thisTargetTheSame)?1:0);
242-
state[hasThis ? 1 : 0] = adviceBindings[targetPositionInAdviceBindings];
243-
}
210+
}
211+
if (hasTarget) {
212+
if (bindsTarget) {
213+
if (thisTargetTheSame) {
214+
// this and target are the same so replace state[0]
215+
firstArgumentIndexIntoAdviceBindings = 1 + (bindsThis ? 1 : 0);
216+
state[0] = adviceBindings[(bindsThis ? 1 : 0)];
244217
} else {
245-
// leave state[0]/state[1] alone, they are OK
218+
// need to replace the target, and it is different to this, whether
219+
// that means replacing state[0] or state[1] depends on whether
220+
// the join point has a this
221+
222+
// This previous variant doesn't seem to cope with only binding target at a joinpoint which has both this and
223+
// target. It forces you to supply this even if you didn't bind it.
224+
/*
225+
firstArgumentIndexIntoAdviceBindings = (hasThis ? 1 : 0) + 1;
226+
state[hasThis ? 1 : 0] = adviceBindings[hasThis ? 1 : 0];
227+
*/
228+
229+
int targetPositionInAdviceBindings = (hasThis && bindsThis) ? 1 : 0;
230+
firstArgumentIndexIntoAdviceBindings = ((hasThis&&bindsThis)?1:0)+((hasTarget&&bindsTarget&&!thisTargetTheSame)?1:0);
231+
state[hasThis ? 1 : 0] = adviceBindings[targetPositionInAdviceBindings];
246232
}
233+
} else {
234+
// leave state[0]/state[1] alone, they are OK
247235
}
236+
}
248237

249-
// copy the rest across
250-
for (int i = firstArgumentIndexIntoAdviceBindings; i < adviceBindings.length; i++) {
251-
state[firstArgumentIndexIntoState + (i - firstArgumentIndexIntoAdviceBindings)] = adviceBindings[i];
252-
}
238+
// copy the rest across
239+
for (int i = firstArgumentIndexIntoAdviceBindings; i < adviceBindings.length; i++) {
240+
state[firstArgumentIndexIntoState + (i - firstArgumentIndexIntoAdviceBindings)] = adviceBindings[i];
241+
}
253242

254-
// old code that did this, didnt allow this/target overriding
255-
// for (int i = state.length-2; i >= 0; i--) {
256-
// int formalIndex = (adviceBindings.length - 1) - (state.length-2) + i;
257-
// if (formalIndex >= 0 && formalIndex < adviceBindings.length) {
258-
// state[i] = adviceBindings[formalIndex];
259-
// }
260-
// }
261-
return ac.run(state);
243+
// old code that did this, didnt allow this/target overriding
244+
/*
245+
for (int i = state.length - 2; i >= 0; i--) {
246+
int formalIndex = (adviceBindings.length - 1) - (state.length - 2) + i;
247+
if (formalIndex >= 0 && formalIndex < adviceBindings.length) {
248+
state[i] = adviceBindings[formalIndex];
249+
}
262250
}
251+
*/
252+
return ac.run(state);
263253
}
264254

265255
}

0 commit comments

Comments
 (0)