KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > Field


1 /*
2   Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

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 JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 public class Field extends Member {
29    
30     public Field() {
31         type = null;
32     }
33
34     public String JavaDoc getPrototype() {
35         if (type==null)
36             throw new RuntimeException JavaDoc("Invalid type for "+getFullName()+": "+type);
37         return (isStatic?"static ":"")+(isTransient?"transient ":"")+
38             type.getGenerationFullName()+" "+getGenerationName();
39     }
40
41     /** The default value of the field */
42     String JavaDoc defaultValue;
43     public String JavaDoc getDefaultValue() {
44         return defaultValue;
45     }
46     public void setDefaultValue(String JavaDoc defaultValue) {
47         this.defaultValue = defaultValue;
48     }
49
50     /** Wether the field is read-only. If it is, it won't have a setter. */
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     /**Wether the field is calculated */
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     /** A custom getter method */
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     /** A custom getter method */
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     /**
96      * Returns all non void types
97      * @param field unused parameter
98      */

99     public static Collection JavaDoc getAvailableTypes(Field field) {
100         Collection JavaDoc types = ObjectRepository.getObjects(
101             ClassRepository.get().getClass(Type.class));
102         Iterator JavaDoc it = types.iterator();
103         Vector JavaDoc result = new Vector JavaDoc();
104         while (it.hasNext()) {
105             Type type = (Type)it.next();
106             if (!type.getName().equals("void") &&
107                 (!(type instanceof Class JavaDoc) || field.getProject()==null ||
108                  ((Class JavaDoc)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