1 18 package org.apache.beehive.netui.compiler.apt; 19 20 import org.apache.beehive.netui.compiler.typesystem.impl.env.AnnotationProcessorEnvironmentImpl; 21 import org.apache.beehive.netui.compiler.typesystem.impl.DelegatingImpl; 22 import org.apache.beehive.netui.compiler.typesystem.impl.WrapperFactory; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration; 24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessor; 25 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 26 27 import java.util.Set ; 28 import java.util.Iterator ; 29 30 import com.sun.mirror.apt.AnnotationProcessorFactory; 31 32 public abstract class BaseAnnotationProcessorFactory 33 implements AnnotationProcessorFactory 34 { 35 public final com.sun.mirror.apt.AnnotationProcessor 36 getProcessorFor( Set annotationTypeDeclarations, com.sun.mirror.apt.AnnotationProcessorEnvironment aptEnv ) 37 { 38 39 AnnotationProcessorEnvironment env = AnnotationProcessorEnvironmentImpl.get( aptEnv ); 40 AnnotationTypeDeclaration[] atds = new AnnotationTypeDeclaration[ annotationTypeDeclarations.size() ]; 41 int j = 0; 42 for ( Iterator i = annotationTypeDeclarations.iterator(); i.hasNext(); ) 43 { 44 com.sun.mirror.declaration.AnnotationTypeDeclaration decl = 45 ( com.sun.mirror.declaration.AnnotationTypeDeclaration ) i.next(); 46 atds[ j++ ] = WrapperFactory.get().getAnnotationTypeDeclaration( decl ); 47 } 48 49 AnnotationProcessor ap = getProcessorFor( atds, env ); 50 return ap != null ? new DelegatingAnnotationProcessor( ap ) : null; 51 } 52 53 private static class DelegatingAnnotationProcessor 54 extends DelegatingImpl 55 implements com.sun.mirror.apt.AnnotationProcessor 56 { 57 public DelegatingAnnotationProcessor( AnnotationProcessor delegate ) 58 { 59 super( delegate ); 60 } 61 62 public void process() 63 { 64 ( ( AnnotationProcessor ) getDelegate() ).process(); 65 } 66 } 67 68 protected abstract AnnotationProcessor getProcessorFor( AnnotationTypeDeclaration[] annotationTypeDeclarations, 69 AnnotationProcessorEnvironment env ); 70 } 71 | Popular Tags |