Skip to content

Commit

Permalink
fix: make NonStaticMethodAccessError do proper bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Nov 30, 2023
1 parent 658ae1f commit d5c0322
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions error_templates/java/non_static_method_access_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ var NonStaticMethodAccessError = lib.ErrorTemplate{
},
OnGenBugFixFn: func(cd *lib.ContextData, gen *lib.BugFixGenerator) {
ctx := cd.MainError.Context.(nonStaticMethodAccessErrorCtx)
startPos := ctx.parent.StartPosition()
spacing := cd.MainError.Document.LineAt(startPos.Line)[:startPos.Column]

gen.Add("Instantiate and call the method", func(s *lib.BugFixSuggestion) {
s.AddStep("Create an instance of the class to access the non-static method").
AddFix(lib.FixSuggestion{
NewText: fmt.Sprintf("%s obj = new %s();\n", ctx.class, ctx.class),
NewText: fmt.Sprintf("%s obj = new %s();\n"+spacing, ctx.class, ctx.class),
StartPosition: lib.Position{
Line: ctx.parent.StartPosition().Line,
Column: ctx.parent.StartPosition().Column,
Line: startPos.Line,
Column: startPos.Column,
},
EndPosition: lib.Position{
Line: ctx.parent.EndPosition().Line,
Expand Down

0 comments on commit d5c0322

Please sign in to comment.