在case语句周围自动插入花括号

时间:2017-08-08 19:54:54

标签: eclipse formatting

在Eclipse中,如何在case 1: break; 语句周围自动放置大括号?

示例:

case 1: {
    break;
}

应该成为

Window > Java > Editor > Templates

我查看过格式化程序和清理工具,似乎没有选项可以执行此操作。当我使用“插入缺失案例陈述”快速修复时,我应该在使用格式化程序时完成此操作。如果Eclipse中没有本机方式,则可以接受插件。

1 个答案:

答案 0 :(得分:0)

我发现这样做的唯一方法是次优且非常繁琐。您可以通过浏览菜单添加新的编辑器模板来执行此操作:New...然后按case ${value}: { ${cursor} break; } 并将其用作模式:

import numpy as np
import os
from itertools import islice
import time


def readwrite():
    tic = time.time()
    f = read_paths('Paths.txt')
    n = pull_size(f)
    hdr, d = read_data(f, n)
    write_data('Data_Py.txt', hdr, d)
    toc = time.time()
    with open('Runtime_Py.txt', 'w') as fid:
        fid.write("Elapsed time is %.6f seconds." % (toc - tic))


def read_paths(f):
    f = np.loadtxt(f, dtype='str', delimiter='\t', skiprows=1)
    return os.path.join(f[0], f[1])


def pull_size(f):
    n = 0
    with open(f, 'r') as fid:
        l = fid.readline()
        h = not(l.count(','))  # headers are not comma delimited
        while h:
            n = n + 1
            l = fid.readline()
            h = not (l.count(','))
    # t = l.count(',') + 1  # file is comma delimited
    return n


def read_data(f, n):
    with open(f, 'r') as fid:
        hdr = ''.join(list(islice(fid, n)))
    hdr = hdr.rstrip('\n')
    d = np.loadtxt(f, dtype='float', delimiter=',', skiprows=n)
    return hdr, d


def write_data(f, hdr, d):
    np.savetxt(f, d, fmt='%.2f', delimiter=',', newline='\n', header=hdr, 
comments='')

readwrite()

您现在可以在代码中的任何位置插入此代码,只需输入“case”然后按 CTRL + SPACE 即可调出templace提案,然后选择“case”(应该在顶部)。