2017-01-24 3 views
1

source_genパッケージを使用する拡張アノテーションを使用してジェネレータを呼び出すにはどうすればよいですか?source_genを使用して拡張アノテーションを使用してジェネレータを呼び出す方法

のは、私は次の発電機を持っているとしましょう:

class MyAnnotationGenerator extends GeneratorForAnnotation<MyAnnotation> { 
const MyAnnotationGenerator(); 

Future<String> generateForAnnotatedElement(ClassElement element, Serializable annotation, BuildStep buildStep) async { 
... 
} 

私はMyAnnotationを拡張して、すべての注釈のためのMyAnnotationGeneratorを呼び出すしたいと思います。たとえば:

class MyAnnotation { 
    const MyAnnotation(); 
} 

class MyExtendedAnnotation extends MyAnnotation { 
    const MyExtendedAnnotation(); 
} 

ので、注釈 MyExtendedAnnotationが使用されるたびに、私は MyAnnotationGeneratorを呼び出すしたいと思います。

答えて

1

GeneratorForAnnotationでできるとは思わない。

Generatorインターフェイスを実装し、自分でチェックを行うことができます。

1

GeneratorForAnnotation拡張アノテーションをチェックしません。

独自のジェネレータを作成してチェックしたい場合は、 を使用することができます。アノテーションクラスでジェネレータを設定する必要があります。

class MyAnnotationGenerator extends GeneratorForAnnotation<MyAnnotation> 
class MyExtendAnnotationGenerator extends GeneratorForAnnotation<MyExtendedAnnotation> 

new GeneratorBuilder(const [ 
    const MyAnnotationGenerator(), 
    const MyExtendAnnotationGenerator() 
    ]) 
関連する問題