修复实时调试时可能会出现空指针异常

This commit is contained in:
makejava 2022-03-22 10:37:41 +08:00
parent c52e93a18b
commit dad911fb9b
4 changed files with 52 additions and 32 deletions

View File

@ -3,18 +3,23 @@ buildscript {
mavenCentral() mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' } maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://oss.sonatype.org/content/repositories/releases/' } maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
maven { url 'https://dl.bintray.com/jetbrains/intellij-plugin-service' } }
maven { url 'https://dl.bintray.com/jetbrains/intellij-third-party-dependencies/' } // https://github.com/JetBrains/gradle-intellij-plugin/
dependencies {
classpath "org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.7.3"
} }
} }
//2.1
//
plugins { plugins {
id 'java' id 'java'
id 'org.jetbrains.intellij' version '0.7.3' id 'org.jetbrains.intellij' version '0.7.3'
} }
group 'com.sjhy' group 'com.sjhy'
version '1.2.6.RELEASE' version '1.2.5-java.RELEASE'
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -25,22 +30,47 @@ repositories {
mavenCentral() mavenCentral()
} }
dependencies { // http://www.jetbrains.org/intellij/sdk/docs/tutorials/build_system/prerequisites.html
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.6' // https://plugins.jetbrains.com/docs/intellij/gradle-guide.html gradle构建教程
testCompile 'junit:junit:4.12'
// lombok
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij { intellij {
version = 'IU-2020.1.2' //
plugins = ['java', 'DatabaseTools'] pluginName 'EasyCode'
updateSinceUntilBuild = false // IDEA的设置build文件下面clean
downloadSources = true
sandboxDirectory = "${rootProject.rootDir}/idea-sandbox" sandboxDirectory = "${rootProject.rootDir}/idea-sandbox"
// 使
version '2021.2.2'
//
// type 'IC'
//
type 'IU'
// IDEA版本去这里找
// https://www.jetbrains.com/intellij-repository/releases
//
plugins = ['java', 'DatabaseTools']
//Disables updating since-build attribute in plugin.xml
updateSinceUntilBuild false
downloadSources = true
}
dependencies {
// jackson工具
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.6'
// guava工具
// compile 'com.google.guava:guava:29.0-jre'
// velocity支持
// compile 'org.apache.velocity:velocity:1.7'
// groovy支持
// compile 'org.codehaus.groovy:groovy:3.0.2'
// beetl支持
// compile 'com.ibeetl:beetl:3.3.0.RELEASE'
// freemarker支持
// compile 'org.freemarker:freemarker:2.3.30'
// lombok
compileOnly 'org.projectlombok:lombok:1.18.2'
annotationProcessor 'org.projectlombok:lombok:1.18.2'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.2'
//
testCompile 'junit:junit:4.12'
} }

View File

@ -58,8 +58,8 @@ public interface AbstractGroup<T, E extends AbstractItem<E>> {
* *
* @return {@link T} * @return {@link T}
*/ */
@SuppressWarnings("unchecked")
default T cloneObj() { default T cloneObj() {
//noinspection unchecked
return (T) CloneUtils.cloneByJson(this); return (T) CloneUtils.cloneByJson(this);
} }
} }

View File

@ -44,7 +44,7 @@ public class LocalFileExportImportSettingsServiceImpl implements ExportImportSet
public void exportConfig(SettingsStorageDTO settingsStorage) { public void exportConfig(SettingsStorageDTO settingsStorage) {
// 1.选择储存位置 // 1.选择储存位置
FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Config As Json", "Save to"), ProjectUtils.getCurrProject()); FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Config As Json", "Save to"), ProjectUtils.getCurrProject());
VirtualFileWrapper saveFile = saveFileDialog.save(null, "EasyCodeConfig.json"); VirtualFileWrapper saveFile = saveFileDialog.save((VirtualFile) null, "EasyCodeConfig.json");
if (saveFile == null) { if (saveFile == null) {
return; return;
} }

View File

@ -14,15 +14,10 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogBuilder; import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.Conditions;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLabel;
import com.intellij.util.ExceptionUtil; import com.intellij.util.ExceptionUtil;
import com.intellij.util.ReflectionUtil; import com.intellij.util.ReflectionUtil;
@ -129,17 +124,12 @@ public class RealtimeDebugComponent {
} }
// 生成代码 // 生成代码
String code = CodeGenerateService.getInstance(ProjectUtils.getCurrProject()).generate(new Template("temp", editorComponent.getFile().getCode()), tableInfo); String code = CodeGenerateService.getInstance(ProjectUtils.getCurrProject()).generate(new Template("temp", editorComponent.getFile().getCode()), tableInfo);
String fileName = editorComponent.getFile().getName();
// 创建编辑框 // 创建编辑框
EditorFactory editorFactory = EditorFactory.getInstance(); EditorFactory editorFactory = EditorFactory.getInstance();
PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(ProjectUtils.getCurrProject()); Document document = editorFactory.createDocument(code);
String fileName = editorComponent.getFile().getName();
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
PsiFile psiFile = psiFileFactory.createFileFromText(fileName, fileType, code, 0, true);
// 标识为模板让velocity跳过语法校验 // 标识为模板让velocity跳过语法校验
psiFile.getViewProvider().putUserData(FileTemplateManager.DEFAULT_TEMPLATE_PROPERTIES, FileTemplateManager.getInstance(ProjectUtils.getCurrProject()).getDefaultProperties()); document.putUserData(FileTemplateManager.DEFAULT_TEMPLATE_PROPERTIES, FileTemplateManager.getInstance(ProjectUtils.getCurrProject()).getDefaultProperties());
Document document = PsiDocumentManager.getInstance(ProjectUtils.getCurrProject()).getDocument(psiFile);
assert document != null;
Editor editor = editorFactory.createViewer(document, ProjectUtils.getCurrProject()); Editor editor = editorFactory.createViewer(document, ProjectUtils.getCurrProject());
// 配置编辑框 // 配置编辑框
EditorSettingsInit.init(editor); EditorSettingsInit.init(editor);