~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.2.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110315235431-iq2gxbsx08kpwuiw
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                this.asm = asm;
42
42
        }
43
43
 
 
44
        public void initialize() {
 
45
                // nothing to do
 
46
        }
 
47
 
44
48
        public String createHandleIdentifier(IProgramElement ipe) {
45
49
                // AjBuildManager.setupModel --> top of the tree is either
46
50
                // <root> or the .lst file
105
109
                                                // escape the @ (pr249216c9)
106
110
                                                handle.append("declare \\@").append(ipe.getName().substring(9)).append(getParameters(ipe));
107
111
                                        } else {
108
 
                                                handle.append(ipe.getName()).append(getParameters(ipe));
 
112
                                                if (ipe.getFullyQualifiedName() != null) {
 
113
                                                        handle.append(ipe.getFullyQualifiedName());
 
114
                                                } else {
 
115
                                                        handle.append(ipe.getName());
 
116
                                                }
 
117
                                                handle.append(getParameters(ipe));
109
118
                                        }
110
119
                                }
111
120
                                // }
123
132
                if (ipe.getParameterSignatures() == null || ipe.getParameterSignatures().isEmpty()) {
124
133
                        return "";
125
134
                }
126
 
                List sourceRefs = ipe.getParameterSignaturesSourceRefs();
127
 
                List parameterTypes = ipe.getParameterSignatures();
 
135
                List<String> sourceRefs = ipe.getParameterSignaturesSourceRefs();
 
136
                List<char[]> parameterTypes = ipe.getParameterSignatures();
128
137
                StringBuffer sb = new StringBuffer();
129
138
                if (sourceRefs != null) {
130
139
                        for (int i = 0; i < sourceRefs.size(); i++) {
131
 
                                String sourceRef = (String) sourceRefs.get(i);
 
140
                                String sourceRef = sourceRefs.get(i);
132
141
                                sb.append(HandleProviderDelimiter.getDelimiter(ipe));
133
142
                                sb.append(sourceRef);
134
143
                        }
135
144
                } else {
136
 
                        for (Iterator iter = parameterTypes.iterator(); iter.hasNext();) {
137
 
                                char[] element = (char[]) iter.next();
 
145
                        for (char[] element : parameterTypes) {
138
146
                                sb.append(HandleProviderDelimiter.getDelimiter(ipe));
139
147
                                sb.append(NameConvertor.createShortName(element, false, false));
140
148
                        }
155
163
 
156
164
                if (ipe.getKind().isInterTypeMember()) {
157
165
                        int count = 1;
158
 
                        List kids = ipe.getParent().getChildren();
159
 
                        int idx = 0;
160
 
                        for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
161
 
                                IProgramElement object = (IProgramElement) iterator.next();
 
166
                        List<IProgramElement> kids = ipe.getParent().getChildren();
 
167
                        for (Iterator<IProgramElement> iterator = kids.iterator(); iterator.hasNext();) {
 
168
                                IProgramElement object = iterator.next();
162
169
                                if (object.equals(ipe)) {
163
170
                                        break;
164
171
                                }
179
186
                        if (count > 1) {
180
187
                                return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
181
188
                        }
182
 
                } else if (ipe.getKind().isDeclareAnnotation()) {
183
 
                        // look at peer declares
184
 
                        int count = 1;
185
 
                        List kids = ipe.getParent().getChildren();
186
 
                        int idx = 0;
187
 
                        for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
188
 
                                IProgramElement object = (IProgramElement) iterator.next();
189
 
                                if (object.equals(ipe)) {
190
 
                                        break;
191
 
                                }
192
 
                                if (object.getKind() == ipe.getKind()) {
193
 
                                        if (object.getKind().toString().equals(ipe.getKind().toString())) {
194
 
                                                String existingHandle = object.getHandleIdentifier();
195
 
                                                int suffixPosition = existingHandle.indexOf('!');
196
 
                                                if (suffixPosition != -1) {
197
 
                                                        count = new Integer(existingHandle.substring(suffixPosition + 1)).intValue() + 1;
198
 
                                                } else {
199
 
                                                        if (count == 1) {
200
 
                                                                count = 2;
201
 
                                                        }
202
 
                                                }
203
 
                                        }
204
 
                                }
205
 
                        }
206
 
                        if (count > 1) {
207
 
                                return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
208
 
                        }
209
189
                } else if (ipe.getKind().isDeclare()) {
210
 
                        int index = CharOperation.lastIndexOf('_', byteCodeName);
211
 
                        if (index != -1) {
212
 
                                return convertCount(CharOperation.subarray(byteCodeName, index + 1, byteCodeName.length));
 
190
                        // // look at peer declares
 
191
                        int count = computeCountBasedOnPeers(ipe);
 
192
                        if (count > 1) {
 
193
                                return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
213
194
                        }
214
195
                } else if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
215
196
                        // Look at any peer advice
216
197
                        int count = 1;
217
 
                        List kids = ipe.getParent().getChildren();
 
198
                        List<IProgramElement> kids = ipe.getParent().getChildren();
218
199
                        String ipeSig = ipe.getBytecodeSignature();
219
200
                        // remove return type from the signature - it should not be included in the comparison
220
201
                        int idx = 0;
221
 
                        if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
222
 
                                ipeSig = ipeSig.substring(0, idx);
223
 
                        }
224
 
                        if (ipeSig != null) {
225
 
                                if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
226
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
227
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
228
 
                                        }
229
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
230
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
231
 
                                        }
232
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
233
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
234
 
                                        }
235
 
                                }
236
 
                        }
237
 
                        for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
238
 
                                IProgramElement object = (IProgramElement) iterator.next();
 
202
                        ipeSig = shortenIpeSig(ipeSig);
 
203
                        for (IProgramElement object : kids) {
239
204
                                if (object.equals(ipe)) {
240
205
                                        break;
241
206
                                }
282
247
                        // return String.valueOf(++initializerCounter).toCharArray();
283
248
                        // Look at any peer advice
284
249
                        int count = 1;
285
 
                        List kids = ipe.getParent().getChildren();
 
250
                        List<IProgramElement> kids = ipe.getParent().getChildren();
286
251
                        String ipeSig = ipe.getBytecodeSignature();
287
252
                        // remove return type from the signature - it should not be included in the comparison
288
253
                        int idx = 0;
289
 
                        if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
290
 
                                ipeSig = ipeSig.substring(0, idx);
291
 
                        }
292
 
                        if (ipeSig != null) {
293
 
                                if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
294
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
295
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
296
 
                                        }
297
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
298
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
299
 
                                        }
300
 
                                        if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
301
 
                                                ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
302
 
                                        }
303
 
                                }
304
 
                        }
305
 
                        for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
306
 
                                IProgramElement object = (IProgramElement) iterator.next();
 
254
                        ipeSig = shortenIpeSig(ipeSig);
 
255
                        for (IProgramElement object : kids) {
307
256
                                if (object.equals(ipe)) {
308
257
                                        break;
309
258
                                }
355
304
                } else if (ipe.getKind() == IProgramElement.Kind.CLASS) {
356
305
                        // depends on previous children
357
306
                        int count = 1;
358
 
                        List kids = ipe.getParent().getChildren();
 
307
                        List<IProgramElement> kids = ipe.getParent().getChildren();
359
308
                        if (ipe.getName().endsWith("{..}")) {
360
309
                                // only depends on previous anonymous children, name irrelevant
361
 
                                for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
362
 
                                        IProgramElement object = (IProgramElement) iterator.next();
 
310
                                for (IProgramElement object : kids) {
363
311
                                        if (object.equals(ipe)) {
364
312
                                                break;
365
313
                                        }
379
327
                                        }
380
328
                                }
381
329
                        } else {
382
 
                                for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
383
 
                                        IProgramElement object = (IProgramElement) iterator.next();
 
330
                                for (IProgramElement object : kids) {
384
331
                                        if (object.equals(ipe)) {
385
332
                                                break;
386
333
                                        }
407
354
                return empty;
408
355
        }
409
356
 
 
357
        private String shortenIpeSig(String ipeSig) {
 
358
                int idx;
 
359
                if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
 
360
                        ipeSig = ipeSig.substring(0, idx);
 
361
                }
 
362
                if (ipeSig != null) {
 
363
                        if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
 
364
                                if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
 
365
                                        ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
 
366
                                }
 
367
                                if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
 
368
                                        ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
 
369
                                }
 
370
                                if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
 
371
                                        ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
 
372
                                }
 
373
                        }
 
374
                }
 
375
                return ipeSig;
 
376
        }
 
377
 
 
378
        private int computeCountBasedOnPeers(IProgramElement ipe) {
 
379
                int count = 1;
 
380
                for (IProgramElement object : ipe.getParent().getChildren()) {
 
381
                        if (object.equals(ipe)) {
 
382
                                break;
 
383
                        }
 
384
                        if (object.getKind() == ipe.getKind()) {
 
385
                                if (object.getKind().toString().equals(ipe.getKind().toString())) {
 
386
                                        String existingHandle = object.getHandleIdentifier();
 
387
                                        int suffixPosition = existingHandle.indexOf('!');
 
388
                                        if (suffixPosition != -1) {
 
389
                                                count = new Integer(existingHandle.substring(suffixPosition + 1)).intValue() + 1;
 
390
                                        } else {
 
391
                                                if (count == 1) {
 
392
                                                        count = 2;
 
393
                                                }
 
394
                                        }
 
395
                                }
 
396
                        }
 
397
                }
 
398
                return count;
 
399
        }
 
400
 
410
401
        /**
411
402
         * Only returns the count if it's not equal to 1
412
403
         */
480
471
                return false;
481
472
        }
482
473
 
483
 
        public void initialize() {
484
 
                // nop
485
 
        }
486
474
}