--- a/Explainer.st Fri Sep 06 09:59:03 2019 +0200
+++ b/Explainer.st Fri Sep 06 10:04:19 2019 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
@@ -292,7 +294,7 @@
implMethod := implClass compiledMethodAt:selector.
clsName := implClass name.
clsName := self asLink:clsName to:(self actionToBrowseClass:implClass selector:selector).
- "/ info := '%1 » %2' bindWith:clsName "allBold" with:selectorString.
+ "/ info := '%1 » %2' bindWith:clsName "allBold" with:selectorString.
info := '%1 %2' bindWith:clsName with:(implMethod methodDefinitionTemplateForSelector:selector).
info := self asLink:info to:(action1 := self actionToBrowseClass:implClass selector:selector info:nil).
@@ -2295,6 +2297,30 @@
"Modified: / 10-10-2017 / 16:57:09 / cg"
!
+addTypesAssignedToInstvar:instVarName inClass:aClass method:methodOrNil source:code to:setOfTypes
+ "look to asssignments to an instance variable, and pick up low hanging class information.
+ This is far from being complete, but often gives a hint good enough for code completion
+ and info in the browser."
+
+ |tree parserClass lang parser|
+
+ "/ quick check (avoids expensive parse)
+ (code includesString:instVarName) ifFalse:[ ^ self ].
+ parserClass := Parser.
+ (methodOrNil notNil
+ and:[(lang := methodOrNil programmingLanguage) notNil]) ifTrue:[
+ parserClass := lang parserClass.
+ ].
+ parser := parserClass parseMethod:code in:aClass.
+ tree := parser tree.
+ "/ tree := parserClass parseMethod:code in:aClass.
+ (tree isNil or:[tree == #Error]) ifTrue:[ ^ self ]. "/ unparsable
+
+ self addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes using:(parserClass parseNodeVisitorClass new).
+
+ "Created: / 30-04-2016 / 15:09:18 / cg"
+!
+
addTypesAssignedToInstvar:instVarName inClass:aClass method:aMethod to:setOfTypes
"look to asssignments to an instance variable, and pick up low hanging class information.
This is far from being complete, but often gives a hint good enough for code completion
@@ -2307,30 +2333,12 @@
code := aMethod source.
].
(code notNil) ifTrue:[
- self addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes
+ self addTypesAssignedToInstvar:instVarName inClass:aClass method:aMethod source:code to:setOfTypes
]
"Created: / 30-04-2016 / 15:07:33 / cg"
!
-addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes
- "look to asssignments to an instance variable, and pick up low hanging class information.
- This is far from being complete, but often gives a hint good enough for code completion
- and info in the browser."
-
- |tree|
-
- "/ quick check (avoids expensive parse)
- (code includesString:instVarName) ifFalse:[ ^ self ].
-
- tree := Parser parse:code class:aClass.
- (tree isNil or:[tree == #Error]) ifTrue:[ ^ self ]. "/ unparsable
-
- self addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes.
-
- "Created: / 30-04-2016 / 15:09:18 / cg"
-!
-
addTypesAssignedToInstvar:instVarName inClass:aClass to:setOfTypes
"look to asssignments to an instance variable, and pick up low hanging class information.
This is far from being complete, but often gives a hint good enough for code completion
@@ -2343,14 +2351,11 @@
"Created: / 30-04-2016 / 14:52:56 / cg"
!
-addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes
+addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes using:visitor
"look to asssignments to an instance variable, and pick up low hanging class information.
This is far from being complete, but often gives a hint good enough for code completion
and info in the browser."
- |visitor|
-
- visitor := PluggableParseNodeVisitor new.
visitor
actionForNodeClass:AssignmentNode
put:[:node |
@@ -2358,11 +2363,20 @@
self addTypeOfExpressionNode:(node expression) forAssignmentTo:instVarName to:setOfTypes
].
true "/ yes - visit subnodes
- ].
+ ].
+ visitor
+ actionForNodeClass:JavaScriptParser::JavaScriptAssignmentNode
+ put:[:node |
+ (node variable isInstanceVariableNamed:instVarName) ifTrue:[
+ self addTypeOfExpressionNode:(node expression) forAssignmentTo:instVarName to:setOfTypes
+ ].
+ true "/ yes - visit subnodes
+ ].
visitor visit:tree.
!
addTypesAssignedToLocal:localName inTree:tree to:setOfTypes
+ <resource: #todo>
"look to asssignments to a local variable, and pick up low hanging class information.
This is far from being complete, but often gives a hint good enough for code completion
and info in the browser."
@@ -2370,6 +2384,8 @@
|visitor|
"/ hack, allowing to deal with both types of AST (sigh)
+ "/ ugly; TODO: unify RB-framework with STX's parser framework.
+ #TODO.
(tree isKindOf:RBProgramNode) ifTrue:[
visitor := RBPluggableProgramNodeVisitor new.
visitor
@@ -2385,7 +2401,7 @@
].
visitor visitNode:tree.
] ifFalse:[
- visitor := PluggableParseNodeVisitor new.
+ visitor := ParseNodeVisitor new.
visitor
actionForNodeClass:AssignmentNode
put:[:node |
@@ -2844,7 +2860,7 @@
to:(self actionToOpenMethodFinderFor:sel))
with:(self
asLink:inheritedClass name "allBold"
- info:('Browse %1 » %2' bindWith:inheritedClass name with:sel)
+ info:('Browse %1 » %2' bindWith:inheritedClass name with:sel)
to:(self actionToBrowseClass:inheritedClass selector:sel)).
].