stx_goodies_smallsense.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 13 Aug 2014 20:40:56 +0100
changeset 279 1dcaf8e06968
parent 278 696843cd1f9d
child 280 100db0f8279b
permissions -rw-r--r--
Improvement in JavaEditSupport - indent when return is pressed.

"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2014 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:goodies/smallsense' }"

LibraryDefinition subclass:#stx_goodies_smallsense
	instanceVariableNames:''
	classVariableNames:'Swizzled'
	poolDictionaries:''
	category:'* Projects & Packages *'
!

!stx_goodies_smallsense class methodsFor:'documentation'!

copyright
"
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
Copyright (C) 2013-2014 Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!stx_goodies_smallsense class methodsFor:'initialization'!

initialize

    "This should be logically done in postload, but postload
     is not called when classlibrary is built-in (i.e., not loaded
     by Smalltalk loadPackage: ...). This is indeed a bug. "

    Swizzled := false.
    self hasAllExtensionsLoaded ifTrue:[
        self swizzle
    ].

    "Created: / 19-08-2013 / 15:24:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2013 / 12:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!stx_goodies_smallsense class methodsFor:'accessing - tests'!

excludedFromTestSuite
    "List of testcases and/or tests excluded from testsuite.
     Entries maybe ClassName or #(ClassName testName)
    "
    ^ #(
        #'SmallSense::BaseTestClass'
        #'SmallSense::TestCase'
        #'SmallSense::FinderTests'
        #'SmallSense::RecognizerTests'
        #'SmallSense::SmalltalkParserTests'
    )

    "Created: / 23-05-2014 / 12:49:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!stx_goodies_smallsense class methodsFor:'description'!

excludedFromPreRequisites
    "list all packages which should be ignored in the automatic
     preRequisites scan. See #preRequisites for more."

    ^ #(
    )
!

mandatoryPreRequisites
    "list packages which are mandatory as a prerequisite.
     This are packages containing superclasses of my classes and classes which
     are extended by myself.
     They are mandatory, because we need these packages as a prerequisite for loading and compiling.
     This method is generated automatically,
     by searching along the inheritance chain of all of my classes."

    ^ #(
        #'stx:goodies/refactoryBrowser/helpers'    "BrowserEnvironment - superclass of SmallSense::SmalltalkUnacceptedMethodEnvironment"
        #'stx:goodies/refactoryBrowser/lint'    "RBLintRule - extended"
        #'stx:goodies/regex'    "Regex::RxCharSetParser - superclass of SmallSense::TokenPatternParser::TokenSpecParser"
        #'stx:goodies/sunit'    "TestAsserter - superclass of SmallSense::AbstractJavaCompletionEngineTests"
        #'stx:libbasic'    "Collection - extended"
        #'stx:libcomp'    "AbstractSyntaxHighlighter - superclass of SmallSense::SmalltalkParser"
        #'stx:libhtml'    "HTMLDocumentFrame - extended"
        #'stx:libtool'    "AbstractSettingsApplication - superclass of SmallSense::SettingsAppl"
        #'stx:libview'    "DisplaySurface - extended"
        #'stx:libview2'    "ApplicationModel - extended"
        #'stx:libwidg'    "EditTextView - extended"
        #'stx:libwidg2'    "DoWhatIMeanSupport - extended"
    )
!

referencedPreRequisites
    "list packages which are a prerequisite, because they contain
     classes which are referenced by my classes.
     We do not need these packages as a prerequisite for loading or compiling.
     This method is generated automatically,
     by searching all classes (and their packages) which are referenced by my classes."

    ^ #(
        #'stx:goodies/refactoryBrowser/parser'    "RBFormatter - referenced by SmallSense::SmalltalkEditSupport>>electricInsertSnippetAfterDoubleColon"
        #'stx:libbasic2'    "BackgroundQueueProcessingJob - referenced by SmallSense::Manager>>initialize"
        #'stx:libbasic3'    "ChangeSet - referenced by RBTransformationRule>>fixes:"
        #'stx:libjava'    "Java - referenced by SmallSense::JavaCompletionEngine>>complete"
        #'stx:libjava/tools'    "GroovyScanner - referenced by SmallSense::GroovyCompletionEngineSimple>>scannerClass"
    )
!

subProjects
    "list packages which are known as subprojects.
     The generated makefile will enter those and make there as well.
     However: they are not forced to be loaded when a package is loaded;
     for those, redefine requiredPrerequisites"

    ^ #(
    )
! !

!stx_goodies_smallsense class methodsFor:'description - actions'!

postLoadAction

    "/ Setup SmallSense completion
    UserPreferences current at: #searchCompletionBlock put: #SmallSense.     

    "/ Swizzle methods. Note, that if they are already swizzled,
    "/ self swizzle is noop.
    self swizzle.

    "Created: / 02-09-2013 / 12:30:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 25-11-2013 / 12:31:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!stx_goodies_smallsense class methodsFor:'description - contents'!

classNamesAndAttributes
    "lists the classes which are to be included in the project.
     Each entry in the list may be: a single class-name (symbol),
     or an array-literal consisting of class name and attributes.
     Attributes are: #autoload or #<os> where os is one of win32, unix,..."

    ^ #(
        "<className> or (<className> attributes...) in load order"
        (#'SmallSense::AbstractTestCase' autoload)
        (#'SmallSense::BaseTestClass' autoload)
        #'SmallSense::CodeHighlightingService'
        #'SmallSense::CodeNavigationService'
        #'SmallSense::CompletionContext'
        #'SmallSense::CompletionController'
        #'SmallSense::CompletionEngine'
        #'SmallSense::CompletionResult'
        #'SmallSense::CompletionView'
        #'SmallSense::CriticsWindow'
        #'SmallSense::EditService'
        #'SmallSense::EditSupport'
        #'SmallSense::Info'
        (#'SmallSense::JavaCompletionEngineEnvironmentResource' autoload)
        #'SmallSense::Manager'
        #'SmallSense::PO'
        #'SmallSense::ParseTreeIndex'
        #'SmallSense::ParseTreeIndexEntry'
        #'SmallSense::ParseTreeInspector'
        #'SmallSense::SelectorNode'
        #'SmallSense::SettingsAppl'
        #'SmallSense::SmalltalkChecker'
        #'SmallSense::SmalltalkInferencerParameters'
        #'SmallSense::SmalltalkLintAnnotation'
        #'SmallSense::SmalltalkLintHighlighter'
        #'SmallSense::SmalltalkLintService'
        #'SmallSense::SmalltalkParseNodeVisitor'
        #'SmallSense::SmalltalkParser'
        #'SmallSense::SmalltalkQuickFixer'
        #'SmallSense::SmalltalkSyntaxHighlighter'
        #'SmallSense::SmalltalkUnacceptedMethodEnvironment'
        (#'SmallSense::TestCase' autoload)
        #'SmallSense::TokenPatternMatcher'
        (#'SmallSense::TokenPatternMatcherTests' autoload)
        #'SmallSense::TokenPatternParser'
        #'SmallSense::TokenPatternToken'
        #'SmallSense::TokenPatternTokenSet'
        #'SmallSense::TokenStream'
        #'SmallSense::Type'
        #'SmallSense::TypeHolder'
        #'stx_goodies_smallsense'
        #'SmallSense::AbstractJavaCompletionEngine'
        #'SmallSense::ClassInfo'
        #'SmallSense::ClassPO'
        #'SmallSense::ClassType'
        (#'SmallSense::CompletionEngineTests' autoload)
        #'SmallSense::ConstantPO'
        (#'SmallSense::EditSupportTests' autoload)
        (#'SmallSense::FinderTests' autoload)
        #'SmallSense::GenericEditSupport'
        #'SmallSense::JavaEditSupport'
        #'SmallSense::JavaImportPO'
        #'SmallSense::MethodInfo'
        #'SmallSense::MethodPO'
        (#'SmallSense::RecognizerTests' autoload)
        #'SmallSense::SmalltalkCompletionEngine'
        #'SmallSense::SmalltalkEditSupport'
        #'SmallSense::SmalltalkInferencer'
        #'SmallSense::SmalltalkParseNodeFinder'
        (#'SmallSense::SmalltalkParserTests' autoload)
        #'SmallSense::SnippetPO'
        #'SmallSense::UnionType'
        #'SmallSense::UnknownType'
        #'SmallSense::VariablePO'
        #'SmallSense::AbstractJavaCompletionEngineSimple'
        (#'SmallSense::AbstractJavaCompletionEngineTests' autoload)
        #'SmallSense::GroovyEditSupport'
        #'SmallSense::JavaCompletionEngine'
        #'SmallSense::JavaConstructorPO'
        (#'SmallSense::JavaEditSupportTests' autoload)
        #'SmallSense::MethodKeywordRestPO'
        (#'SmallSense::SmalltalkCompletionEngineTests' autoload)
        (#'SmallSense::SmalltalkEditSupportTests' autoload)
        (#'SmallSense::GroovyCompletionEngineSimpleTests' autoload)
        #'SmallSense::JavaCompletionEngineSimple'
        (#'SmallSense::JavaCompletionEngineTests' autoload)
        #'SmallSense::GroovyCompletionEngineSimple'
    )
!

extensionMethodNames
    "list class/selector pairs of extensions.
     A correponding method with real names must be present in my concrete subclasses"

    ^ #(
        ParseNode isSelector
        AssignmentNode childNamesAndValuesDo:
        AssignmentNode inferedType
        AssignmentNode inferedType:
        MessageNode childNamesAndValuesDo:
        ParseErrorNode childNamesAndValuesDo:
        ParseNode childNamesAndValuesDo:
        ParseNode inferedType
        ParseNode inferedType:
        PrimaryNode childNamesAndValuesDo:
        StatementNode childNamesAndValuesDo:
        StatementNode inferedType
        StatementNode inferedType:
        UserPreferences smallSenseEnabled
        UserPreferences smallSenseEnabled:
        VariableNode isGlobalOrPrivateClass
        'ConfigurableFeatures class' hasSmallSenseEnabled
        UserPreferences smallSenseBackgroundLintEnabled
        UserPreferences smallSenseBackgroundLintEnabled:
        RBLintRule fixes:
        RBTransformationRule fixes:
        UserPreferences smallSenseBackgroundTypingEnabled
        UserPreferences smallSenseBackgroundTypingEnabled:
        HTMLDocumentView doQuickFix:
        'Tools::CodeHighlightingService class' new
        DoWhatIMeanSupport smallSenseCodeCompletionForClass:context:codeView:
        #'Tools::NavigationState' smallSenseSelectedClasses
        'Tools::CodeCompletionService class' smallSenseIsUsefulFor:
        BlockNode childNamesAndValuesDo:
        'Tools::CodeNavigationService class' new
        'Workspace class' smallSenseCodeCompletionServiceClass
        ParseNode navigateToUsing:
        MessageNode navigateToUsing:
        VariableNode navigateToUsing:
        EditTextView autoIndent
        #'Tools::NewSystemBrowser' #'searchCompletionBlock_SmallSense'
        #'Tools::NewSystemBrowser' smallSenseSearchCompletion:
        #'Tools::NewSystemBrowser' smallSenseSearchCompletionBlock
        #'Tools::NewSystemBrowser' smallSenseSearchCompletionEntryForClass:showPrefix:
        #'Tools::NewSystemBrowser' smallSenseSearchCompletionNewForClass:
        PrimitiveNode inferedType
        UserPreferences smallSenseCompleteIfUnambiguous
        UserPreferences smallSenseCompleteIfUnambiguous:
        UserPreferences smallSenseCompletionEnabled
        UserPreferences smallSenseCompletionEnabled:
        Method inspector2TabParseTreeInspector
        Method inspector2Tabs
        ReturnNode childNamesAndValuesDo:
        UserPreferences smallSenseSmalltalkIndentOnPasteEnabled
        UserPreferences smallSenseSmalltalkIndentOnPasteEnabled:
        EditTextViewCompletionSupport isCompletionViewShown
    )
! !

!stx_goodies_smallsense class methodsFor:'description - project information'!

applicationIconFileName
    "Return the name (without suffix) of an icon-file (the app's icon); will be included in the rc-resource file"

    ^ nil
    "/ ^ self applicationName
!

companyName
    "Return a companyname which will appear in <lib>.rc"

    ^ 'Jan Vrany'

    "Modified: / 17-07-2014 / 22:57:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

description
    "Return a description string which will appear in vc.def / bc.def"

    ^ 'Smalltalk/X IDE Productivity Tool'

    "Modified: / 17-07-2014 / 23:06:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

legalCopyright
    "Return a copyright string which will appear in <lib>.rc"

    ^ 'Copyright Jan Vrany 2013-2014'

    "Modified: / 17-07-2014 / 22:57:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

productName
    "Return a product name which will appear in <lib>.rc"

    ^ 'SmallSense'

    "Modified: / 17-07-2014 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!stx_goodies_smallsense class methodsFor:'description - svn'!

svnRepositoryUrlString
    "Return a SVN repository URL of myself.
     (Generated since 2011-04-08)
    "        

    ^ '$URL: https://vranyj1@swing.fit.cvut.cz/svn/stx/libtool/branches/jv/smallsense/stx_goodies_smallsense.st $'
!

svnRevisionNr
    "Return a SVN revision number of myself.
     This number is updated after a commit"

    ^ "$SVN-Revision:"'7962            '"$"
! !

!stx_goodies_smallsense class methodsFor:'swizzling'!

swizzle
    "Swizzle all methods annotated as <swizzle:>"

    Swizzled ifTrue:[ ^ self ].
    [
        self extensionMethods do:[:m|self swizzle: m].
        Swizzled := true.
    ] on: Error do:[:ex |
        Logger log: ('Cannot swizzle: %1' bindWith: ex description) severity: #error
    ].


    "
    stx_goodies_smallsense swizzle
    "

    "Created: / 19-08-2013 / 14:54:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-09-2013 / 12:30:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

swizzle: method
    "Swizzle the method if it is annotated by <swizzle:> annotation"

    | annotation |

    [
        annotation := method annotationAt: #swizzle:.
        annotation notNil ifTrue:[
            self swizzle: method as: (annotation argumentAt: 1).
        ]
    ] on: Error do:[:ex|
        Logger log: ('Cannot swizzle %1: %2' bindWith: method with: ex description) severity: #error
    ]

    "Created: / 19-08-2013 / 14:53:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

swizzle: originalMethod as: selector
    "Given an extension method, swizzle it into method's class
     under given selector."

    | cls overwrittenMethod swizzledMethod |

    cls := originalMethod mclass.
    overwrittenMethod := cls compiledMethodAt: selector.
    overwrittenMethod isNil ifTrue:[
        "/ Oops, method gone?
        self breakPoint: #jv.
        ^ self.
    ].

    self assert: originalMethod numArgs == overwrittenMethod numArgs.

    swizzledMethod := originalMethod copy.
    "/ Now, fake the package and source of swizzled method
    "/ so on fileout, original code gets filed out.
    swizzledMethod setPackage: overwrittenMethod package.
    swizzledMethod setCategory: overwrittenMethod category.
    swizzledMethod source: overwrittenMethod source.

    "/ Install the swizzled method
    cls methodDictionary at: selector put: swizzledMethod

    "Created: / 19-08-2013 / 14:01:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-08-2013 / 15:03:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!stx_goodies_smallsense class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id: stx_goodies_smallsense.st,v 1.2 2014/02/12 14:49:29 sr Exp $'
! !


stx_goodies_smallsense initialize!