Skip to content

Commit 22a4c2b

Browse files
committed
fix(java): do not show additional solution on PrecisionLossError if target type is int
1 parent 66b671a commit 22a4c2b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

error_templates/java/precision_loss_error.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,30 @@ var PrecisionLossError = lib.ErrorTemplate{
4545
})
4646
})
4747

48-
gen.Add(fmt.Sprintf("Use an 'f' suffix for the %s literal", cd.Variables["targetType"]), func(s *lib.BugFixSuggestion) {
49-
nearestTree := cd.InitOrGetSymbolTree(cd.MainError.DocumentPath()).GetNearestScopedTree(variableInvolved.StartPosition().Index)
48+
if cd.Variables["targetType"] != "int" {
49+
gen.Add(fmt.Sprintf("Use an 'f' suffix for the %s literal", cd.Variables["targetType"]), func(s *lib.BugFixSuggestion) {
50+
nearestTree := cd.InitOrGetSymbolTree(cd.MainError.DocumentPath()).GetNearestScopedTree(variableInvolved.StartPosition().Index)
5051

51-
involvedVariable := nearestTree.GetSymbolByNode(variableInvolved)
52-
if involvedVariable == nil {
53-
// TODO: remove this check(?)
54-
return
55-
}
52+
involvedVariable := nearestTree.GetSymbolByNode(variableInvolved)
53+
if involvedVariable == nil {
54+
// TODO: remove this check(?)
55+
return
56+
}
5657

57-
node := cd.MainError.Document.RootNode().
58-
NamedDescendantForPointRange(involvedVariable.Location())
58+
node := cd.MainError.Document.RootNode().
59+
NamedDescendantForPointRange(involvedVariable.Location())
5960

60-
involvedVariableValueNode := node.ChildByFieldName("value")
61+
involvedVariableValueNode := node.ChildByFieldName("value")
6162

62-
s.AddStep(
63-
"Alternatively, you can use the 'f' suffix to specify that the literal is of type %s.",
64-
cd.Variables["targetType"]).AddFix(lib.FixSuggestion{
65-
NewText: involvedVariableValueNode.Text() + "f",
66-
StartPosition: variableInvolved.StartPosition(),
67-
EndPosition: variableInvolved.EndPosition(),
68-
Description: "This way, you directly define the float variable without the need for casting.",
63+
s.AddStep(
64+
"Alternatively, you can use the 'f' suffix to specify that the literal is of type %s.",
65+
cd.Variables["targetType"]).AddFix(lib.FixSuggestion{
66+
NewText: involvedVariableValueNode.Text() + "f",
67+
StartPosition: variableInvolved.StartPosition(),
68+
EndPosition: variableInvolved.EndPosition(),
69+
Description: "This way, you directly define the float variable without the need for casting.",
70+
})
6971
})
70-
})
72+
}
7173
},
7274
}

0 commit comments

Comments
 (0)