java - 如何在 Eclipse 中为 Java 匿名方法设置代码格式化程序

标签 java eclipse coding-style

我正在使用 Eclipse 进行 Android 开发,我已经设置了我的代码格式样式,但仍然有我无法弄清楚如何在 Eclipse 中格式化的匿名方法。这就是 Eclipse 现在格式化匿名方法的方式:

// The BroadcastReceiver that listens for discovered devices and
    // changes the title when discovery is finished
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
                                                  @Override
                                                  public void onReceive(Context context, Intent intent) {
                                                      String action = intent.getAction();
                                                      Utils.Log.i("BLUETOOTH: " + action);
                                                      if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                                                          // Get the
                                                          // BluetoothDevice
                                                          // object from the
                                                          // Intent
                                                          BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                                                          // If it's already
                                                          // paired, skip it,
                                                          // because it's been
                                                          // listed already
                                                          if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
                                                              if (mNewDevicesArrayAdapter.getCount() == 0) {
                                                                  mNewDevicesArrayAdapter.add(device);
                                                              }
                                                              btDevicesUpdateList.add(device);
                                                          }
                                                      }
                                                      else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
                                                          mNewDevicesArrayAdapter.setItems(btDevicesUpdateList);
                                                          mNewDevicesArrayAdapter.notifyDataSetChanged();
                                                          btDevicesUpdateList.clear();
                                                          mBtAdapter.startDiscovery();
                                                      }
                                                      else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                                                          if (mBtAdapter.getState() == BluetoothAdapter.STATE_ON) {
                                                              switchToView(viewBluetoothOn);
                                                              firstTimeDiscover();
                                                          }
                                                          else if (mBtAdapter.getState() == BluetoothAdapter.STATE_OFF) {
                                                              switchToView(viewBluetoothOff);
                                                          }
                                                      }
                                                  }
                                              };

看到了吗?它非常糟糕。将匿名方法声明格式化为保留在左侧并且不在 = 等号下方的正确设置是什么?

最佳答案

我认为导致这种错误格式的设置是“按列对齐字段”,如果您关闭此设置,类/接口(interface)实现应该从行的开头缩进,而不是等号。

我在 eclipse 上打开了一个错误来修复默认行为或为类/接口(interface)实现添加另一个设置。

https://bugs.eclipse.org/bugs/show_bug.cgi?id=385901

关于java - 如何在 Eclipse 中为 Java 匿名方法设置代码格式化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11161444/

相关文章:

java - 在 Windows Android Studio 中收到错误消息 "Error:(16) undefined reference to ' JNI_CreateJavaVM'"

java - 在 Eclipse 中调试 Java 在没有断点的情况下停止

logging - 哪个最好 : First Log then do the Operation OR First do the Operation then Log it?

if-statement - 最佳实践 : if logic control

java - 在另一个包的 main 中使用一个包中的 java 类(同一项目)

coding-style - 第一次将库从一种语言移植到另一种语言

java - 线程池任务列表更新问题

java - 布局自定义按钮

java - 参数化类和方法 : making a method returns a correct type with java generics

java - 尝试运行 Maven 项目 Java 时如何解决 Unsupported Major.minor version 51.0 错误