@@ -478,14 +478,10 @@ public List<Node> visitParagraphName(ParagraphNameContext ctx) {
478
478
@ Override
479
479
public List <Node > visitDataDescriptionEntryFormat1 (DataDescriptionEntryFormat1Context ctx ) {
480
480
variablesDelegate .defineVariable (ctx );
481
- String name =
482
- ofNullable (ctx .entryName ())
483
- .map (EntryNameContext ::dataName1 )
484
- .map (RuleContext ::getText )
485
- .orElse (FILLER_NAME );
486
- String levelNumber = ctx .LEVEL_NUMBER ().getText ();
487
- int level = Integer .parseInt (levelNumber );
488
- outlineTreeBuilder .addVariable (level , name , getDataDescriptionNodeType (ctx ), ctx );
481
+ String name = VisitorHelper .getName (ctx .entryName ());
482
+ NodeType nodeType = getDataDescriptionNodeType (ctx );
483
+ int level = VisitorHelper .getLevel (ctx .LEVEL_NUMBER ());
484
+ outlineTreeBuilder .addVariable (level , name , nodeType , ctx );
489
485
Node node = new AntlrVariableDefinitionNode (ctx );
490
486
visitChildren (ctx ).forEach (node ::addChild );
491
487
return ImmutableList .of (node );
@@ -517,25 +513,34 @@ public List<Node> visitEnvironmentSwitchNameClause(EnvironmentSwitchNameClauseCo
517
513
@ Override
518
514
public List <Node > visitDataDescriptionEntryFormat2 (DataDescriptionEntryFormat2Context ctx ) {
519
515
variablesDelegate .defineVariable (ctx );
520
- String name =
521
- ofNullable (ctx .entryName ())
522
- .map (EntryNameContext ::dataName1 )
523
- .map (RuleContext ::getText )
524
- .orElse (FILLER_NAME );
516
+ String name = VisitorHelper .getName (ctx .entryName ());
525
517
outlineTreeBuilder .addVariable (LEVEL_66 , name , NodeType .FIELD_66 , ctx );
526
518
Node node = new AntlrVariableDefinitionNode (ctx );
527
519
visitChildren (ctx ).forEach (node ::addChild );
528
520
return ImmutableList .of (node );
529
521
}
530
522
523
+ @ Override
524
+ public List <Node > visitDataRedefinesClause (DataRedefinesClauseContext ctx ) {
525
+ String name = VisitorHelper .getName (ctx .dataName ());
526
+ List <Node > result = new ArrayList <>();
527
+
528
+ getLocality (ctx .dataName ().getStart ())
529
+ .ifPresent (locality -> {
530
+ Node node = new VariableRedefinitionNode (locality , ctx );
531
+ visitChildren (ctx ).forEach (node ::addChild );
532
+
533
+ variableUsageDelegate .handleDataName (name , locality );
534
+ node .addChild (new VariableUsageNode (name , locality ));
535
+ result .add (node );
536
+ });
537
+ return result ;
538
+ }
539
+
531
540
@ Override
532
541
public List <Node > visitDataDescriptionEntryFormat3 (DataDescriptionEntryFormat3Context ctx ) {
533
542
variablesDelegate .defineVariable (ctx );
534
- String name =
535
- ofNullable (ctx .entryName ())
536
- .map (EntryNameContext ::dataName1 )
537
- .map (RuleContext ::getText )
538
- .orElse (FILLER_NAME );
543
+ String name = VisitorHelper .getName (ctx .entryName ());
539
544
outlineTreeBuilder .addVariable (LEVEL_88 , name , NodeType .FIELD_88 , ctx );
540
545
Node node = new AntlrVariableDefinitionNode (ctx );
541
546
visitChildren (ctx ).forEach (node ::addChild );
@@ -546,12 +551,7 @@ public List<Node> visitDataDescriptionEntryFormat3(DataDescriptionEntryFormat3Co
546
551
public List <Node > visitDataDescriptionEntryFormat1Level77 (
547
552
DataDescriptionEntryFormat1Level77Context ctx ) {
548
553
variablesDelegate .defineVariable (ctx );
549
- String name =
550
- ofNullable (ctx .entryName ())
551
- .map (EntryNameContext ::dataName1 )
552
- .map (RuleContext ::getText )
553
- .orElse (FILLER_NAME );
554
-
554
+ String name = VisitorHelper .getName (ctx .entryName ());
555
555
outlineTreeBuilder .addVariable (LEVEL_77 , name , NodeType .FIELD , ctx );
556
556
Node node = new AntlrVariableDefinitionNode (ctx );
557
557
visitChildren (ctx ).forEach (node ::addChild );
@@ -681,7 +681,6 @@ public List<Node> visitIfStatement(IfStatementContext ctx) {
681
681
return addTreeNode (ctx , locality -> new IfNode (locality , ctx ));
682
682
}
683
683
684
-
685
684
private void throwException (String wrongToken , @ NonNull Locality locality , String message ) {
686
685
SyntaxError error =
687
686
SyntaxError .syntaxError ()
@@ -700,21 +699,12 @@ private Optional<Locality> getLocality(Token childToken) {
700
699
return ofNullable (positionMapping .get (childToken ));
701
700
}
702
701
703
- private Locality getIntervalPosition (Locality start , Locality stop ) {
704
- return Locality .builder ()
705
- .uri (start .getUri ())
706
- .range (new Range (start .getRange ().getStart (), stop .getRange ().getEnd ()))
707
- .recognizer (CobolVisitor .class )
708
- .copybookId (start .getCopybookId ())
709
- .build ();
710
- }
711
-
712
702
private void reportSubroutineNotDefined (String name , Locality locality ) {
713
703
SyntaxError error =
714
704
SyntaxError .syntaxError ()
715
705
.suggestion (messageService .getMessage ("CobolVisitor.subroutineNotFound" , name ))
716
706
.severity (ErrorSeverity .INFO )
717
- .locality (getIntervalPosition (locality , locality ))
707
+ .locality (VisitorHelper . getIntervalPosition (locality , locality ))
718
708
.build ();
719
709
LOG .debug ("Syntax error by CobolVisitor#reportSubroutineNotDefined: {}" , error );
720
710
errors .add (error );
0 commit comments