--- a/Parser.st Thu Apr 26 14:21:28 2001 +0200
+++ b/Parser.st Tue Jun 26 14:02:06 2001 +0200
@@ -2129,6 +2129,97 @@
"Modified: / 19.1.2000 / 16:34:55 / cg"
!
+correctSelector:aSelectorString message:msg position:pos1 to:pos2 in:aClassOrNil for:receiverNode
+ "notify error and correct if user wants to;
+ return #Error if there was no correction
+ or a ParseNode as returned by variable"
+
+ |correctIt suggestedNames newSelector className classToGenerateCode|
+
+ alreadyWarnedUnimplementedSelectors isNil ifTrue:[
+ alreadyWarnedUnimplementedSelectors := Set new
+ ].
+
+ (alreadyWarnedUnimplementedSelectors includes:aSelectorString) ifTrue:[
+ ^ aSelectorString
+ ].
+
+ "
+ sorry, but I cannot handle keywords with more than one-part
+ currently (too much work - maybe Ill do it later when everything else works :-)
+ "
+ (aSelectorString occurrencesOf:$:) > 1 ifTrue:[
+ self warning:msg position:pos1 to:pos2.
+ alreadyWarnedUnimplementedSelectors add:aSelectorString.
+ ^ aSelectorString
+ ].
+
+ correctIt := self correctableSelectorWarning:msg position:pos1 to:pos2.
+ correctIt == #generate ifTrue:[
+ receiverNode isSelf ifTrue:[
+ classToGenerateCode := classToCompileFor
+ ] ifFalse:[
+ receiverNode isVariable ifTrue:[
+ receiverNode isGlobal ifTrue:[
+ classToGenerateCode := receiverNode evaluate.
+ classToGenerateCode isBehavior ifFalse:[
+ classToGenerateCode := nil
+ ].
+ ].
+ ]
+ ].
+ classToGenerateCode isNil ifTrue:[
+ className := Dialog request:'Generate code in class:' initialAnswer:classToCompileFor name.
+ className size == 0 ifTrue:[
+ ^ aSelectorString
+ ].
+ classToGenerateCode := Smalltalk at:className asSymbol.
+ classToGenerateCode isNil ifTrue:[
+ self warn:'No such class.'.
+ ^ aSelectorString
+ ].
+ ].
+ classToGenerateCode
+ compile:((self class methodSpecificationForSelector:aSelectorString) , '\ self halt. self error:''to be implemented'' mayProceed:true' withCRs)
+ classified:'* as yet uncategorized *'.
+
+ correctIt := false.
+ ].
+ correctIt ifFalse:[
+ alreadyWarnedUnimplementedSelectors add:aSelectorString.
+ ^ aSelectorString
+ ].
+
+ suggestedNames := self findBestSelectorsFor:aSelectorString in:aClassOrNil.
+ suggestedNames notNil ifTrue:[
+ newSelector := self askForCorrection:'correct selector to: ' fromList:suggestedNames.
+ newSelector isNil ifTrue:[^ aSelectorString].
+ ] ifFalse:[
+ self information:'no good correction found'.
+ ^ aSelectorString
+ ].
+
+ "
+ tell requestor (i.e. CodeView) about the change
+ this will update what the requestor shows.
+ "
+
+ requestor replaceSelectionBy:newSelector keepCursor:false.
+ "
+ get the updated source-string
+ which is needed, when we eventually install the new method
+ "
+ correctedSource := requestor currentSourceCode.
+ source := (ReadStream on:correctedSource)
+ position:(source position + newSelector size - aSelectorString size).
+
+ ^ newSelector
+
+ "Modified: / 22.1.1998 / 16:36:04 / stefan"
+ "Created: / 19.1.2000 / 16:34:01 / cg"
+ "Modified: / 19.1.2000 / 16:34:55 / cg"
+!
+
correctVariable
"notify error and correct if user wants to;
return #Error if there was no correction
@@ -2700,7 +2791,12 @@
]
].
- err := ' may not be understood here (is currently ' , rec classNameWithArticle , ')'.
+ (rec isBehavior
+ and:[rec theNonMetaclass name = receiver name]) ifTrue:[
+ err := ' will not be understood by ' , rec theNonMetaclass name.
+ ] ifFalse:[
+ err := ' might be not understood here (is currently ' , rec classNameWithArticle , ')'.
+ ]
] ifFalse:[
"if its a super- or self-send, we can do more checking"
(receiver isSuper or:[receiver isSelf]) ifTrue:[
@@ -2821,7 +2917,7 @@
err := aSelectorString allBold , err
].
newSelector := self correctSelector:aSelectorString
- message:err position:pos1 to:pos2 in:selClass.
+ message:err position:pos1 to:pos2 in:selClass for:receiver.
"/ self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2.
^ newSelector.
].
@@ -5773,6 +5869,6 @@
!Parser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.282 2001-04-26 12:21:28 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.283 2001-06-26 12:02:06 cg Exp $'
! !
Parser initialize!