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>






已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页