大家好,我正在尝试在intellij中构建一个插件,并且在运行时得到以下错误:
Caused by: java.lang.ClassNotFoundException: com.intellij.psi.JavaRecursiveElementVisitor PluginClassLoader[com.rahul.gqlformat, 1.0] com.intellij.ide.plugins.cl.PluginClassLoader@2a707a23我在名为- printSelectedFileName的function中得到了一个异常,这是完整的类-
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
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.*'
}发布于 2020-07-06 20:00:58
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>"""
}https://stackoverflow.com/questions/62373823
复制相似问题