This commit is contained in:
Roman Shevchenko
2011-03-07 22:01:52 +01:00
parent a39faeffca
commit a9c8cd157b
8 changed files with 143 additions and 132 deletions
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2009 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.codeInsight.daemon.impl;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.editor.SyntaxHighlighterColors;
import com.intellij.openapi.editor.colors.CodeInsightColors;
/**
* @author anna
* Date: 01-Feb-2008
*/
public interface JavaHighlightInfoTypes extends HighlightInfoType {
HighlightInfoType UNUSED_IMPORT = new HighlightInfoType.HighlightInfoTypeSeverityByKey(
HighlightDisplayKey.findOrRegister(UnusedImportLocalInspection.SHORT_NAME, UnusedImportLocalInspection.DISPLAY_NAME),
CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
HighlightInfoType JAVA_KEYWORD = new HighlightInfoType.HighlightInfoTypeImpl(
HighlightSeverity.INFORMATION, SyntaxHighlighterColors.KEYWORD);
}
@@ -1,43 +0,0 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 01-Feb-2008
*/
package com.intellij.codeInsight.daemon.impl;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection;
import com.intellij.openapi.editor.colors.CodeInsightColors;
public class JavaHightlightInfoTypes {
public static final HighlightInfoType UNUSED_IMPORT = new HighlightInfoType.HighlightInfoTypeSeverityByKey(
HighlightDisplayKey.find(UnusedImportLocalInspection.SHORT_NAME) == null ?
HighlightDisplayKey.register(UnusedImportLocalInspection.SHORT_NAME, UnusedImportLocalInspection.DISPLAY_NAME) : HighlightDisplayKey.find(UnusedImportLocalInspection.SHORT_NAME), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
public static final HighlightInfoType JAVADOC_WRONG_REF = new HighlightInfoType.HighlightInfoTypeSeverityByKey(HighlightDisplayKey.find(
JavaDocReferenceInspection.SHORT_NAME) == null ?
HighlightDisplayKey.register(JavaDocReferenceInspection.SHORT_NAME, JavaDocReferenceInspection.DISPLAY_NAME) : HighlightDisplayKey.find(JavaDocReferenceInspection.SHORT_NAME), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
public static final HighlightInfoType UNCHECKED_WARNING = new HighlightInfoType.HighlightInfoTypeSeverityByKeyAttrBySeverity(HighlightDisplayKey.find(
UncheckedWarningLocalInspection.SHORT_NAME) == null ?
HighlightDisplayKey.register(UncheckedWarningLocalInspection.SHORT_NAME, UncheckedWarningLocalInspection.DISPLAY_NAME, UncheckedWarningLocalInspection.ID) : HighlightDisplayKey.find(UncheckedWarningLocalInspection.SHORT_NAME));
private JavaHightlightInfoTypes() {
}
}
@@ -674,7 +674,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
}
private HighlightInfo registerRedundantImport(PsiImportStatementBase importStatement, HighlightDisplayKey unusedImportKey) {
HighlightInfo info = HighlightInfo.createHighlightInfo(JavaHightlightInfoTypes.UNUSED_IMPORT, importStatement, InspectionsBundle.message("unused.import.statement"));
HighlightInfo info = HighlightInfo.createHighlightInfo(JavaHighlightInfoTypes.UNUSED_IMPORT, importStatement, InspectionsBundle.message("unused.import.statement"));
QuickFixAction.registerQuickFixAction(info, new OptimizeImportsFix(), unusedImportKey);
QuickFixAction.registerQuickFixAction(info, new EnableOptimizeImportsOnTheFlyFix(), unusedImportKey);
@@ -533,7 +533,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIllegalVoidType(keyword));
if (PsiTreeUtil.getParentOfType(keyword, PsiDocTagValue.class) != null) {
myHolder.add(HighlightInfo.createHighlightInfo(HighlightInfoType.JAVA_KEYWORD, keyword, null));
myHolder.add(HighlightInfo.createHighlightInfo(JavaHighlightInfoTypes.JAVA_KEYWORD, keyword, null));
}
}
@@ -79,21 +79,21 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
public void testImportDefaultPackage2() throws Exception { doTest(BASE_PATH+"/importDefaultPackage/x/ImportOnDemandUsage.java", BASE_PATH+"/importDefaultPackage", false, false); }
public void testScopeBased() throws Exception {
NamedScope xscope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null));
NamedScope utilscope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null));
NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject());
scopeManager.addScope(xscope);
scopeManager.addScope(utilscope);
scopeManager.addScope(xScope);
scopeManager.addScope(utilScope);
EditorColorsManager manager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone();
manager.addColorsScheme(scheme);
EditorColorsManager.getInstance().setGlobalScheme(scheme);
TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xscope.getName());
TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xScope.getName());
TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC);
scheme.setAttributes(xKey, xAttributes);
TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilscope.getName());
TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilScope.getName());
TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD);
scheme.setAttributes(utilKey, utilAttributes);
@@ -105,21 +105,21 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
}
}
public void testSharedScopeBased() throws Exception {
NamedScope xscope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null));
NamedScope utilscope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null));
NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null));
NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject());
scopeManager.addScope(xscope);
scopeManager.addScope(utilscope);
scopeManager.addScope(xScope);
scopeManager.addScope(utilScope);
EditorColorsManager manager = EditorColorsManager.getInstance();
EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone();
manager.addColorsScheme(scheme);
EditorColorsManager.getInstance().setGlobalScheme(scheme);
TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xscope.getName());
TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xScope.getName());
TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC);
scheme.setAttributes(xKey, xAttributes);
TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilscope.getName());
TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilScope.getName());
TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD);
scheme.setAttributes(utilKey, utilAttributes);
@@ -158,6 +158,7 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
}
});
assert root != null;
configureByExistingFile(root.findFileByRelativePath("moduleJava5/com/Java5.java"));
Collection<HighlightInfo> infos = highlightErrors();
assertEmpty(infos);
@@ -168,6 +169,7 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
loadAllModulesUnder(root);
assert root != null;
configureByExistingFile(root.findFileByRelativePath("client/src/BugTest.java"));
Collection<HighlightInfo> infos = highlightErrors();
assertEmpty(infos);
@@ -178,12 +180,18 @@ public class AdvHighlightingTest extends DaemonAnalyzerTestCase {
VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
loadAllModulesUnder(root);
assert root != null;
configureByExistingFile(root.findFileByRelativePath("src/ppp/SomeClass.java"));
PsiField field = ((PsiJavaFile)myFile).getClasses()[0].findFieldByName("f", false);
assert field != null;
PsiClass aClass = ((PsiClassType)field.getType()).resolve();
assert aClass != null;
assertEquals("ppp.BadClass", aClass.getQualifiedName());
//lies in source
assertEquals(myFile.getVirtualFile().getParent(), aClass.getContainingFile().getVirtualFile().getParent());
final VirtualFile vFile1 = myFile.getVirtualFile();
final VirtualFile vFile2 = aClass.getContainingFile().getVirtualFile();
assert vFile1 != null;
assert vFile2 != null;
assertEquals(vFile1.getParent(), vFile2.getParent());
}
}
@@ -4,8 +4,6 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
@@ -47,9 +45,7 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testInlineTagAsDescription() throws Exception {
doTest();
}
public void testInlineTagAsDescription() throws Exception { doTest(); }
public void testParam0() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); }
public void testParam1() throws Exception { doTest(); }
@@ -62,8 +58,8 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testSee3() throws Exception { doTest(); }
public void testSee4() throws Exception { doTest(); }
public void testSee5() throws Exception { doTest(); }
public void testSee6() throws Exception {doTest();}
public void testSeeConstants() throws Exception { doTest();}
public void testSee6() throws Exception { doTest(); }
public void testSeeConstants() throws Exception { doTest(); }
public void testReturn0() throws Exception { doTest(); }
public void testException0() throws Exception { doTest(); }
public void testException1() throws Exception { doTest(); }
@@ -73,7 +69,7 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testMultipleThrows() throws Exception { doTest(); }
public void testInheritJavaDoc() throws Exception {doTestWithLangLevel(LanguageLevel.JDK_1_3);}
public void testLink0() throws Exception { doTest(); }
public void testLinkFromInnerClassToSelfMethod() throws Exception {doTest();}
public void testLinkFromInnerClassToSelfMethod() throws Exception { doTest(); }
public void testValueBadReference() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); }
public void testValueGoodReference() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); }
@@ -83,20 +79,18 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testValueNotOnStaticField() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); }
public void testValueOnNotInitializedField() throws Exception { doTestWithLangLevel(LanguageLevel.HIGHEST); }
public void testUnknownInlineTag() throws Exception {doTest();}
public void testUnknownTags() throws Exception {doTest();}
public void testUnknownInlineTag() throws Exception { doTest(); }
public void testUnknownTags() throws Exception { doTest(); }
public void testBadCharacters() throws Exception {doTest();}
public void testBadCharacters() throws Exception { doTest(); }
public void testVararg() throws Exception {doTest();}
public void testVararg() throws Exception { doTest(); }
public void testInnerClassReferenceInSignature() throws Exception {doTest();}
public void testInnerClassReferenceInSignature() throws Exception { doTest(); }
public void testBadReference() throws Exception{
doTest();
}
public void testBadReference() throws Exception { doTest(); }
public void testMissingReturnDescription() throws Exception {doTest();}
public void testMissingReturnDescription() throws Exception { doTest(); }
private void doTestWithLangLevel(final LanguageLevel langLevel) throws Exception {
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(langLevel);