-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use
GtPharoMethodNodeSourceIntervalFinder
instead of `SmaCCMethodNo…
…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
1 parent
886e126
commit a02ad70
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/GToolkit-Pharo-Coder-Method/GtPharoMethodNodeSourceIntervalFinder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |