1 package org.apache.beehive.controls.runtime.generator; 2 19 20 import java.util.Collection ; 21 22 import com.sun.mirror.declaration.ClassDeclaration; 23 import com.sun.mirror.declaration.FieldDeclaration; 24 import com.sun.mirror.declaration.InterfaceDeclaration; 25 import com.sun.mirror.declaration.TypeDeclaration; 26 import com.sun.mirror.type.DeclaredType; 27 import com.sun.mirror.type.InterfaceType; 28 import com.sun.mirror.type.TypeMirror; 29 30 import org.apache.beehive.controls.api.bean.ControlExtension; 31 import org.apache.beehive.controls.api.bean.ControlInterface; 32 import org.apache.beehive.controls.api.versioning.VersionRequired; 33 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor; 34 35 38 public class AptControlField extends AptEventField 39 { 40 44 public AptControlField(AptType controlClient, FieldDeclaration controlDecl, 45 TwoPhaseAnnotationProcessor ap) 46 { 47 super( controlDecl ); 48 _controlClient = controlClient; 49 _ap = ap; 50 _controlBean = new ControlBean(getControlInterface()); 51 }; 52 53 57 public boolean hasVersionRequired() 58 { 59 return ( _fieldDecl.getAnnotation( VersionRequired.class ) != null ); 60 } 61 62 65 protected AptControlInterface initControlInterface() 66 { 67 TypeMirror controlType = _fieldDecl.getType(); 68 if (! (controlType instanceof DeclaredType)) 69 { 70 _ap.printError( _fieldDecl, "control.field.bad.type" ); 71 return null; 72 } 73 74 TypeDeclaration typeDecl = ((DeclaredType)controlType).getDeclaration(); 80 InterfaceDeclaration controlIntf = null; 81 82 if ( typeDecl == null ) 88 { 89 String className = controlType.toString(); 90 String intfName = className.substring(0, className.length() - 4); 91 controlIntf = (InterfaceDeclaration)_ap.getAnnotationProcessorEnvironment().getTypeDeclaration(intfName); 92 if (controlIntf == null) 93 { 94 for (TypeDeclaration td :_ap.getAnnotationProcessorEnvironment().getSpecifiedTypeDeclarations()) 97 { 98 if (td instanceof InterfaceDeclaration && 99 td.getSimpleName().equals(intfName)) 100 { 101 controlIntf = (InterfaceDeclaration)td; 102 break; 103 } 104 } 105 } 106 } 107 else if (typeDecl instanceof ClassDeclaration) 108 { 109 Collection <InterfaceType> implIntfs = ((ClassDeclaration)typeDecl).getSuperinterfaces(); 110 for (InterfaceType intfType : implIntfs) 111 { 112 InterfaceDeclaration intfDecl = intfType.getDeclaration(); 113 114 if ( intfDecl == null ) 115 return null; 116 117 if (intfDecl.getAnnotation(ControlInterface.class) != null|| 118 intfDecl.getAnnotation(ControlExtension.class) != null) 119 { 120 controlIntf = intfDecl; 121 break; 122 } 123 } 124 } 125 else if (typeDecl instanceof InterfaceDeclaration) 126 { 127 controlIntf = (InterfaceDeclaration)typeDecl; 128 } 129 130 if (controlIntf == null) 131 { 132 _ap.printError( _fieldDecl, "control.field.bad.type.2" ); 133 return null; 134 } 135 136 return new AptControlInterface(controlIntf, _ap); 137 } 138 139 142 public ControlBean getControlBean() { return _controlBean; } 143 144 private TwoPhaseAnnotationProcessor _ap; 145 private AptType _controlClient; 146 private ControlBean _controlBean; 147 } 148 | Popular Tags |