Skip to content

Commit

Permalink
fix: add missing line number info (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored Nov 16, 2024
1 parent 4b47b7d commit e96c76c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/grammar/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/thoughtworks/qdox/RecordsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e96c76c

Please sign in to comment.