KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > rebind > AbstractSourceCreator


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.rebind;
17
18 import com.google.gwt.core.ext.Generator;
19 import com.google.gwt.core.ext.TreeLogger;
20 import com.google.gwt.core.ext.UnableToCompleteException;
21 import com.google.gwt.core.ext.typeinfo.JPrimitiveType;
22
23 /**
24  * Super class for AbstractMethod and AbstractClass creators. The primary
25  * purpose is to pull up helper methods for logging and printing.
26  */

27 public class AbstractSourceCreator {
28   
29   /**
30    * Creates a branch for the treelogger.
31    * @param logger
32    * @param message
33    * @return treelogger
34    */

35   protected static TreeLogger branch(TreeLogger logger, String JavaDoc message) {
36     return logger.branch(TreeLogger.TRACE, message, null);
37   }
38
39   /**
40    * Convenience method to use TreeLogger error pattern.
41    * @param logger logger to print to
42    * @param msg msg
43    * @return the exception to throw
44    */

45   protected static UnableToCompleteException error(TreeLogger logger, String JavaDoc msg) {
46     logger.log(TreeLogger.ERROR, msg, null);
47     return new UnableToCompleteException();
48   }
49
50   /**
51    * Convenience method to use TreeLogger error pattern.
52    * @param logger logger to print to
53    * @param msg msg
54    * @return the exception to throw
55    */

56   protected static UnableToCompleteException error(TreeLogger logger, String JavaDoc msg, Throwable JavaDoc cause) {
57     logger.log(TreeLogger.ERROR, msg, cause);
58     return new UnableToCompleteException();
59   }
60   
61   /**
62    * Convenience method to use TreeLogger error pattern.
63    * @param logger logger to print to
64    * @param e throwable
65    * @return th exception to throw
66    */

67   protected static UnableToCompleteException error(TreeLogger logger,
68       Throwable JavaDoc e) {
69     logger.log(TreeLogger.ERROR, e.getMessage(), e);
70     return new UnableToCompleteException();
71   }
72
73   /**
74    * Returns the String represention of the java type for a primitive for
75    * example int/Integer, float/Float.
76    *
77    * @param type
78    * @return the string representation
79    */

80   protected static String JavaDoc getJavaObjectTypeFor(JPrimitiveType type) {
81     if (type == JPrimitiveType.INT) {
82       return "Integer";
83     } else {
84       String JavaDoc s = type.getSimpleSourceName();
85       return s.substring(0, 1).toUpperCase() + s.substring(1);
86     }
87   }
88
89   /**
90    * Helper method used to wrap a string constant with quotes. Must use to
91    * enable string escaping.
92    *
93    * @param wrapMe String to wrap
94    * @return wrapped String
95    */

96   protected static String JavaDoc wrap(String JavaDoc wrapMe) {
97     return "\"" + Generator.escape(wrapMe) + "\"";
98   }
99 }
100
Popular Tags