775 |cls codePieces skip protoSpec thisCode |
775 |cls codePieces skip protoSpec thisCode |
776 definedMethodSelectors iVars t exportSels| |
776 definedMethodSelectors iVars t exportSels| |
777 |
777 |
778 cls := self targetClass. |
778 cls := self targetClass. |
779 cls isNil ifTrue:[ |
779 cls isNil ifTrue:[ |
780 ^ nil |
780 ^ nil |
781 ]. |
781 ]. |
782 |
782 |
783 codePieces := OrderedCollection new. |
783 codePieces := OrderedCollection new. |
784 definedMethodSelectors := IdentitySet new. |
784 definedMethodSelectors := IdentitySet new. |
785 |
785 |
786 treeView propertiesDo:[:aProp| |
786 treeView propertiesDo:[:aProp| |
787 |modelSelector| |
787 |modelSelector| |
788 |
788 |
789 protoSpec := aProp spec. |
789 protoSpec := aProp spec. |
790 |
790 |
791 (modelSelector := aProp model) notNil ifTrue:[ |
791 (modelSelector := aProp model) notNil ifTrue:[ |
792 self generateCodeFrom:(Array with:modelSelector) in:cls |
792 self generateCodeFrom:(Array with:modelSelector) in:cls |
793 do:[:aSel| |
793 do:[:aSel| |
794 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
794 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
795 skip := false. |
795 skip := false. |
796 |
796 |
797 (cls isSubclassOf:SimpleDialog) ifTrue:[ |
797 (cls isSubclassOf:SimpleDialog) ifTrue:[ |
798 skip := SimpleDialog includesSelector:aSel |
798 skip := SimpleDialog includesSelector:aSel |
799 ]. |
799 ]. |
800 (definedMethodSelectors includes:aSel) ifTrue:[ |
800 (definedMethodSelectors includes:aSel) ifTrue:[ |
801 skip := true. |
801 skip := true. |
802 ]. |
802 ]. |
803 |
803 |
804 skip ifFalse:[ |
804 skip ifFalse:[ |
805 "/ kludge .. |
805 "/ kludge .. |
806 "/ (protoSpec isKindOf:ActionButtonSpec) |
806 "/ (protoSpec isKindOf:ActionButtonSpec) |
807 (protoSpec defaultModelIsCallBackMethodSelector:aSel) |
807 (protoSpec defaultModelIsCallBackMethodSelector:aSel) |
808 ifTrue:[ |
808 ifTrue:[ |
809 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
809 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
810 ] ifFalse:[ |
810 ] ifFalse:[ |
811 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
811 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
812 ]. |
812 ]. |
813 codePieces add:thisCode. |
813 codePieces add:thisCode. |
814 definedMethodSelectors add:aSel. |
814 definedMethodSelectors add:aSel. |
815 Transcript showCR:'code generated for aspect: ' , aSel |
815 Transcript showCR:'code generated for aspect: ' , aSel |
816 ] ifTrue:[ |
816 ] ifTrue:[ |
817 Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)' |
817 Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)' |
818 ]. |
818 ]. |
819 ]. |
819 ]. |
820 ]. |
820 ]. |
821 ]. |
821 ]. |
822 |
822 |
823 "/ for each aspect, generate getter (if not yet implemented) |
823 "/ for each aspect, generate getter (if not yet implemented) |
824 self generateCodeFrom:(aProp spec aspectSelectors) in:cls |
824 self generateCodeFrom:(aProp spec aspectSelectors) in:cls |
825 do:[:aSel| |
825 do:[:aSel| |
826 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
826 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
827 (definedMethodSelectors includes:aSel) ifFalse:[ |
827 (definedMethodSelectors includes:aSel) ifFalse:[ |
828 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
828 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
829 codePieces add:thisCode. |
829 codePieces add:thisCode. |
830 definedMethodSelectors add:aSel. |
830 definedMethodSelectors add:aSel. |
831 Transcript showCR:'code generated for aspect: ' , aSel |
831 Transcript showCR:'code generated for aspect: ' , aSel |
832 ] |
832 ] |
833 ] |
833 ] |
834 ]. |
834 ]. |
835 |
835 |
836 "/ exported aspects - need setter methods |
836 "/ exported aspects - need setter methods |
837 exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect , ':') asSymbol]. |
837 exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect , ':') asSymbol]. |
838 self generateCodeFrom:exportSels in:cls |
838 self generateCodeFrom:exportSels in:cls |
839 do:[:aSel| |
839 do:[:aSel| |
840 |aspect| |
840 |aspect| |
841 |
841 |
842 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
842 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
843 (definedMethodSelectors includes:aSel) ifFalse:[ |
843 (definedMethodSelectors includes:aSel) ifFalse:[ |
844 aspect := (aSel copyWithoutLast:1) asSymbol. |
844 aspect := (aSel copyWithoutLast:1) asSymbol. |
845 thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls). |
845 thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls). |
846 codePieces add:thisCode. |
846 codePieces add:thisCode. |
847 definedMethodSelectors add:aSel. |
847 definedMethodSelectors add:aSel. |
848 Transcript showCR:'export code generated for aspect: ' , aSel |
848 Transcript showCR:'export code generated for aspect: ' , aSel |
849 ] |
849 ] |
850 ] |
850 ] |
851 ]. |
851 ]. |
852 |
852 |
853 self generateCodeFrom:(aProp spec actionSelectors) in:cls |
853 self generateCodeFrom:(aProp spec actionSelectors) in:cls |
854 do:[:aSel| |
854 do:[:aSel| |
855 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
855 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
856 (definedMethodSelectors includes:aSel) ifFalse:[ |
856 (definedMethodSelectors includes:aSel) ifFalse:[ |
857 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
857 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
858 codePieces add:thisCode. |
858 codePieces add:thisCode. |
859 definedMethodSelectors add:aSel. |
859 definedMethodSelectors add:aSel. |
860 Transcript showCR:'action generated for aspect: ' , aSel |
860 Transcript showCR:'action generated for aspect: ' , aSel |
861 ] |
861 ] |
862 ] |
862 ] |
863 ]. |
863 ]. |
864 |
864 |
865 self generateCodeFrom:(aProp spec valueSelectors) in:cls |
865 self generateCodeFrom:(aProp spec valueSelectors) in:cls |
866 do:[:aSel| |
866 do:[:aSel| |
867 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
867 (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
868 (definedMethodSelectors includes:aSel) ifFalse:[ |
868 (definedMethodSelectors includes:aSel) ifFalse:[ |
869 "/ uppercase: - assume its a globals name. |
869 "/ uppercase: - assume its a globals name. |
870 aSel first isUppercase ifFalse:[ |
870 aSel isUppercaseFirst ifFalse:[ |
871 thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls). |
871 thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls). |
872 codePieces add:thisCode. |
872 codePieces add:thisCode. |
873 definedMethodSelectors add:aSel. |
873 definedMethodSelectors add:aSel. |
874 Transcript showCR:'code generated for aspect: ' , aSel |
874 Transcript showCR:'code generated for aspect: ' , aSel |
875 ] |
875 ] |
876 ] |
876 ] |
877 ] |
877 ] |
878 ]. |
878 ]. |
879 ]. |
879 ]. |
880 |
880 |
881 AspectsAsInstances ifTrue:[ |
881 AspectsAsInstances ifTrue:[ |
882 iVars := cls instVarNames asOrderedCollection. |
882 iVars := cls instVarNames asOrderedCollection. |
883 definedMethodSelectors do:[:ivar | |
883 definedMethodSelectors do:[:ivar | |
884 (iVars includes:ivar) ifFalse:[ |
884 (iVars includes:ivar) ifFalse:[ |
885 iVars add:ivar |
885 iVars add:ivar |
886 ] |
886 ] |
887 ]. |
887 ]. |
888 iVars := iVars asArray. |
888 iVars := iVars asArray. |
889 t := cls shallowCopy. |
889 t := cls shallowCopy. |
890 t setInstanceVariableString:iVars asStringCollection asString. |
890 t setInstanceVariableString:iVars asStringCollection asString. |
891 codePieces addFirst:(t definition , '!!\' withCRs). |
891 codePieces addFirst:(t definition , '!!\' withCRs). |
892 ]. |
892 ]. |
893 |
893 |
894 ^ String |
894 ^ String |
895 streamContents: |
895 streamContents: |
896 [:codeStream | |
896 [:codeStream | |
897 codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece]. |
897 codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece]. |
898 ]. |
898 ]. |
899 |
899 |
900 "Modified: / 29.7.1998 / 12:21:19 / cg" |
900 "Modified: / 29.7.1998 / 12:21:19 / cg" |
901 ! |
901 ! |
902 |
902 |
903 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
903 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |