第八章-注解的实现

 

参考博文:

(1)关于注解Annotation第一篇 

(2)关于注解Annotation第二篇

(3)Annotate类

(4)JavacProcessingEnvironment类解读

(5)Java的注解相关的命令

 

 

调用步骤:

(1)调用JavacProcessingEnvironment的doProcessing()方法

其中的主要逻辑代码如下:

Round round = new Round(context,this, roots, classSymbols);

boolean errorStatus;
boolean moreToDo;
do {
    // Run processors for round n
    round.run(false, false);

    // Processors for round n have run to completion.
    // Check for errors and whether there is more work to do.
    errorStatus = round.unrecoverableError();
    moreToDo = moreToDo();

    round.showDiagnostics(errorStatus || showResolveErrors);

    // Set up next round.
    // Copy mutable collections returned from filer.
    Set gsfs = filer.getGeneratedSourceFileObjects();
    Map gcs = filer.getGeneratedClasses();
    round = round.next(this,
            new LinkedHashSet(gsfs),
            new LinkedHashMap(gcs));

     // Check for errors during setup.
    if (round.unrecoverableError()) {
        errorStatus = true;
    }

} while (moreToDo && !errorStatus);

// run last round
round.run(true, errorStatus);

 

(2)

lastRound=false时调用JavacProcessingEnvironment的discoverAndRunProcs()方法,传递Round对象在创建时准备好的一些参数,如:

 

/** The set of annotations to be processed this round. */
Set annotationsPresent;
/** The set of top level classes to be processed this round. */
List topLevelClasses;

 

 

在discoverAndRunProcs()方法中获取ProcessorStateIterator迭代器变量psi,创建JavacRoundEnvironment对象。

  

 

 

lastRound=true时调用DiscoveredProcessors.ProcessorStateIterator对象的runContributingProcs()方法

 

 

 

 

 

  

 

你可能感兴趣的:(第八章-注解的实现)