From e96c76c252b6dc47988525b17faba7295d6bbc6e Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Sat, 16 Nov 2024 15:24:23 +0100 Subject: [PATCH] fix: add missing line number info (#208) --- src/grammar/parser.y | 2 ++ src/test/java/com/thoughtworks/qdox/RecordsTest.java | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/grammar/parser.y b/src/grammar/parser.y index a96f010b..c92e6ebe 100644 --- a/src/grammar/parser.y +++ b/src/grammar/parser.y @@ -770,6 +770,7 @@ RecordComponent: Annotations_opt /* ={RecordComponentModifier} */ Type /* =Unann param.setName($3); param.setDimensions(0); param.setVarArgs(false); + param.setLineNumber(lexer.getLine()); builder.addParameter(param); recordHeaderStack.getFirst().addField(param); param = new FieldDef(); @@ -785,6 +786,7 @@ VariableArityRecordComponent: Annotations_opt /* ={RecordComponentModifier} */ T param.setName($4); param.setDimensions(0); param.setVarArgs(true); + param.setLineNumber(lexer.getLine()); builder.addParameter(param); recordHeaderStack.getFirst().addField(param); param = new FieldDef(); diff --git a/src/test/java/com/thoughtworks/qdox/RecordsTest.java b/src/test/java/com/thoughtworks/qdox/RecordsTest.java index baa4b9ea..d9f75f24 100644 --- a/src/test/java/com/thoughtworks/qdox/RecordsTest.java +++ b/src/test/java/com/thoughtworks/qdox/RecordsTest.java @@ -23,19 +23,25 @@ public class RecordsTest @Test public void withTwoFields() { - String source = "record Rectangle(double length, double width) { }"; + String source = + "/* comment */" + + "record Rectangle(double length, double width) { }"; JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder(); javaDocBuilder.addSource( new StringReader(source) ); JavaClass cls = javaDocBuilder.getClassByName("Rectangle"); + Assertions.assertTrue( cls.getLineNumber() == 1 ); Assertions.assertTrue( cls.isRecord() ); JavaField field = cls.getFieldByName("length"); + Assertions.assertTrue( field.getLineNumber() == 1 ); Assertions.assertTrue( field.getType().isA("double") ); JavaConstructor constructor = cls.getConstructors().get(0); JavaParameter lengthParam = constructor.getParameterByName("length"); Assertions.assertTrue( lengthParam != null ); JavaMethod lengthGetter = cls.getMethod( "length", new LinkedList(), false ); Assertions.assertTrue( lengthGetter.getReturns().isA( "double" ) ); + JavaMethod widthGetter = cls.getMethod( "width", new LinkedList(), false ); + Assertions.assertTrue( widthGetter.getLineNumber() == 1 ); } @Test