Added test checking names highlighting.

This commit is contained in:
Evgeny Gerashchenko
2012-04-05 17:42:54 +04:00
parent acbeae64ee
commit 33320075d6
6 changed files with 127 additions and 1 deletions
@@ -31,6 +31,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.diagnostics.*;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
@@ -48,6 +49,7 @@ import java.util.Set;
*/
public class JetPsiChecker implements Annotator {
private static volatile boolean errorReportingEnabled = true;
private static boolean namesHighlightingTest;
public static void setErrorReportingEnabled(boolean value) {
errorReportingEnabled = value;
@@ -57,8 +59,13 @@ public class JetPsiChecker implements Annotator {
return errorReportingEnabled;
}
@TestOnly
public static void setNamesHighlightingTest(boolean namesHighlightingTest) {
JetPsiChecker.namesHighlightingTest = namesHighlightingTest;
}
static boolean isNamesHighlightingEnabled() {
return !ApplicationManager.getApplication().isUnitTestMode();
return !ApplicationManager.getApplication().isUnitTestMode() || namesHighlightingTest;
}
static void highlightName(@NotNull AnnotationHolder holder,
+17
View File
@@ -0,0 +1,17 @@
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">global</info>() {
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">inner</info>() {
}
<info textAttributesKey="KOTLIN_FUNCTION_CALL">inner</info>()
}
fun Int.<info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">ext</info>() {
}
<info textAttributesKey="KOTLIN_KEYWORD">open</info> class <info textAttributesKey="KOTLIN_CLASS">Container</info> {
<info textAttributesKey="KOTLIN_KEYWORD">open</info> fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">member</info>() {
<info textAttributesKey="KOTLIN_NAMESPACE_FUNCTION_CALL">global</info>()
5.<info textAttributesKey="KOTLIN_EXTENSION_FUNCTION_CALL">ext</info>()
<info textAttributesKey="KOTLIN_FUNCTION_CALL">member</info>()
}
}
@@ -0,0 +1,12 @@
trait <info textAttributesKey="KOTLIN_TRAIT">TheTrait</info> {
}
class <info textAttributesKey="KOTLIN_CLASS">TheClass</info> : <info textAttributesKey="KOTLIN_TRAIT">TheTrait</info> {
}
<info textAttributesKey="KOTLIN_KEYWORD">annotation</info> class <info textAttributesKey="KOTLIN_ANNOTATION">magnificent</info>
<info textAttributesKey="KOTLIN_KEYWORD">annotation</info> class <info textAttributesKey="KOTLIN_ANNOTATION">deprecated</info>
[<info textAttributesKey="KOTLIN_ANNOTATION">deprecated</info>]
<info textAttributesKey="KOTLIN_ANNOTATION">magnificent</info> <info textAttributesKey="KOTLIN_KEYWORD">abstract</info> class <info textAttributesKey="KOTLIN_ABSTRACT_CLASS">AbstractClass</info><<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>> {
}
+25
View File
@@ -0,0 +1,25 @@
var <info textAttributesKey="KOTLIN_MUTABLE_VARIABLE"><info textAttributesKey="KOTLIN_PROPERTY_WITH_BACKING_FIELD"><info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY">x</info></info></info> = 5
val Int.<info textAttributesKey="KOTLIN_EXTENSION_PROPERTY">sq</info> : Int
<info textAttributesKey="KOTLIN_KEYWORD">get</info>() {
return this * this
}
val <info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_PROPERTY_WITH_BACKING_FIELD">y</info></info> : Int = 1
<info textAttributesKey="KOTLIN_KEYWORD">get</info>() {
return 5.<info textAttributesKey="KOTLIN_EXTENSION_PROPERTY">sq</info> + <info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_BACKING_FIELD_ACCESS">$y</info></info> + <info textAttributesKey="KOTLIN_MUTABLE_VARIABLE"><info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY">x</info></info>
}
class <info textAttributesKey="KOTLIN_CLASS">Foo</info>(val <info textAttributesKey="KOTLIN_PARAMETER"><info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_PROPERTY_WITH_BACKING_FIELD">a</info></info></info> : Int, <info textAttributesKey="KOTLIN_PARAMETER">b</info> : String) {
{
<info textAttributesKey="KOTLIN_PARAMETER">b</info>
}
var <info textAttributesKey="KOTLIN_MUTABLE_VARIABLE"><info textAttributesKey="KOTLIN_INSTANCE_PROPERTY">v</info></info> : Int
<info textAttributesKey="KOTLIN_KEYWORD">get</info>() {
return 1;
}
<info textAttributesKey="KOTLIN_KEYWORD">set</info>(<info textAttributesKey="KOTLIN_PARAMETER">value</info>) {
<info textAttributesKey="KOTLIN_PARAMETER">value</info>
}
}
@@ -0,0 +1,13 @@
var <info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_PROPERTY_WITH_BACKING_FIELD"><info textAttributesKey="KOTLIN_MUTABLE_VARIABLE">global</info></info></info> : () -> Unit = {}
val Int.<info textAttributesKey="KOTLIN_EXTENSION_PROPERTY">ext</info> : () -> Unit
<info textAttributesKey="KOTLIN_KEYWORD">get</info>() {
return {}
}
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>(<info textAttributesKey="KOTLIN_PARAMETER">a</info> : () -> Unit) {
<info textAttributesKey="KOTLIN_PARAMETER">a</info>()
<info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_MUTABLE_VARIABLE">global</info></info>()
// TODO uncomment next line and replace "[" with "<" when KT-1728 is fixed
// 1.[info textAttributesKey="KOTLIN_EXTENSION_PROPERTY">ext</info>()
}
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2012 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 org.jetbrains.jet.plugin;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import org.jetbrains.jet.plugin.highlighter.JetPsiChecker;
/**
* @author Evgeny Gerashchenko
* @since 4/4/12
*/
public class JetNamesHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testTypesAndAnnotations() throws Exception {
doTest();
}
public void testVariables() throws Exception {
doTest();
}
public void testFunctions() throws Exception {
doTest();
}
public void testVariablesAsFunctions() throws Exception {
doTest();
}
private void doTest() throws Exception {
JetPsiChecker.setNamesHighlightingTest(true);
doTest(getTestName(false) + ".kt", false, true);
}
@Override
protected String getTestDataPath() {
return PluginTestCaseBase.getTestDataPathBase() + "/highlighter/";
}
}