[java] minor optimization (IDEA-CR-16521)

This commit is contained in:
Roman Shevchenko
2016-12-06 11:46:39 +01:00
parent 815cadf8e4
commit aa5275a82a
3 changed files with 48 additions and 4 deletions
@@ -0,0 +1,42 @@
/*
* Copyright 2000-2016 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.lang.java.lexer
import com.intellij.pom.java.LanguageLevel
import com.intellij.util.text.ByteArrayCharSequence
import com.intellij.util.text.CharArrayCharSequence
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class JavaKeywordsTest {
@Test fun hardAndSoft() {
assertTrue(JavaLexer.isKeyword("char", LanguageLevel.JDK_1_9))
assertFalse(JavaLexer.isSoftKeyword("char", LanguageLevel.JDK_1_9))
assertFalse(JavaLexer.isKeyword("module", LanguageLevel.JDK_1_9))
assertTrue(JavaLexer.isSoftKeyword("module", LanguageLevel.JDK_1_9))
}
@Test fun sequences() {
assertTrue(JavaLexer.isSoftKeyword(ByteArrayCharSequence.convertToBytesIfAsciiString("module"), LanguageLevel.JDK_1_9))
assertTrue(JavaLexer.isSoftKeyword(CharArrayCharSequence("[module]".toCharArray(), 1, 7), LanguageLevel.JDK_1_9))
}
@Test fun nullTolerance() {
assertFalse(JavaLexer.isKeyword(null, LanguageLevel.JDK_1_3))
assertFalse(JavaLexer.isSoftKeyword(null, LanguageLevel.JDK_1_9))
}
}