Code Fragment-有趣的注释

本文参考了《编写可读代码的艺术》,写的好!

参考链接:http://www.cnblogs.com/pengyingh/articles/2445826.html

一、特殊的注释

  • FIXME 
    • 来源:android/packages/apps/Mms/src/com/android/mms/ui/SlideView.java
    • 表意:代码不能正常工作,急需修复的
    • private Uri getSelectedUriFromMessageList(ListView listView, int position) {
          ....
          MessageListItem msglistItem = (MessageListItem) listView.getChildAt(position);
          if (msglistItem == null) {
              // FIXME: Should get the correct view. No such interface in ListView currently
              // to get the view by position. The ListView.getChildAt(position) cannot
              // get correct view since the list doesn't create one child for each item.
              // And if setSelection(position) then getSelectedView(),
              // cannot get corrent view when in touch mode.
              return null;
          }
      
          ....
      
          return null;
      }
  • TODO  
    • 来源:android/packages/apps/Launcher/src/com/android/launcher2/AllAppsList.java
    • 表意:此处功能有待处理
    • public void clear() {
          data.clear();
          // TODO: do we clear these too?
          added.clear();
          removed.clear();
          modified.clear();
      }
  • XXX
    • 来源:android/packages/apps/DeskClock/src/com/android/deskclock/Alarms.java
    • 表意:虽然实现了功能,但是处理方法有待商榷。
    •     /**
           * Sets alert in AlarmManger and StatusBar.  This is what will
           * actually launch the alert when the alarm triggers.
           *
           * @param alarm Alarm.
           * @param atTimeInMillis milliseconds since epoch
           */
          private static void enableAlert(Context context, final Alarm alarm,
                  final long atTimeInMillis) {
              ....
              Intent intent = new Intent(ALARM_ALERT_ACTION);
      
              // XXX: This is a slight hack to avoid an exception in the remote
              // AlarmManagerService process. The AlarmManager adds extra data to
              // this Intent which causes it to inflate. Since the remote process
              // does not know about the Alarm class, it throws a
              // ClassNotFoundException.
              //
              // To avoid this, we marshall the data ourselves and then parcel a plain
              // byte[] array. The AlarmReceiver class knows to build the Alarm
              // object from the byte[] array.
              Parcel out = Parcel.obtain();
              alarm.writeToParcel(out, 0);
              out.setDataPosition(0);
              intent.putExtra(ALARM_RAW_DATA, out.marshall());
      
              ....
          }
二、让注释更有表现力

  • Example
    • // Example: Strip("ab", "a") return "b"
      public String Strip(String src, String chars){
      	....
      }
  • 数字符号
    • // VideoId -> VideoURL
      HashMap<Integer, String> map = new HashMap<Integer, String>();
  • 生动描述
    • <!-- Set of tips to show the user.
      
           First line is the tip title, which is shown in bold on its own line.
      
           All subsequent text is placed into the tip body.
      
           The occurrence of @drawable/foo causes the bitmap drawable named "foo"
           to be displayed to the right of the tip text.
      
           Example for tip #1:
            _____________________________________________     \_/
           |                                             |   /._.\
           |  See all your apps.         [all_apps.png]   > U|   |U
           |  Touch the Launcher icon.                   |   |___|
           |_____________________________________________|    U U
      -->
      <string-array name="tips">
          <!-- Tip: Where the launcher icon is and what it does. With icon. -->
          <item>See all your apps.\n
          Touch the Launcher icon. @drawable/all_apps</item>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值