Namespace tree calculation for java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Namespace tree calculation for java

Stephan Eggermont-3
This looks like a rather slow way to calculate a namespace tree.
I'm pretty sure it can be done in such a way that a Task is not needed.


MooseModel>inferNamespaceParentsBasedOnNames
        <menuItem: 'Infer Namespace Parents Based on Names' category: 'Utilities'>
        | parent parentNameSize currentPosition parentName namespaces |
        namespaces := self allNamespaces.
        MooseCustomTask new with: [:task |
                namespaces do: [ :each |
                        currentPosition := 1.
                        each name: (each name copyReplaceAll: '.' with: '::').
                        [ currentPosition := each name indexOf: $: startingAt: currentPosition.
                        currentPosition isZero not ] whileTrue: [
                                parentName := (each name copyFrom: 1 to: currentPosition - 1) asSymbol.
                                namespaces
                                        detect: [ :x | parentName = x mooseName ]
                                        ifNone: [
                                                | newNamespace |
                                                newNamespace := FAMIXNamespace new name: parentName.
                                                namespaces add: newNamespace.
                                                self add: newNamespace ].
                                currentPosition := currentPosition + 2 ].
                        task increment].
                namespaces do: [ :each |
                        each belongsTo isNil ifTrue: [
                                parentNameSize := (each name lastIndexOf: $:) - 2.
                                parentNameSize > 0 ifTrue: [
                                        parent := namespaces detect: [ :x |
                                                (each name copyFrom: 1 to: parentNameSize) asSymbol = x mooseName ]
                                                ifNone: [ nil ].
                                        parent isNil ifFalse: [
                                                each name: (each name copyFrom: parentNameSize + 3 to: each name size) asSymbol.
                                                each parentScope: parent ] ] ].
                        task increment]
                ] description: 'Infer namespace parents based on names' length: (namespaces size * 2);
        runWithProgress.
        ^ self allNamespaces
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Namespace tree calculation for java

Tudor Girba-2
Propose a fix? :)

In any case, this should not be needed anymore when using VerveineJ.

Doru


On Fri, Sep 20, 2013 at 1:40 PM, Stephan Eggermont <[hidden email]> wrote:
This looks like a rather slow way to calculate a namespace tree.
I'm pretty sure it can be done in such a way that a Task is not needed.


MooseModel>inferNamespaceParentsBasedOnNames
        <menuItem: 'Infer Namespace Parents Based on Names' category: 'Utilities'>
        | parent parentNameSize currentPosition parentName namespaces |
        namespaces := self allNamespaces.
        MooseCustomTask new with: [:task |
                namespaces do: [ :each |
                        currentPosition := 1.
                        each name: (each name copyReplaceAll: '.' with: '::').
                        [ currentPosition := each name indexOf: $: startingAt: currentPosition.
                        currentPosition isZero not ] whileTrue: [
                                parentName := (each name copyFrom: 1 to: currentPosition - 1) asSymbol.
                                namespaces
                                        detect: [ :x | parentName = x mooseName ]
                                        ifNone: [
                                                | newNamespace |
                                                newNamespace := FAMIXNamespace new name: parentName.
                                                namespaces add: newNamespace.
                                                self add: newNamespace ].
                                currentPosition := currentPosition + 2 ].
                        task increment].
                namespaces do: [ :each |
                        each belongsTo isNil ifTrue: [
                                parentNameSize := (each name lastIndexOf: $:) - 2.
                                parentNameSize > 0 ifTrue: [
                                        parent := namespaces detect:    [ :x |
                                                (each name copyFrom: 1 to: parentNameSize) asSymbol = x mooseName ]
                                                ifNone: [ nil ].
                                        parent isNil ifFalse: [
                                                each name: (each name copyFrom: parentNameSize + 3 to: each name size) asSymbol.
                                                each parentScope: parent ] ] ].
                        task increment]
                ] description: 'Infer namespace parents based on names' length: (namespaces size * 2);
        runWithProgress.
        ^ self allNamespaces
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev



--

"Every thing has its own flow"

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev