/[classpath]/gjdoc/src/gnu/classpath/tools/gjdoc/FieldDocImpl.java
ViewVC logotype

Diff of /gjdoc/src/gnu/classpath/tools/gjdoc/FieldDocImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by julian, Tue Dec 7 15:00:01 2004 UTC revision 1.6 by julian, Mon Dec 13 17:39:51 2004 UTC
# Line 24  import java.util.*; Line 24  import java.util.*;
24  import com.sun.javadoc.*;  import com.sun.javadoc.*;
25  import java.lang.reflect.Modifier;  import java.lang.reflect.Modifier;
26    
27  public class FieldDocImpl extends MemberDocImpl implements FieldDoc, Cloneable {  import gnu.classpath.tools.gjdoc.expr.Evaluator;
28    import gnu.classpath.tools.gjdoc.expr.IllegalExpressionException;
29    
30    public class FieldDocImpl
31       extends MemberDocImpl
32       implements FieldDoc, Cloneable
33    {
34    
35       private boolean isTransient;
36       private boolean isVolatile;
37       private String valueLiteral;
38       private Object constantValue;
39       private boolean constantValueEvaluated;
40    
41     private FieldDocImpl(ClassDoc containingClass,     private FieldDocImpl(ClassDoc containingClass,
42                          PackageDoc containingPackage,                          PackageDoc containingPackage,
# Line 112  public class FieldDocImpl extends Member Line 124  public class FieldDocImpl extends Member
124    
125        for (Iterator it = fieldDefComponents.iterator(); it.hasNext(); ) {        for (Iterator it = fieldDefComponents.iterator(); it.hasNext(); ) {
126           String fieldDef = (String) it.next();           String fieldDef = (String) it.next();
127             String fieldValueLiteral = null;
128    
129           int endx=fieldDef.indexOf('=');           int endx=fieldDef.indexOf('=');
130           if (endx>=0) fieldDef=fieldDef.substring(0,endx);           if (endx>=0) {
131                fieldValueLiteral = fieldDef.substring(endx + 1);
132                fieldDef = fieldDef.substring(0,endx);
133             }
134           Debug.log(9,"  Field Definition: '"+fieldDef+"'");           Debug.log(9,"  Field Definition: '"+fieldDef+"'");
135                    
136           try {           try {
# Line 128  public class FieldDocImpl extends Member Line 144  public class FieldDocImpl extends Member
144              }              }
145    
146              fieldDoc.setTypeName(fieldDoc.getTypeName()+dimSuffix);              fieldDoc.setTypeName(fieldDoc.getTypeName()+dimSuffix);
   
147              fieldDoc.setName(fieldDef.trim());              fieldDoc.setName(fieldDef.trim());
148                fieldDoc.setValueLiteral(fieldValueLiteral);
149              rcList.add(fieldDoc);              rcList.add(fieldDoc);
150           }           }
151           catch (CloneNotSupportedException e) {           catch (CloneNotSupportedException e) {
# Line 174  public class FieldDocImpl extends Member Line 190  public class FieldDocImpl extends Member
190        }        }
191     }     }
192    
    private boolean isTransient;  
    private boolean isVolatile;  
   
193     void resolve() {     void resolve() {
194        resolveTags();        resolveTags();
195     }     }
# Line 188  public class FieldDocImpl extends Member Line 201  public class FieldDocImpl extends Member
201     public String toString() { return name(); }     public String toString() { return name(); }
202    
203     public Object constantValue() {     public Object constantValue() {
204        return new Integer(0); // FIXME        if (!isStatic()
205              || !isFinal()
206              || (!type().isPrimitive() && !"java.lang.String".equals(type().qualifiedTypeName()))
207              || type.dimension().length()>0
208              || null == valueLiteral) {
209    
210             return null;
211    
212          }
213          else {
214             if (!constantValueEvaluated) {
215                String expression = "(" + type().typeName() + ")(" + valueLiteral + ")";
216                try {
217                   this.constantValue = Evaluator.evaluate(expression,
218                                                           (ClassDocImpl)containingClass());
219                }
220                catch (IllegalExpressionException ignore) {
221                }
222                constantValueEvaluated = true;
223             }
224             return this.constantValue;
225          }
226       }
227    
228       private static void appendCharString(StringBuffer result, char c, boolean inSingleCuotes)
229       {
230          switch (c) {
231          case '\b': result.append("\\b"); break;
232          case '\t': result.append("\\t"); break;
233          case '\n': result.append("\\n"); break;
234          case '\f': result.append("\\f"); break;
235          case '\r': result.append("\\r"); break;
236          case '\"': result.append("\\\""); break;
237          case '\'': result.append(inSingleCuotes ? "\\'" : "'"); break;
238          default:
239             if (c >= 32 && c <= 127) {
240                result.append(c);
241             }
242             else {
243                result.append("\\u");
244                String hexValue = Integer.toString((int)c, 16);
245                int zeroCount = 4 - hexValue.length();
246                for (int i=0; i<zeroCount; ++i) {
247                   result.append('0');
248                }
249                result.append(hexValue);
250             }
251          }
252       }
253    
254       public String constantValueExpression() {
255          Object value = constantValue();
256    
257          if (null == value) {
258             return "null";
259          }
260          else if (value instanceof String) {
261             StringBuffer result = new StringBuffer("\"");
262             char[] chars = ((String)value).toCharArray();
263             for (int i=0; i<chars.length; ++i) {
264                appendCharString(result, chars[i], false);
265             }
266             result.append("\"");
267             return result.toString();
268          }
269          else if (value instanceof Float) {
270             return value.toString() + "f";
271          }
272          else if (value instanceof Long) {
273             return value.toString() + "L";
274          }
275          else if (value instanceof Character) {
276             StringBuffer result = new StringBuffer("'");
277             appendCharString(result, ((Character)value).charValue(), false);
278             result.append("'");
279             return result.toString();
280          }
281          else /* if (value instanceof Double
282                   || value instanceof Integer
283                   || value instanceof Short
284                   || value instanceof Byte) */ {
285             return value.toString();
286          }
287       }
288    
289       void setValueLiteral(String valueLiteral)
290       {
291          this.valueLiteral = valueLiteral;
292       }
293    
294       public boolean isStatic()
295       {
296          return super.isStatic() || containingClass().isInterface();
297       }
298    
299       public boolean isFinal()
300       {
301          return super.isFinal() || containingClass().isInterface();
302     }     }
303  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26