362 |
362 |
363 compile:theCode forClass:aClass inCategory:cat |
363 compile:theCode forClass:aClass inCategory:cat |
364 "install some code for a class. |
364 "install some code for a class. |
365 If refactory browser stuff is avaliable the refactory tools are used to support undo" |
365 If refactory browser stuff is avaliable the refactory tools are used to support undo" |
366 |
366 |
367 ^ self new compile:theCode forClass:aClass inCategory:cat |
367 self new compile:theCode forClass:aClass inCategory:cat |
368 ! ! |
368 ! ! |
369 |
369 |
370 !CodeGeneratorTool class methodsFor:'defaults'! |
370 !CodeGeneratorTool class methodsFor:'defaults'! |
371 |
371 |
372 copyrightTemplate |
372 copyrightTemplate |
1707 |
1707 |
1708 compile:theCode forClass:aClass inCategory:categoryOrNil skipIfSame:skipIfSame |
1708 compile:theCode forClass:aClass inCategory:categoryOrNil skipIfSame:skipIfSame |
1709 "install some code for a class. |
1709 "install some code for a class. |
1710 If refactory browser stuff is avaliable the refactory tools are used to support undo" |
1710 If refactory browser stuff is avaliable the refactory tools are used to support undo" |
1711 |
1711 |
1712 |change compiler selector oldMethod isSame category| |
1712 |change compiler selector oldMethod category| |
1713 |
1713 |
1714 isSame := false. |
1714 category := categoryOrNil. |
1715 category := categoryOrNil ? (Compiler defaultMethodCategory). |
|
1716 |
1715 |
1717 skipIfSame ifTrue:[ |
1716 skipIfSame ifTrue:[ |
1718 "JV: Do not use class's compilerClass, it may differ from |
1717 "JV: Do not use class's compilerClass, it may differ from |
1719 the compiler of this generator's language. For instance, |
1718 the compiler of this generator's language. For instance, |
1720 when compiling Smalltalk extension to Java or JavaScript class. |
1719 when compiling Smalltalk extension to Java or JavaScript class. |
1727 compiler parseMethod:theCode in:aClass ignoreErrors:true ignoreWarnings:true. |
1726 compiler parseMethod:theCode in:aClass ignoreErrors:true ignoreWarnings:true. |
1728 |
1727 |
1729 selector := compiler selector. |
1728 selector := compiler selector. |
1730 selector notNil ifTrue:[ |
1729 selector notNil ifTrue:[ |
1731 oldMethod := aClass compiledMethodAt:selector. |
1730 oldMethod := aClass compiledMethodAt:selector. |
1732 isSame := (oldMethod notNil and:[oldMethod source = theCode]). |
|
1733 isSame ifTrue:[^ self ]. |
|
1734 oldMethod notNil ifTrue:[ |
1731 oldMethod notNil ifTrue:[ |
1735 category := categoryOrNil ? (oldMethod category). |
1732 oldMethod source = theCode ifTrue:[^ self ]. "/ the same. |
|
1733 |
|
1734 categoryOrNil isNil ifTrue:[ |
|
1735 "/ if no category given, take the existing one. |
|
1736 category := oldMethod category. |
|
1737 ]. |
1736 ]. |
1738 ]. |
1737 ]. |
1739 ]. |
1738 ]. |
1740 ]. |
1739 |
1741 |
|
1742 category isNil ifTrue:[ |
|
1743 category := Compiler defaultMethodCategory. |
|
1744 ]. |
|
1745 |
1740 self canUseRefactoringSupport ifFalse:[ |
1746 self canUseRefactoringSupport ifFalse:[ |
1741 "/ compile immediately |
1747 "/ compile immediately |
1742 aClass compile:theCode classified:category. |
1748 ^ aClass compile:theCode classified:category. |
1743 ^ self. |
|
1744 ]. |
1749 ]. |
1745 |
1750 |
1746 change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:category. |
1751 change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:category. |
1747 change controller:(CompilationErrorHandlerQuery query). |
1752 change controller:(CompilationErrorHandlerQuery query). |
1748 |
1753 |
1749 "/ if collecting, add to changes (to be executed as one change at the end, |
|
1750 "/ in order to have only one change in the undo-list (instead of many) |
|
1751 compositeChangeCollector notNil ifTrue:[ |
1754 compositeChangeCollector notNil ifTrue:[ |
1752 compositeChangeCollector addChange:change |
1755 "/ if collecting, add to changes, to be executed as one change at the end. |
|
1756 "/ In order to have only one change in the undo-list (instead of many) |
|
1757 compositeChangeCollector addChange:change. |
1753 ] ifFalse:[ |
1758 ] ifFalse:[ |
|
1759 "/ do it now. |
1754 RefactoryChangeManager performChange:change. |
1760 RefactoryChangeManager performChange:change. |
1755 ] |
1761 ]. |
1756 |
1762 |
1757 "Modified: / 21-08-2006 / 18:39:06 / cg" |
1763 "Modified: / 21-08-2006 / 18:39:06 / cg" |
1758 "Modified (format): / 21-01-2012 / 10:40:59 / cg" |
1764 "Modified (format): / 21-01-2012 / 10:40:59 / cg" |
1759 "Modified (format): / 05-08-2014 / 21:06:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1765 "Modified (format): / 05-08-2014 / 21:06:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1760 ! |
1766 ! |
1761 |
1767 |