1 package org.apache.beehive.controls.runtime.generator; 2 19 import java.util.Collection ; 20 import java.util.Map ; 21 22 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; 23 import com.sun.mirror.declaration.AnnotationMirror; 24 import com.sun.mirror.declaration.AnnotationValue; 25 import com.sun.mirror.type.AnnotationType; 26 import com.sun.mirror.type.PrimitiveType; 27 28 import org.apache.beehive.controls.api.packaging.FeatureInfo; 29 import org.apache.beehive.controls.api.packaging.PropertyInfo; 30 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor; 31 32 36 public class AptProperty 37 { 38 44 public AptProperty(AptPropertySet propertySet, AnnotationTypeElementDeclaration propDecl, 45 TwoPhaseAnnotationProcessor ap) 46 { 47 _propertySet = propertySet; 48 _propDecl = propDecl; 49 _ap = ap; 50 51 if (propDecl.getReturnType() instanceof PrimitiveType && 58 propDecl.getDefaultValue() == null) 59 { 60 _ap.printError( propDecl, "property.primitive.without.default", propDecl.getSimpleName() ); 61 } 62 } 63 64 67 public AptPropertySet getPropertySet() { return _propertySet; } 68 69 73 public String getAccessorName() 74 { 75 StringBuffer sb = new StringBuffer (); 76 sb.append(_propertySet.getPrefix()); 77 78 String name = getName(); 79 sb.append(Character.toUpperCase(name.charAt(0))); 80 if (name.length() > 0) 81 sb.append(name.substring(1)); 82 return sb.toString(); 83 } 84 85 88 public String getReadMethod() 89 { 90 StringBuffer sb = new StringBuffer (); 91 if (getType().equals("boolean")) 92 sb.append("is"); 93 else 94 sb.append("get"); 95 sb.append(getAccessorName()); 96 return sb.toString(); 97 } 98 99 102 public String getWriteMethod() 103 { 104 return "set" + getAccessorName(); 105 } 106 107 110 public String getName() 111 { 112 if ( _propDecl == null ) 113 return ""; 114 115 return _propDecl.getSimpleName(); 119 } 120 121 124 public String getKeyName() 125 { 126 return getAccessorName() + "Key"; 127 } 128 129 132 public String getType() 133 { 134 if ( _propDecl == null || _propDecl.getReturnType() == null ) 135 return ""; 136 137 return _propDecl.getReturnType().toString(); 138 } 139 140 143 public boolean isAnnotation() 144 { 145 if ( _propDecl == null ) 146 return false; 147 148 return _propDecl.getReturnType() instanceof AnnotationType; 149 } 150 151 154 public PropertyInfo getPropertyInfo() 155 { 156 if ( _propDecl == null ) 157 return null; 158 159 return _propDecl.getAnnotation(PropertyInfo.class); 160 } 161 162 165 public FeatureInfo getFeatureInfo() 166 { 167 if ( _propDecl == null ) 168 return null; 169 170 return _propDecl.getAnnotation(FeatureInfo.class); 171 } 172 173 177 public boolean isBound() 178 { 179 PropertyInfo propInfo = getPropertyInfo(); 184 return propInfo != null && (propInfo.bound() || propInfo.constrained()); 185 } 186 187 191 public boolean isConstrained() 192 { 193 PropertyInfo propInfo = getPropertyInfo(); 194 return propInfo != null && propInfo.constrained(); 195 } 196 197 200 public String getEditorClass() 201 { 202 PropertyInfo pi = getPropertyInfo(); 203 if (pi == null) 204 return null; 205 206 Collection <AnnotationMirror> annotMirrors = _propDecl.getAnnotationMirrors(); 211 for (AnnotationMirror am: annotMirrors) 212 { 213 if (am.getAnnotationType().toString().equals( 214 "org.apache.beehive.controls.api.packaging.PropertyInfo")) 215 { 216 Map <AnnotationTypeElementDeclaration,AnnotationValue> avs = 217 am.getElementValues(); 218 for (AnnotationTypeElementDeclaration ated: avs.keySet()) 219 { 220 if (ated.toString().equals("editorClass()")) 221 { 222 String editorClass = avs.get(ated).getValue().toString(); 227 if (editorClass.equals("org.apache.beehive.controls.api.packaging.PropertyInfo.NoEditor.class")) 228 return null; 229 230 return editorClass; 231 } 232 } 233 break; 234 } 235 } 236 return null; 237 } 238 239 AnnotationTypeElementDeclaration _propDecl; 240 private AptPropertySet _propertySet; 241 TwoPhaseAnnotationProcessor _ap; 242 } 243 | Popular Tags |