diff --git a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileType.java b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileType.java
index c83d99c05b70..68e7c31f8fbe 100644
--- a/java/java-impl/src/com/intellij/ide/highlighter/JavaFileType.java
+++ b/java/java-impl/src/com/intellij/ide/highlighter/JavaFileType.java
@@ -31,7 +31,7 @@ public class JavaFileType extends LanguageFileType {
public static final JavaFileType INSTANCE = new JavaFileType();
private JavaFileType() {
- super(new JavaLanguage());
+ super(JavaLanguage.INSTANCE);
}
@NotNull
diff --git a/java/java-impl/src/com/intellij/lang/java/JavaLanguage.java b/java/java-impl/src/com/intellij/lang/java/JavaLanguage.java
index 5282be171fe4..33f139ffac15 100644
--- a/java/java-impl/src/com/intellij/lang/java/JavaLanguage.java
+++ b/java/java-impl/src/com/intellij/lang/java/JavaLanguage.java
@@ -29,6 +29,9 @@ import org.jetbrains.annotations.NotNull;
* @author max
*/
public class JavaLanguage extends Language {
+
+ public static JavaLanguage INSTANCE = new JavaLanguage();
+
public JavaLanguage() {
super("JAVA", "text/java", "application/x-java", "text/x-java");
SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SyntaxHighlighterFactory() {
diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementType.java b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementType.java
index f60e6593f60b..b1e8746abc14 100644
--- a/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementType.java
+++ b/java/java-impl/src/com/intellij/psi/impl/java/stubs/JavaStubElementType.java
@@ -16,7 +16,7 @@
package com.intellij.psi.impl.java.stubs;
import com.intellij.lang.ASTNode;
-import com.intellij.openapi.fileTypes.StdFileTypes;
+import com.intellij.lang.java.JavaLanguage;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.ILightStubElementType;
import com.intellij.psi.stubs.PsiFileStub;
@@ -37,7 +37,7 @@ public abstract class JavaStubElementType
+
+
diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/JavaParsingTestCase.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/JavaParsingTestCase.java
index 121ea006d4ff..895eb1ac833b 100644
--- a/java/java-tests/testSrc/com/intellij/lang/java/parser/JavaParsingTestCase.java
+++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/JavaParsingTestCase.java
@@ -15,10 +15,19 @@
*/
package com.intellij.lang.java.parser;
+import com.intellij.jsp.impl.JspSpiUtilImpl;
import com.intellij.lang.ASTNode;
+import com.intellij.lang.LanguageASTFactory;
import com.intellij.lang.PsiBuilder;
-import com.intellij.lang.StdLanguages;
+import com.intellij.lang.java.JavaLanguage;
+import com.intellij.lang.java.JavaParserDefinition;
+import com.intellij.lang.jsp.JavaInJspProvider;
+import com.intellij.mock.MockModule;
+import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.fileTypes.StdFileTypes;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.LanguageLevelProjectExtension;
+import com.intellij.openapi.roots.impl.LanguageLevelProjectExtensionImpl;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiFile;
@@ -26,31 +35,80 @@ import com.intellij.psi.PsiManager;
import com.intellij.psi.SingleRootFileViewProvider;
import com.intellij.psi.impl.source.PsiJavaFileImpl;
import com.intellij.psi.impl.source.tree.FileElement;
+import com.intellij.psi.impl.source.tree.JavaASTFactory;
+import com.intellij.psi.jsp.JspSpiUtil;
+import com.intellij.psi.jsp.MockJavaInJspHandler;
import com.intellij.psi.tree.IFileElementType;
-import com.intellij.testFramework.*;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.testFramework.IdeaTestCase;
+import com.intellij.testFramework.LightVirtualFile;
+import com.intellij.testFramework.ParsingTestCase;
import org.jetbrains.annotations.NonNls;
import java.io.IOException;
public abstract class JavaParsingTestCase extends ParsingTestCase {
+
+ private Module myModule;
+ private LanguageLevel myLanguageLevel;
+
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
public JavaParsingTestCase(@NonNls final String dataPath) {
- super(dataPath, "java");
+ super("psi/"+dataPath, "java", new JavaParserDefinition());
IdeaTestCase.initPlatformPrefix();
}
- protected static void withLevel(final LanguageLevel level, final Runnable r) {
- IdeaTestUtil.withLevel(getModule(), level, r);
+ protected void withLevel(final LanguageLevel level, final Runnable r) {
+ LanguageLevel prev = myLanguageLevel;
+ myLanguageLevel = level;
+ try {
+ r.run();
+ }
+ finally {
+ myLanguageLevel = prev;
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myModule = disposeOnTearDown(new MockModule(getProject()));
+ myLanguageLevel = LanguageLevel.JDK_1_6;
+ getProject().registerService(LanguageLevelProjectExtension.class, new LanguageLevelProjectExtensionImpl(getProject()));
+ addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new JavaASTFactory());
+ final ExtensionPointName javaInJspEP = ExtensionPointName.create("com.intellij.jsp.javaInJspProvider");
+ registerExtensionPoint(javaInJspEP, JavaInJspProvider.class);
+ registerExtension(javaInJspEP, new MockJavaInJspHandler());
+ registerApplicationService(JspSpiUtil.class, new JspSpiUtilImpl());
+ }
+
+ @Override
+ protected PsiFile createFile(String name, String text) {
+ final PsiFile file = super.createFile(name, text);
+ file.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, myLanguageLevel);
+ return file;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ myModule = null;
}
protected interface TestParser {
void parse(PsiBuilder builder);
}
+ public Module getModule() {
+ return myModule;
+ }
+
+
protected void doParserTest(final String text, final TestParser parser) {
final String name = getTestName(false);
myFile = createPsiFile(name, text, parser);
+ myFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, myLanguageLevel);
try {
checkResult(name + ".txt", myFile);
}
@@ -64,7 +122,7 @@ public abstract class JavaParsingTestCase extends ParsingTestCase {
private PsiFile createPsiFile(final String name, final String text, final TestParser parser) {
if (TEST_FILE_ELEMENT_TYPE == null) {
- TEST_FILE_ELEMENT_TYPE = new IFileElementType("test.java.file", StdLanguages.JAVA) {
+ TEST_FILE_ELEMENT_TYPE = new IFileElementType("test.java.file", JavaLanguage.INSTANCE) {
@Override
public ASTNode parseContents(final ASTNode chameleon) {
final PsiBuilder builder = createBuilder(chameleon);
diff --git a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java
index 55c37a52f2f4..7b9d54b665ae 100644
--- a/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/NormalizeDeclarationTest.java
@@ -1,19 +1,20 @@
package com.intellij.psi;
import com.intellij.JavaTestUtil;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PsiTestCase;
import com.intellij.testFramework.PsiTestUtil;
-import java.io.File;
-
@PlatformTestCase.WrapInCommand
public class NormalizeDeclarationTest extends PsiTestCase{
private static final String BASE_PATH = JavaTestUtil.getJavaTestDataPath() + "/psi/normalizeDeclaration";
+ @Override
+ protected String getTestDataPath() {
+ return BASE_PATH;
+ }
+
public void test1() throws Exception { doTest(); }
public void test2() throws Exception { doTest(); }
@@ -37,10 +38,4 @@ public class NormalizeDeclarationTest extends PsiTestCase{
PsiTestUtil.checkFileStructure(myFile);
}
- private static String loadFile(String name) throws Exception {
- String fullName = BASE_PATH + File.separatorChar + name;
- String text = FileUtil.loadFile(new File(fullName));
- text = StringUtil.convertLineSeparators(text);
- return text;
- }
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
index a786eedc1342..571a88a8f84e 100644
--- a/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/OptimizeImportsTest.java
@@ -18,19 +18,18 @@ package com.intellij.psi;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.testFramework.PsiTestCase;
-import java.io.File;
-
public class OptimizeImportsTest extends PsiTestCase{
private static final String BASE_PATH = PathManagerEx.getTestDataPath() + "/psi/optimizeImports";
+ @Override
+ protected String getTestDataPath() {
+ return BASE_PATH;
+ }
+
public void testSCR6138() throws Exception { doTest(); }
public void testSCR18364() throws Exception { doTest(); }
public void testStaticImports1() throws Exception { doTest(); }
@@ -77,11 +76,4 @@ public class OptimizeImportsTest extends PsiTestCase{
}, "", "");
}
-
- private static String loadFile(String name) throws Exception {
- String fullName = BASE_PATH + File.separatorChar + name;
- String text = FileUtil.loadFile(new File(fullName));
- text = StringUtil.convertLineSeparators(text);
- return text;
- }
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java
index b0a51718337d..8887124d13c5 100644
--- a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java
+++ b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java
@@ -3,22 +3,23 @@ package com.intellij.psi.impl.source.tree.java;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.PsiTestCase;
-import java.io.File;
-
/**
* @author dsl
*/
public class ShortenClassReferencesTest extends PsiTestCase {
private static final String BASE_PATH = PathManagerEx.getTestDataPath() + "/psi/shortenClassRefs";
+ @Override
+ protected String getTestDataPath() {
+ return BASE_PATH;
+ }
+
public void testSCR22368() throws Exception { doTest(); }
public void testSCR37254() throws Exception { doTest(); }
@@ -71,11 +72,4 @@ public class ShortenClassReferencesTest extends PsiTestCase {
}
}, "", "");
}
-
- private String loadFile(String name) throws Exception {
- String fullName = BASE_PATH + File.separatorChar + name;
- String text = FileUtil.loadFile(new File(fullName));
- text = StringUtil.convertLineSeparators(text);
- return text;
- }
}
diff --git a/java/java-tests/testSrc/com/intellij/psi/jsp/MockJavaInJspHandler.java b/java/java-tests/testSrc/com/intellij/psi/jsp/MockJavaInJspHandler.java
new file mode 100644
index 000000000000..2d101d2e2833
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/psi/jsp/MockJavaInJspHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2011 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.jsp;
+
+import com.intellij.jsp.impl.JavaInJspHandler;
+import com.intellij.lang.jsp.JspFileViewProviderImpl;
+import com.intellij.lang.jsp.JspxFileViewProvider;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.util.PsiUtil;
+import org.jetbrains.annotations.NotNull;
+
+/**
+* @author gregsh
+*/
+public class MockJavaInJspHandler extends JavaInJspHandler {
+ @NotNull
+ @Override
+ public PsiFile createJavaFile(@NotNull JspxFileViewProvider provider) {
+ final PsiFile file = super.createJavaFile(provider);
+ file.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.JDK_1_6);
+ return file;
+ }
+
+ @Override
+ public void fillContextPrefixes(JspFileViewProviderImpl viewProvider,
+ JspFileViewProviderImpl.PrefixesWithLanguage prefixes,
+ boolean includesOnly) {
+ viewProvider.fillLocalPrefixes(prefixes);
+ }
+}
diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java
index 9eb59e0a27c8..7bdb083af317 100644
--- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java
+++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java
@@ -27,6 +27,7 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.JDOMUtil;
+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;
@@ -136,6 +137,11 @@ public abstract class PsiTestCase extends ModuleTestCase {
return PathManagerEx.getTestDataPath();
}
+ protected String loadFile(String name) throws Exception {
+ String result = FileUtil.loadFile(new File(getTestDataPath() + File.separatorChar + name));
+ return StringUtil.convertLineSeparators(result);
+ }
+
private PsiTestData loadData(String dataName) throws Exception {
Document document = JDOMUtil.loadDocument(new File(myDataRoot + "/" + "data.xml"));
diff --git a/platform/lang-impl/src/com/intellij/extapi/psi/PsiElementBase.java b/platform/lang-impl/src/com/intellij/extapi/psi/PsiElementBase.java
index 123bb7ebb624..9fb1296e1a8f 100644
--- a/platform/lang-impl/src/com/intellij/extapi/psi/PsiElementBase.java
+++ b/platform/lang-impl/src/com/intellij/extapi/psi/PsiElementBase.java
@@ -102,7 +102,9 @@ public abstract class PsiElementBase extends ElementBase implements NavigatableP
@NotNull
public Project getProject() {
final PsiManager manager = getManager();
- if (manager == null) throw new PsiInvalidElementAccessException(this);
+ if (manager == null) {
+ throw new PsiInvalidElementAccessException(this);
+ }
return manager.getProject();
}
diff --git a/platform/lang-impl/src/com/intellij/extapi/psi/PsiFileBase.java b/platform/lang-impl/src/com/intellij/extapi/psi/PsiFileBase.java
index dfd8d5792c11..153a089bee01 100644
--- a/platform/lang-impl/src/com/intellij/extapi/psi/PsiFileBase.java
+++ b/platform/lang-impl/src/com/intellij/extapi/psi/PsiFileBase.java
@@ -40,7 +40,7 @@ public abstract class PsiFileBase extends PsiFileImpl {
myLanguage = findLanguage(language, viewProvider);
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(myLanguage);
if (parserDefinition == null) {
- throw new RuntimeException("PsiFileBase: language.getParserDefinition() returned null.");
+ throw new RuntimeException("PsiFileBase: language.getParserDefinition() returned null for: "+myLanguage);
}
myParserDefinition = parserDefinition;
final IFileElementType nodeType = parserDefinition.getFileNodeType();
diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java
index e9d402d6754b..43f158ef6c22 100644
--- a/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java
+++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java
@@ -229,7 +229,10 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
}
if (getViewProvider().isEventSystemEnabled()) {
- ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myManager.getProject())).contentsLoaded(this);
+ final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myManager.getProject());
+ if (documentManager instanceof PsiDocumentManagerImpl) {
+ ((PsiDocumentManagerImpl)documentManager).contentsLoaded(this);
+ }
}
return treeElement;
diff --git a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java
index 986150d61d9a..cb059af64f84 100644
--- a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java
+++ b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java
@@ -49,7 +49,7 @@ import javax.swing.*;
public class TemplateDataElementType extends IFileElementType implements ITemplateDataElementType {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.templateLanguages.TemplateDataElementType");
- private static final LanguageExtension TREE_PATCHER = new LanguageExtension("com.intellij.lang.treePatcher", new SimpleTreePatcher());
+ public static final LanguageExtension TREE_PATCHER = new LanguageExtension("com.intellij.lang.treePatcher", new SimpleTreePatcher());
private final IElementType myTemplateElementType;
private final IElementType myOuterElementType;
diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java
index 83228c5437e7..6f54d2ae3998 100644
--- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java
+++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java
@@ -18,7 +18,10 @@ package com.intellij.ide.startup.impl;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.caches.CacheUpdater;
import com.intellij.ide.startup.StartupManagerEx;
-import com.intellij.notification.*;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
+import com.intellij.notification.Notifications;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
@@ -203,6 +206,8 @@ public class StartupManagerImpl extends StartupManagerEx {
final Runnable runnable;
final Application application = ApplicationManager.getApplication();
+ if (application == null) return;
+
if (DumbService.isDumbAware(action)) {
runnable = new DumbAwareRunnable() {
public void run() {
diff --git a/platform/testFramework/src/com/intellij/mock/MockFileDocumentManagerImpl.java b/platform/testFramework/src/com/intellij/mock/MockFileDocumentManagerImpl.java
new file mode 100644
index 000000000000..0d4c81841f68
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockFileDocumentManagerImpl.java
@@ -0,0 +1,112 @@
+package com.intellij.mock;
+
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.EditorFactory;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.fileEditor.FileDocumentManagerListener;
+import com.intellij.openapi.fileEditor.FileDocumentSynchronizationVetoListener;
+import com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.FileViewProvider;
+import com.intellij.util.containers.WeakFactoryMap;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.lang.ref.Reference;
+
+public class MockFileDocumentManagerImpl extends FileDocumentManager {
+ private static final Key MOCK_VIRTUAL_FILE_KEY = Key.create("MockVirtualFile");
+
+ public VirtualFile myFile;
+ public FileViewProvider myViewProvider;
+ private final WeakFactoryMap myDocuments = new WeakFactoryMap() {
+ @Override
+ protected Document create(final VirtualFile key) {
+ try {
+ final Document document = EditorFactory.getInstance().createDocument(new String(key.contentsToByteArray()));
+ document.putUserData(MOCK_VIRTUAL_FILE_KEY, key);
+ return document;
+ }
+ catch (IOException e) {
+ return null;
+ }
+ }
+ };
+
+ @Override
+ public Document getDocument(@NotNull VirtualFile file) {
+ return myDocuments.get(file);
+ }
+
+ @Override
+ public Document getCachedDocument(@NotNull VirtualFile file) {
+ Reference reference = file.getUserData(FileDocumentManagerImpl.DOCUMENT_KEY);
+ return reference != null ? reference.get() : null;
+ }
+
+ @Override
+ public VirtualFile getFile(@NotNull Document document) {
+ return document.getUserData(MOCK_VIRTUAL_FILE_KEY);
+ }
+
+ @Override
+ public void saveAllDocuments() {
+ }
+
+ @Override
+ public void saveDocument(@NotNull Document document) {
+ }
+
+ @Override
+ @NotNull
+ public Document[] getUnsavedDocuments() {
+ return new Document[0];
+ }
+
+ @Override
+ public boolean isDocumentUnsaved(@NotNull Document document) {
+ return false;
+ }
+
+ @Override
+ public boolean isFileModified(@NotNull VirtualFile file) {
+ return false;
+ }
+
+ @Override
+ public void addFileDocumentSynchronizationVetoer(@NotNull FileDocumentSynchronizationVetoListener vetoer) {
+ }
+
+ @Override
+ public void removeFileDocumentSynchronizationVetoer(@NotNull FileDocumentSynchronizationVetoListener vetoer) {
+ }
+
+ @Override
+ public void addFileDocumentManagerListener(@NotNull FileDocumentManagerListener listener) {
+ }
+
+ @Override
+ public void removeFileDocumentManagerListener(@NotNull FileDocumentManagerListener listener) {
+ }
+
+ @Override
+ public void reloadFromDisk(@NotNull Document document) {
+ }
+
+ @Override
+ public void reloadFiles(final VirtualFile... files) {
+ }
+
+ @Override
+ @NotNull
+ public String getLineSeparator(VirtualFile file, Project project) {
+ return "";
+ }
+
+ @Override
+ public boolean requestWriting(@NotNull Document document, @NotNull Project project) {
+ return true;
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/mock/MockFileTypeManager.java b/platform/testFramework/src/com/intellij/mock/MockFileTypeManager.java
new file mode 100644
index 000000000000..2639e1d6e9cc
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockFileTypeManager.java
@@ -0,0 +1,171 @@
+package com.intellij.mock;
+
+import com.intellij.lang.Language;
+import com.intellij.openapi.fileTypes.*;
+import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
+import com.intellij.openapi.fileTypes.impl.AbstractFileType;
+import com.intellij.openapi.options.SchemesManager;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ArrayUtil;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+import java.util.List;
+
+public class MockFileTypeManager extends FileTypeManagerEx {
+
+ private FileType fileType;
+
+ public MockFileTypeManager(FileType fileType) {
+ this.fileType = fileType;
+ }
+
+ @Override
+ public void registerFileType(FileType fileType) {
+ }
+
+ @Override
+ public void unregisterFileType(FileType fileType) {
+ }
+
+ @Override
+ @NotNull
+ public String getIgnoredFilesList() {
+ throw new IncorrectOperationException();
+ }
+
+ @Override
+ public void setIgnoredFilesList(@NotNull String list) {
+ }
+
+ @Override
+ public boolean isIgnoredFilesListEqualToCurrent(String list) {
+ return false;
+ }
+
+ public void save() {
+ }
+
+ @Override
+ @NotNull
+ public String getExtension(String fileName) {
+ return "";
+ }
+
+ @Override
+ public void registerFileType(@NotNull FileType type, @NotNull List defaultAssociations) {
+ }
+
+ @Override
+ public void fireFileTypesChanged() {
+ }
+
+ @Override
+ @NotNull
+ public FileType getFileTypeByFileName(@NotNull String fileName) {
+ return fileType;
+ }
+
+ @Override
+ @NotNull
+ public FileType getFileTypeByFile(@NotNull VirtualFile file) {
+ return fileType;
+ }
+
+ @Override
+ @NotNull
+ public FileType getFileTypeByExtension(@NotNull String extension) {
+ return fileType;
+ }
+
+ @Override
+ @NotNull
+ public FileType[] getRegisteredFileTypes() {
+ return FileType.EMPTY_ARRAY;
+ }
+
+ @Override
+ public boolean isFileIgnored(@NotNull String name) {
+ return false;
+ }
+
+ @Override
+ public boolean isFileIgnored(@NonNls @NotNull VirtualFile file) {
+ return false;
+ }
+
+ @Override
+ @NotNull
+ public String[] getAssociatedExtensions(@NotNull FileType type) {
+ return ArrayUtil.EMPTY_STRING_ARRAY;
+ }
+
+ @Override
+ public void fireBeforeFileTypesChanged() {
+ }
+
+ @Override
+ public void addFileTypeListener(@NotNull FileTypeListener listener) {
+ }
+
+ @Override
+ public void removeFileTypeListener(@NotNull FileTypeListener listener) {
+ }
+
+ @Override
+ public FileType getKnownFileTypeOrAssociate(@NotNull VirtualFile file) {
+ return file.getFileType();
+ }
+
+ @Override
+ @NotNull
+ public List getAssociations(@NotNull FileType type) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void associate(@NotNull FileType type, @NotNull FileNameMatcher matcher) {
+ }
+
+ @Override
+ public void removeAssociation(@NotNull FileType type, @NotNull FileNameMatcher matcher) {
+ }
+
+ @Override
+ @NotNull
+ public FileType getStdFileType(@NotNull @NonNls final String fileTypeName) {
+ if ("ARCHIVE".equals(fileTypeName) || "CLASS".equals(fileTypeName)) return UnknownFileType.INSTANCE;
+ if ("PLAIN_TEXT".equals(fileTypeName)) return PlainTextFileType.INSTANCE;
+ Language language = Language.findLanguageByID(fileTypeName);
+ if (language == null) {
+ try {
+ // StdFileTypes initialization..
+ if ("JAVA".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.java.JavaLanguage").getField("INSTANCE").get(null);
+ if ("XML".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.xml.XMLLanguage").getField("INSTANCE").get(null);
+ if ("DTD".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.dtd.DTDLanguage").getField("INSTANCE").get(null);
+ if ("JSP".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.jsp.NewJspLanguage").getField("INSTANCE").get(null);
+ if ("JSPX".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.jspx.JSPXLanguage").getField("INSTANCE").get(null);
+ if ("HTML".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.html.HTMLLanguage").getField("INSTANCE").get(null);
+ if ("XHTML".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.xhtml.XHTMLLanguage").getField("INSTANCE").get(null);
+ if ("JavaScript".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.javascript.JavascriptLanguage").getField("INSTANCE").get(null);
+ if ("Properties".equals(fileTypeName)) language = (Language)Class.forName("com.intellij.lang.properties.PropertiesLanguage").getField("INSTANCE").get(null);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return new MockLanguageFileType(language == null? PlainTextLanguage.INSTANCE : language, fileTypeName.toLowerCase());
+ }
+
+ @Override
+ public SchemesManager getSchemesManager() {
+ return SchemesManager.EMPTY;
+ }
+
+ @Override
+ public boolean isFileOfType(VirtualFile file, FileType type) {
+ return false;
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/mock/MockLanguageFileType.java b/platform/testFramework/src/com/intellij/mock/MockLanguageFileType.java
new file mode 100644
index 000000000000..d789e952643c
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockLanguageFileType.java
@@ -0,0 +1,49 @@
+package com.intellij.mock;
+
+import com.intellij.lang.Language;
+import com.intellij.openapi.fileTypes.LanguageFileType;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+/**
+ * @author gregsh
+ */
+public class MockLanguageFileType extends LanguageFileType{
+
+ private final String myExtension;
+
+ public MockLanguageFileType(@NotNull Language language, String extension) {
+ super(language);
+ myExtension = extension;
+ }
+
+ @NotNull
+ @Override
+ public String getName() {
+ return getLanguage().getID();
+ }
+
+ @NotNull
+ @Override
+ public String getDescription() {
+ return "";
+ }
+
+ @NotNull
+ @Override
+ public String getDefaultExtension() {
+ return myExtension;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof MockLanguageFileType)) return false;
+ return getLanguage().equals(((MockLanguageFileType)obj).getLanguage());
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/mock/MockModule.java b/platform/testFramework/src/com/intellij/mock/MockModule.java
new file mode 100644
index 000000000000..c900ec975d69
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockModule.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
+ */
+package com.intellij.mock;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleType;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.search.GlobalSearchScope;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author peter
+ */
+public class MockModule extends MockComponentManager implements Module {
+ private final Project myProject;
+
+ public MockModule() {
+ this(null);
+ }
+
+ public MockModule(final Project project) {
+ super(project == null ? null : project.getPicoContainer());
+ myProject = project;
+ }
+
+ @Override
+ public VirtualFile getModuleFile() {
+ throw new UnsupportedOperationException("Method getModuleFile is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ @NotNull
+ public String getModuleFilePath() {
+ return "";
+ }
+
+ @Override
+ public GlobalSearchScope getModuleRuntimeScope(final boolean includeTests) {
+ return new MockGlobalSearchScope();
+ }
+
+ @Override
+ public GlobalSearchScope getModuleScope() {
+ return new MockGlobalSearchScope();
+ }
+
+ @Override
+ public GlobalSearchScope getModuleScope(boolean includeTests) {
+ return new MockGlobalSearchScope();
+ }
+
+ @Override
+ public GlobalSearchScope getModuleTestsWithDependentsScope() {
+ return new MockGlobalSearchScope();
+ }
+
+ @Override
+ @NotNull
+ public ModuleType getModuleType() {
+ throw new UnsupportedOperationException("Method getModuleType is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(final boolean includeTests) {
+ return new MockGlobalSearchScope();
+
+ //throw new UnsupportedOperationException( "Method getModuleWithDependenciesAndLibrariesScope is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public GlobalSearchScope getModuleWithDependenciesScope() {
+ return new MockGlobalSearchScope();
+ }
+
+ @Override
+ public GlobalSearchScope getModuleWithDependentsScope() {
+ throw new UnsupportedOperationException("Method getModuleWithDependentsScope is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public GlobalSearchScope getModuleWithLibrariesScope() {
+ throw new UnsupportedOperationException("Method getModuleWithLibrariesScope is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ @NotNull
+ public String getName() {
+ return "MockModule";
+ }
+
+ @Override
+ public boolean isLoaded() {
+ return !isDisposed();
+ }
+
+ @Override
+ @Nullable
+ public String getOptionValue(@NotNull final String optionName) {
+ throw new UnsupportedOperationException("Method getOptionValue is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ @NotNull
+ public Project getProject() {
+ return myProject;
+ }
+
+ @Override
+ public void setOption(@NotNull final String optionName, @NotNull final String optionValue) {
+ throw new UnsupportedOperationException("Method setOption is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public void clearOption(@NotNull String optionName) {
+ throw new UnsupportedOperationException("Method clearOption is not yet implemented in " + getClass().getName());
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/mock/MockPsiDocumentManager.java b/platform/testFramework/src/com/intellij/mock/MockPsiDocumentManager.java
new file mode 100644
index 000000000000..4f6e66eb5c83
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockPsiDocumentManager.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
+ */
+package com.intellij.mock;
+
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author peter
+ */
+public class MockPsiDocumentManager extends PsiDocumentManager {
+ @Override
+ @Nullable
+ public PsiFile getPsiFile(@NotNull Document document) {
+ throw new UnsupportedOperationException("Method getPsiFile is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ @Nullable
+ public PsiFile getCachedPsiFile(@NotNull Document document) {
+ throw new UnsupportedOperationException("Method getCachedPsiFile is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ @Nullable
+ public Document getDocument(@NotNull PsiFile file) {
+ return null;
+ }
+
+ @Override
+ @Nullable
+ public Document getCachedDocument(@NotNull PsiFile file) {
+ VirtualFile vFile = file.getViewProvider().getVirtualFile();
+ return FileDocumentManager.getInstance().getCachedDocument(vFile);
+ }
+
+ @Override
+ public void commitAllDocuments() {
+ }
+
+ @Override
+ public void performForCommittedDocument(@NotNull final Document document, @NotNull final Runnable action) {
+ action.run();
+ }
+
+ @Override
+ public void commitDocument(@NotNull Document document) {
+ }
+
+ @Override
+ @NotNull
+ public Document[] getUncommittedDocuments() {
+ throw new UnsupportedOperationException("Method getUncommittedDocuments is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public boolean isUncommited(@NotNull Document document) {
+ throw new UnsupportedOperationException("Method isUncommited is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public boolean isCommitted(@NotNull Document document) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasUncommitedDocuments() {
+ throw new UnsupportedOperationException("Method hasUncommitedDocuments is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public void commitAndRunReadAction(@NotNull Runnable runnable) {
+ throw new UnsupportedOperationException("Method commitAndRunReadAction is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public T commitAndRunReadAction(@NotNull Computable computation) {
+ throw new UnsupportedOperationException("Method commitAndRunReadAction is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public void addListener(@NotNull Listener listener) {
+ throw new UnsupportedOperationException("Method addListener is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public void removeListener(@NotNull Listener listener) {
+ throw new UnsupportedOperationException("Method removeListener is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public boolean isDocumentBlockedByPsi(@NotNull Document doc) {
+ throw new UnsupportedOperationException("Method isDocumentBlockedByPsi is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public void doPostponedOperationsAndUnblockDocument(@NotNull Document doc) {
+ throw new UnsupportedOperationException(
+ "Method doPostponedOperationsAndUnblockDocument is not yet implemented in " + getClass().getName());
+ }
+
+ @Override
+ public boolean cancelAndRunWhenAllCommitted(@NotNull Object key, @NotNull Runnable action) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/mock/MockRunManager.java b/platform/testFramework/src/com/intellij/mock/MockRunManager.java
new file mode 100644
index 000000000000..5014b49a9383
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/mock/MockRunManager.java
@@ -0,0 +1,163 @@
+package com.intellij.mock;
+
+import com.intellij.execution.*;
+import com.intellij.execution.configurations.ConfigurationFactory;
+import com.intellij.execution.configurations.ConfigurationType;
+import com.intellij.execution.configurations.RunConfiguration;
+import com.intellij.openapi.util.Key;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author gregsh
+ */
+public class MockRunManager extends RunManagerEx {
+ @Override
+ public ConfigurationType[] getConfigurationFactories() {
+ return new ConfigurationType[0];
+ }
+
+ @Override
+ public RunConfiguration[] getConfigurations(ConfigurationType type) {
+ return new RunConfiguration[0];
+ }
+
+ @Override
+ public RunConfiguration[] getAllConfigurations() {
+ return new RunConfiguration[0];
+ }
+
+ @Override
+ public RunConfiguration[] getTempConfigurations() {
+ return new RunConfiguration[0];
+ }
+
+ @Override
+ public boolean isTemporary(RunConfiguration configuration) {
+ return false;
+ }
+
+ @Override
+ public void makeStable(RunConfiguration configuration) {
+ }
+
+ @Override
+ public RunnerAndConfigurationSettings getSelectedConfiguration() {
+ return null;
+ }
+
+ @Override
+ public RunnerAndConfigurationSettings createRunConfiguration(String name, ConfigurationFactory type) {
+ throw new UnsupportedOperationException();
+ }
+
+ @NotNull
+ @Override
+ public RunnerAndConfigurationSettings createConfiguration(RunConfiguration runConfiguration, ConfigurationFactory factory) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public RunnerAndConfigurationSettings[] getConfigurationSettings(ConfigurationType type) {
+ return new RunnerAndConfigurationSettings[0];
+ }
+
+ @Override
+ public boolean isTemporary(RunnerAndConfigurationSettings configuration) {
+ return false;
+ }
+
+ @Override
+ public void setActiveConfiguration(RunnerAndConfigurationSettings configuration) {
+ }
+
+ @Override
+ public void setSelectedConfiguration(RunnerAndConfigurationSettings configuration) {
+ }
+
+ @Override
+ public void setTemporaryConfiguration(RunnerAndConfigurationSettings tempConfiguration) {
+ }
+
+ @Override
+ public void setEditBeforeRun(RunConfiguration settings, boolean edit) {
+ }
+
+ @Override
+ public RunManagerConfig getConfig() {
+ return null;
+ }
+
+ @NotNull
+ @Override
+ public RunnerAndConfigurationSettings createConfiguration(String name, ConfigurationFactory type) {
+ return null;
+ }
+
+ @Override
+ public void addConfiguration(RunnerAndConfigurationSettings settings,
+ boolean isShared,
+ Map, BeforeRunTask> tasks) {
+ }
+
+ @Override
+ public void addConfiguration(RunnerAndConfigurationSettings settings, boolean isShared) {
+ }
+
+ @Override
+ public boolean isConfigurationShared(RunnerAndConfigurationSettings settings) {
+ return false;
+ }
+
+ @NotNull
+ @Override
+ public Map, BeforeRunTask> getBeforeRunTasks(RunConfiguration settings) {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public T getBeforeRunTask(RunConfiguration settings, Key taskProviderID) {
+ return null;
+ }
+
+ @NotNull
+ @Override
+ public Collection getBeforeRunTasks(Key taskProviderID, boolean includeOnlyActiveTasks) {
+ return null;
+ }
+
+ @Override
+ public RunnerAndConfigurationSettings findConfigurationByName(@NotNull String name) {
+ return null;
+ }
+
+ @Override
+ public Icon getConfigurationIcon(@NotNull RunnerAndConfigurationSettings settings) {
+ return null;
+ }
+
+ @Override
+ public void invalidateConfigurationIcon(@NotNull RunnerAndConfigurationSettings settings) {
+ }
+
+ @Override
+ public Collection getSortedConfigurations() {
+ return null;
+ }
+
+ @Override
+ public void removeConfiguration(RunnerAndConfigurationSettings settings) {
+ }
+
+ @Override
+ public void addRunManagerListener(RunManagerListener listener) {
+ }
+
+ @Override
+ public void removeRunManagerListener(RunManagerListener listener) {
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java
index 2167ee325863..a9e6435fcc9b 100644
--- a/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/LexerTestCase.java
@@ -68,7 +68,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
}
}
- private String printTokens(String text, int start) {
+ protected String printTokens(String text, int start) {
return printTokens(text, start, createLexer());
}
diff --git a/platform/testFramework/src/com/intellij/testFramework/MockSchemesManagerFactory.java b/platform/testFramework/src/com/intellij/testFramework/MockSchemesManagerFactory.java
new file mode 100644
index 000000000000..b74bb8e204b5
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/testFramework/MockSchemesManagerFactory.java
@@ -0,0 +1,17 @@
+package com.intellij.testFramework;
+
+import com.intellij.openapi.components.RoamingType;
+import com.intellij.openapi.options.*;
+
+public class MockSchemesManagerFactory extends SchemesManagerFactory {
+ @Override
+ public SchemesManager createSchemesManager(final String fileSpec,
+ final SchemeProcessor processor, final RoamingType roamingType) {
+ return SchemesManager.EMPTY;
+ }
+
+ @Override
+ public void updateConfigFilesFromStreamProviders() {
+
+ }
+}
diff --git a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java
index 69cb188f5026..5cd3e532c1c7 100644
--- a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java
@@ -15,34 +15,137 @@
*/
package com.intellij.testFramework;
+import com.intellij.ide.startup.impl.StartupManagerImpl;
+import com.intellij.lang.*;
+import com.intellij.lang.impl.PsiBuilderFactoryImpl;
+import com.intellij.mock.*;
+import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.editor.EditorFactory;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.fileTypes.FileTypeFactory;
+import com.intellij.openapi.fileTypes.FileTypeManager;
+import com.intellij.openapi.options.SchemesManagerFactory;
+import com.intellij.openapi.startup.StartupManager;
+import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiRecursiveElementVisitor;
+import com.intellij.psi.*;
import com.intellij.psi.impl.DebugUtil;
+import com.intellij.psi.impl.PsiFileFactoryImpl;
+import com.intellij.psi.util.CachedValuesManager;
+import com.intellij.util.CachedValuesManagerImpl;
+import com.intellij.util.DefaultCachedValuesFactory;
+import com.intellij.util.messages.MessageBus;
+import com.intellij.util.messages.MessageBusFactory;
import org.jetbrains.annotations.NonNls;
+import org.picocontainer.MutablePicoContainer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
-public abstract class ParsingTestCase extends LightPlatformTestCase {
+public abstract class ParsingTestCase extends PlatformLiteFixture {
+ protected String myFilePrefix = "";
protected String myFileExt;
@NonNls private final String myFullDataPath;
protected PsiFile myFile;
+ private MockPsiManager myPsiManager;
+ private PsiFileFactoryImpl myFileFactory;
+ protected Language myLanguage;
+ private ParserDefinition[] myDefinitions = new ParserDefinition[0];
public ParsingTestCase(@NonNls String dataPath, String fileExt) {
myFullDataPath = getTestDataPath() + "/psi/" + dataPath;
myFileExt = fileExt;
}
+ public ParsingTestCase(@NonNls String dataPath, String fileExt, Language language) {
+ myLanguage = language;
+ myFullDataPath = getTestDataPath() + dataPath;
+ myFileExt = fileExt;
+ }
+
+ public ParsingTestCase(@NonNls String dataPath, String fileExt, ParserDefinition... definitions) {
+ myDefinitions = definitions;
+ myFullDataPath = getTestDataPath() + "/" + dataPath;
+ myFileExt = fileExt;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ initApplication();
+ myProject = disposeOnTearDown(new MockProject());
+ myPsiManager = new MockPsiManager(myProject);
+ myFileFactory = new PsiFileFactoryImpl(myPsiManager);
+ final MutablePicoContainer appContainer = getApplication().getPicoContainer();
+ registerComponentInstance(appContainer, MessageBus.class, MessageBusFactory.newMessageBus(getApplication()));
+ registerComponentInstance(appContainer, SchemesManagerFactory.class, new MockSchemesManagerFactory());
+ registerComponentInstance(appContainer, EditorFactory.class, new MockEditorFactory());
+ registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl());
+ registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
+ myLanguage = myLanguage == null && myDefinitions != null && myDefinitions.length > 0? myDefinitions[0].getFileNodeType().getLanguage() : myLanguage;
+ registerComponentInstance(appContainer, FileTypeManager.class, new MockFileTypeManager(new MockLanguageFileType(myLanguage, myFileExt)));
+ registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
+ myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new DefaultCachedValuesFactory(myProject)));
+ myProject.registerService(PsiManager.class, myPsiManager);
+ myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));
+ registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
+
+ for (ParserDefinition definition : myDefinitions) {
+ addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
+ }
+ }
+
+ protected void addExplicitExtension(final LanguageExtension instance, final Language language, final T object) {
+ instance.addExplicitExtension(language, object);
+ Disposer.register(myProject, new Disposable() {
+ @Override
+ public void dispose() {
+ instance.removeExplicitExtension(language, object);
+ }
+ });
+ }
+
+ @Override
+ protected void registerExtensionPoint(final ExtensionPointName extensionPointName, Class aClass) {
+ super.registerExtensionPoint(extensionPointName, aClass);
+ Disposer.register(myProject, new Disposable() {
+ @Override
+ public void dispose() {
+ Extensions.getRootArea().unregisterExtensionPoint(extensionPointName.getName());
+ }
+ });
+ }
+
+ protected void registerApplicationService(final Class aClass, T object) {
+ getApplication().registerService(aClass, object);
+ Disposer.register(myProject, new Disposable() {
+ @Override
+ public void dispose() {
+ getApplication().getPicoContainer().unregisterComponent(aClass.getName());
+ }
+ });
+ }
+
+ public MockProject getProject() {
+ return myProject;
+ }
+
+ public MockPsiManager getPsiManager() {
+ return myPsiManager;
+ }
+
@Override
protected void tearDown() throws Exception {
- myFile = null;
super.tearDown();
+ myFile = null;
+ myProject = null;
+ myPsiManager = null;
}
protected String getTestDataPath() {
@@ -53,6 +156,14 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
return false;
}
+ protected boolean skipSpaces() {
+ return false;
+ }
+
+ protected boolean checkAllPsiRoots() {
+ return true;
+ }
+
protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
@@ -64,7 +175,7 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
checkResult(name + ".txt", myFile);
}
else{
- toParseTreeText(myFile, includeRanges());
+ toParseTreeText(myFile, skipSpaces(), includeRanges());
}
}
catch (IOException e) {
@@ -81,24 +192,42 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
checkResult(name + suffix + ".txt", myFile);
}
+ protected void doCodeTest(String code) throws IOException {
+ String name = getTestName(false);
+ myFile = createPsiFile("a", code);
+ myFile.accept(new PsiRecursiveElementVisitor(){});
+ assertEquals(code, myFile.getText());
+ checkResult(myFilePrefix + name + ".txt", myFile);
+ }
+
protected PsiFile createPsiFile(String name, String text) {
return createFile(name + "." + myFileExt, text);
}
- protected void checkResult(@NonNls @TestDataFile String targetDataName, final PsiFile file) throws IOException {
- doCheckResult(myFullDataPath, file, targetDataName, includeRanges());
+ protected PsiFile createFile(String name, String text) {
+ LightVirtualFile virtualFile = new LightVirtualFile(name, myLanguage, text);
+ return myFileFactory.trySetupPsiForFile(virtualFile, myLanguage, true, false);
}
- public static void doCheckResult(String myFullDataPath, PsiFile file, String targetDataName, boolean printRanges) throws IOException {
- final PsiElement[] psiRoots = file.getPsiRoots();
+ protected void checkResult(@NonNls @TestDataFile String targetDataName, final PsiFile file) throws IOException {
+ doCheckResult(myFullDataPath, file, checkAllPsiRoots(), targetDataName, skipSpaces(), includeRanges());
+ }
+
+ public static void doCheckResult(String myFullDataPath,
+ PsiFile file,
+ boolean checkAllPsiRoots,
+ String targetDataName,
+ boolean skipSpaces,
+ boolean printRanges) throws IOException {
+ final PsiElement[] psiRoots = checkAllPsiRoots? file.getPsiRoots() : PsiElement.EMPTY_ARRAY;
if(psiRoots.length > 1){
for (int i = 0; i < psiRoots.length; i++) {
final PsiElement psiRoot = psiRoots[i];
- doCheckResult(myFullDataPath, targetDataName + "." + i, toParseTreeText(psiRoot, printRanges).trim());
+ doCheckResult(myFullDataPath, targetDataName + "." + i, toParseTreeText(psiRoot, skipSpaces, printRanges).trim());
}
}
else{
- doCheckResult(myFullDataPath, targetDataName, toParseTreeText(file, printRanges).trim());
+ doCheckResult(myFullDataPath, targetDataName, toParseTreeText(file, skipSpaces, printRanges).trim());
}
}
@@ -125,8 +254,8 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
}
}
- protected static String toParseTreeText(final PsiElement file, boolean printRanges) {
- return DebugUtil.psiToString(file, false, printRanges);
+ protected static String toParseTreeText(final PsiElement file, boolean skipSpaces, boolean printRanges) {
+ return DebugUtil.psiToString(file, skipSpaces, printRanges);
}
protected String loadFile(@NonNls @TestDataFile String name) throws IOException {
diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java
index d29e1dfa0ae5..de266621e071 100644
--- a/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java
+++ b/plugins/ant/tests/src/com/intellij/lang/ant/AntParsingTest.java
@@ -16,19 +16,33 @@
package com.intellij.lang.ant;
+import com.intellij.lang.LanguageASTFactory;
+import com.intellij.lang.xml.XMLLanguage;
+import com.intellij.lang.xml.XMLParserDefinition;
+import com.intellij.lang.xml.XmlASTFactory;
import com.intellij.openapi.application.PluginPathManager;
+import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.util.SystemInfo;
+import com.intellij.psi.xml.XmlChildRole;
import com.intellij.testFramework.ParsingTestCase;
public class AntParsingTest extends ParsingTestCase {
public AntParsingTest() {
- super("", "ant");
+ super("", "ant", new XMLParserDefinition());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ addExplicitExtension(LanguageASTFactory.INSTANCE, XMLLanguage.INSTANCE, new XmlASTFactory());
+ registerExtensionPoint(new ExtensionPointName("com.intellij.xml.startTagEndToken"),
+ XmlChildRole.StartTagEndTokenProvider.class);
}
@Override
protected String getTestDataPath() {
- return PluginPathManager.getPluginHomePath("ant") + "/tests/data";
+ return PluginPathManager.getPluginHomePath("ant") + "/tests/data/psi";
}
public void testSingleProject() throws Exception {
diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java
index f7db59fbe095..aff6c1fda08f 100644
--- a/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java
+++ b/plugins/ant/tests/src/com/intellij/lang/ant/CustomTypesTest.java
@@ -25,22 +25,20 @@ import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
-import com.intellij.testFramework.ParsingTestCase;
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.util.PathUtil;
import java.io.File;
import java.io.IOException;
-public class CustomTypesTest extends ParsingTestCase {
+public class CustomTypesTest extends LightCodeInsightFixtureTestCase {
private static final String myCustomTaskClass = "com.intellij.lang.ant.typedefs.AntCustomTask";
public CustomTypesTest() {
- super("", "ant");
}
- @Override
- protected String getTestDataPath() {
+ protected String getMyTestDataPath() {
return PluginPathManager.getPluginHomePath("ant") + "/tests/data/psi/customTypes";
}
@@ -50,8 +48,8 @@ public class CustomTypesTest extends ParsingTestCase {
protected void doTest() throws Exception {
String name = getTestName(false);
- String text = loadFile(name + "." + myFileExt);
- PsiFile file = createFile(name + "." + myFileExt, text);
+ String text = loadFile(name + ".ant");
+ PsiFile file = myFixture.addFileToProject(name + ".ant", text);
final AntDomProject antProject = AntSupport.getAntDomProject(file);
final Ref found = new Ref(false);
antProject.accept(new AntDomRecursiveVisitor() {
@@ -77,9 +75,8 @@ public class CustomTypesTest extends ParsingTestCase {
assertTrue(found.get());
}
- @Override
protected String loadFile(String name) throws IOException {
- String fullName = getTestDataPath() + File.separatorChar + name;
+ String fullName = getMyTestDataPath() + File.separatorChar + name;
String text = FileUtil.loadFile(new File(fullName)).trim();
text = StringUtil.convertLineSeparators(text);
final String root = PathUtil.getJarPathForClass(this.getClass());
diff --git a/plugins/properties/src/com/intellij/lang/properties/parsing/PropertiesElementTypes.java b/plugins/properties/src/com/intellij/lang/properties/parsing/PropertiesElementTypes.java
index 3922811aeeed..7b4410dc09cc 100644
--- a/plugins/properties/src/com/intellij/lang/properties/parsing/PropertiesElementTypes.java
+++ b/plugins/properties/src/com/intellij/lang/properties/parsing/PropertiesElementTypes.java
@@ -15,7 +15,6 @@
*/
package com.intellij.lang.properties.parsing;
-import com.intellij.lang.Language;
import com.intellij.lang.properties.PropertiesLanguage;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.tree.IFileElementType;
@@ -26,7 +25,7 @@ import com.intellij.psi.tree.TokenSet;
* @author max
*/
public interface PropertiesElementTypes {
- PropertiesLanguage LANG = Language.findInstance(PropertiesLanguage.class);
+ PropertiesLanguage LANG = PropertiesLanguage.INSTANCE;
IFileElementType FILE = new IStubFileElementType(LANG);
IStubElementType PROPERTY = new PropertyStubElementType();
diff --git a/plugins/properties/src/com/intellij/lang/properties/psi/impl/PropertiesFileImpl.java b/plugins/properties/src/com/intellij/lang/properties/psi/impl/PropertiesFileImpl.java
index b2607dd2119f..ae24c2abb274 100644
--- a/plugins/properties/src/com/intellij/lang/properties/psi/impl/PropertiesFileImpl.java
+++ b/plugins/properties/src/com/intellij/lang/properties/psi/impl/PropertiesFileImpl.java
@@ -18,6 +18,7 @@ package com.intellij.lang.properties.psi.impl;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.ASTNode;
+import com.intellij.lang.properties.PropertiesLanguage;
import com.intellij.lang.properties.PropertiesUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.ResourceBundleImpl;
@@ -48,7 +49,7 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
private List myProperties;
public PropertiesFileImpl(FileViewProvider viewProvider) {
- super(viewProvider, StdFileTypes.PROPERTIES.getLanguage());
+ super(viewProvider, PropertiesLanguage.INSTANCE);
}
@NotNull
diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java
index 9073cc6fbb92..ec8ced434e32 100644
--- a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java
+++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java
@@ -15,6 +15,9 @@
*/
package com.intellij.lang.properties;
+import com.intellij.lang.LanguageASTFactory;
+import com.intellij.lang.properties.parsing.PropertiesParserDefinition;
+import com.intellij.lang.properties.psi.impl.PropertiesASTFactory;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.testFramework.ParsingTestCase;
import com.intellij.testFramework.PlatformTestCase;
@@ -25,13 +28,19 @@ import com.intellij.testFramework.PlatformTestCase;
public class PropertiesParsingTest extends ParsingTestCase {
public PropertiesParsingTest() {
- super("", "properties");
+ super("", "properties", new PropertiesParserDefinition());
PlatformTestCase.initPlatformLangPrefix();
}
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ addExplicitExtension(LanguageASTFactory.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesASTFactory());
+ }
+
@Override
protected String getTestDataPath() {
- return PluginPathManager.getPluginHomePath("properties") + "/testData/propertiesFile";
+ return PluginPathManager.getPluginHomePath("properties") + "/testData/propertiesFile/psi";
}
public void testProp1() throws Exception { doTest(true); }
diff --git a/plugins/relaxng/test/org/intellij/plugins/relaxNG/AbstractParsingTest.java b/plugins/relaxng/test/org/intellij/plugins/relaxNG/AbstractParsingTest.java
index 956eb4af68bb..a06ffa0f6973 100644
--- a/plugins/relaxng/test/org/intellij/plugins/relaxNG/AbstractParsingTest.java
+++ b/plugins/relaxng/test/org/intellij/plugins/relaxNG/AbstractParsingTest.java
@@ -16,11 +16,9 @@
package org.intellij.plugins.relaxNG;
-import com.intellij.javaee.ExternalResourceManagerEx;
import com.intellij.openapi.application.PluginPathManager;
-import com.intellij.openapi.application.Result;
-import com.intellij.openapi.application.WriteAction;
import com.intellij.testFramework.ParsingTestCase;
+import org.intellij.plugins.relaxNG.compact.RncParserDefinition;
/*
* Created by IntelliJ IDEA.
@@ -29,21 +27,11 @@ import com.intellij.testFramework.ParsingTestCase;
*/
public abstract class AbstractParsingTest extends ParsingTestCase {
public AbstractParsingTest(String s) {
- super(s, "rnc");
+ super("psi/"+s, "rnc", new RncParserDefinition());
}
protected String getTestDataPath() {
return PluginPathManager.getPluginHomePath("relaxng") + "/testData/parsing";
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- new WriteAction() {
- protected void run(Result result) throws Throwable {
- new ApplicationLoader().initComponent();
- ExternalResourceManagerEx.getInstanceEx().addIgnoredResource("urn:test:undefined");
- }
- }.execute();
- }
}
\ No newline at end of file
diff --git a/xml/impl/src/com/intellij/xml/util/XmlUtil.java b/xml/impl/src/com/intellij/xml/util/XmlUtil.java
index 4db106df213d..b9d602d506f7 100644
--- a/xml/impl/src/com/intellij/xml/util/XmlUtil.java
+++ b/xml/impl/src/com/intellij/xml/util/XmlUtil.java
@@ -1028,8 +1028,7 @@ public class XmlUtil {
static {
URL schemaLocationURL = XmlUtil.class.getResource(ExternalResourceManagerImpl.STANDARD_SCHEMAS + "html5/xhtml5.xsd");
- VirtualFile relativeFile = schemaLocationURL != null ? VfsUtil.findFileByURL(schemaLocationURL):null;
- HTML5_SCHEMA_LOCATION = relativeFile != null ? relativeFile.getPath():"";
+ HTML5_SCHEMA_LOCATION = VfsUtil.urlToPath(VfsUtil.fixURLforIDEA(schemaLocationURL.toExternalForm()));
}
@Nullable