mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight implicit constructor call as method (IDEA-152964)
This commit is contained in:
+9
-4
@@ -52,8 +52,11 @@ public class HighlightNamesUtil {
|
||||
return highlightMethodName(method, elementToHighlight, elementToHighlight.getTextRange(), colorsScheme, isDeclaration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param methodOrClass method to highlight; class is passed instead of implicit constructor
|
||||
*/
|
||||
@Nullable
|
||||
static HighlightInfo highlightMethodName(@NotNull PsiMethod method,
|
||||
static HighlightInfo highlightMethodName(@NotNull PsiMember methodOrClass,
|
||||
@NotNull PsiElement elementToHighlight,
|
||||
@NotNull TextRange range,
|
||||
@NotNull TextAttributesScheme colorsScheme,
|
||||
@@ -62,7 +65,7 @@ public class HighlightNamesUtil {
|
||||
|
||||
if (!isDeclaration) {
|
||||
if (isCalledOnThis(elementToHighlight)) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
|
||||
PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
|
||||
while (enclosingClass != null) {
|
||||
isInherited = enclosingClass.isInheritor(containingClass, true);
|
||||
@@ -72,9 +75,11 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration, isInherited);
|
||||
LOG.assertTrue(methodOrClass instanceof PsiMethod || !isDeclaration);
|
||||
HighlightInfoType type = methodOrClass instanceof PsiMethod ? getMethodNameHighlightType((PsiMethod)methodOrClass, isDeclaration, isInherited)
|
||||
: JavaHighlightInfoTypes.CONSTRUCTOR_CALL;
|
||||
if (type != null) {
|
||||
TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme);
|
||||
TextAttributes attributes = mergeWithScopeAttributes(methodOrClass, type, colorsScheme);
|
||||
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
|
||||
if (attributes != null) {
|
||||
builder.textAttributes(attributes);
|
||||
|
||||
+3
-7
@@ -830,17 +830,13 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
else if (parent instanceof PsiConstructorCall) {
|
||||
try {
|
||||
PsiMethod method = ((PsiConstructorCall)parent).resolveConstructor();
|
||||
if (method == null) {
|
||||
if (resolved instanceof PsiClass) {
|
||||
myHolder.add(HighlightNamesUtil.highlightClassName((PsiClass)resolved, element, colorsScheme));
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiMember methodOrClass = method != null ? method : resolved instanceof PsiClass ? (PsiClass)resolved : null;
|
||||
if (methodOrClass != null) {
|
||||
final PsiElement referenceNameElement = element.getReferenceNameElement();
|
||||
if(referenceNameElement != null) {
|
||||
// exclude type parameters from the highlighted text range
|
||||
TextRange range = new TextRange(element.getTextRange().getStartOffset(), referenceNameElement.getTextRange().getEndOffset());
|
||||
myHolder.add(HighlightNamesUtil.highlightMethodName(method, referenceNameElement, range, colorsScheme, false));
|
||||
myHolder.add(HighlightNamesUtil.highlightMethodName(methodOrClass, referenceNameElement, range, colorsScheme, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -47,8 +47,7 @@ class <symbolName descr="null" type="CLASS_NAME">a</symbolName> {
|
||||
|
||||
class <symbolName descr="null" type="CLASS_NAME">NoCtrClass</symbolName> {
|
||||
{
|
||||
// default constructor call looks like class
|
||||
new <symbolName descr="null" type="CLASS_NAME">NoCtrClass</symbolName>();
|
||||
new <symbolName descr="null" type="CONSTRUCTOR_CALL">NoCtrClass</symbolName>();
|
||||
}
|
||||
|
||||
void <symbolName descr="null" type="METHOD_DECLARATION">ff</symbolName>(int <symbolName descr="null" type="REASSIGNED_PARAMETER">param</symbolName>) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package x;
|
||||
class <symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName> {
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName>();
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CONSTRUCTOR_CALL" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">Shared</symbolName>();
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x000000" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</symbolName>
|
||||
<symbolName descr="null" type="METHOD_DECLARATION">list</symbolName>(
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x000000" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</symbolName> <symbolName descr="null" type="PARAMETER">map</symbolName>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package x;
|
||||
class <symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName> {
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName>();
|
||||
<symbolName descr="null" type="CLASS_NAME" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName> <symbolName descr="null" type="INSTANCE_FIELD">x</symbolName> = new <symbolName descr="null" type="CONSTRUCTOR_CALL" foreground="0x000000" background="0x404040" effectcolor="0x0000ff" effecttype="BOXED" fonttype="2">X</symbolName>();
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x000000" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.List</symbolName>
|
||||
<symbolName descr="null" type="METHOD_DECLARATION">list</symbolName>(
|
||||
<symbolName descr="null" type="INTERFACE_NAME" foreground="0x000000" background="0xff00ff" effectcolor="0xffc800" effecttype="STRIKEOUT" fonttype="1">java.util.Map</symbolName> <symbolName descr="null" type="PARAMETER">map</symbolName>
|
||||
|
||||
Reference in New Issue
Block a user