KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > apt > BaseAnnotationProcessorFactory


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

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 JavaDoc;
28 import java.util.Iterator JavaDoc;
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 JavaDoc 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 JavaDoc 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