mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlighting for type parameters in Groovy
This commit is contained in:
@@ -221,6 +221,10 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resolveResult.getElement() instanceof PsiMember) {
|
||||
highlightMemberResolved(myHolder, refElement, ((PsiMember)resolveResult.getElement()));
|
||||
}
|
||||
|
||||
checkSingleResolvedElement(myHolder, refElement, resolveResult, true);
|
||||
|
||||
if (resolveResult.getElement() == null) {
|
||||
@@ -512,7 +516,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
@Override
|
||||
public void visitTypeDefinition(GrTypeDefinition typeDefinition) {
|
||||
final PsiElement parent = typeDefinition.getParent();
|
||||
if (!typeDefinition.isAnonymous() && !(parent instanceof GrTypeDefinitionBody || parent instanceof GroovyFile)) {
|
||||
if (!(typeDefinition.isAnonymous() || parent instanceof GrTypeDefinitionBody || parent instanceof GroovyFile || typeDefinition instanceof GrTypeParameter)) {
|
||||
final TextRange range = getClassHeaderTextRange(typeDefinition);
|
||||
final Annotation errorAnnotation =
|
||||
myHolder.createErrorAnnotation(range, GroovyBundle.message("class.definition.is.not.expected.here"));
|
||||
@@ -524,7 +528,12 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
checkDuplicateMethod(typeDefinition.getMethods(), myHolder);
|
||||
checkImplementedMethodsOfClass(myHolder, typeDefinition);
|
||||
checkConstructors(myHolder, typeDefinition);
|
||||
highligtClassReference(myHolder, typeDefinition.getNameIdentifierGroovy());
|
||||
if (typeDefinition instanceof GrTypeParameter) {
|
||||
highlightTypeParameterReference(myHolder, typeDefinition.getNameIdentifierGroovy());
|
||||
}
|
||||
else {
|
||||
highlightClassReference(myHolder, typeDefinition.getNameIdentifierGroovy());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkReferenceList(AnnotationHolder holder,
|
||||
@@ -1059,8 +1068,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
if (aPackage != null) {
|
||||
String packageName = aPackage.getQualifiedName();
|
||||
if (!packageName.equals(packageDefinition.getPackageName())) {
|
||||
final Annotation annotation = myHolder.createWarningAnnotation(packageDefinition, GroovyBundle
|
||||
.message("wrong.package.name", packageName, aPackage.getQualifiedName()));
|
||||
final Annotation annotation = myHolder.createWarningAnnotation(packageDefinition, GroovyBundle.message("wrong.package.name", packageName, aPackage.getQualifiedName()));
|
||||
annotation.registerFix(new ChangePackageQuickFix((GroovyFile)packageDefinition.getContainingFile(), packageName));
|
||||
annotation.registerFix(new GrMoveToDirFix(packageDefinition.getPackageName()));
|
||||
}
|
||||
@@ -1819,31 +1827,31 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void highlightMemberResolved(AnnotationHolder holder, GrReferenceExpression refExpr, PsiMember member) {
|
||||
private static void highlightMemberResolved(AnnotationHolder holder, GrReferenceElement refExpr, PsiMember member) {
|
||||
boolean isStatic = member.hasModifierProperty(PsiModifier.STATIC);
|
||||
final PsiElement refNameElement = getElementToHighlight(refExpr);
|
||||
Annotation annotation = holder.createInfoAnnotation(refNameElement, null);
|
||||
|
||||
if (member instanceof PsiField) {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD);
|
||||
return;
|
||||
}
|
||||
else if (member instanceof GrAccessorMethod) {
|
||||
annotation
|
||||
.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
return;
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
if (member instanceof PsiMethod) {
|
||||
else if (member instanceof PsiMethod) {
|
||||
if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)member)) {
|
||||
annotation
|
||||
.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
}
|
||||
else {
|
||||
annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL);
|
||||
}
|
||||
}
|
||||
if (member instanceof PsiClass) {
|
||||
highligtClassReference(holder, refExpr);
|
||||
else if (member instanceof PsiTypeParameter) {
|
||||
highlightTypeParameterReference(holder, refExpr);
|
||||
|
||||
}
|
||||
else if (member instanceof PsiClass) {
|
||||
highlightClassReference(holder, refExpr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1993,13 +2001,21 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
annotation.setTextAttributes(DefaultHighlighter.ANNOTATION);
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiTypeParameter) {
|
||||
highlightTypeParameterReference(holder, refElement);
|
||||
}
|
||||
else {
|
||||
highligtClassReference(holder, refElement);
|
||||
highlightClassReference(holder, refElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void highligtClassReference(AnnotationHolder holder, PsiElement classReference) {
|
||||
private static void highlightTypeParameterReference(AnnotationHolder holder, PsiElement element) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(element, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.TYPE_PARAMETER);
|
||||
}
|
||||
|
||||
private static void highlightClassReference(AnnotationHolder holder, PsiElement classReference) {
|
||||
final Annotation annotation = holder.createInfoAnnotation(classReference, null);
|
||||
annotation.setTextAttributes(DefaultHighlighter.CLASS_REFERENCE);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ public class DefaultHighlighter {
|
||||
@NonNls
|
||||
static final String CLASS_REFERENCE_ID = "Class";
|
||||
@NonNls
|
||||
static final String TYPE_PARAMETER_ID = "Type parameter";
|
||||
@NonNls
|
||||
static final String INSTANCE_PROPERTY_REFERENCE_ID = "Instance property reference ID";
|
||||
@NonNls
|
||||
static final String STATIC_PROPERTY_REFERENCE_ID = "Static property reference ID";
|
||||
@@ -130,6 +132,9 @@ public class DefaultHighlighter {
|
||||
public static TextAttributesKey CLASS_REFERENCE =
|
||||
TextAttributesKey.createTextAttributesKey(CLASS_REFERENCE_ID, HighlighterColors.TEXT.getDefaultAttributes().clone());
|
||||
|
||||
public static TextAttributesKey TYPE_PARAMETER =
|
||||
TextAttributesKey.createTextAttributesKey(TYPE_PARAMETER_ID, CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES.getDefaultAttributes().clone());
|
||||
|
||||
public static final TextAttributes INSTANCE_PROPERTY_REFERENCE_ATTRIBUTES = INSTANCE_FIELD.getDefaultAttributes().clone();
|
||||
public static final TextAttributes STATIC_PROPERTY_REFERENCE_ATTRIBUTES = STATIC_FIELD.getDefaultAttributes().clone();
|
||||
static {
|
||||
|
||||
+5
@@ -77,6 +77,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
new AttributesDescriptor("Static method call", DefaultHighlighter.STATIC_METHOD_ACCESS),
|
||||
new AttributesDescriptor("Method declaration", DefaultHighlighter.METHOD_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),
|
||||
new AttributesDescriptor("Instance property reference", DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE),
|
||||
new AttributesDescriptor("Static property reference", DefaultHighlighter.STATIC_PROPERTY_REFERENCE),
|
||||
@@ -115,6 +116,9 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
" return [<param>i</param>, <instfield>property</instfield>]\n" +
|
||||
" }\n" +
|
||||
" static def <statfield>panel</statfield> = new <classref>JPanel</classref>()\n" +
|
||||
" def <<typeparam>T</typeparam>> foo() {" +
|
||||
" <typeparam>T</typeparam> list = null" +
|
||||
" }\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"<classref>Demo</classref>.<statfield>panel</statfield>.size = " +
|
||||
@@ -141,6 +145,7 @@ public class GroovyColorsAndFontsPage implements ColorSettingsPage {
|
||||
map.put("doctag", DefaultHighlighter.DOC_COMMENT_TAG);
|
||||
map.put("unresolved", DefaultHighlighter.UNRESOLVED_ACCESS);
|
||||
map.put("classref", DefaultHighlighter.CLASS_REFERENCE);
|
||||
map.put("typeparam", DefaultHighlighter.TYPE_PARAMETER);
|
||||
map.put("literal", DefaultHighlighter.LITERAL_CONVERSION);
|
||||
map.put("mapkey", DefaultHighlighter.MAP_KEY);
|
||||
map.put("prop", DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE);
|
||||
|
||||
@@ -1034,7 +1034,7 @@ public @interface CompileStatic {
|
||||
}
|
||||
}
|
||||
''')
|
||||
myFixture.testHighlighting(true, true, false)
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user