IDEA-227674: fix JavaColorProvider for scala

do not rely on exact number of parents, use `findContaining` instead

GitOrigin-RevId: 5b4590789c77b2c52c9135fbe64e7990d00c1e95
This commit is contained in:
Nikolay.Tropin
2019-12-26 19:55:29 +03:00
committed by intellij-monorepo-bot
parent 844bf6657b
commit 0858d89e31

View File

@@ -38,13 +38,14 @@ public class JavaColorProvider implements ElementColorProvider {
if (element instanceof PsiWhiteSpace) return null;
if (!myUastMetaLanguage.matchesLanguage(element.getLanguage())) return null;
PsiElement parent = element.getParent();
Color color = getJavaColorFromExpression(parent);
UCallExpression newExpression = UastUtils.findContaining(parent, UCallExpression.class);
Color color = getJavaColorFromExpression(parent, newExpression);
if (color == null) {
parent = parent == null ? null : parent.getParent();
color = getJavaColorFromExpression(parent);
}
UCallExpression newExpression = UastContextKt.toUElement(parent, UCallExpression.class);
if (newExpression != null) {
if (newExpression != null && color != null) {
UReferenceExpression uRef = newExpression.getClassReference();
String resolvedName = uRef == null ? null : uRef.getResolvedName();
if (resolvedName != null && element.textMatches(resolvedName)) {
@@ -73,7 +74,12 @@ public class JavaColorProvider implements ElementColorProvider {
@Nullable
public static Color getJavaColorFromExpression(@Nullable PsiElement element) {
UCallExpression newExpression = UastContextKt.toUElement(element, UCallExpression.class);
UCallExpression newExpression = UastUtils.findContaining(element, UCallExpression.class);
return getJavaColorFromExpression(element, newExpression);
}
@Nullable
private static Color getJavaColorFromExpression(@Nullable PsiElement element, @Nullable UCallExpression newExpression) {
if (newExpression != null && newExpression.getKind() == UastCallKind.CONSTRUCTOR_CALL &&
isColorType(newExpression.getReturnType())) {
return getColor(newExpression.getValueArguments());