1 18 package org.apache.beehive.netui.compiler.processor; 19 20 import java.util.*; 21 import java.text.MessageFormat ; 22 23 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessor; 24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration; 26 import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration; 27 import org.apache.beehive.netui.compiler.Diagnostics; 28 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 29 30 67 public abstract class TwoPhaseAnnotationProcessor 68 extends Diagnostics 69 implements AnnotationProcessor 70 { 71 protected TwoPhaseAnnotationProcessor( AnnotationTypeDeclaration[] atds, AnnotationProcessorEnvironment env ) 72 { 73 super( env ); 74 _atds = atds; 75 _locale = Locale.getDefault(); 76 } 77 78 82 public void process() 83 { 84 try 85 { 86 check(); 87 88 if ( ! hasErrors() ) generate(); 90 } 91 catch ( FatalCompileTimeException e ) 92 { 93 e.printDiagnostic( this ); 94 } 95 } 96 97 101 public void check() 102 throws FatalCompileTimeException 103 { 104 HashSet declsToCheck = new HashSet(); 105 106 for ( int i = 0; i < _atds.length; ++i ) 110 { 111 AnnotationTypeDeclaration atd = _atds[i]; 112 Declaration[] decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith( atd ); 113 for ( int j = 0; j < decls.length; j++ ) 114 { 115 declsToCheck.add( decls[j] ); 116 } 117 } 118 119 for ( Iterator i = declsToCheck.iterator(); i.hasNext(); ) 123 { 124 Declaration decl = ( Declaration ) i.next(); 125 check( decl ); 126 } 127 } 128 129 133 public void generate() 134 { 135 try 136 { 137 for ( int i = 0; i < _atds.length; i++ ) 138 { 139 AnnotationTypeDeclaration atd = _atds[i]; 140 Declaration[] decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith( atd ); 141 142 for ( int j = 0; j < decls.length; j++ ) 143 { 144 generate( decls[j] ); 145 } 146 } 147 } 148 catch ( FatalCompileTimeException e ) 149 { 150 e.printDiagnostic( this ); 151 } 152 } 153 154 168 public abstract void check( Declaration decl ) 169 throws FatalCompileTimeException; 170 171 175 public abstract void generate( Declaration decl ) 176 throws FatalCompileTimeException; 177 178 182 protected String getResourceString( String id, Object [] args ) 183 { 184 ResourceBundle rb = ResourceBundle.getBundle( getClass().getPackage().getName() + ".strings", _locale ); 185 String pattern = rb.getString( id ); 186 return MessageFormat.format( pattern, args ); 187 } 188 189 private AnnotationTypeDeclaration[] _atds; 190 private Locale _locale; 191 } 192 | Popular Tags |