10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 "{ Package: 'stx:libbasic' }" |
12 "{ Package: 'stx:libbasic' }" |
13 |
13 |
14 CompiledCode variableSubclass:#Method |
14 CompiledCode variableSubclass:#Method |
15 instanceVariableNames:'source sourcePosition category package mclass' |
15 instanceVariableNames:'source sourcePosition category package mclass lookupObject |
|
16 annotations' |
16 classVariableNames:'PrivateMethodSignal LastFileReference LastSourceFileName |
17 classVariableNames:'PrivateMethodSignal LastFileReference LastSourceFileName |
17 LastWhoClass LastFileLock LastMethodSources LastMethodSourcesLock |
18 LastWhoClass LastFileLock LastMethodSources LastMethodSourcesLock |
18 CompilationLock' |
19 CompilationLock Overrides' |
19 poolDictionaries:'' |
20 poolDictionaries:'' |
20 category:'Kernel-Methods' |
21 category:'Kernel-Methods' |
21 ! |
22 ! |
22 |
23 |
23 Object subclass:#MethodWhoInfo |
24 Object subclass:#MethodWhoInfo |
314 ^ self sends:aSelectorSymbol |
316 ^ self sends:aSelectorSymbol |
315 ! ! |
317 ! ! |
316 |
318 |
317 |
319 |
318 !Method methodsFor:'accessing'! |
320 !Method methodsFor:'accessing'! |
|
321 |
|
322 annotateWith: annotation |
|
323 |
|
324 | index | |
|
325 index := self annotationIndexOf: annotation key. |
|
326 index |
|
327 ifNil: |
|
328 [annotations := annotations |
|
329 ifNil:[Array with: annotation] |
|
330 ifNotNil:[annotations copyWith:annotation]] |
|
331 ifNotNil: |
|
332 [annotations at: index put: annotation]. |
|
333 "/ annotation annotatesMethod: self. |
|
334 |
|
335 " |
|
336 (Object >> #yourself) annotateWith: (Annotation namespace: 'Fictious'). |
|
337 (Object >> #yourself) annotations. |
|
338 (Object >> #yourself) annotationAt: #namespace: |
|
339 " |
|
340 |
|
341 "Created: / 19-05-2010 / 16:20:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
342 "Modified: / 20-05-2010 / 11:22:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
343 ! |
|
344 |
|
345 annotationAt: key |
|
346 |
|
347 | index | |
|
348 |
|
349 index := self annotationIndexOf: key. |
|
350 index ifNil:[^nil]. |
|
351 ^self annotationAtIndex: index. |
|
352 |
|
353 " |
|
354 (Object >> #yourself) annotationAt: #namespace: |
|
355 " |
|
356 |
|
357 "Created: / 19-05-2010 / 16:16:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
358 "Modified: / 02-07-2010 / 22:35:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
359 ! |
|
360 |
|
361 annotations |
|
362 "Returns annotations" |
|
363 |
|
364 annotations ifNil:[^#()]. |
|
365 "iterate over annotation array to |
|
366 trigger lazy-loading" |
|
367 self annotationsDo:[:ignored]. |
|
368 ^ annotations |
|
369 |
|
370 "Modified: / 11-07-2010 / 19:25:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
371 ! |
|
372 |
|
373 annotations: anObject |
|
374 "set the annotations" |
|
375 |
|
376 self setAnnotations: anObject. |
|
377 "/ "iterate over annotations just to invoke |
|
378 "/ annotationAtIndex: which lazyliyinitialize annotations |
|
379 "/ and send #annotatesMethod:" |
|
380 "/ self annotationsDo:[:annotation|] |
|
381 |
|
382 "Created: / 02-07-2010 / 22:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
383 ! |
|
384 |
|
385 annotationsAt: key |
|
386 |
|
387 ^OrderedCollection streamContents: |
|
388 [:annotStream| |
|
389 self annotationsAt: key do: |
|
390 [:annot|annotStream nextPut: annot]] |
|
391 |
|
392 "Created: / 16-07-2010 / 11:41:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
393 ! |
|
394 |
|
395 annotationsAt: key do: block |
|
396 |
|
397 | annots | |
|
398 annots := OrderedCollection new: 1. |
|
399 self annotationsDo: |
|
400 [:annot| |
|
401 annot key == key ifTrue: |
|
402 [block value: annot]] |
|
403 |
|
404 "Created: / 16-07-2010 / 11:48:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
405 ! |
|
406 |
|
407 annotationsAt: key1 orAt: key2 |
|
408 |
|
409 ^OrderedCollection streamContents: |
|
410 [:annotStream| |
|
411 self annotationsAt: key1 orAt: key2 do: |
|
412 [:annot|annotStream nextPut: annot]] |
|
413 |
|
414 "Created: / 16-07-2010 / 11:41:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
415 ! |
|
416 |
|
417 annotationsAt: key1 orAt: key2 do: block |
|
418 |
|
419 | annots | |
|
420 annots := OrderedCollection new: 1. |
|
421 self annotationsDo: |
|
422 [:annot| |
|
423 (annot key == key1 or:[annot key == key2]) ifTrue: |
|
424 [block value: annot]] |
|
425 |
|
426 "Created: / 16-07-2010 / 11:47:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
427 ! |
|
428 |
|
429 annotationsDo: aBlock |
|
430 |
|
431 annotations ifNil:[^nil]. |
|
432 1 to: annotations size do: |
|
433 [:i|aBlock value: (self annotationAtIndex: i)]. |
|
434 |
|
435 "Created: / 02-07-2010 / 22:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
436 "Modified: / 11-07-2010 / 19:38:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
437 ! |
319 |
438 |
320 category |
439 category |
321 "return the methods category or nil" |
440 "return the methods category or nil" |
322 |
441 |
323 ^ category |
442 ^ category |
397 sourcePosition := aNumber negated |
516 sourcePosition := aNumber negated |
398 |
517 |
399 "Created: 16.1.1997 / 01:25:52 / cg" |
518 "Created: 16.1.1997 / 01:25:52 / cg" |
400 ! |
519 ! |
401 |
520 |
|
521 lookupObject |
|
522 |
|
523 ^lookupObject ifNil:[Lookup builtin]. |
|
524 |
|
525 "Created: / 28-04-2010 / 18:36:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
526 ! |
|
527 |
|
528 lookupObject: anObject |
|
529 |
|
530 self setLookupObject: anObject. |
|
531 |
|
532 "Created: / 28-04-2010 / 18:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
533 "Modified: / 11-07-2010 / 19:32:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
534 ! |
|
535 |
402 makeLocalStringSource |
536 makeLocalStringSource |
403 "assure that the methods source code is stored locally as a string |
537 "assure that the methods source code is stored locally as a string |
404 within the method (as opposed to an external string, which is accessed |
538 within the method (as opposed to an external string, which is accessed |
405 by reading the source code file). |
539 by reading the source code file). |
406 This is required, when a methods package is changed, to assure that its |
540 This is required, when a methods package is changed, to assure that its |
427 mclass := aClass. |
561 mclass := aClass. |
428 |
562 |
429 "Modified: / 28-11-2006 / 12:12:27 / cg" |
563 "Modified: / 28-11-2006 / 12:12:27 / cg" |
430 ! |
564 ! |
431 |
565 |
|
566 nameSpace |
|
567 |
|
568 "Returns my namespace or nil. If no explicit method namespace |
|
569 is set, my programmming language is used as default namespace |
|
570 (for compatibility reasons, for smalltalk methods nil is returned, |
|
571 which means that the method is not namespaced). |
|
572 " |
|
573 |
|
574 | nsA lang | |
|
575 nsA := self annotationAt: #namespace:. |
|
576 nsA ifNotNil:[^nsA nameSpace]. |
|
577 |
|
578 ^(lang := self programmingLanguage) isSmalltalk |
|
579 ifTrue:[nil] |
|
580 ifFalse:[lang]. |
|
581 |
|
582 " |
|
583 (Method >> #nameSpace) nameSpace |
|
584 (Object >> #yourself) nameSpace |
|
585 |
|
586 " |
|
587 |
|
588 "Created: / 26-04-2010 / 16:30:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
589 "Modified: / 20-05-2010 / 09:38:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
590 ! |
|
591 |
|
592 nameSpace: aNameSpace |
|
593 |
|
594 self annotateWith: (Annotation namespace: aNameSpace name) |
|
595 |
|
596 "Created: / 20-05-2010 / 10:05:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
597 "Modified: / 20-05-2010 / 11:30:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
598 ! |
|
599 |
|
600 nameSpaceName |
|
601 |
|
602 | ns | |
|
603 ^(ns := self nameSpace) |
|
604 ifNotNil:[ns name] |
|
605 ifNil:[''] |
|
606 ! |
|
607 |
432 originalMethodIfWrapped |
608 originalMethodIfWrapped |
433 "return the method the receiver is wrapping - none here" |
609 "return the method the receiver is wrapping - none here" |
434 |
610 |
435 ^ self |
611 ^ self |
436 |
612 |
437 "Created: / 22-10-2010 / 11:46:07 / cg" |
613 "Created: / 22-10-2010 / 11:46:07 / cg" |
|
614 ! |
|
615 |
|
616 overriddenMethod |
|
617 |
|
618 "Answers overridden method or nil." |
|
619 |
|
620 Overrides ifNil:[^nil]. |
|
621 ^(Overrides includesKey: self) |
|
622 ifTrue:[Overrides at: self] |
|
623 |
|
624 "Created: / 17-06-2009 / 19:09:58 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
625 ! |
|
626 |
|
627 overriddenMethod: aMethod |
|
628 |
|
629 "Set overridden method to aMethod" |
|
630 |
|
631 Overrides ifNil:[Overrides := WeakIdentityDictionary new:10]. |
|
632 aMethod ifNotNil:[aMethod makeLocalStringSource]. |
|
633 Overrides at: self put: aMethod |
|
634 |
|
635 "Created: / 17-06-2009 / 19:09:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
636 "Modified: / 22-08-2009 / 10:47:42 / Jan Vrany <vranyj1@fel.cvut.cz>" |
438 ! |
637 ! |
439 |
638 |
440 package |
639 package |
441 "return the package-ID of the method (nil is translated to noProject here)" |
640 "return the package-ID of the method (nil is translated to noProject here)" |
442 |
641 |
482 Smalltalk changed:#projectOrganization with:(Array with:cls with:self with:oldPackage). |
681 Smalltalk changed:#projectOrganization with:(Array with:cls with:self with:oldPackage). |
483 cls addChangeRecordForMethodPackage:self package:newPackage. |
682 cls addChangeRecordForMethodPackage:self package:newPackage. |
484 ] |
683 ] |
485 |
684 |
486 "Modified: / 23-11-2006 / 17:01:02 / cg" |
685 "Modified: / 23-11-2006 / 17:01:02 / cg" |
|
686 ! |
|
687 |
|
688 setAnnotations: anObject |
|
689 "set the annotations (low level - use do not use)" |
|
690 |
|
691 annotations := anObject |
|
692 |
|
693 "Created: / 20-05-2010 / 11:27:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
487 ! |
694 ! |
488 |
695 |
489 setCategory:aStringOrSymbol |
696 setCategory:aStringOrSymbol |
490 "set the methods category (without change notification)" |
697 "set the methods category (without change notification)" |
491 |
698 |
1591 "Modified: 1.11.1996 / 16:27:04 / cg" |
1798 "Modified: 1.11.1996 / 16:27:04 / cg" |
1592 ! ! |
1799 ! ! |
1593 |
1800 |
1594 !Method methodsFor:'private'! |
1801 !Method methodsFor:'private'! |
1595 |
1802 |
|
1803 annotationAtIndex: index |
|
1804 |
|
1805 "return annotation at given index. |
|
1806 any raw annotation array is lazily |
|
1807 initialized" |
|
1808 |
|
1809 | annotation args | |
|
1810 annotations ifNil:[^nil]. |
|
1811 annotation := annotations at: index. |
|
1812 annotation isArray ifTrue:[ |
|
1813 args := annotation size == 2 |
|
1814 ifTrue:[annotation second] |
|
1815 ifFalse:[#()]. |
|
1816 args isArray ifFalse:[args := Array with: args]. |
|
1817 annotation := Annotation |
|
1818 key: annotation first |
|
1819 arguments: args. |
|
1820 annotation isUnknown ifFalse:[ |
|
1821 annotations at: index put: annotation. |
|
1822 "/ annotation annotatesMethod: self |
|
1823 ]. |
|
1824 ]. |
|
1825 ^annotation |
|
1826 |
|
1827 "Created: / 02-07-2010 / 22:30:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1828 "Modified: / 11-07-2010 / 19:39:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1829 ! |
|
1830 |
|
1831 annotationIndexOf: key |
|
1832 |
|
1833 "Returns index of annotation with given key |
|
1834 or nil if there is no such annotation" |
|
1835 |
|
1836 annotations ifNil:[^nil]. |
|
1837 |
|
1838 annotations keysAndValuesDo: |
|
1839 [:index :annotationOrArray| |
|
1840 annotationOrArray isArray |
|
1841 ifTrue: [annotationOrArray first == key ifTrue:[^index]] |
|
1842 ifFalse:[annotationOrArray key == key ifTrue:[^index]]]. |
|
1843 ^nil. |
|
1844 |
|
1845 "Created: / 19-05-2010 / 16:40:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1846 "Modified: / 11-07-2010 / 19:23:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1847 ! |
|
1848 |
1596 cacheSourceStream:aStream |
1849 cacheSourceStream:aStream |
1597 "remember a (raw) source stream for later use" |
1850 "remember a (raw) source stream for later use" |
1598 |
1851 |
1599 |lastStream| |
1852 |lastStream| |
1600 |
1853 |
1606 ]. |
1859 ]. |
1607 LastSourceFileName := package,'/',source. |
1860 LastSourceFileName := package,'/',source. |
1608 LastFileReference at:1 put:aStream. |
1861 LastFileReference at:1 put:aStream. |
1609 ]. |
1862 ]. |
1610 ]. |
1863 ]. |
|
1864 ! |
|
1865 |
|
1866 getAnnotations |
|
1867 |
|
1868 ^annotations |
|
1869 |
|
1870 "Created: / 10-07-2010 / 21:55:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1871 "Modified: / 11-07-2010 / 19:30:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1872 ! |
|
1873 |
|
1874 getLookupObject |
|
1875 |
|
1876 ^lookupObject |
|
1877 |
|
1878 "Created: / 10-07-2010 / 21:55:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1611 ! |
1879 ! |
1612 |
1880 |
1613 localSourceStream |
1881 localSourceStream |
1614 "try to open a stream from a local source file, |
1882 "try to open a stream from a local source file, |
1615 searching in standard places." |
1883 searching in standard places." |
1995 (IDispatchPointer compiledMethodAt:#'invokeGetTypeInfo:_:_:') |
2272 (IDispatchPointer compiledMethodAt:#'invokeGetTypeInfo:_:_:') |
1996 externalLibraryFunction |
2273 externalLibraryFunction |
1997 " |
2274 " |
1998 ! |
2275 ! |
1999 |
2276 |
|
2277 hasAnnotation |
|
2278 |
|
2279 "Return true iff method has any annotation" |
|
2280 |
|
2281 ^annotations notNil |
|
2282 |
|
2283 "Created: / 11-07-2010 / 19:27:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2284 ! |
|
2285 |
|
2286 hasAnnotation: key |
|
2287 |
|
2288 "Return true iff method is annotated with |
|
2289 given key" |
|
2290 |
|
2291 ^(self annotationIndexOf: key) notNil |
|
2292 |
|
2293 "Created: / 11-07-2010 / 19:28:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2294 ! |
|
2295 |
2000 hasAnyResource:aCollectionOfSymbols |
2296 hasAnyResource:aCollectionOfSymbols |
2001 "return true if the method has a <resource> definition for any symbol in aCollectionOfSymbols" |
2297 "return true if the method has a <resource> definition for any symbol in aCollectionOfSymbols" |
2002 |
2298 |
2003 ^ self hasResource and:[ self resources keys includesAny:aCollectionOfSymbols ] |
2299 ^ self hasResource and:[ self resources keys includesAny:aCollectionOfSymbols ] |
2004 |
2300 |
2418 ^ self selector |
2719 ^ self selector |
2419 |
2720 |
2420 "Created: / 9.11.1998 / 06:15:08 / cg" |
2721 "Created: / 9.11.1998 / 06:15:08 / cg" |
2421 ! |
2722 ! |
2422 |
2723 |
|
2724 overrides: aMethod |
|
2725 |
|
2726 | mth | |
|
2727 mth := self overriddenMethod. |
|
2728 [ mth notNil ] whileTrue: |
|
2729 [mth == aMethod ifTrue:[^true]. |
|
2730 mth := mth overriddenMethod]. |
|
2731 ^false |
|
2732 |
|
2733 "Modified: / 18-06-2009 / 12:15:53 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
2734 ! |
|
2735 |
2423 parse:parseSelector return:accessSelector or:valueIfNoSource |
2736 parse:parseSelector return:accessSelector or:valueIfNoSource |
2424 "helper for methodArgNames, methodVarNames etc. |
2737 "helper for methodArgNames, methodVarNames etc. |
2425 Get the source, let parser parse it using parseSelector, |
2738 Get the source, let parser parse it using parseSelector, |
2426 return parser-info using accessSelector" |
2739 return parser-info using accessSelector" |
2427 |
2740 |
2455 |
2768 |
2456 " |
2769 " |
2457 (Method compiledMethodAt:#parse:return:or:) |
2770 (Method compiledMethodAt:#parse:return:or:) |
2458 parse:#'parseMethodSilent:' return:#sentMessages or:#() |
2771 parse:#'parseMethodSilent:' return:#sentMessages or:#() |
2459 " |
2772 " |
|
2773 ! |
|
2774 |
|
2775 parseAnnotations |
|
2776 |
|
2777 "return the methods annotations." |
|
2778 |
|
2779 |src parser| |
|
2780 |
|
2781 src := self source. |
|
2782 src isNil ifTrue:[ |
|
2783 ^ nil "/ actually: dont know |
|
2784 ]. |
|
2785 |
|
2786 self parserClass isNil ifTrue:[ |
|
2787 ^ nil |
|
2788 ]. |
|
2789 parser := self parserClass parseMethod: src. |
|
2790 (parser isNil or: [parser == #Error]) ifTrue:[ |
|
2791 ^ nil "/ actually error |
|
2792 ]. |
|
2793 ^ annotations := parser annotations. |
|
2794 |
|
2795 "Created: / 10-07-2010 / 21:16:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2460 ! |
2796 ! |
2461 |
2797 |
2462 parseResources |
2798 parseResources |
2463 "return the methods resource spec; either nil or a collection of symbols." |
2799 "return the methods resource spec; either nil or a collection of symbols." |
2464 |
2800 |
2606 ! |
2942 ! |
2607 |
2943 |
2608 resources |
2944 resources |
2609 "return the methods resource spec; either nil or a collection of symbols." |
2945 "return the methods resource spec; either nil or a collection of symbols." |
2610 |
2946 |
|
2947 | resources | |
2611 self hasResource ifFalse:[^ nil]. |
2948 self hasResource ifFalse:[^ nil]. |
2612 ^ self parseResources. |
2949 annotations ifNil:[^ self parseResources]. |
2613 |
2950 |
2614 "Modified: / 01-12-2010 / 13:59:48 / cg" |
2951 resources := IdentityDictionary new. |
|
2952 self annotationsAt: #resource: orAt: #resource:value: do: |
|
2953 [:annot| |
|
2954 resources at: annot type put: annot value ? true]. |
|
2955 ^resources |
|
2956 |
|
2957 "Modified: / 16-07-2010 / 11:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2615 ! |
2958 ! |
2616 |
2959 |
2617 selector |
2960 selector |
2618 "return the selector under which I am found in my containingClasses |
2961 "return the selector under which I am found in my containingClasses |
2619 method-table. |
2962 method-table. |