use of com.intellij.openapi.fileEditor.FileEditorManager in project GsonFormat by zzz40500.
the class PsiClassUtil method getPsiClass.
public static PsiClass getPsiClass(PsiFile psiFile, Project project, String generateClass) throws Throwable {
PsiClass psiClass = null;
PsiDirectory psiDirectory = getJavaSrc(psiFile);
if (psiDirectory == null || psiDirectory.getVirtualFile().getCanonicalPath() == null) {
return null;
}
File file = new File(psiDirectory.getVirtualFile().getCanonicalPath().concat("/").concat(generateClass.trim().replace(".", "/")).concat(".java"));
String[] strArray = generateClass.replace(" ", "").split("\\.");
if (TextUtils.isEmpty(generateClass)) {
return null;
}
String className = strArray[strArray.length - 1];
String packName = generateClass.substring(0, generateClass.length() - className.length());
if (file.exists()) {
for (int i = 0; i < strArray.length - 1; i++) {
psiDirectory = psiDirectory.findSubdirectory(strArray[i]);
if (psiDirectory == null) {
return null;
}
}
PsiFile psiFile1 = psiDirectory.findFile(className + ".java");
if ((psiFile1 instanceof PsiJavaFile) && ((PsiJavaFile) psiFile1).getClasses().length > 0) {
psiClass = ((PsiJavaFile) psiFile1).getClasses()[0];
}
if (psiClass != null) {
FileEditorManager manager = FileEditorManager.getInstance(project);
manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
}
} else {
if (!file.getParentFile().exists() && !TextUtils.isEmpty(packName)) {
psiDirectory = createPackageInSourceRoot(packName, psiDirectory);
} else {
for (int i = 0; i < strArray.length - 1; i++) {
psiDirectory = psiDirectory.findSubdirectory(strArray[i]);
if (psiDirectory == null) {
return null;
}
}
}
psiClass = JavaDirectoryService.getInstance().createClass(psiDirectory, className);
FileEditorManager manager = FileEditorManager.getInstance(project);
manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
}
return psiClass;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class ResourceBundleManager method closeResourceBundleEditors.
private static void closeResourceBundleEditors(@NotNull ResourceBundle resourceBundle) {
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(resourceBundle.getProject());
fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
fileEditorManager.closeFile(propertiesFile.getVirtualFile());
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class JavaFormatterPerformanceTest method testPaymentManager.
public void testPaymentManager() throws Exception {
final FileEditorManager editorManager = FileEditorManager.getInstance(LightPlatformTestCase.getProject());
try {
getSettings().getCommonSettings(JavaLanguage.INSTANCE).KEEP_LINE_BREAKS = false;
doTest();
} finally {
getSettings().getCommonSettings(JavaLanguage.INSTANCE).KEEP_LINE_BREAKS = true;
editorManager.closeFile(editorManager.getSelectedFiles()[0]);
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class CodeInsightTestCase method tearDown.
@Override
protected void tearDown() throws Exception {
try {
if (myProject != null) {
FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
for (VirtualFile openFile : editorManager.getOpenFiles()) {
editorManager.closeFile(openFile);
}
}
} finally {
myEditor = null;
super.tearDown();
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class BraceHighlighter method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
// sorry, upsource
if (ApplicationManager.getApplication().isHeadlessEnvironment())
return;
final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster();
CaretListener myCaretListener = new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
myAlarm.cancelAllRequests();
Editor editor = e.getEditor();
final SelectionModel selectionModel = editor.getSelectionModel();
// Don't update braces in case of the active selection.
if (editor.getProject() != project || selectionModel.hasSelection()) {
return;
}
final Document document = editor.getDocument();
int line = e.getNewPosition().line;
if (line < 0 || line >= document.getLineCount()) {
return;
}
updateBraces(editor, myAlarm);
}
};
eventMulticaster.addCaretListener(myCaretListener, project);
final SelectionListener mySelectionListener = new SelectionListener() {
@Override
public void selectionChanged(SelectionEvent e) {
myAlarm.cancelAllRequests();
Editor editor = e.getEditor();
if (editor.getProject() != project) {
return;
}
final TextRange oldRange = e.getOldRange();
final TextRange newRange = e.getNewRange();
if (oldRange != null && newRange != null && !(oldRange.isEmpty() ^ newRange.isEmpty())) {
// Don't perform braces update in case of active/absent selection.
return;
}
updateBraces(editor, myAlarm);
}
};
eventMulticaster.addSelectionListener(mySelectionListener, project);
DocumentListener documentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
myAlarm.cancelAllRequests();
Editor[] editors = EditorFactory.getInstance().getEditors(e.getDocument(), project);
for (Editor editor : editors) {
updateBraces(editor, myAlarm);
}
}
};
eventMulticaster.addDocumentListener(documentListener, project);
final FocusChangeListener myFocusChangeListener = new FocusChangeListener() {
@Override
public void focusLost(Editor editor) {
clearBraces(editor);
}
@Override
public void focusGained(Editor editor) {
updateBraces(editor, myAlarm);
}
};
((EditorEventMulticasterEx) eventMulticaster).addFocusChangeListner(myFocusChangeListener, project);
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent e) {
myAlarm.cancelAllRequests();
}
}, project);
}
Aggregations