for (AnnotationTypeDeclaration atd : _atds)
{
if (atd.getSimpleName().equals("Control") )
{
AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
for (Declaration decl : decls)
{
if ( decl instanceof FieldDeclaration )
{
FieldDeclaration fd = (FieldDeclaration)decl;
TypeDeclaration clientType = fd.getDeclaringType();
TypeMirror controlFieldType = fd.getType();
addControlType( clientsMap, clientType, controlFieldType );
/*
If this field is public or protected, add the control type to any derived class. Private
fields are also included here as private controls in superclasses may be exposed through public
or protected methods to subclasses
*/
Collection<Modifier> modifiers = fd.getModifiers();
if (modifiers.contains( Modifier.PUBLIC ) ||
modifiers.contains( Modifier.PROTECTED ) ||
modifiers.contains( Modifier.PRIVATE) )
{
Collection<TypeDeclaration> specifiedTypeDeclartions = env.getSpecifiedTypeDeclarations();
for (TypeDeclaration td : specifiedTypeDeclartions)
{
if ( td instanceof ClassDeclaration )
{
ClassType superclass = ( ( ClassDeclaration ) td ).getSuperclass();
while ( superclass != null )
{
if ( superclass.getDeclaration().equals( clientType ) )
{
addControlType( clientsMap, td, controlFieldType );
break;
}
superclass = superclass.getSuperclass();
}
}
}
}
}
}
}
else if (atd.getSimpleName().equals("ControlReferences"))
{
Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd);
for (Declaration decl : decls)
{
if ( decl instanceof TypeDeclaration )
{
TypeDeclaration clientType = (TypeDeclaration)decl;
Set<TypeMirror> controlTypes = clientsMap.get( clientType );
if ( controlTypes == null )
{
controlTypes = new HashSet<TypeMirror>();
clientsMap.put( clientType, controlTypes );
}
// Read ControlReferences annotation
AnnotationMirror controlMirror = null;
for (AnnotationMirror annot : clientType.getAnnotationMirrors())
{
if (annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
"org.apache.beehive.controls.api.bean.ControlReferences"))
{
controlMirror = annot;
break;
}
}
assert( controlMirror != null );
// Add each control type listed in the ControlReferences annotation
AptAnnotationHelper controlAnnot = new AptAnnotationHelper(controlMirror);
Collection<AnnotationValue> references = (Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
if ( references != null )
{
for ( AnnotationValue av : references )
{
TypeMirror crType = (TypeMirror)av.getValue();
controlTypes.add( crType );
}
}
}
}
}
}
// For each client type:
// 1 - emit a controls client manifest in the same dir as the client type's class.
// 2 - emit a controls client initializer class in the same pkg/dir as the client type's class
Filer f = getAnnotationProcessorEnvironment().getFiler();
Set<TypeDeclaration> clientTypes = clientsMap.keySet();
for ( TypeDeclaration clientType : clientTypes )
{
// Emit manifest
String clientPkg = clientType.getPackage().getQualifiedName();
File clientManifestName =
new File( clientType.getSimpleName() + ControlClientManifest.FILE_EXTENSION );
ControlClientManifest mf = new ControlClientManifest( clientType.getQualifiedName() );
try
{
Set<TypeMirror> controlTypes = clientsMap.get( clientType );
for ( TypeMirror controlType : controlTypes )
{
InterfaceDeclaration controlIntfOrExt = getControlInterfaceOrExtension(controlType);
InterfaceDeclaration controlIntf = getMostDerivedControlInterface( controlIntfOrExt );
assert controlIntf != null : "Can't find most derived control intf for=" + controlIntfOrExt;
ControlInterface annot = controlIntf.getAnnotation(ControlInterface.class);
String defBinding = annot.defaultBinding();
defBinding = ControlBeanContext.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );
mf.addControlType( controlIntfOrExt.getQualifiedName(), defBinding );
}
mf.emit( f, clientPkg, clientManifestName, null );
}
catch ( IOException ie )
{
printError( clientType, "controls.client.manifest.ioerror" );
ie.printStackTrace( );
}
// Emit initializer
AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
Generator genClass = new AptControlClient( clientType, this );
if ( genClass != null )
{
try
{
List<GeneratorOutput> genList = genClass.getGenerateOutput(env.getFiler());
if (genList == null || genList.size() == 0)
return;
for (GeneratorOutput genOut : genList)
{