1414use Doctrine \Common \Annotations \DocParser ;
1515use PhpParser \Node ;
1616use Symfony \Component \Finder \SplFileInfo ;
17+ use Translation \Extractor \Annotation \Desc ;
1718use Translation \Extractor \Annotation \Ignore ;
1819use Translation \Extractor \Model \Error ;
1920use Translation \Extractor \Model \SourceCollection ;
21+ use Translation \Extractor \Model \SourceLocation ;
2022
2123/**
2224 * Base class for any visitor.
@@ -77,6 +79,30 @@ protected function addError(Node $node, $errorMessage)
7779 $ this ->collection ->addError (new Error ($ errorMessage , $ file , $ line ));
7880 }
7981
82+ /**
83+ * @param string $text
84+ * @param int $line
85+ * @param Node|null $node
86+ * @param array $context
87+ */
88+ protected function addLocation ($ text , $ line , Node $ node = null , array $ context = [])
89+ {
90+ $ file = $ this ->getAbsoluteFilePath ();
91+ if (null !== $ node && null !== $ docComment = $ node ->getDocComment ()) {
92+ $ parserContext = 'file ' .$ file .' near line ' .$ line ;
93+ foreach ($ this ->getDocParser ()->parse ($ docComment ->getText (), $ parserContext ) as $ annotation ) {
94+ if ($ annotation instanceof Ignore) {
95+ return ;
96+ } elseif ($ annotation instanceof Desc) {
97+ $ context ['desc ' ] = $ annotation ->text ;
98+ }
99+ }
100+ }
101+
102+ $ source = new SourceLocation ($ text , $ file , $ line , $ context );
103+ $ this ->collection ->addLocation ($ source );
104+ }
105+
80106 /**
81107 * @return DocParser
82108 */
@@ -87,6 +113,7 @@ private function getDocParser()
87113
88114 $ this ->docParser ->setImports ([
89115 'ignore ' => Ignore::class,
116+ 'desc ' => Desc::class,
90117 ]);
91118 $ this ->docParser ->setIgnoreNotImportedAnnotations (true );
92119 }
0 commit comments