1 package org.apache.beehive.controls.runtime.generator.apt; 2 3 20 21 import java.util.*; 22 import java.text.MessageFormat ; 23 24 import com.sun.mirror.apt.AnnotationProcessor; 25 import com.sun.mirror.apt.AnnotationProcessorEnvironment; 26 import com.sun.mirror.declaration.AnnotationTypeDeclaration; 27 import com.sun.mirror.declaration.Declaration; 28 29 import org.apache.beehive.controls.runtime.generator.CodeGenerationException; 30 31 68 abstract public class TwoPhaseAnnotationProcessor 69 extends Diagnostics 70 implements AnnotationProcessor 71 { 72 public TwoPhaseAnnotationProcessor(Set<AnnotationTypeDeclaration> atds, 73 AnnotationProcessorEnvironment env) 74 { 75 super( env ); 76 _atds = atds; 77 _locale = Locale.getDefault(); 78 } 79 80 84 public void process() 85 { 86 check(); 87 88 if ( !hasErrors() ) 90 generate(); 91 } 92 93 97 public void check() 98 { 99 for (AnnotationTypeDeclaration atd : _atds) 100 { 101 Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd); 102 for (Declaration decl : decls) 103 { 104 check(decl); 105 } 106 } 107 } 108 109 113 public void generate() throws CodeGenerationException 114 { 115 for (AnnotationTypeDeclaration atd : _atds) 116 { 117 Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd); 118 for (Declaration decl : decls) 119 { 120 generate(decl); 121 } 122 } 123 } 124 125 141 abstract public void check(Declaration decl); 142 143 147 abstract public void generate(Declaration decl); 148 149 153 157 public void printError( Declaration d, String id, Object ... args ) 158 { 159 addError( d, id, args ); 160 } 161 162 166 public void printWarning( Declaration d, String id, Object ... args ) 167 { 168 addWarning( d, id, args ); 169 } 170 171 protected String getResourceString( String id, Object ... args ) 172 { 173 ResourceBundle rb = ResourceBundle.getBundle( 174 this.getClass().getPackage().getName() + ".strings", _locale ); 175 String pattern = rb.getString(id); 176 return MessageFormat.format(pattern, args); 177 } 178 179 Set<AnnotationTypeDeclaration> _atds; 180 Locale _locale; 181 } 182 | Popular Tags |