mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
notnull
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.command.undo.UndoManager;
|
||||
@@ -44,6 +43,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -68,6 +68,7 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Mike
|
||||
@@ -75,7 +76,7 @@ import java.util.List;
|
||||
public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
protected Editor myEditor;
|
||||
|
||||
protected Editor createEditor(VirtualFile file) {
|
||||
protected Editor createEditor(@NotNull VirtualFile file) {
|
||||
final FileEditorManager instance = FileEditorManager.getInstance(myProject);
|
||||
|
||||
if (file.getFileType().isBinary()) return null;
|
||||
@@ -112,7 +113,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
/**
|
||||
* @param files the first file will be loaded in editor
|
||||
*/
|
||||
protected VirtualFile configureByFiles(@Nullable String projectRoot,String... files) throws Exception {
|
||||
protected VirtualFile configureByFiles(@Nullable String projectRoot, @NotNull String... files) throws Exception {
|
||||
if (files.length == 0) return null;
|
||||
final VirtualFile[] vFiles = new VirtualFile[files.length];
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
@@ -128,7 +129,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return configureByFiles(projectFile, vFiles);
|
||||
}
|
||||
|
||||
protected VirtualFile configureByFile(@NonNls String filePath, String projectRoot) throws Exception {
|
||||
protected VirtualFile configureByFile(@NonNls String filePath, @Nullable String projectRoot) throws Exception {
|
||||
String fullPath = getTestDataPath() + filePath;
|
||||
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
|
||||
@@ -139,11 +140,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return configureByFile(vFile, projectFile);
|
||||
}
|
||||
|
||||
protected PsiFile configureByText(@NotNull FileType fileType, @NonNls final String text) {
|
||||
protected PsiFile configureByText(@NotNull FileType fileType, @NonNls @NotNull final String text) {
|
||||
return configureByText(fileType, text, null);
|
||||
}
|
||||
|
||||
protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls final String text, @Nullable String _extension) {
|
||||
protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls @NotNull String text, @Nullable String _extension) {
|
||||
try {
|
||||
final String extension = _extension == null ? fileType.getDefaultExtension():_extension;
|
||||
|
||||
@@ -177,16 +178,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PathManagerEx.getTestDataPath();
|
||||
}
|
||||
|
||||
protected void configureByFile(final VirtualFile vFile) throws IOException {
|
||||
protected void configureByFile(@NotNull VirtualFile vFile) throws IOException {
|
||||
configureByFile(vFile, null);
|
||||
}
|
||||
|
||||
protected void configureByExistingFile(final VirtualFile virtualFile) {
|
||||
protected void configureByExistingFile(@NotNull final VirtualFile virtualFile) {
|
||||
myFile = null;
|
||||
myEditor = null;
|
||||
|
||||
@@ -216,7 +212,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}
|
||||
|
||||
protected VirtualFile configureByFiles(@Nullable final File rawProjectRoot, final VirtualFile... vFiles) throws IOException {
|
||||
protected VirtualFile configureByFiles(@Nullable final File rawProjectRoot, @NotNull final VirtualFile... vFiles) throws IOException {
|
||||
myFile = null;
|
||||
myEditor = null;
|
||||
|
||||
@@ -235,7 +231,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
|
||||
// auxiliary files should be copied first
|
||||
VirtualFile[] reversed = ArrayUtil.reverseArray(vFiles);
|
||||
final LinkedHashMap<VirtualFile, EditorInfo> editorInfos;
|
||||
Map<VirtualFile, EditorInfo> editorInfos;
|
||||
if (rawProjectRoot != null) {
|
||||
final File projectRoot = rawProjectRoot.getCanonicalFile();
|
||||
FileUtil.copyDir(projectRoot, toDirIO);
|
||||
@@ -288,22 +284,26 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void doCommitModel(final ModifiableRootModel rootModel) {
|
||||
protected void doCommitModel(@NotNull ModifiableRootModel rootModel) {
|
||||
rootModel.commit();
|
||||
}
|
||||
|
||||
protected void sourceRootAdded(final VirtualFile dir) {
|
||||
}
|
||||
|
||||
protected LinkedHashMap<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(String testDataFromDir,
|
||||
final VirtualFile toDir,
|
||||
final String... relativePaths) throws IOException {
|
||||
@NotNull
|
||||
protected Map<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(@NotNull String testDataFromDir,
|
||||
@NotNull VirtualFile toDir,
|
||||
@NotNull String... relativePaths) throws IOException {
|
||||
if (!testDataFromDir.startsWith("/")) testDataFromDir = "/" + testDataFromDir;
|
||||
return copyFilesFillingEditorInfos(LocalFileSystem.getInstance().refreshAndFindFileByPath(getTestDataPath() + testDataFromDir), toDir, relativePaths);
|
||||
}
|
||||
|
||||
protected LinkedHashMap<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(final VirtualFile fromDir, final VirtualFile toDir, final String... relativePaths) throws IOException {
|
||||
LinkedHashMap<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
|
||||
@NotNull
|
||||
protected Map<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(@NotNull VirtualFile fromDir,
|
||||
@NotNull VirtualFile toDir,
|
||||
@NotNull String... relativePaths) throws IOException {
|
||||
Map<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
|
||||
|
||||
List<OutputStream> streamsToClose = new ArrayList<OutputStream>();
|
||||
|
||||
@@ -356,28 +356,30 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}
|
||||
}*/
|
||||
|
||||
private EditorInfo copyContent(final VirtualFile from, final VirtualFile to, final List<OutputStream> streamsToClose) throws IOException {
|
||||
private EditorInfo copyContent(@NotNull VirtualFile from, @NotNull VirtualFile to, @NotNull List<OutputStream> streamsToClose) throws IOException {
|
||||
byte[] content = from.getFileType().isBinary() ? from.contentsToByteArray(): null;
|
||||
final String fileText = from.getFileType().isBinary() ? null : StringUtil.convertLineSeparators(VfsUtil.loadText(from));
|
||||
final String fileText = from.getFileType().isBinary() ? null : StringUtil.convertLineSeparators(VfsUtilCore.loadText(from));
|
||||
|
||||
EditorInfo editorInfo = fileText != null ? new EditorInfo(fileText) : null;
|
||||
String newFileText = fileText != null ? editorInfo.getNewFileText() : null;
|
||||
EditorInfo editorInfo = fileText == null ? null : new EditorInfo(fileText);
|
||||
String newFileText = fileText == null ? null : editorInfo.getNewFileText();
|
||||
doWrite(newFileText, to, content, streamsToClose);
|
||||
return editorInfo;
|
||||
}
|
||||
|
||||
protected final void setActiveEditor(Editor editor) {
|
||||
protected final void setActiveEditor(@NotNull Editor editor) {
|
||||
myEditor = editor;
|
||||
myFile = getPsiFile(editor.getDocument());
|
||||
}
|
||||
|
||||
protected List<Editor> openEditorsAndActivateLast(final LinkedHashMap<VirtualFile, EditorInfo> editorInfos) {
|
||||
@NotNull
|
||||
protected List<Editor> openEditorsAndActivateLast(@NotNull Map<VirtualFile, EditorInfo> editorInfos) {
|
||||
final List<Editor> list = openEditors(editorInfos);
|
||||
setActiveEditor(list.get(list.size() - 1));
|
||||
return list;
|
||||
}
|
||||
|
||||
protected final List<Editor> openEditors(final LinkedHashMap<VirtualFile, EditorInfo> editorInfos) {
|
||||
@NotNull
|
||||
protected final List<Editor> openEditors(@NotNull final Map<VirtualFile, EditorInfo> editorInfos) {
|
||||
return ContainerUtil.map(editorInfos.keySet(), new Function<VirtualFile, Editor>() {
|
||||
@Override
|
||||
public Editor fun(final VirtualFile newVFile) {
|
||||
@@ -396,14 +398,18 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
private void doWrite(final String newFileText, final VirtualFile newVFile, final byte[] content, final List<OutputStream> streamsToClose) throws IOException {
|
||||
if (newFileText != null) {
|
||||
VfsUtil.saveText(newVFile, newFileText);
|
||||
} else {
|
||||
private void doWrite(final String newFileText,
|
||||
@NotNull VirtualFile newVFile,
|
||||
byte[] content,
|
||||
@NotNull List<OutputStream> streamsToClose) throws IOException {
|
||||
if (newFileText == null) {
|
||||
final OutputStream outputStream = newVFile.getOutputStream(this, -1, -1);
|
||||
outputStream.write(content);
|
||||
streamsToClose.add(outputStream);
|
||||
}
|
||||
else {
|
||||
VfsUtil.saveText(newVFile, newFileText);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isAddDirToContentRoot() {
|
||||
@@ -414,7 +420,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected VirtualFile configureByFile(final VirtualFile vFile, final File projectRoot) throws IOException {
|
||||
protected VirtualFile configureByFile(@NotNull VirtualFile vFile, File projectRoot) throws IOException {
|
||||
return configureByFiles(projectRoot, vFile);
|
||||
}
|
||||
|
||||
@@ -422,7 +428,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void setupCursorAndSelection(final Editor editor) {
|
||||
protected void setupCursorAndSelection(@NotNull final Editor editor) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -466,7 +472,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(String path, String dataName) throws Exception {
|
||||
protected void configure(@NotNull String path, String dataName) throws Exception {
|
||||
super.configure(path, dataName);
|
||||
|
||||
myEditor = createEditor(myFile.getVirtualFile());
|
||||
@@ -487,11 +493,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
myEditor.getSelectionModel().setSelection(selectionStart, selectionEnd);
|
||||
}
|
||||
|
||||
protected void checkResultByFile(@NonNls String filePath) throws Exception {
|
||||
protected void checkResultByFile(@NonNls @NotNull String filePath) throws Exception {
|
||||
checkResultByFile(filePath, false);
|
||||
}
|
||||
|
||||
protected void checkResultByFile(@NonNls final String filePath, final boolean stripTrailingSpaces) throws Exception {
|
||||
protected void checkResultByFile(@NonNls @NotNull final String filePath, final boolean stripTrailingSpaces) throws Exception {
|
||||
new WriteCommandAction<Document>(getProject()) {
|
||||
@Override
|
||||
protected void run(@NotNull Result<Document> result) throws Throwable {
|
||||
@@ -508,7 +514,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
assertNotNull("Cannot find file " + fullPath, vFile);
|
||||
String ft = null;
|
||||
try {
|
||||
ft = VfsUtil.loadText(vFile);
|
||||
ft = VfsUtilCore.loadText(vFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -626,7 +632,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return CommonDataKeys.EDITOR.is(dataId) ? myEditor : super.getData(dataId);
|
||||
}
|
||||
|
||||
protected VirtualFile getVirtualFile(@NonNls String filePath) {
|
||||
protected VirtualFile getVirtualFile(@NonNls @NotNull String filePath) {
|
||||
String fullPath = getTestDataPath() + filePath;
|
||||
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
|
||||
@@ -634,6 +640,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return vFile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getTestRoot(){
|
||||
return FileUtil.toSystemIndependentName(getTestDataPath());
|
||||
}
|
||||
@@ -673,7 +680,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
action.execute(getEditor(), DataManager.getInstance().getDataContext());
|
||||
}
|
||||
|
||||
protected void type(@NonNls String s) {
|
||||
protected void type(@NonNls @NotNull String s) {
|
||||
for (char c : s.toCharArray()) {
|
||||
type(c);
|
||||
}
|
||||
@@ -688,7 +695,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
protected void backspace() {
|
||||
backspace(getEditor());
|
||||
}
|
||||
protected void backspace(final Editor editor) {
|
||||
protected void backspace(@NotNull final Editor editor) {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -71,6 +72,7 @@ public abstract class MultiFileTestCase extends CodeInsightTestCase {
|
||||
PsiTestUtil.addSourceContentToRoots(myModule, rootDir);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@NonNls
|
||||
protected abstract String getTestRoot();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,6 +38,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -122,7 +123,7 @@ public abstract class PsiTestCase extends ModuleTestCase {
|
||||
return myFile.findElementAt(offset);
|
||||
}
|
||||
|
||||
protected void configure(String path, String dataName) throws Exception {
|
||||
protected void configure(@NotNull String path, String dataName) throws Exception {
|
||||
myDataRoot = getTestDataPath() + path;
|
||||
|
||||
myTestDataBefore = loadData(dataName);
|
||||
|
||||
Reference in New Issue
Block a user