IntelliJ IDEA将final添加到自动生成的setter中

时间:2015-05-04 15:56:53

标签: java intellij-idea

我正在尝试将最终关键字添加到IntelliJ IDEA 14中自动生成的setter中的参数。我知道我可以创建用于setter方法的当前模板的副本:

public static void main(String args[]) {

Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            checkAlerts();
        }
        }, 30000, 30000);
    }

public static Boolean checkAlerts(){

          if(count ==  0){
               JOptionPane.showMessageDialog(null, "No results");
           } else {
                toggleVisible();
                JOptionPane.showMessageDialog(null, "Some results back");
           }
    }

public void toggleVisible() {
      setVisible(!isVisible());
      if (isVisible()) {
        toFront();
        requestFocus();
        setAlwaysOnTop(true);
        try {
          //remember the last location of mouse
          final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

          //simulate a mouse click on title bar of window
          Robot robot = new Robot();
          robot.mouseMove(mainFrame.getX() + 100, mainFrame.getY() + 5);
          robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
          robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

          //move mouse to old location
          robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
        } catch (Exception ex) {
          //just ignore exception, or you can handle it as you want
        } finally {
          setAlwaysOnTop(false);
        }
      }
    }

但即使在玩了好几个小时之后,我也无法弄清楚如何将“final”添加到它并让它在IntelliJ中工作。

1 个答案:

答案 0 :(得分:14)

您无需使用模板执行此操作。

转到设置(Windows: Ctrl + Alt + S )/首选项(Mac:命令 +

  • Products = new Mongo.Collection("products"); var productImagesStore = new FS.Store.FileSystem('productImages', { path: '~/uploads/full' }); productImages = new FS.Collection('productImages', { stores: [productImagesStore] }); productImages.allow({ insert: function () { return true; }, update: function () { return true; }, remove: function () { return true; }, download: function () { return true; } }); if (Meteor.isClient) { // This code only runs on the client Template.home.helpers({ products: function () { return Products.find({}); }, image:function(){ return productImages.findOne({'metadata.productId':this._id}) } }); Template.add.helpers({ categories: function(){ return categories.find({}); } }); Template.add.events({ "submit form": function(event, template) { event.preventDefault(); var file = $('#file').get(0).files[0], fsFile = new FS.File(file), productData = { title:$('#title').val(), price:$('#price').val(), category:$('#category').val() } Products.insert(productData,function(err,result){ if(!err){ fsFile.metadata = { productId:result, //we use metadata to refer the recent object id with the product images } productImages.insert(fsFile,function(err,result){ if(!err){ console.log("New images inserted") } }); } }); } }); }
  • 选择代码生成标签
  • 勾选Editor | Code Style | Java