Skip to content

Commit

Permalink
use GtPharoMethodNodeSourceIntervalFinder instead of `SmaCCMethodNo…
Browse files Browse the repository at this point in the history
…deSourceIntervalFinder` [feenkcom/gtoolkit#3735]

`SmaCCMethodNodeSourceIntervalFinder` needs to be moved to a non-UI package/baseline first. Then we can remove the code duplication.
  • Loading branch information
JurajKubelka committed May 15, 2024
1 parent 886e126 commit a02ad70
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ GtPharoEvaluatedCode >> findSourceIntervalForContext: aContext sourceString: aSo
<return: #Interval or: nil>
| aUsedAst anInterval |
aUsedAst := aContext method sourceNodeForPC: aContext pc.
anInterval := SmaCCMethodNodeSourceIntervalFinder new
anInterval := GtPharoMethodNodeSourceIntervalFinder new
methodNode: aUsedAst;
sourceString: aSourceString;
find.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Class {
#name : #GtPharoMethodNodeSourceIntervalFinder,
#superclass : #Object,
#instVars : [
'methodNode',
'sourceString',
'sourceAst',
'sourceNode',
'sourceInterval'
],
#category : #'GToolkit-Pharo-Coder-Method-Context'
}

{ #category : #finding }
GtPharoMethodNodeSourceIntervalFinder >> equivalentNodeTo: aNode in: otherTree [
| equivParent nodeIndex equivNode |
aNode isMethod ifTrue: [ ^ otherTree ].
(aNode parent isReturn and: [ aNode parent parent parent isMethod ])
ifTrue: [ equivNode := otherTree isSequence
ifTrue: [ otherTree statements last ]
ifFalse: [ otherTree ].
^ equivNode isReturn ifTrue: [ equivNode value ] ifFalse: [ equivNode ] ].
aNode parent isMethod
ifTrue: [ otherTree isSequence ifTrue: [ ^ otherTree ] ifFalse: [ ^ otherTree parent ] ].
equivParent := self equivalentNodeTo: aNode parent in: otherTree.
equivParent ifNil: [ ^ nil ].
nodeIndex := aNode parent children identityIndexOf: aNode.
^ equivParent children at: nodeIndex ifAbsent: [ nil ]
]

{ #category : #finding }
GtPharoMethodNodeSourceIntervalFinder >> find [
<return: #Interval>
sourceAst := RBParser
parseExpression: sourceString
onError: [ :msg :pos | ^ sourceInterval := 1 to: 0 ].
sourceNode := self equivalentNodeTo: methodNode in: sourceAst.
sourceNode ifNil: [ ^ sourceInterval := 1 to: 0 ].
^ sourceInterval := sourceNode start to: sourceNode stop
]

{ #category : #accessing }
GtPharoMethodNodeSourceIntervalFinder >> methodNode [
^ methodNode
]

{ #category : #accessing }
GtPharoMethodNodeSourceIntervalFinder >> methodNode: anObject [
methodNode := anObject
]

{ #category : #'accessing - computed' }
GtPharoMethodNodeSourceIntervalFinder >> sourceAst [
^ sourceAst
]

{ #category : #'accessing - computed' }
GtPharoMethodNodeSourceIntervalFinder >> sourceInterval [
^ sourceInterval
]

{ #category : #'accessing - computed' }
GtPharoMethodNodeSourceIntervalFinder >> sourceNode [
^ sourceNode
]

{ #category : #accessing }
GtPharoMethodNodeSourceIntervalFinder >> sourceString [
^ sourceString
]

{ #category : #accessing }
GtPharoMethodNodeSourceIntervalFinder >> sourceString: anObject [
sourceString := anObject
]

0 comments on commit a02ad70

Please sign in to comment.