IDEA-97659 Groovy color style for "Method declaration" is not in use

This commit is contained in:
Max Medvedev
2012-12-17 18:56:26 +04:00
parent 116b8ce362
commit a1f96bf916
6 changed files with 52 additions and 19 deletions
@@ -27,7 +27,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
@@ -47,6 +47,8 @@ import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
import java.util.Set;
import static org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter.*;
/**
* @author Max Medvedev
*/
@@ -103,44 +105,63 @@ public class GrHighlightUtil {
}
@Nullable
static TextAttributesKey getDeclarationHighlightingAttribute(PsiElement resolved) {
static TextAttributesKey getDeclarationHighlightingAttribute(PsiElement resolved, @Nullable PsiElement refElement) {
if (resolved instanceof PsiField || resolved instanceof GrVariable && ResolveUtil.isScriptField((GrVariable)resolved)) {
boolean isStatic = ((PsiVariable)resolved).hasModifierProperty(PsiModifier.STATIC);
return isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD;
return isStatic ? STATIC_FIELD : INSTANCE_FIELD;
}
else if (resolved instanceof GrAccessorMethod) {
boolean isStatic = ((GrAccessorMethod)resolved).hasModifierProperty(PsiModifier.STATIC);
return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE;
return isStatic ? STATIC_PROPERTY_REFERENCE : INSTANCE_PROPERTY_REFERENCE;
}
else if (resolved instanceof PsiMethod) {
if (!((PsiMethod)resolved).isConstructor()) {
boolean isStatic = ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC);
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)resolved)) {
return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE;
if (((PsiMethod)resolved).isConstructor()) {
if (refElement != null) {
if (refElement.getNode().getElementType() == GroovyTokenTypes.kTHIS || //don't highlight this() or super()
refElement.getNode().getElementType() == GroovyTokenTypes.kSUPER) {
return null;
}
else {
return CONSTRUCTOR_CALL;
}
}
else {
return isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL;
return CONSTRUCTOR_DECLARATION;
}
}
else {
boolean isStatic = ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC);
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)resolved)) {
return isStatic ? STATIC_PROPERTY_REFERENCE : INSTANCE_PROPERTY_REFERENCE;
}
else {
if (refElement != null) {
return isStatic ? STATIC_METHOD_ACCESS : METHOD_CALL;
}
else {
return METHOD_DECLARATION;
}
}
}
}
else if (resolved instanceof PsiTypeParameter) {
return DefaultHighlighter.TYPE_PARAMETER;
return TYPE_PARAMETER;
}
else if (resolved instanceof PsiClass) {
if (((PsiClass)resolved).isAnnotationType()) {
return DefaultHighlighter.ANNOTATION;
return ANNOTATION;
}
else {
return DefaultHighlighter.CLASS_REFERENCE;
return CLASS_REFERENCE;
}
}
else if (resolved instanceof GrParameter) {
boolean reassigned = isReassigned((GrParameter)resolved);
return reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER;
return reassigned ? REASSIGNED_PARAMETER : PARAMETER;
}
else if (resolved instanceof GrVariable) {
boolean reassigned = isReassigned((GrVariable)resolved);
return reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE;
return reassigned ? REASSIGNED_LOCAL_VARIABLE : LOCAL_VARIABLE;
}
return null;
}
@@ -136,6 +136,6 @@ public class GrKeywordAndDeclarationHighlighter extends TextEditorHighlightingPa
//don't highlight local vars and parameters here because their highlighting needs index.
if (GroovyRefactoringUtil.isLocalVariable(parent) || parent instanceof GrParameter) return null;
return GrHighlightUtil.getDeclarationHighlightingAttribute(parent);
return GrHighlightUtil.getDeclarationHighlightingAttribute(parent, null);
}
}
@@ -82,7 +82,7 @@ public class GrReferenceHighlighter extends TextEditorHighlightingPass {
super.visitVariable(variable);
if (GroovyRefactoringUtil.isLocalVariable(variable) || variable instanceof GrParameter) {
final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(variable);
final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(variable, null);
if (attribute != null) {
final PsiElement nameElement = variable.getNameIdentifierGroovy();
myInfos.add(HighlightInfo.createHighlightInfo(HighlightInfoType.INFORMATION, nameElement, null, attribute));
@@ -93,7 +93,7 @@ public class GrReferenceHighlighter extends TextEditorHighlightingPass {
private void visit(GrReferenceElement element) {
final PsiElement resolved = element.resolve();
final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(resolved);
final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(resolved, element);
if (attribute != null) {
final PsiElement refNameElement = GrHighlightUtil.getElementToHighlight(element);
myInfos.add(HighlightInfo.createHighlightInfo(HighlightInfoType.INFORMATION, refNameElement, null, attribute));
@@ -115,12 +115,19 @@ public class DefaultHighlighter {
TextAttributesKey.createTextAttributesKey("Groovy method declaration",
HighlightInfoType.METHOD_DECLARATION.getAttributesKey().getDefaultAttributes());
public static final TextAttributesKey CONSTRUCTOR_DECLARATION = TextAttributesKey
.createTextAttributesKey("Groovy constructor declaration",
HighlightInfoType.CONSTRUCTOR_DECLARATION.getAttributesKey().getDefaultAttributes());
public static final TextAttributesKey INSTANCE_FIELD =
TextAttributesKey.createTextAttributesKey(INSTANCE_FIELD_ID, HighlightInfoType.INSTANCE_FIELD.getAttributesKey().getDefaultAttributes());
public static final TextAttributesKey METHOD_CALL =
TextAttributesKey.createTextAttributesKey(METHOD_CALL_ID, HighlightInfoType.METHOD_CALL.getAttributesKey().getDefaultAttributes());
public static final TextAttributesKey CONSTRUCTOR_CALL = TextAttributesKey
.createTextAttributesKey("Groovy constructor call", HighlightInfoType.CONSTRUCTOR_CALL.getAttributesKey().getDefaultAttributes());
public static final TextAttributesKey STATIC_FIELD =
TextAttributesKey.createTextAttributesKey(STATIC_FIELD_ID, HighlightInfoType.STATIC_FINAL_FIELD.getAttributesKey().getDefaultAttributes());
@@ -73,9 +73,11 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
new AttributesDescriptor("Reassigned parameter", DefaultHighlighter.REASSIGNED_PARAMETER),
new AttributesDescriptor("Static field", DefaultHighlighter.STATIC_FIELD),
new AttributesDescriptor("Instance field", DefaultHighlighter.INSTANCE_FIELD),
new AttributesDescriptor("Constructor call", DefaultHighlighter.CONSTRUCTOR_CALL),
new AttributesDescriptor("Instance method call", DefaultHighlighter.METHOD_CALL),
new AttributesDescriptor("Static method call", DefaultHighlighter.STATIC_METHOD_ACCESS),
new AttributesDescriptor("Method declaration", DefaultHighlighter.METHOD_DECLARATION),
new AttributesDescriptor("Constructor declaration", DefaultHighlighter.CONSTRUCTOR_DECLARATION),
new AttributesDescriptor("Class reference", DefaultHighlighter.CLASS_REFERENCE),
new AttributesDescriptor("Type parameter reference", DefaultHighlighter.TYPE_PARAMETER),
new AttributesDescriptor("Map key accessed as a property", DefaultHighlighter.MAP_KEY),
@@ -107,6 +109,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
" */</gdoc>\n" +
"<annotation>@SpecialBean</annotation> \n" +
"<keyword>class</keyword> <classref>Demo</classref> {\n" +
" <keyword>public</keyword> <constructor>Demo</constructor>() {}\n" +
" <keyword>def</keyword> <instfield>property</instfield>\n" +
"//This is a line comment\n" +
"/* This is a block comment */\n" +
@@ -129,7 +132,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
"<label>label</label>:<keyword>def</keyword> <reLocal>f1</reLocal> = []\n" +
"<reLocal>f1</reLocal> = [2]\n" +
"<classref>File</classref> <local>f</local>=<literal>[</literal>'path'<literal>]</literal>\n" +
"<instmet>print</instmet> <keyword>new</keyword> <classref>Demo</classref>().<prop>property</prop>\n" +
"<instmet>print</instmet> <keyword>new</keyword> <constructorCall>Demo</constructorCall>().<prop>property</prop>\n" +
"<instmet>print</instmet> '<validescape>\\n</validescape> <invalidescape>\\x</invalidescape>'"
;
@@ -142,6 +145,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
map.put("annotation", DefaultHighlighter.ANNOTATION);
map.put("statmet", DefaultHighlighter.STATIC_METHOD_ACCESS);
map.put("instmet", DefaultHighlighter.METHOD_CALL);
map.put("constructorCall", DefaultHighlighter.CONSTRUCTOR_CALL);
map.put("statfield", DefaultHighlighter.STATIC_FIELD);
map.put("instfield", DefaultHighlighter.INSTANCE_FIELD);
map.put("gdoc", DefaultHighlighter.DOC_COMMENT_CONTENT);
@@ -160,6 +164,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
map.put("param", DefaultHighlighter.PARAMETER);
map.put("reParam", DefaultHighlighter.REASSIGNED_PARAMETER);
map.put("method", DefaultHighlighter.METHOD_DECLARATION);
map.put("constructor", DefaultHighlighter.CONSTRUCTOR_DECLARATION);
map.put("label", DefaultHighlighter.LABEL);
return map;
}
@@ -16,6 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
B () { <info descr="null">this</info>.<info descr="null">i</info> = 42 }
<info descr="null">B</info>() { <info descr="null">this</info>.<info descr="null">i</info> = 42 }
}
}