1 18 19 package org.objectweb.jac.ide; 20 21 import org.objectweb.jac.core.ObjectRepository; 22 import org.objectweb.jac.core.rtti.ClassRepository; 23 import org.objectweb.jac.core.rtti.NamingConventions; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.Vector ; 27 28 public class Field extends Member { 29 30 public Field() { 31 type = null; 32 } 33 34 public String getPrototype() { 35 if (type==null) 36 throw new RuntimeException ("Invalid type for "+getFullName()+": "+type); 37 return (isStatic?"static ":"")+(isTransient?"transient ":"")+ 38 type.getGenerationFullName()+" "+getGenerationName(); 39 } 40 41 42 String defaultValue; 43 public String getDefaultValue() { 44 return defaultValue; 45 } 46 public void setDefaultValue(String defaultValue) { 47 this.defaultValue = defaultValue; 48 } 49 50 51 boolean readOnly = false; 52 public boolean isReadOnly() { 53 return readOnly; 54 } 55 public void setReadOnly(boolean readOnly) { 56 this.readOnly = readOnly; 57 } 58 59 60 boolean calculated = false; 61 public boolean isCalculated() { 62 return calculated; 63 } 64 public void setCalculated(boolean calculated) { 65 this.calculated = calculated; 66 } 67 68 69 Getter getter; 70 public Getter getGetter() { 71 return getter; 72 } 73 public void setGetter(Getter getter) { 74 this.getter = getter; 75 } 76 public void initGetter(Getter getter) { 77 getter.setName(CodeGeneration.getGetterName(name)); 78 getter.setType(type); 79 } 80 81 82 Setter setter; 83 public Setter getSetter() { 84 return setter; 85 } 86 public void setSetter(Setter setter) { 87 this.setter = setter; 88 } 89 public void initSetter(Setter setter) { 90 setter.setType(Projects.types.resolveType("void")); 91 setter.addParameter(new Parameter(NamingConventions.lowerFirst(name),type)); 92 setter.setName(CodeGeneration.getSetterName(name)); 93 } 94 95 99 public static Collection getAvailableTypes(Field field) { 100 Collection types = ObjectRepository.getObjects( 101 ClassRepository.get().getClass(Type.class)); 102 Iterator it = types.iterator(); 103 Vector result = new Vector (); 104 while (it.hasNext()) { 105 Type type = (Type)it.next(); 106 if (!type.getName().equals("void") && 107 (!(type instanceof Class ) || field.getProject()==null || 108 ((Class )type).getProject()==field.getProject())) { 109 result.add(type); 110 } 111 } 112 return result; 113 } 114 115 boolean isTransient; 116 public boolean isTransient() { 117 return isTransient; 118 } 119 public void setTransient(boolean isTransient) { 120 this.isTransient = isTransient; 121 } 122 } 123 | Popular Tags |