首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClassNotFoundException JavaRecursiveElementVisitor

ClassNotFoundException JavaRecursiveElementVisitor
EN

Stack Overflow用户
提问于 2020-06-14 22:23:06
回答 1查看 148关注 0票数 0

大家好,我正在尝试在intellij中构建一个插件,并且在运行时得到以下错误:

代码语言:javascript
复制
Caused by: java.lang.ClassNotFoundException: com.intellij.psi.JavaRecursiveElementVisitor PluginClassLoader[com.rahul.gqlformat, 1.0] com.intellij.ide.plugins.cl.PluginClassLoader@2a707a23

我在名为- printSelectedFileNamefunction中得到了一个异常,这是完整的类-

代码语言:javascript
复制
package com.rahul.gqlformat;

import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.psi.*;

import javax.swing.*;

public class GqlView {
    private JTextArea textArea;
    private JButton btn;
    private JPanel panel;
    private Project project;

    public GqlView(Project project) {
        this.project = project;
        btn.addActionListener(actionEvent -> {
            textArea.append("Hello");
//            printSelectedFileName();
        });

    }


    void printSelectedFileName() {
        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        VirtualFile[] virtualFile = fileEditorManager.getOpenFiles();
        if (virtualFile != null && virtualFile.length > 0) {
            VirtualFile vf = virtualFile[0];
            PsiFile psiFile = PsiManager.getInstance(project).findFile(vf);

            psiFile.accept(new JavaRecursiveElementVisitor() {
                @Override
                public void visitLocalVariable(PsiLocalVariable variable) {
                    super.visitLocalVariable(variable);
                    System.out.println("Found a variable at offset " + variable.getTextRange().getStartOffset());
                }
            });
        }

    }

    public JPanel getPanel() {
        return panel;
    }
}

build.gradle

代码语言:javascript
复制
plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '0.4.21'
    id 'org.jetbrains.kotlin.jvm' version '1.3.72'
}

group 'com.rahul.gqlformal'
version '1.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

intellij {
    version = '2020.1'
    plugins = ['java']
}


buildSearchableOptions {
    enabled = false
}

patchPluginXml {
    version = project.version
    sinceBuild = '201'
    untilBuild = '201.*'
}
EN

回答 1

Stack Overflow用户

发布于 2020-07-06 20:00:58

  1. 将新依赖项编译组添加到build.gradle

代码语言:javascript
复制
plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '0.4.21'

}

group 'com.jb'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'com.github.adedayo.intellij.sdk', name: 'java-psi-api', version: '142.1'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}


intellij {
    version '2020.1.2'
}
patchPluginXml {
    changeNotes """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}

  1. 重新加载IntelliJ IDEA
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62373823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档