From dca2d151b334da9b55e77ae88f4b49671989773a Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Wed, 20 Sep 2023 12:24:47 -0400 Subject: [PATCH] :bug: Add one to line numbers from java bundle (#339) This should correct the off-by-one issues with java line numbers. Signed-off-by: Fabian von Feilitzsch --- demo-output.yaml | 22 +++++++++++----------- provider/internal/java/filter.go | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/demo-output.yaml b/demo-output.yaml index b625f9ff..f11e596b 100644 --- a/demo-output.yaml +++ b/demo-output.yaml @@ -202,7 +202,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java message: apiextensions/v1beta1/customresourcedefinitions is deprecated, apiextensions/v1/customresourcedefinitions should be used instead codeSnip: " 1 package com.example.apps;\n 2 \n 3 import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;\n 4 \n 5 public class App \n 6 {\n 7 \n 8 public static void main( String[] args )\n 9 {\n10 CustomResourceDefinition crd = new CustomResourceDefinition();\n11 System.out.println( crd );\n12 \n13 GenericClass element = new GenericClass(\"Hello world!\");" - lineNumber: 2 + lineNumber: 3 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java kind: Method @@ -210,7 +210,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java message: apiextensions/v1beta1/customresourcedefinitions is deprecated, apiextensions/v1/customresourcedefinitions should be used instead codeSnip: " 1 package com.example.apps;\n 2 \n 3 import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;\n 4 \n 5 public class App \n 6 {\n 7 \n 8 public static void main( String[] args )\n 9 {\n10 CustomResourceDefinition crd = new CustomResourceDefinition();\n11 System.out.println( crd );\n12 \n13 GenericClass element = new GenericClass(\"Hello world!\");\n14 element.get();\n15 }\n16 }\n" - lineNumber: 9 + lineNumber: 10 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java kind: Method @@ -225,17 +225,17 @@ category: potential incidents: - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java - message: java found apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java:2 + message: java found apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java:3 codeSnip: " 1 package com.example.apps;\n 2 \n 3 import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;\n 4 \n 5 public class App \n 6 {\n 7 \n 8 public static void main( String[] args )\n 9 {\n10 CustomResourceDefinition crd = new CustomResourceDefinition();\n11 System.out.println( crd );\n12 \n13 GenericClass element = new GenericClass(\"Hello world!\");" - lineNumber: 2 + lineNumber: 3 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java kind: Method name: main - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java - message: java found apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java:9 + message: java found apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java:10 codeSnip: " 1 package com.example.apps;\n 2 \n 3 import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;\n 4 \n 5 public class App \n 6 {\n 7 \n 8 public static void main( String[] args )\n 9 {\n10 CustomResourceDefinition crd = new CustomResourceDefinition();\n11 System.out.println( crd );\n12 \n13 GenericClass element = new GenericClass(\"Hello world!\");\n14 element.get();\n15 }\n16 }\n" - lineNumber: 9 + lineNumber: 10 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java kind: Method @@ -247,7 +247,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java message: found generic call codeSnip: " 4 \n 5 public class App \n 6 {\n 7 \n 8 public static void main( String[] args )\n 9 {\n10 CustomResourceDefinition crd = new CustomResourceDefinition();\n11 System.out.println( crd );\n12 \n13 GenericClass element = new GenericClass(\"Hello world!\");\n14 element.get();\n15 }\n16 }\n" - lineNumber: 13 + lineNumber: 14 variables: VariableName: element file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/App.java @@ -269,7 +269,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java message: condition entries should evaluate out of order codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public class Bean implements SessionBean {\n 8 }\n" - lineNumber: 5 + lineNumber: 6 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java kind: Class @@ -277,7 +277,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java message: condition entries should evaluate out of order codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public class Bean implements SessionBean {\n 8 }\n" - lineNumber: 6 + lineNumber: 7 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java kind: Class @@ -289,7 +289,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java message: condition entries should evaluate in order codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public class Bean implements SessionBean {\n 8 }\n" - lineNumber: 5 + lineNumber: 6 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java kind: Class @@ -297,7 +297,7 @@ - uri: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java message: condition entries should evaluate in order codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public class Bean implements SessionBean {\n 8 }\n" - lineNumber: 6 + lineNumber: 7 variables: file: file:///analyzer-lsp/examples/java/src/main/java/com/example/apps/Singleton.java kind: Class diff --git a/provider/internal/java/filter.go b/provider/internal/java/filter.go index 06caf982..36080b51 100644 --- a/provider/internal/java/filter.go +++ b/provider/internal/java/filter.go @@ -129,7 +129,7 @@ func (p *javaServiceClient) convertToIncidentContext(symbol protocol.WorkspaceSy return provider.IncidentContext{}, err } - lineNumber := int(symbol.Location.Range.Start.Line) + lineNumber := int(symbol.Location.Range.Start.Line) + 1 incident := provider.IncidentContext{ FileURI: u, LineNumber: &lineNumber, @@ -184,7 +184,7 @@ func (p *javaServiceClient) convertSymbolRefToIncidentContext(symbol protocol.Wo Character: ref.Range.End.Character, }, } - lineNumber := int(ref.Range.Start.Line) + lineNumber := int(ref.Range.Start.Line) + 1 incident.LineNumber = &lineNumber return incident, nil