[groovy] allow 'trait' as package name (IDEA-127422)

This commit is contained in:
Daniil Ovchinnikov
2016-09-06 21:32:35 +03:00
parent cd8b579973
commit 8fd6e6d59d
3 changed files with 15 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* 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.
@@ -99,8 +99,8 @@ public class GrKeywordAndDeclarationHighlighter extends TextEditorHighlightingPa
if (parent instanceof GrArgumentLabel) return false; //don't highlight: print (void:'foo')
if (PsiTreeUtil.getParentOfType(element, GrCodeReferenceElement.class) != null) {
if (token == GroovyTokenTypes.kDEF || token == GroovyTokenTypes.kIN || token == GroovyTokenTypes.kAS) {
return false; //It is allowed to name packages 'as', 'in' or 'def'
if (TokenSets.CODE_REFERENCE_ELEMENT_NAME_TOKENS.contains(token)) {
return false; //It is allowed to name packages 'as', 'in', 'def' or 'trait'
}
}
else if (token == GroovyTokenTypes.kDEF && element.getParent() instanceof GrAnnotationNameValuePair) {
@@ -280,7 +280,8 @@ public abstract class TokenSets {
GroovyElementTypes.COMPOSITE_RSHIFT_SIGN,
GroovyElementTypes.COMPOSITE_TRIPLE_SHIFT_SIGN);
public static final TokenSet CODE_REFERENCE_ELEMENT_NAME_TOKENS = TokenSet.create(GroovyTokenTypes.mIDENT, GroovyTokenTypes.kDEF,
GroovyTokenTypes.kIN, GroovyTokenTypes.kAS);
GroovyTokenTypes.kIN, GroovyTokenTypes.kAS,
GroovyTokenTypes.kTRAIT);
public static final TokenSet BLOCK_SET = TokenSet.create(GroovyElementTypes.CLOSABLE_BLOCK, GroovyElementTypes.BLOCK_STATEMENT,
GroovyElementTypes.CONSTRUCTOR_BODY, GroovyElementTypes.OPEN_BLOCK,
@@ -2011,4 +2011,14 @@ def foo = new <error descr="Cannot resolve symbol 'Rrrrrrrr'">Rrrrrrrr</error>()
void testLocalVariableModifiers() { doTest() }
void testFieldModifiers() { doTest() }
void "test allow and do not highlight 'trait', 'as', 'def', 'in' within package"() {
myFixture.addClass '''\
package a.b.c.trait.d.as.e.def.f.in.g;
public class Foo {}
'''
testHighlighting '''\
<info>import</info> a.b.c.trait.d.as.e.def.f.in.g.*
''', false, true
}
}