1 18 package org.apache.beehive.netui.compiler.processor; 19 20 import org.apache.beehive.netui.compiler.*; 21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance; 22 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration; 23 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration; 24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment; 25 26 import java.io.File ; 27 28 29 public class PageFlowAnnotationProcessor 30 extends BaseAnnotationProcessor 31 implements JpfLanguageConstants 32 { 33 public PageFlowAnnotationProcessor( AnnotationTypeDeclaration[] annotationTypeDecls, 34 AnnotationProcessorEnvironment env ) 35 { 36 super( annotationTypeDecls, env ); 37 } 38 39 public BaseChecker getChecker( ClassDeclaration classDecl, Diagnostics diagnostics ) 40 { 41 AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment(); 42 43 if ( CompilerUtils.isAssignableFrom( JPF_BASE_CLASS, classDecl, env ) ) 44 { 45 if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, JPF_FILE_EXTENSION_DOT, JPF_BASE_CLASS, diagnostics ) ) 46 { 47 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl ); 48 setSourceFileInfo( classDecl, fcInfo ); 49 50 return new PageFlowChecker( env, diagnostics, fcInfo ); 51 } 52 } 53 else if ( CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, classDecl, env ) ) 54 { 55 if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, SHARED_FLOW_FILE_EXTENSION_DOT, 56 SHARED_FLOW_BASE_CLASS, diagnostics ) ) 57 { 58 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl ); 59 setSourceFileInfo( classDecl, fcInfo ); 60 61 return new SharedFlowChecker( env, fcInfo, diagnostics ); 62 } 63 } 64 else if ( CompilerUtils.isAssignableFrom( GLOBALAPP_BASE_CLASS, classDecl, env ) ) 65 { 66 if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, GLOBALAPP_FILE_EXTENSION_DOT, GLOBALAPP_BASE_CLASS, 67 diagnostics ) ) 68 { 69 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl ); 70 setSourceFileInfo( classDecl, fcInfo ); 71 72 return new SharedFlowChecker( env, fcInfo, diagnostics ); 73 } 74 } 75 else if ( CompilerUtils.isAssignableFrom( FACES_BACKING_BEAN_CLASS, classDecl, env ) ) 76 { 77 if ( expectAnnotation( classDecl, FACES_BACKING_TAG_NAME, JPF_FILE_EXTENSION_DOT, JPF_BASE_CLASS, diagnostics ) ) 78 { 79 File originalFile = CompilerUtils.getSourceFile( classDecl, true ); 80 FacesBackingInfo fbInfo = new FacesBackingInfo( originalFile, classDecl.getQualifiedName() ); 81 setSourceFileInfo( classDecl, fbInfo ); 82 return new FacesBackingChecker( env, fbInfo, diagnostics ); 83 } 84 } 85 else 86 { 87 AnnotationInstance ann = CompilerUtils.getAnnotation( classDecl, CONTROLLER_TAG_NAME ); 88 89 if ( ann != null ) 90 { 91 diagnostics.addError( ann, "error.annotation-invalid-base-class2", 92 CONTROLLER_TAG_NAME, JPF_BASE_CLASS, SHARED_FLOW_BASE_CLASS ); 93 } 94 95 ann = CompilerUtils.getAnnotation( classDecl, FACES_BACKING_TAG_NAME ); 96 97 if ( ann != null ) 98 { 99 diagnostics.addError( ann, "error.annotation-invalid-base-class", 100 FACES_BACKING_TAG_NAME, FACES_BACKING_BEAN_CLASS ); 101 } 102 } 103 104 return null; 105 } 106 107 public BaseGenerator getGenerator( ClassDeclaration classDecl, Diagnostics diags ) 108 { 109 AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment(); 110 SourceFileInfo sourceFileInfo = getSourceFileInfo( classDecl ); 111 112 if ( CompilerUtils.isAssignableFrom( JPF_BASE_CLASS, classDecl, env ) ) 113 { 114 assert sourceFileInfo != null : classDecl.getQualifiedName(); 115 assert sourceFileInfo instanceof FlowControllerInfo : sourceFileInfo.getClass().getName(); 116 return new PageFlowGenerator( env, ( FlowControllerInfo ) sourceFileInfo, diags ); 117 } 118 else if ( CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, classDecl, env ) ) 119 { 120 assert sourceFileInfo != null : classDecl.getQualifiedName(); 121 assert sourceFileInfo instanceof FlowControllerInfo : sourceFileInfo.getClass().getName(); 122 return new SharedFlowGenerator( env, ( FlowControllerInfo ) sourceFileInfo, diags ); 123 } 124 else if ( CompilerUtils.isAssignableFrom( FACES_BACKING_BEAN_CLASS, classDecl, env ) ) 125 { 126 assert sourceFileInfo != null : classDecl.getQualifiedName(); 127 assert sourceFileInfo instanceof FacesBackingInfo : sourceFileInfo.getClass().getName(); 128 return new FacesBackingGenerator( env, sourceFileInfo, diags ); 129 } 130 131 return null; 132 } 133 } 134 | Popular Tags |