mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
separate usage type "New inner class instance creation" (IDEA-75343)
This commit is contained in:
@@ -16,9 +16,12 @@
|
||||
package com.intellij.usages.impl.rules;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiSuperMethodImplUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.usages.PsiElementUsageTarget;
|
||||
import com.intellij.usages.UsageTarget;
|
||||
import com.intellij.util.Processor;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,15 +34,22 @@ import java.util.Set;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JavaUsageTypeProvider implements UsageTypeProvider {
|
||||
public class JavaUsageTypeProvider implements UsageTypeProviderEx {
|
||||
public UsageType getUsageType(final PsiElement element) {
|
||||
UsageType classUsageType = getClassUsageType(element);
|
||||
return getUsageType(element, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsageType getUsageType(PsiElement element, @Nullable UsageTarget[] targets) {
|
||||
UsageType classUsageType = getClassUsageType(element, targets);
|
||||
if (classUsageType != null) return classUsageType;
|
||||
|
||||
UsageType methodUsageType = getMethodUsageType(element);
|
||||
if (methodUsageType != null) return methodUsageType;
|
||||
|
||||
if (element instanceof PsiLiteralExpression) {return UsageType.LITERAL_USAGE; }
|
||||
if (element instanceof PsiLiteralExpression) {
|
||||
return UsageType.LITERAL_USAGE;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -144,8 +154,7 @@ public class JavaUsageTypeProvider implements UsageTypeProvider {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static UsageType getClassUsageType(PsiElement element) {
|
||||
|
||||
private static UsageType getClassUsageType(PsiElement element, @Nullable UsageTarget[] targets) {
|
||||
if (element.getParent() instanceof PsiAnnotation &&
|
||||
element == ((PsiAnnotation)element.getParent()).getNameReferenceElement()) return UsageType.ANNOTATION;
|
||||
|
||||
@@ -208,6 +217,9 @@ public class JavaUsageTypeProvider implements UsageTypeProvider {
|
||||
if (psiNewExpression != null) {
|
||||
final PsiJavaCodeReferenceElement classReference = psiNewExpression.getClassReference();
|
||||
if (classReference != null && PsiTreeUtil.isAncestor(classReference, element, false)) {
|
||||
if (isInnerClassOf(classReference, targets)) {
|
||||
return UsageType.CLASS_INNER_NEW_OPERATOR;
|
||||
}
|
||||
if (psiNewExpression.getArrayDimensions().length > 0) {
|
||||
return UsageType.CLASS_NEW_ARRAY;
|
||||
}
|
||||
@@ -217,4 +229,25 @@ public class JavaUsageTypeProvider implements UsageTypeProvider {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isInnerClassOf(PsiJavaCodeReferenceElement classReference, @Nullable UsageTarget[] targets) {
|
||||
if (targets == null) {
|
||||
return false;
|
||||
}
|
||||
PsiElement qualifier = classReference.getQualifier();
|
||||
if (qualifier instanceof PsiJavaCodeReferenceElement) {
|
||||
for (UsageTarget target : targets) {
|
||||
if (target instanceof PsiElementUsageTarget) {
|
||||
PsiElement element = ((PsiElementUsageTarget)target).getElement();
|
||||
if (element instanceof PsiClass) {
|
||||
String name = target.getName();
|
||||
if (Comparing.equal(((PsiJavaCodeReferenceElement)qualifier).getReferenceName(), name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ usage.target.xml.tag.of.file={0} of file {1}
|
||||
usage.target.package.in.directory={0} (in {1})
|
||||
usage.target.exception=Exception
|
||||
usage.type.new=New instance creation
|
||||
usage.type.new.inner=New inner class instance creation
|
||||
usage.type.new.array=New array creation
|
||||
usage.type.annotation=Annotation
|
||||
usage.type.type.parameter=Type parameter
|
||||
|
||||
@@ -31,6 +31,7 @@ public final class UsageType {
|
||||
public static final UsageType CLASS_CATCH_CLAUSE_PARAMETER_DECLARATION = new UsageType(UsageViewBundle.message("usage.type.catch.declaration"));
|
||||
public static final UsageType CLASS_METHOD_RETURN_TYPE = new UsageType(UsageViewBundle.message("usage.type.return"));
|
||||
public static final UsageType CLASS_NEW_OPERATOR = new UsageType(UsageViewBundle.message("usage.type.new"));
|
||||
public static final UsageType CLASS_INNER_NEW_OPERATOR = new UsageType(UsageViewBundle.message("usage.type.new.inner"));
|
||||
public static final UsageType CLASS_NEW_ARRAY = new UsageType(UsageViewBundle.message("usage.type.new.array"));
|
||||
public static final UsageType ANNOTATION = new UsageType(UsageViewBundle.message("usage.type.annotation"));
|
||||
public static final UsageType TYPE_PARAMETER = new UsageType(UsageViewBundle.message("usage.type.type.parameter"));
|
||||
|
||||
Reference in New Issue
Block a user