mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-67098 + com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase.testFile fluent interface
This commit is contained in:
@@ -30,6 +30,5 @@ public interface JavaHighlightInfoTypes extends HighlightInfoType {
|
||||
HighlightDisplayKey.findOrRegister(UnusedImportLocalInspection.SHORT_NAME, UnusedImportLocalInspection.DISPLAY_NAME),
|
||||
CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
|
||||
|
||||
HighlightInfoType JAVA_KEYWORD = new HighlightInfoType.HighlightInfoTypeImpl(
|
||||
HighlightSeverity.INFORMATION, SyntaxHighlighterColors.KEYWORD);
|
||||
HighlightInfoType JAVA_KEYWORD = new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, SyntaxHighlighterColors.KEYWORD);
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
class <symbolName descr="null" type="CLASS_NAME">Test</symbolName>{
|
||||
int <symbolName descr="null" type="INSTANCE_FIELD">field1</symbolName> = 0, <symbolName descr="null" type="INSTANCE_FIELD">field2</symbolName> = 0;
|
||||
int <symbolName descr="null" type="INSTANCE_FIELD">field3</symbolName>, <symbolName descr="null" type="INSTANCE_FIELD">field4</symbolName>;
|
||||
}
|
||||
+32
-32
@@ -1,59 +1,59 @@
|
||||
import <info descr="null" type="CLASS_NAME">java.io</info>.*; // highlight on demand import as class name
|
||||
import <symbolName descr="null" type="CLASS_NAME">java.io</symbolName>.*; // highlight on demand import as class name
|
||||
|
||||
class <info descr="null" type="CLASS_NAME">a</info> {
|
||||
void <info descr="null" type="METHOD_DECLARATION">method</info>() {
|
||||
<info descr="null" type="METHOD_CALL">method</info>();
|
||||
class <symbolName descr="null" type="CLASS_NAME">a</symbolName> {
|
||||
void <symbolName descr="null" type="METHOD_DECLARATION">method</symbolName>() {
|
||||
<symbolName descr="null" type="METHOD_CALL">method</symbolName>();
|
||||
|
||||
new <info descr="null" type="CONSTRUCTOR_CALL">Exception</info>();
|
||||
new <info descr="null" type="CONSTRUCTOR_CALL">java.lang.Exception</info>();
|
||||
new <symbolName descr="null" type="CONSTRUCTOR_CALL">Exception</symbolName>();
|
||||
new <symbolName descr="null" type="CONSTRUCTOR_CALL">java.lang.Exception</symbolName>();
|
||||
}
|
||||
<info descr="null" type="CONSTRUCTOR_DECLARATION">a</info>() {
|
||||
new <info descr="null" type="CONSTRUCTOR_CALL">a</info>();
|
||||
<symbolName descr="null" type="CONSTRUCTOR_DECLARATION">a</symbolName>() {
|
||||
new <symbolName descr="null" type="CONSTRUCTOR_CALL">a</symbolName>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <info descr="null" type="INTERFACE_NAME">itf</info>#<info descr="null" type="METHOD_CALL">method</info>(<info descr="null" type="JAVA_KEYWORD">double</info>)
|
||||
* @see <symbolName descr="null" type="INTERFACE_NAME">itf</symbolName>#<symbolName descr="null" type="METHOD_CALL">method</symbolName>(double)
|
||||
*/
|
||||
static void <info descr="null" type="METHOD_DECLARATION">f</info>() {
|
||||
<info descr="null" type="CLASS_NAME">Integer</info>.<info descr="null" type="STATIC_METHOD">parseInt</info>("");
|
||||
<info descr="null" type="CLASS_NAME">java.lang.Integer</info>.<info descr="null" type="STATIC_METHOD">parseInt</info>("");
|
||||
<info descr="null" type="STATIC_METHOD">f</info>();
|
||||
static void <symbolName descr="null" type="METHOD_DECLARATION">f</symbolName>() {
|
||||
<symbolName descr="null" type="CLASS_NAME">Integer</symbolName>.<symbolName descr="null" type="STATIC_METHOD">parseInt</symbolName>("");
|
||||
<symbolName descr="null" type="CLASS_NAME">java.lang.Integer</symbolName>.<symbolName descr="null" type="STATIC_METHOD">parseInt</symbolName>("");
|
||||
<symbolName descr="null" type="STATIC_METHOD">f</symbolName>();
|
||||
}
|
||||
|
||||
interface <info descr="null" type="INTERFACE_NAME">itf</info>{
|
||||
int <info descr="null" type="STATIC_FIELD">CONST</info> = 0;
|
||||
interface <symbolName descr="null" type="INTERFACE_NAME">itf</symbolName>{
|
||||
int <symbolName descr="null" type="STATIC_FIELD">CONST</symbolName> = 0;
|
||||
/** .
|
||||
* @param <info descr="null" type="PARAMETER">d</info> Important param
|
||||
* @param <symbolName descr="null" type="PARAMETER">d</symbolName> Important param
|
||||
*/
|
||||
void <info descr="null" type="METHOD_DECLARATION">method</info>(double <info descr="null" type="PARAMETER">d</info>);
|
||||
void <symbolName descr="null" type="METHOD_DECLARATION">method</symbolName>(double <symbolName descr="null" type="PARAMETER">d</symbolName>);
|
||||
}
|
||||
void <info descr="null" type="METHOD_DECLARATION">ff</info>(<info descr="null" type="INTERFACE_NAME">Runnable</info> <info descr="null" type="PARAMETER">r</info>) {
|
||||
<info descr="null" type="METHOD_CALL">ff</info>(
|
||||
new <info descr="null" type="INTERFACE_NAME">java.lang.Runnable</info>()
|
||||
void <symbolName descr="null" type="METHOD_DECLARATION">ff</symbolName>(<symbolName descr="null" type="INTERFACE_NAME">Runnable</symbolName> <symbolName descr="null" type="PARAMETER">r</symbolName>) {
|
||||
<symbolName descr="null" type="METHOD_CALL">ff</symbolName>(
|
||||
new <symbolName descr="null" type="INTERFACE_NAME">java.lang.Runnable</symbolName>()
|
||||
{
|
||||
public void <info descr="null" type="METHOD_DECLARATION">run</info>() {}
|
||||
int <info descr="null" type="INSTANCE_FIELD">instance</info> = 0;
|
||||
public void <symbolName descr="null" type="METHOD_DECLARATION">run</symbolName>() {}
|
||||
int <symbolName descr="null" type="INSTANCE_FIELD">instance</symbolName> = 0;
|
||||
}
|
||||
);
|
||||
|
||||
int <info descr="null" type="LOCAL_VARIABLE">i</info> = <info descr="null" type="CLASS_NAME">java.lang.Integer</info>.<info descr="null" type="STATIC_FIELD">MIN_VALUE</info>;
|
||||
int <info descr="null" type="LOCAL_VARIABLE">j</info> = <info descr="null" type="INTERFACE_NAME">itf</info>.<info descr="null" type="STATIC_FIELD">CONST</info>;
|
||||
int <symbolName descr="null" type="LOCAL_VARIABLE">i</symbolName> = <symbolName descr="null" type="CLASS_NAME">java.lang.Integer</symbolName>.<symbolName descr="null" type="STATIC_FIELD">MIN_VALUE</symbolName>;
|
||||
int <symbolName descr="null" type="LOCAL_VARIABLE">j</symbolName> = <symbolName descr="null" type="INTERFACE_NAME">itf</symbolName>.<symbolName descr="null" type="STATIC_FIELD">CONST</symbolName>;
|
||||
}
|
||||
}
|
||||
|
||||
class <info descr="null" type="CLASS_NAME">NoCtrClass</info> {
|
||||
class <symbolName descr="null" type="CLASS_NAME">NoCtrClass</symbolName> {
|
||||
{
|
||||
// default constructor call looks like class
|
||||
new <info descr="null" type="CLASS_NAME">NoCtrClass</info>();
|
||||
new <symbolName descr="null" type="CLASS_NAME">NoCtrClass</symbolName>();
|
||||
}
|
||||
void <info descr="null" type="METHOD_DECLARATION">ff</info>(int <info descr="null" type="REASSIGNED_PARAMETER">param</info>) {
|
||||
int <info descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</info> = 1;
|
||||
<info descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</info> ++;
|
||||
void <symbolName descr="null" type="METHOD_DECLARATION">ff</symbolName>(int <symbolName descr="null" type="REASSIGNED_PARAMETER">param</symbolName>) {
|
||||
int <symbolName descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</symbolName> = 1;
|
||||
<symbolName descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</symbolName> ++;
|
||||
|
||||
<info descr="null" type="REASSIGNED_PARAMETER">param</info> = 0;
|
||||
<symbolName descr="null" type="REASSIGNED_PARAMETER">param</symbolName> = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class <info descr="null" type="CLASS_NAME">Generic</info><<info descr="null" type="TYPE_PARAMETER_NAME">TT</info> extends <info descr="null" type="INTERFACE_NAME">Runnable</info>> {
|
||||
<info descr="null" type="TYPE_PARAMETER_NAME">TT</info> <info descr="null" type="INSTANCE_FIELD">field</info>;
|
||||
class <symbolName descr="null" type="CLASS_NAME">Generic</symbolName><<symbolName descr="null" type="TYPE_PARAMETER_NAME">TT</symbolName> extends <symbolName descr="null" type="INTERFACE_NAME">Runnable</symbolName>> {
|
||||
<symbolName descr="null" type="TYPE_PARAMETER_NAME">TT</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">field</symbolName>;
|
||||
}
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
package x;
|
||||
class <info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</info> {
|
||||
<info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</info> <info descr="null" type="INSTANCE_FIELD">x</info> = new <info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</info>();
|
||||
<info descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</info>
|
||||
<info descr="null" type="METHOD_DECLARATION">list</info>(
|
||||
<info descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</info> <info descr="null" type="PARAMETER">map</info>
|
||||
class <symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName> {
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName>();
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</symbolName>
|
||||
<symbolName descr="null" type="METHOD_DECLARATION">list</symbolName>(
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</symbolName> <symbolName descr="null" type="PARAMETER">map</symbolName>
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
package x;
|
||||
class <info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</info> {
|
||||
<info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</info> <info descr="null" type="INSTANCE_FIELD">x</info> = new <info descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</info>();
|
||||
<info descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</info>
|
||||
<info descr="null" type="METHOD_DECLARATION">list</info>(
|
||||
<info descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</info> <info descr="null" type="PARAMETER">map</info>
|
||||
class <symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName> {
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CLASS_NAME" foreground="0x00ffff" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName>();
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</symbolName>
|
||||
<symbolName descr="null" type="METHOD_DECLARATION">list</symbolName>(
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x808080" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</symbolName> <symbolName descr="null" type="PARAMETER">map</symbolName>
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
class <info>Test</info>{
|
||||
int <info>field1</info> = 0, <info>field2</info> = 0;
|
||||
int <info>field3</info>, <info>field4</info>;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
scheme.setAttributes(utilKey, utilAttributes);
|
||||
|
||||
try {
|
||||
doTest(BASE_PATH+"/scopeBased/x/X.java", BASE_PATH+"/scopeBased", false, true);
|
||||
testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test();
|
||||
}
|
||||
finally {
|
||||
scopeManager.removeAllSets();
|
||||
@@ -132,7 +132,7 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
scheme.setAttributes(projectKey, projectAttributes);
|
||||
|
||||
try {
|
||||
doTest(BASE_PATH+"/scopeBased/x/Shared.java", BASE_PATH+"/scopeBased", false, true);
|
||||
testFile(BASE_PATH+"/scopeBased/x/Shared.java").projectRoot(BASE_PATH+"/scopeBased").checkSymbolNames().test();
|
||||
}
|
||||
finally {
|
||||
scopeManager.removeAllSets();
|
||||
|
||||
+4
-1
@@ -265,7 +265,10 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
public void testNamesHighlighting() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
doTest(false, true);
|
||||
testFile(BASE_PATH + "/" + getTestName(false) + ".java").checkSymbolNames().test();
|
||||
}
|
||||
public void testMultiFieldDeclNames() throws Exception {
|
||||
testFile(BASE_PATH + "/" + getTestName(false) + ".java").checkSymbolNames().test();
|
||||
}
|
||||
|
||||
public static class MyAnnotator implements Annotator {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
public class VariableHighlightingTest extends DaemonAnalyzerTestCase{
|
||||
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/variables";
|
||||
|
||||
public void testMultiFieldDecl() throws Exception {
|
||||
doTest("MultiFieldDecl.java");
|
||||
}
|
||||
|
||||
protected void doTest(String filePath) throws Exception {
|
||||
super.doTest(BASE_PATH + "/" + filePath, false, true);
|
||||
}
|
||||
}
|
||||
+34
-13
@@ -75,6 +75,7 @@ import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.psi.xml.XmlFileNSInfoProvider;
|
||||
import com.intellij.testFramework.ExpectedHighlightingData;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.HighlightTestInfo;
|
||||
import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -98,7 +99,6 @@ import java.util.Map;
|
||||
public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
private final Map<String, LocalInspectionTool> myAvailableTools = new THashMap<String, LocalInspectionTool>();
|
||||
private final Map<String, LocalInspectionToolWrapper> myAvailableLocalTools = new THashMap<String, LocalInspectionToolWrapper>();
|
||||
private boolean toInitializeDaemon;
|
||||
private final FileTreeAccessFilter myFileTreeAccessFilter = new FileTreeAccessFilter();
|
||||
|
||||
@Override
|
||||
@@ -246,29 +246,45 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
return result.toArray(new LocalInspectionTool[result.size()]);
|
||||
}
|
||||
|
||||
protected void doTest(String filePath, boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) throws Exception {
|
||||
protected void doTest(@NonNls @NotNull String filePath, boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doDoTest(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
|
||||
protected void doTest(String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
protected void doTest(@NonNls @NotNull String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
doTest(filePath, checkWarnings, checkInfos, false);
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, @NonNls String projectRoot, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
protected void doTest(@NonNls @NotNull String filePath, @NonNls String projectRoot, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath, projectRoot);
|
||||
doDoTest(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
protected void doTest(VirtualFile vFile, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
@NotNull
|
||||
@SuppressWarnings("TestMethodWithIncorrectSignature")
|
||||
protected HighlightTestInfo testFile(@NonNls @NotNull String... filePath) {
|
||||
return new HighlightTestInfo(getTestRootDisposable(), filePath){
|
||||
@Override
|
||||
public HighlightTestInfo doTest() throws Exception {
|
||||
configureByFiles(projectRoot, filePaths);
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
if (checkSymbolNames) data.checkSymbolNames();
|
||||
checkHighlighting(data);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void doTest(@NotNull VirtualFile vFile, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
doTest(new VirtualFile[] { vFile }, checkWarnings, checkInfos );
|
||||
}
|
||||
|
||||
protected void doTest(VirtualFile[] vFile, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
protected void doTest(@NotNull VirtualFile[] vFile, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFiles(null, vFile);
|
||||
doDoTest(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<HighlightInfo> doDoTest(boolean checkWarnings, boolean checkInfos) {
|
||||
return doDoTest(checkWarnings, checkInfos, false);
|
||||
}
|
||||
@@ -277,7 +293,9 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
return checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(),checkWarnings, checkWeakWarnings, checkInfos, myFile));
|
||||
}
|
||||
|
||||
protected Collection<HighlightInfo> checkHighlighting(final ExpectedHighlightingData data) {
|
||||
@NotNull
|
||||
protected Collection<HighlightInfo> checkHighlighting(@NotNull final ExpectedHighlightingData data) {
|
||||
data.init();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
|
||||
//to load text
|
||||
@@ -309,14 +327,16 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
return infos;
|
||||
}
|
||||
|
||||
public void allowTreeAccessForFile(final VirtualFile file) {
|
||||
public void allowTreeAccessForFile(@NotNull VirtualFile file) {
|
||||
myFileTreeAccessFilter.allowTreeAccessForFile(file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<HighlightInfo> highlightErrors() {
|
||||
return filter(doHighlighting(), HighlightSeverity.ERROR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<HighlightInfo> doHighlighting() {
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
|
||||
@@ -359,7 +379,8 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
return annotatedWith(CanChangeDocumentDuringHighlighting.class);
|
||||
}
|
||||
|
||||
public static List<HighlightInfo> filter(final List<HighlightInfo> infos, HighlightSeverity minSeverity) {
|
||||
@NotNull
|
||||
public static List<HighlightInfo> filter(@NotNull List<HighlightInfo> infos, @NotNull HighlightSeverity minSeverity) {
|
||||
ArrayList<HighlightInfo> result = new ArrayList<HighlightInfo>();
|
||||
for (final HighlightInfo info : infos) {
|
||||
if (info.getSeverity().compareTo(minSeverity) >= 0) result.add(info);
|
||||
@@ -379,16 +400,16 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void findAndInvokeIntentionAction(final Collection<HighlightInfo> infos, String intentionActionName, final Editor editor,
|
||||
final PsiFile file) throws IncorrectOperationException {
|
||||
protected static void findAndInvokeIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor,
|
||||
@NotNull PsiFile file) throws IncorrectOperationException {
|
||||
IntentionAction intentionAction = findIntentionAction(infos, intentionActionName, editor, file);
|
||||
|
||||
assertNotNull(intentionActionName, intentionAction);
|
||||
assertTrue(ShowIntentionActionsHandler.chooseActionAndInvoke(file, editor, intentionAction, intentionActionName));
|
||||
}
|
||||
|
||||
protected static IntentionAction findIntentionAction(final Collection<HighlightInfo> infos, final String intentionActionName, final Editor editor,
|
||||
final PsiFile file) {
|
||||
protected static IntentionAction findIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor,
|
||||
@NotNull PsiFile file) {
|
||||
List<IntentionAction> actions = LightQuickFixTestCase.getAvailableActions(editor, file);
|
||||
IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
|
||||
|
||||
|
||||
+23
-2
@@ -28,6 +28,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.ExpectedHighlightingData;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.HighlightTestInfo;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -80,7 +81,12 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
ExpectedHighlightingData expectedData = new ExpectedHighlightingData(getEditor().getDocument(),checkWarnings, checkInfos);
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(getEditor().getDocument(),checkWarnings, checkInfos);
|
||||
checkHighlighting(data);
|
||||
}
|
||||
|
||||
private void checkHighlighting(ExpectedHighlightingData data) {
|
||||
data.init();
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
getFile().getText(); //to load text
|
||||
@@ -91,7 +97,22 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
expectedData.checkResult(infos, getEditor().getDocument().getText());
|
||||
data.checkResult(infos, getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
protected HighlightTestInfo testFile(@NonNls @NotNull String filePath) {
|
||||
return new HighlightTestInfo(getTestRootDisposable(), filePath){
|
||||
@Override
|
||||
public HighlightTestInfo doTest() throws Exception {
|
||||
String path = assertOneElement(filePaths);
|
||||
configureByFile(path);
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
if (checkSymbolNames) data.checkSymbolNames();
|
||||
|
||||
checkHighlighting(data);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+4
-42
@@ -41,7 +41,6 @@ import com.intellij.openapi.editor.ex.MarkupModelEx;
|
||||
import com.intellij.openapi.editor.ex.RangeHighlighterEx;
|
||||
import com.intellij.openapi.editor.impl.DocumentMarkupModel;
|
||||
import com.intellij.openapi.editor.markup.MarkupModel;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
@@ -61,7 +60,10 @@ import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -596,46 +598,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
return true;
|
||||
}
|
||||
|
||||
static void addHighlight(MarkupModel markup,
|
||||
Project project,
|
||||
HighlightInfo toAdd) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
stripWarningsCoveredByErrors(project, toAdd, markup.getDocument());
|
||||
}
|
||||
|
||||
private static void stripWarningsCoveredByErrors(Project project, final HighlightInfo toAdd, Document document) {
|
||||
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(project);
|
||||
final Set<HighlightInfo> covered = new THashSet<HighlightInfo>();
|
||||
|
||||
// either toAdd is warning and covered by one of errors in highlightsToSet or toAdd is an error and covers warnings in highlightsToSet or it is OK
|
||||
final boolean addingError = severityRegistrar.compare(HighlightSeverity.ERROR, toAdd.getSeverity()) <= 0;
|
||||
boolean toAddIsVisible = processHighlights(document, project, null, toAdd.getActualStartOffset(),
|
||||
toAdd.getActualEndOffset(), new Processor<HighlightInfo>() {
|
||||
public boolean process(HighlightInfo interval) {
|
||||
boolean isError = severityRegistrar.compare(HighlightSeverity.ERROR, interval.getSeverity()) <= 0;
|
||||
if (addingError && !isError && isCoveredBy(interval, toAdd)) {
|
||||
covered.add(interval);
|
||||
}
|
||||
return addingError || !isError || !isCoveredBy(toAdd, interval);
|
||||
}
|
||||
});
|
||||
if (!toAddIsVisible) {
|
||||
// toAdd is covered by
|
||||
toAdd.highlighter.dispose();
|
||||
}
|
||||
for (HighlightInfo warning : covered) {
|
||||
RangeHighlighter highlighter = warning.highlighter;
|
||||
if (highlighter != null) {
|
||||
highlighter.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isCoveredBy(HighlightInfo info, HighlightInfo coveredBy) {
|
||||
return coveredBy.startOffset <= info.startOffset && info.endOffset <= coveredBy.endOffset && info.getGutterIconRenderer() == null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<LineMarkerInfo> getLineMarkers(Document document, Project project) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
+22
-20
@@ -52,8 +52,7 @@ public interface HighlightInfoType {
|
||||
|
||||
HighlightInfoType WRONG_REF = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
|
||||
|
||||
HighlightInfoType GENERIC_WARNINGS_OR_ERRORS_FROM_SERVER = new HighlightInfoTypeImpl(
|
||||
HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING, CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING);
|
||||
HighlightInfoType GENERIC_WARNINGS_OR_ERRORS_FROM_SERVER = new HighlightInfoTypeImpl(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING, CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING);
|
||||
|
||||
HighlightInfoType DUPLICATE_FROM_SERVER = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.DUPLICATE_FROM_SERVER);
|
||||
|
||||
@@ -65,25 +64,28 @@ public interface HighlightInfoType {
|
||||
HighlightDisplayKey.findOrRegister(DEPRECATION_SHORT_NAME, DEPRECATION_DISPLAY_NAME, DEPRECATION_ID),
|
||||
CodeInsightColors.DEPRECATED_ATTRIBUTES);
|
||||
|
||||
HighlightInfoType LOCAL_VARIABLE = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES);
|
||||
HighlightInfoType INSTANCE_FIELD = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES);
|
||||
HighlightInfoType STATIC_FIELD = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.STATIC_FIELD_ATTRIBUTES);
|
||||
HighlightInfoType PARAMETER = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.PARAMETER_ATTRIBUTES);
|
||||
HighlightSeverity SYMBOL_TYPE_SEVERITY = new HighlightSeverity("SYMBOL_TYPE_SEVERITY", HighlightSeverity.INFORMATION.myVal-2);
|
||||
|
||||
HighlightInfoType LOCAL_VARIABLE = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES);
|
||||
HighlightInfoType INSTANCE_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES);
|
||||
HighlightInfoType STATIC_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_FIELD_ATTRIBUTES);
|
||||
HighlightInfoType PARAMETER = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.PARAMETER_ATTRIBUTES);
|
||||
HighlightInfoType METHOD_CALL = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.METHOD_CALL_ATTRIBUTES);
|
||||
HighlightInfoType METHOD_DECLARATION = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.METHOD_DECLARATION_ATTRIBUTES);
|
||||
HighlightInfoType CONSTRUCTOR_CALL = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES);
|
||||
HighlightInfoType CONSTRUCTOR_DECLARATION = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES);
|
||||
HighlightInfoType STATIC_METHOD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
|
||||
HighlightInfoType CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CLASS_NAME_ATTRIBUTES);
|
||||
HighlightInfoType INTERFACE_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
|
||||
HighlightInfoType TYPE_PARAMETER_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ABSTRACT_CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ANNOTATION_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ANNOTATION_ATTRIBUTE_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES);
|
||||
HighlightInfoType REASSIGNED_LOCAL_VARIABLE = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES);
|
||||
HighlightInfoType REASSIGNED_PARAMETER = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.REASSIGNED_PARAMETER_ATTRIBUTES);
|
||||
HighlightInfoType IMPLICIT_ANONYMOUS_CLASS_PARAMETER = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES);
|
||||
|
||||
HighlightInfoType TODO = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, null); // t.o.d.o attributes depend on the t.o.d.o text
|
||||
HighlightInfoType METHOD_CALL = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.METHOD_CALL_ATTRIBUTES);
|
||||
HighlightInfoType METHOD_DECLARATION = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.METHOD_DECLARATION_ATTRIBUTES);
|
||||
HighlightInfoType CONSTRUCTOR_CALL = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES);
|
||||
HighlightInfoType CONSTRUCTOR_DECLARATION = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES);
|
||||
HighlightInfoType STATIC_METHOD = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
|
||||
HighlightInfoType CLASS_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.CLASS_NAME_ATTRIBUTES);
|
||||
HighlightInfoType INTERFACE_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
|
||||
HighlightInfoType TYPE_PARAMETER_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ABSTRACT_CLASS_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ANNOTATION_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES);
|
||||
HighlightInfoType ANNOTATION_ATTRIBUTE_NAME = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES);
|
||||
HighlightInfoType REASSIGNED_LOCAL_VARIABLE = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES);
|
||||
HighlightInfoType REASSIGNED_PARAMETER = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.REASSIGNED_PARAMETER_ATTRIBUTES);
|
||||
HighlightInfoType IMPLICIT_ANONYMOUS_CLASS_PARAMETER = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES);
|
||||
HighlightInfoType UNHANDLED_EXCEPTION = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.ERRORS_ATTRIBUTES);
|
||||
|
||||
HighlightSeverity INJECTED_FRAGMENT_SEVERITY = new HighlightSeverity("INJECTED_FRAGMENT_SEVERITY", HighlightSeverity.INFORMATION.myVal-1);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
|
||||
private final JDOMExternalizableStringList myOrder = new JDOMExternalizableStringList();
|
||||
private JDOMExternalizableStringList myReadOrder;
|
||||
|
||||
private static final Map<String, HighlightInfoType> STANDARD_SEVERITIES = new HashMap<String, HighlightInfoType>();
|
||||
private static final Map<String, HighlightInfoType> STANDARD_SEVERITIES = new THashMap<String, HighlightInfoType>();
|
||||
|
||||
static {
|
||||
STANDARD_SEVERITIES.put(HighlightSeverity.ERROR.toString(), HighlightInfoType.ERROR);
|
||||
@@ -102,7 +102,7 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
|
||||
return collection;
|
||||
}
|
||||
|
||||
private SeverityBasedTextAttributes getSeverityBasedTextAttributes(HighlightInfoType type) {
|
||||
private SeverityBasedTextAttributes getSeverityBasedTextAttributes(@NotNull HighlightInfoType type) {
|
||||
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
|
||||
final TextAttributes textAttributes = scheme.getAttributes(type.getAttributesKey());
|
||||
if (textAttributes != null) {
|
||||
@@ -169,7 +169,7 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
|
||||
myOrder.retainAll(knownSeverities);
|
||||
|
||||
if (myOrder.isEmpty()) {
|
||||
myOrder.addAll(getDefaultOrder());
|
||||
myOrder.addAll(knownSeverities);
|
||||
}
|
||||
//enforce include all known
|
||||
for (int i = 0; i < knownSeverities.size(); i++) {
|
||||
|
||||
+26
-17
@@ -121,6 +121,10 @@ public class UpdateHighlightersUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isCoveredBy(HighlightInfo info, HighlightInfo coveredBy) {
|
||||
return coveredBy.startOffset <= info.startOffset && info.endOffset <= coveredBy.endOffset && info.getGutterIconRenderer() == null;
|
||||
}
|
||||
|
||||
private static class HighlightersRecycler {
|
||||
private final MultiMap<TextRange, RangeHighlighter> incinerator = new MultiMap<TextRange, RangeHighlighter>(){
|
||||
@Override
|
||||
@@ -167,10 +171,17 @@ public class UpdateHighlightersUtil {
|
||||
@NotNull Map<TextRange, RangeMarker> ranges2markersCache) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
if (info.isFileLevelAnnotation || info.getGutterIconRenderer() != null) return;
|
||||
if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset) return;
|
||||
|
||||
MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
|
||||
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(project);
|
||||
final boolean myInfoIsError = isSevereError(info, severityRegistrar);
|
||||
Processor<HighlightInfo> otherHighlightInTheWayProcessor = new Processor<HighlightInfo>() {
|
||||
public boolean process(HighlightInfo oldInfo) {
|
||||
if (!myInfoIsError && isSevereError(oldInfo, severityRegistrar) && isCoveredBy(info, oldInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return oldInfo.group != group || !oldInfo.equalsByActualOffset(info);
|
||||
}
|
||||
};
|
||||
@@ -180,10 +191,7 @@ public class UpdateHighlightersUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset) return;
|
||||
|
||||
createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx)markup, null, ranges2markersCache,
|
||||
SeverityRegistrar.getInstance(project));
|
||||
createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx)markup, null, ranges2markersCache, severityRegistrar);
|
||||
|
||||
clearWhiteSpaceOptimizationFlag(document);
|
||||
assertMarkupConsistent(markup, project);
|
||||
@@ -373,10 +381,10 @@ public class UpdateHighlightersUtil {
|
||||
private static boolean isWarningCoveredByError(HighlightInfo info,
|
||||
Collection<HighlightInfo> overlappingIntervals,
|
||||
SeverityRegistrar severityRegistrar) {
|
||||
if (!isError(info, severityRegistrar)) {
|
||||
if (!isSevereError(info, severityRegistrar)) {
|
||||
for (HighlightInfo overlapping : overlappingIntervals) {
|
||||
boolean overlapIsError = isError(overlapping, severityRegistrar);
|
||||
if (overlapIsError && DaemonCodeAnalyzerImpl.isCoveredBy(info, overlapping)) {
|
||||
boolean overlapIsError = isSevereError(overlapping, severityRegistrar);
|
||||
if (overlapIsError && isCoveredBy(info, overlapping)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -384,20 +392,21 @@ public class UpdateHighlightersUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isError(HighlightInfo info, SeverityRegistrar severityRegistrar) {
|
||||
return severityRegistrar.compare(HighlightSeverity.ERROR, info.getSeverity()) <= 0;
|
||||
private static boolean isSevereError(HighlightInfo info, SeverityRegistrar severityRegistrar) {
|
||||
HighlightSeverity severity = info.getSeverity();
|
||||
return severityRegistrar.compare(HighlightSeverity.ERROR, severity) <= 0 || severity == HighlightInfoType.SYMBOL_TYPE_SEVERITY;
|
||||
}
|
||||
|
||||
// return true if changed
|
||||
private static RangeHighlighter createOrReuseHighlighterFor(@NotNull final HighlightInfo info,
|
||||
@Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
|
||||
@NotNull final Document document,
|
||||
final int group,
|
||||
@NotNull final PsiFile psiFile,
|
||||
@NotNull MarkupModelEx markup,
|
||||
@Nullable HighlightersRecycler infosToRemove,
|
||||
@NotNull final Map<TextRange, RangeMarker> ranges2markersCache,
|
||||
SeverityRegistrar severityRegistrar) {
|
||||
@Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
|
||||
@NotNull final Document document,
|
||||
final int group,
|
||||
@NotNull final PsiFile psiFile,
|
||||
@NotNull MarkupModelEx markup,
|
||||
@Nullable HighlightersRecycler infosToRemove,
|
||||
@NotNull final Map<TextRange, RangeMarker> ranges2markersCache,
|
||||
SeverityRegistrar severityRegistrar) {
|
||||
final int infoStartOffset = info.startOffset;
|
||||
int infoEndOffset = info.endOffset;
|
||||
|
||||
|
||||
@@ -96,10 +96,6 @@ public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExt
|
||||
return myVal - highlightSeverity.myVal;
|
||||
}
|
||||
|
||||
public void setVal(final int val) {
|
||||
myVal = val;
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
}
|
||||
|
||||
+62
-22
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeveritiesProvider;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -64,22 +65,21 @@ public class ExpectedHighlightingData {
|
||||
@NonNls private static final String END_LINE_WARNING_MARKER = "EOLWarning";
|
||||
@NonNls private static final String LINE_MARKER = "lineMarker";
|
||||
|
||||
@NotNull private final Document myDocument;
|
||||
private final PsiFile myFile;
|
||||
@NonNls private static final String ANY_TEXT = "*";
|
||||
String myText;
|
||||
private final String myText;
|
||||
|
||||
public static class ExpectedHighlightingSet {
|
||||
private static class ExpectedHighlightingSet {
|
||||
private final boolean endOfLine;
|
||||
final boolean enabled;
|
||||
final Set<HighlightInfo> infos;
|
||||
final HighlightInfoType defaultErrorType;
|
||||
final HighlightSeverity severity;
|
||||
|
||||
public ExpectedHighlightingSet(HighlightInfoType defaultErrorType, HighlightSeverity severity, boolean endOfLine, boolean enabled) {
|
||||
public ExpectedHighlightingSet(@NotNull HighlightSeverity severity, boolean endOfLine, boolean enabled) {
|
||||
this.endOfLine = endOfLine;
|
||||
this.enabled = enabled;
|
||||
infos = new THashSet<HighlightInfo>();
|
||||
this.defaultErrorType = defaultErrorType;
|
||||
this.severity = severity;
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,16 @@ public class ExpectedHighlightingData {
|
||||
protected final Map<String,ExpectedHighlightingSet> highlightingTypes;
|
||||
private final Map<RangeMarker, LineMarkerInfo> lineMarkerInfos = new THashMap<RangeMarker, LineMarkerInfo>();
|
||||
|
||||
public void init() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
extractExpectedLineMarkerSet(myDocument);
|
||||
extractExpectedHighlightsSet(myDocument);
|
||||
refreshLineMarkers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ExpectedHighlightingData(@NotNull Document document,boolean checkWarnings, boolean checkInfos) {
|
||||
this(document, checkWarnings, false, checkInfos);
|
||||
}
|
||||
@@ -98,35 +108,64 @@ public class ExpectedHighlightingData {
|
||||
this(document, checkWarnings, checkWeakWarnings, checkInfos, null);
|
||||
}
|
||||
|
||||
public ExpectedHighlightingData(@NotNull final Document document,
|
||||
final boolean checkWarnings,
|
||||
final boolean checkWeakWarnings,
|
||||
final boolean checkInfos,
|
||||
PsiFile file) {
|
||||
public ExpectedHighlightingData(@NotNull final Document document, PsiFile file) {
|
||||
myDocument = document;
|
||||
myFile = file;
|
||||
myText = document.getText();
|
||||
highlightingTypes = new LinkedHashMap<String,ExpectedHighlightingSet>();
|
||||
new WriteCommandAction.Simple(file == null ? null : file.getProject()) {
|
||||
public void run() {
|
||||
highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, false, true));
|
||||
highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, false, checkWarnings));
|
||||
highlightingTypes.put(INFORMATION_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WEAK_WARNING, HighlightSeverity.WEAK_WARNING, false, checkWeakWarnings));
|
||||
highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos));
|
||||
highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightInfoType.TODO, HighlightSeverity.INFORMATION, false, checkInfos));
|
||||
boolean checkWarnings= false;
|
||||
boolean checkWeakWarnings = false;
|
||||
boolean checkInfos = false;
|
||||
|
||||
|
||||
|
||||
highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, false, true));
|
||||
highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, checkWarnings));
|
||||
highlightingTypes.put(INFORMATION_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, checkWeakWarnings));
|
||||
highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos));
|
||||
highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, checkInfos));
|
||||
highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false));
|
||||
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
|
||||
for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) {
|
||||
final HighlightSeverity severity = type.getSeverity(null);
|
||||
highlightingTypes.put(severity.toString(), new ExpectedHighlightingSet(type, severity, false, true));
|
||||
highlightingTypes.put(severity.toString(), new ExpectedHighlightingSet(severity, false, true));
|
||||
}
|
||||
}
|
||||
highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER,new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, true, true));
|
||||
highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, true, checkWarnings));
|
||||
highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, true, true));
|
||||
highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, checkWarnings));
|
||||
initAdditionalHighlightingTypes();
|
||||
extractExpectedLineMarkerSet(document);
|
||||
extractExpectedHighlightsSet(document);
|
||||
refreshLineMarkers();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
}
|
||||
public ExpectedHighlightingData(@NotNull final Document document,
|
||||
final boolean checkWarnings,
|
||||
final boolean checkWeakWarnings,
|
||||
final boolean checkInfos,
|
||||
PsiFile file) {
|
||||
this(document, file);
|
||||
if (checkWarnings) checkWarnings();
|
||||
if (checkWeakWarnings) checkWeakWarnings();
|
||||
if (checkInfos) checkInfos();
|
||||
}
|
||||
|
||||
public void checkWarnings() {
|
||||
highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, true));
|
||||
highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, true));
|
||||
|
||||
}
|
||||
public void checkWeakWarnings() {
|
||||
highlightingTypes.put(INFORMATION_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, true));
|
||||
}
|
||||
public void checkInfos() {
|
||||
highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true));
|
||||
highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true));
|
||||
|
||||
}
|
||||
public void checkSymbolNames() {
|
||||
highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true));
|
||||
}
|
||||
|
||||
private void refreshLineMarkers() {
|
||||
@@ -242,7 +281,8 @@ public class ExpectedHighlightingData {
|
||||
Field field = HighlightInfoType.class.getField(typeString);
|
||||
type = (HighlightInfoType)field.get(null);
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
LOG.assertTrue(type != null, "Wrong highlight type: " + typeString);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.testFramework;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class HighlightTestInfo implements Disposable {
|
||||
@NotNull protected final String[] filePaths;
|
||||
protected boolean checkWarnings;
|
||||
protected boolean checkInfos;
|
||||
protected boolean checkSymbolNames;
|
||||
protected boolean checkWeakWarnings;
|
||||
protected String projectRoot;
|
||||
private boolean tested;
|
||||
private final String myPlace;
|
||||
|
||||
public HighlightTestInfo(@NotNull Disposable parentDisposable, @NonNls @NotNull String... filePaths) {
|
||||
this.filePaths = filePaths;
|
||||
// disposer here for catching the case of not calling test()
|
||||
Disposer.register(parentDisposable, this);
|
||||
myPlace = parentDisposable.toString();
|
||||
}
|
||||
public HighlightTestInfo checkWarnings() { checkWarnings = true; return this; }
|
||||
public HighlightTestInfo checkWeakWarnings() { checkWeakWarnings = true; return this; }
|
||||
public HighlightTestInfo checkInfos() { checkInfos = true; return this; }
|
||||
public HighlightTestInfo checkSymbolNames() { checkSymbolNames = true; return this; }
|
||||
public HighlightTestInfo projectRoot(@NonNls @NotNull String root) { projectRoot = root; return this; }
|
||||
|
||||
public HighlightTestInfo test() throws Exception {
|
||||
doTest();
|
||||
tested = true;
|
||||
Disposer.dispose(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
assert tested : "You must call HighlightTestInfo.test() in " + myPlace;
|
||||
}
|
||||
|
||||
protected abstract HighlightTestInfo doTest() throws Exception;
|
||||
}
|
||||
@@ -463,10 +463,13 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
checkForSettingsDamage();
|
||||
doTearDown(getProject(), ourApplication, true);
|
||||
|
||||
super.tearDown();
|
||||
|
||||
myThreadTracker.checkLeak();
|
||||
((InjectedLanguageManagerImpl)InjectedLanguageManager.getInstance(getProject())).checkInjectorsAreDisposed();
|
||||
try {
|
||||
super.tearDown();
|
||||
}
|
||||
finally {
|
||||
myThreadTracker.checkLeak();
|
||||
((InjectedLanguageManagerImpl)InjectedLanguageManager.getInstance(getProject())).checkInjectorsAreDisposed();
|
||||
}
|
||||
}
|
||||
|
||||
public static void doTearDown(final Project project, IdeaTestApplication application, boolean checkForEditors) throws Exception {
|
||||
|
||||
@@ -68,7 +68,17 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
private static final String ORIGINAL_TEMP_DIR = FileUtil.getTempDirectory();
|
||||
public static final String IDEA_MARKER_CLASS = "com.intellij.openapi.components.impl.stores.IdeaProjectStoreImpl";
|
||||
|
||||
protected final Disposable myTestRootDisposable = Disposer.newDisposable();
|
||||
protected final Disposable myTestRootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String testName = getTestName(false);
|
||||
return UsefulTestCase.this.getClass() + (StringUtil.isEmpty(testName) ? "" : ".test" + testName);
|
||||
}
|
||||
};
|
||||
private CodeStyleSettings myOldCodeStyleSettings;
|
||||
private String myTempDir;
|
||||
|
||||
|
||||
+2
@@ -37,6 +37,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.testFramework.HighlightTestInfo;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -147,6 +148,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
|
||||
long testHighlighting(@NonNls String... filePaths);
|
||||
|
||||
long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, VirtualFile file);
|
||||
HighlightTestInfo testFile(@NonNls @NotNull String... filePath);
|
||||
|
||||
void testInspection(String testDir, InspectionTool tool);
|
||||
|
||||
|
||||
+22
-12
@@ -360,8 +360,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
assertNotNull(psiFile);
|
||||
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
|
||||
assertNotNull(document);
|
||||
return Trinity.create(psiFile, createEditor(file),
|
||||
new ExpectedHighlightingData(document, checkWarnings, checkWeakWarnings, checkInfos, psiFile));
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(document, checkWarnings, checkWeakWarnings, checkInfos, psiFile);
|
||||
data.init();
|
||||
return Trinity.create(psiFile, createEditor(file), data);
|
||||
}
|
||||
});
|
||||
for (Trinity<PsiFile, Editor, ExpectedHighlightingData> trinity : datas) {
|
||||
@@ -409,6 +410,21 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HighlightTestInfo testFile(@NonNls @NotNull String... filePath) {
|
||||
return new HighlightTestInfo(getTestRootDisposable(), filePath){
|
||||
@Override
|
||||
public HighlightTestInfo doTest() throws Exception {
|
||||
configureByFiles(filePaths);
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
if (checkSymbolNames) data.checkSymbolNames();
|
||||
data.init();
|
||||
collectAndCheckHighlightings(data, Ref.create(0L));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void openFileInEditor(@NotNull final VirtualFile file) {
|
||||
myFile = myPsiManager.findFile(file);
|
||||
myEditor = createEditor(file);
|
||||
@@ -1305,7 +1321,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
throws Exception {
|
||||
ExpectedHighlightingData data =
|
||||
new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
|
||||
data.init();
|
||||
collectAndCheckHighlightings(data, duration);
|
||||
}
|
||||
|
||||
@@ -1364,13 +1380,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@NotNull
|
||||
public List<HighlightInfo> doHighlighting() {
|
||||
final Project project = getProject();
|
||||
new WriteCommandAction.Simple(project) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
return
|
||||
ApplicationManager.getApplication().runReadAction(new Computable<List<HighlightInfo>>() {
|
||||
@@ -1430,7 +1440,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return myFile;
|
||||
}
|
||||
|
||||
public static List<IntentionAction> getAvailableIntentions(final Editor editor, final PsiFile file) {
|
||||
public static List<IntentionAction> getAvailableIntentions(@NotNull final Editor editor, @NotNull final PsiFile file) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<List<IntentionAction>>() {
|
||||
@Override
|
||||
public List<IntentionAction> compute() {
|
||||
@@ -1439,7 +1449,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
});
|
||||
}
|
||||
|
||||
private static List<IntentionAction> doGetAvailableIntentions(Editor editor, PsiFile file) {
|
||||
private static List<IntentionAction> doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) {
|
||||
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
|
||||
ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
|
||||
List<HighlightInfo.IntentionActionDescriptor> descriptors = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
|
||||
@@ -188,6 +188,7 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide
|
||||
final PsiFile file = myTestFixture.getFile();
|
||||
final Document doc = myTestFixture.getEditor().getDocument();
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(doc, true, checkWeakWarnings, false, file);
|
||||
data.init();
|
||||
PsiDocumentManager.getInstance(myTestFixture.getProject()).commitAllDocuments();
|
||||
|
||||
Collection<HighlightInfo> highlights1 = doHighlighting(includeExternalToolPass);
|
||||
|
||||
Reference in New Issue
Block a user