• IDEA插件笔记


    1. Setter生成源码:

    https://github.com/donnie0915/GenerateAllSetter

    2. 代码示例

    PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    // final Document document = editor.getDocument();
    //获取光标所在位置
    final int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);

    // final int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset) + 1);
    // document.insertString(lineEndOffset, ";");

    3. IDEA插件如果想修改代码,IDEA为了不影响主线程,要求使用子线程进行操作

    WriteCommandAction.runWriteCommandAction(project, () -> {

      //todo 编写更改操作的代码

    }

    4. 格式化代码

    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
    codeStyleManager.reformat(psiJavaFile);

  • 相关阅读:
    msp430入门编程41
    msp430入门编程40
    msp430入门编程37
    msp430入门编程36
    msp430入门编程35
    msp430入门编程34
    msp430入门编程33
    msp430入门编程31
    msp430入门编程32
    msp430入门编程30
  • 原文地址:https://www.cnblogs.com/hujiapeng/p/16391692.html
Copyright © 2020-2023  润新知