gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:18:34 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com