@@ -207,16 +207,20 @@ public void translate(AX2JCodeBlock codeBlock, Attribute attr, int priority) {
207207 * @param attr the attribute to be translated
208208 * @return the value after translating
209209 */
210- protected String translateValue (AX2JCodeBlock codeBlock , AX2JAttribute attribute , AX2JMethod method ) {
211- String value = attribute .getValue ().getValue ();
212- String attrName = attribute .getName ().getQualifiedName ();
213-
210+ private String translateValue (AX2JCodeBlock codeBlock , AX2JAttribute attribute , AX2JMethod method ) {
214211 int argOrder = attribute .getTypeValue (AX2JAttribute .TYPE_ARGUMENTS_ORDER );
215212 if (argOrder == AX2JAttribute .TYPE_ARGUMENTS_ALL_THE_SAME ) {
216213 argOrder = 1 ;
217214 }
218215 Class <?> argType = method .getArgType (argOrder );
219-
216+
217+ return translateValue (codeBlock , method , attribute .getValue (), argType );
218+ }
219+
220+ protected final String translateValue (AX2JCodeBlock codeBlock , AX2JMethod method , Attribute attribute , Class <?> argType ) {
221+ String value = attribute .getValue ();
222+ String name = attribute .getQualifiedName ();
223+
220224 if (argType .equals (Integer .class )) {
221225 //dp, px, sp
222226 if (value .matches ("[0-9.]+dp" )) {
@@ -247,8 +251,8 @@ else if (value.contains("@string/")) {
247251 value = value .substring (value .indexOf ('/' ) + 1 );
248252 value = Config .R_CLASS + ".string." + value ;
249253 value = Config .RESOURCES_NAME + ".getString(" + value + ")" ;
250- } else if (attrName .equals ("android:text" ) ||
251- attrName .equals ("android:hint" )) {
254+ } else if (name .equals ("android:text" ) ||
255+ name .equals ("android:hint" )) {
252256 value = "\" " + value + "\" " ;
253257 }
254258
@@ -289,19 +293,19 @@ else if (value.equals("vertical")) {
289293 }
290294
291295 //gravity
292- else if (attrName .equals ("android:gravity" ) ||
293- attrName .equals ("android:layout_gravity" )) {
296+ else if (name .equals ("android:gravity" ) ||
297+ name .equals ("android:layout_gravity" )) {
294298 value = Utils .prefixParams (value , "Gravity" );
295299 codeBlock .addImport (Gravity .class .getName ());
296300 }
297301
298302 //margin
299- else if (attrName .matches ("android:layout_margin(Left)|(Top)|(Right)|(Bottom)" )) {
303+ else if (name .matches ("android:layout_margin(Left)|(Top)|(Right)|(Bottom)" )) {
300304 codeBlock .addImport (ViewGroup .class .getName ());
301305 }
302306
303307 //text
304- else if (attrName .equals ("android:textAppearance" )) {
308+ else if (name .equals ("android:textAppearance" )) {
305309 String style = AX2JStyle .getStyle (value ).name ;
306310 style = style .replace ('.' , '_' );
307311 style = "android.R.style." + style ;
@@ -310,7 +314,7 @@ else if (attrName.equals("android:textAppearance")) {
310314
311315 /** independent part **/
312316 //RelativeLayout rule
313- if (method .getMethodName ().equals ("addRule" )) {
317+ if (method != null && method .getMethodName ().equals ("addRule" )) {
314318 if (value .equals ("true" )) {
315319 value = "RelativeLayout.TRUE" ;
316320 } else if (value .equals ("false" )) {
@@ -320,7 +324,7 @@ else if (attrName.equals("android:textAppearance")) {
320324 }
321325
322326 //divider
323- if (attrName .equals ("android:divider" )) {
327+ if (name .equals ("android:divider" )) {
324328 codeBlock .addImport (ColorDrawable .class .getName ());
325329 }
326330
@@ -351,8 +355,8 @@ else if (argType.equals(Drawable.class) || argType.equals(ColorStateList.class))
351355 if (value .startsWith ("@drawable/" )) {
352356 value = value .substring (value .indexOf ('/' ) + 1 );
353357 value = Config .R_CLASS + ".drawable." + value ;
354- if (attrName .contains ("Color" ) ||
355- attrName .contains ("TintList" )) {
358+ if (name .contains ("Color" ) ||
359+ name .contains ("TintList" )) {
356360 value = "resources.getColorStateList(" + value + ")" ;
357361 } else {
358362 value = "resources.getDrawable(" + value + ")" ;
@@ -362,21 +366,21 @@ else if (argType.equals(Drawable.class) || argType.equals(ColorStateList.class))
362366
363367 else if (argType .equals (TransformationMethod .class )) {
364368 //text
365- if (attrName .equals ("android:password" )) {
369+ if (name .equals ("android:password" )) {
366370 value = "new PasswordTransformationMethod()" ;
367371 codeBlock .addImport (PasswordTransformationMethod .class .getName ());
368- } else if (attrName .equals ("android:singleLine" )) {
372+ } else if (name .equals ("android:singleLine" )) {
369373 value = "new SingleLineTransformationMethod()" ;
370374 codeBlock .addImport (SingleLineTransformationMethod .class .getName ());
371- } else if (attrName .equals ("android:inputType" )) {
375+ } else if (name .equals ("android:inputType" )) {
372376 String error = value ;
373377 value = Config .INPUT_TYPE_MAP .get (value );
374378 if (value == null ) {
375379 throw new AX2JException (AX2JException .ATTRIBUTE_VALUE_ERROR , error );
376380 }
377381 value = Utils .prefixParams (value , "InputType" );
378382 codeBlock .addImport (InputType .class .getName ());
379- } else if (attrName .equals ("android:ellipsize" )) {
383+ } else if (name .equals ("android:ellipsize" )) {
380384 value = value .toUpperCase ();
381385 value = "TextUtils.TruncateAt." + value ;
382386 codeBlock .addImport (TextUtils .class .getName ());
0 commit comments