001 /* 002 Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.ide; 020 021 import org.objectweb.jac.core.ObjectRepository; 022 import org.objectweb.jac.core.rtti.ClassRepository; 023 import org.objectweb.jac.core.rtti.NamingConventions; 024 import java.util.Collection; 025 import java.util.Iterator; 026 import java.util.Vector; 027 028 public class Field extends Member { 029 030 public Field() { 031 type = null; 032 } 033 034 public String getPrototype() { 035 if (type==null) 036 throw new RuntimeException("Invalid type for "+getFullName()+": "+type); 037 return (isStatic?"static ":"")+(isTransient?"transient ":"")+ 038 type.getGenerationFullName()+" "+getGenerationName(); 039 } 040 041 /** The default value of the field */ 042 String defaultValue; 043 public String getDefaultValue() { 044 return defaultValue; 045 } 046 public void setDefaultValue(String defaultValue) { 047 this.defaultValue = defaultValue; 048 } 049 050 /** Wether the field is read-only. If it is, it won't have a setter. */ 051 boolean readOnly = false; 052 public boolean isReadOnly() { 053 return readOnly; 054 } 055 public void setReadOnly(boolean readOnly) { 056 this.readOnly = readOnly; 057 } 058 059 /**Wether the field is calculated */ 060 boolean calculated = false; 061 public boolean isCalculated() { 062 return calculated; 063 } 064 public void setCalculated(boolean calculated) { 065 this.calculated = calculated; 066 } 067 068 /** A custom getter method */ 069 Getter getter; 070 public Getter getGetter() { 071 return getter; 072 } 073 public void setGetter(Getter getter) { 074 this.getter = getter; 075 } 076 public void initGetter(Getter getter) { 077 getter.setName(CodeGeneration.getGetterName(name)); 078 getter.setType(type); 079 } 080 081 /** A custom getter method */ 082 Setter setter; 083 public Setter getSetter() { 084 return setter; 085 } 086 public void setSetter(Setter setter) { 087 this.setter = setter; 088 } 089 public void initSetter(Setter setter) { 090 setter.setType(Projects.types.resolveType("void")); 091 setter.addParameter(new Parameter(NamingConventions.lowerFirst(name),type)); 092 setter.setName(CodeGeneration.getSetterName(name)); 093 } 094 095 /** 096 * Returns all non void types 097 * @param field unused parameter 098 */ 099 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 }