简体   繁体   English

IntelliJ Idea-如何通过所选变量生成Java代码

[英]IntelliJ Idea - How to generate java code by selected variable

I tried to get a solution from google but failed. 我试图从Google获得解决方案,但失败了。 Seems nobody did this. 似乎没有人这样做。

Background I am automation engineer and I am writing some page-model based java class for our business. 背景信息我是自动化工程师,并且正在为我们的业务编写一些基于页面模型的Java类。

Like following - 像以下-

public class PersonalCenterPage extends BasePage {
     MyWebElement button1;
}

Here button1 is a element from specific webpage. 这里的button1是来自特定网页的元素。 Generally I must define some common methods for it such as click, verify or wait for, like following: 通常,我必须为其定义一些常用方法,例如单击,验证或等待,如下所示:

public void click_button1(){
    button1.click();
}

There are many elements that I must write common methods for them, which would take so much time. 我必须为许多元素编写通用方法,这将花费大量时间。

What I did by eclipse 我通过日食做了什么

While using eclipse, I can write a code template called "common" which contains all those common methods. 在使用eclipse时,我可以编写一个名为“ common”的代码模板,其中包含所有这些通用方法。 When I want to automatically generate the "methods suit", I can select the variable "button1", press "alt + /" and choose "common" in the displayed list. 当我想自动生成“方法套”时,可以选择变量“ button1”,按“ alt + /”,然后在显示的列表中选择“ common”。

So how could I implement the same thing by using IntelliJ Idea? 那么,如何使用IntelliJ Idea实现同一件事呢?

Thank you very much! 非常感谢你!

In Intelliji, You can achieve this using File and Code Template option, also live template option. 在Intelliji中,您可以使用“文件和代码模板”选项以及实时模板选项来实现此目的。

Open Settings/Preferences dialog and under the Editor node, select File and Code Templates page. 打开“设置/首选项”对话框,然后在“编辑器”节点下,选择“文件和代码模板”页面。 More details here File and Code Templates 此处有更多详细信息文件和代码模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM