mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix npe
This commit is contained in:
@@ -245,7 +245,9 @@ public class ValueHint extends AbstractValueHint {
|
||||
|
||||
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
|
||||
|
||||
if(psiFile == null || !psiFile.isValid()) return;
|
||||
if(psiFile == null || !psiFile.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int selectionStart = editor.getSelectionModel().getSelectionStart();
|
||||
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
|
||||
@@ -255,11 +257,16 @@ public class ValueHint extends AbstractValueHint {
|
||||
try {
|
||||
String text = editor.getSelectionModel().getSelectedText();
|
||||
if(text != null && ctx != null) {
|
||||
selectedExpression.set(JVMElementFactories.getFactory(ctx.getLanguage(), project).createExpressionFromText(text, ctx));
|
||||
final JVMElementFactory factory = JVMElementFactories.getFactory(ctx.getLanguage(), project);
|
||||
if (factory == null) {
|
||||
return;
|
||||
}
|
||||
selectedExpression.set(factory.createExpressionFromText(text, ctx));
|
||||
currentRange.set(new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()));
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException ignored) { }
|
||||
catch (IncorrectOperationException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if(currentRange.get() == null) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.psi;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageExtension;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Medvedev Max
|
||||
@@ -29,8 +30,9 @@ public class JVMElementFactories extends LanguageExtension<JVMElementFactoryProv
|
||||
super("com.intellij.generation.topLevelFactory");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JVMElementFactory getFactory(Language language, Project project) {
|
||||
final JVMElementFactoryProvider provider = INSTANCE.forLanguage(language);
|
||||
return provider.getFactory(project);
|
||||
return provider != null? provider.getFactory(project) : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user