mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
performance
This commit is contained in:
+4
-6
@@ -254,11 +254,10 @@ public class RefCountHolder {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isReferencedForRead(@NotNull PsiElement element) {
|
||||
LOG.assertTrue(element instanceof PsiVariable);
|
||||
public boolean isReferencedForRead(@NotNull PsiVariable variable) {
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(element);
|
||||
array = myLocalRefsMap.getKeysByValue(variable);
|
||||
}
|
||||
if (array == null) return false;
|
||||
for (PsiReference ref : array) {
|
||||
@@ -278,11 +277,10 @@ public class RefCountHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isReferencedForWrite(@NotNull PsiElement element) {
|
||||
LOG.assertTrue(element instanceof PsiVariable);
|
||||
public boolean isReferencedForWrite(@NotNull PsiVariable variable) {
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(element);
|
||||
array = myLocalRefsMap.getKeysByValue(variable);
|
||||
}
|
||||
if (array == null) return false;
|
||||
for (PsiReference ref : array) {
|
||||
|
||||
+2
-2
@@ -163,7 +163,7 @@ public class AnnotationsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkDuplicateAnnotations(@NotNull PsiAnnotation annotationToCheck) {
|
||||
static HighlightInfo checkDuplicateAnnotations(@NotNull PsiAnnotation annotationToCheck, @NotNull LanguageLevel languageLevel) {
|
||||
PsiAnnotationOwner owner = annotationToCheck.getOwner();
|
||||
if (owner == null) return null;
|
||||
|
||||
@@ -186,7 +186,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
}
|
||||
else if (isAnnotationRepeatedTwice(owner, annotationType.getQualifiedName())) {
|
||||
if (!PsiUtil.isLanguageLevel8OrHigher(annotationToCheck)) {
|
||||
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
String description = JavaErrorMessages.message("annotation.duplicate.annotation");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
+19
-26
@@ -506,36 +506,29 @@ public class HighlightMethodUtil {
|
||||
if (methodCandidate2 != null) {
|
||||
return null;
|
||||
}
|
||||
if (element != null && !resolveResult.isAccessible()) {
|
||||
description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult);
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
}
|
||||
else if (element != null && !resolveResult.isStaticsScopeCorrect()) {
|
||||
description = HighlightUtil.buildProblemWithStaticDescription(element);
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
}
|
||||
else {
|
||||
if (element != null && !resolveResult.isAccessible()) {
|
||||
description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult);
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
}
|
||||
else if (element != null && !resolveResult.isStaticsScopeCorrect()) {
|
||||
description = HighlightUtil.buildProblemWithStaticDescription(element);
|
||||
String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list);
|
||||
description = JavaErrorMessages.message("cannot.resolve.method", methodName);
|
||||
if (candidates.length == 0) {
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
highlightInfoType = HighlightInfoType.WRONG_REF;
|
||||
}
|
||||
else {
|
||||
String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list);
|
||||
description = JavaErrorMessages.message("cannot.resolve.method", methodName);
|
||||
if (candidates.length == 0) {
|
||||
elementToHighlight = referenceToMethod.getReferenceNameElement();
|
||||
highlightInfoType = HighlightInfoType.WRONG_REF;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
toolTip = XmlStringUtil.escapeString(description);
|
||||
}
|
||||
toolTip = XmlStringUtil.escapeString(description);
|
||||
HighlightInfo info =
|
||||
HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight).description(description).escapedToolTip(toolTip).create();
|
||||
if (methodCandidate2 == null) {
|
||||
registerMethodCallIntentions(info, methodCall, list, resolveHelper);
|
||||
}
|
||||
if (!resolveResult.isAccessible() && resolveResult.isStaticsScopeCorrect() && methodCandidate2 != null) {
|
||||
HighlightUtil.registerAccessQuickFixAction((PsiMember)element, referenceToMethod, info, resolveResult.getCurrentFileResolveScope());
|
||||
}
|
||||
registerMethodCallIntentions(info, methodCall, list, resolveHelper);
|
||||
if (element != null && !resolveResult.isStaticsScopeCorrect()) {
|
||||
HighlightUtil.registerStaticProblemQuickFixAction(element, info, referenceToMethod);
|
||||
}
|
||||
@@ -1014,7 +1007,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMethodCanHaveBody(PsiMethod method, @NotNull LanguageLevel languageLevel,@NotNull PsiFile containingFile) {
|
||||
static HighlightInfo checkMethodCanHaveBody(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
boolean hasNoBody = method.getBody() == null;
|
||||
boolean isInterface = aClass != null && aClass.isInterface();
|
||||
@@ -1035,7 +1028,7 @@ public class HighlightMethodUtil {
|
||||
else if (isInterface) {
|
||||
if (!isExtension && !isStatic) {
|
||||
description = JavaErrorMessages.message("interface.methods.cannot.have.body");
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(method)) {
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.DEFAULT, true, false));
|
||||
additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, true, false));
|
||||
}
|
||||
@@ -1242,7 +1235,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
return createIncompatibleReturnTypeMessage(currentMethod, otherSuperMethod, otherSuperReturnType,
|
||||
currentType, JavaErrorMessages.message("unrelated.overriding.methods.return.types"),
|
||||
false ? currentMethod.getReturnTypeElement().getTextRange() : TextRange.EMPTY_RANGE);
|
||||
TextRange.EMPTY_RANGE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1262,7 +1255,7 @@ public class HighlightMethodUtil {
|
||||
if (aClass.equals(containingClass)) continue; //to be checked at method level
|
||||
|
||||
if (aClass.isInterface() && !containingClass.isInterface()) continue;
|
||||
HighlightInfo highlightInfo = null;
|
||||
HighlightInfo highlightInfo;
|
||||
if (allAbstracts) {
|
||||
superSignatures = new ArrayList<HierarchicalMethodSignature>(superSignatures);
|
||||
superSignatures.add(signature);
|
||||
|
||||
+10
-8
@@ -299,12 +299,12 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression) {
|
||||
static HighlightInfo checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression, @NotNull LanguageLevel languageLevel) {
|
||||
final PsiTypeElement castTypeElement = expression.getCastType();
|
||||
if (castTypeElement == null) return null;
|
||||
PsiType castType = castTypeElement.getType();
|
||||
if (isIntersection(castTypeElement, castType)) {
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(expression)) {
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class);
|
||||
if (conjuncts != null) {
|
||||
final List<PsiTypeElement> conjList = new ArrayList<PsiTypeElement>(Arrays.asList(conjuncts));
|
||||
@@ -680,8 +680,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static HighlightInfo checkUnderscore(@NotNull PsiIdentifier identifier, @NotNull PsiVariable variable) {
|
||||
if ("_".equals(variable.getName()) && PsiUtil.isLanguageLevel8OrHigher(variable)) {
|
||||
public static HighlightInfo checkUnderscore(@NotNull PsiIdentifier identifier, @NotNull PsiVariable variable, @NotNull LanguageLevel languageLevel) {
|
||||
if ("_".equals(variable.getName()) && languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
if (variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiLambdaExpression) {
|
||||
String message = JavaErrorMessages.message("underscore.lambda.identifier");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(identifier).descriptionAndTooltip(message).create();
|
||||
@@ -1416,7 +1416,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkThisOrSuperExpressionInIllegalContext(@NotNull PsiExpression expr,
|
||||
@Nullable PsiJavaCodeReferenceElement qualifier) {
|
||||
@Nullable PsiJavaCodeReferenceElement qualifier,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
if (expr instanceof PsiSuperExpression) {
|
||||
final PsiElement parent = expr.getParent();
|
||||
if (!(parent instanceof PsiReferenceExpression)) {
|
||||
@@ -1442,7 +1443,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (aClass == null) return null;
|
||||
|
||||
if (!InheritanceUtil.hasEnclosingInstanceInScope(aClass, expr, false, false) &&
|
||||
!resolvesToImmediateSuperInterface(expr, qualifier, aClass)) {
|
||||
!resolvesToImmediateSuperInterface(expr, qualifier, aClass, languageLevel)) {
|
||||
return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr);
|
||||
}
|
||||
|
||||
@@ -1492,8 +1493,9 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
private static boolean resolvesToImmediateSuperInterface(@NotNull PsiExpression expr,
|
||||
@Nullable PsiJavaCodeReferenceElement qualifier,
|
||||
@NotNull PsiClass aClass) {
|
||||
if (!(expr instanceof PsiSuperExpression) || qualifier == null || !PsiUtil.isLanguageLevel8OrHigher(expr)) return false;
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
if (!(expr instanceof PsiSuperExpression) || qualifier == null || !languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) return false;
|
||||
final PsiType superType = expr.getType();
|
||||
if (!(superType instanceof PsiClassType)) return false;
|
||||
final PsiClass superClass = ((PsiClassType)superType).resolve();
|
||||
|
||||
+7
-7
@@ -220,7 +220,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkAnnotationType(annotation));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkMissingAttributes(annotation));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkTargetAnnotationDuplicates(annotation));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkDuplicateAnnotations(annotation));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkDuplicateAnnotations(annotation, myLanguageLevel));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkForeignInnerClassesUsed(annotation));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkFunctionalInterface(annotation, myLanguageLevel));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkRepeatableAnnotation(annotation));
|
||||
@@ -590,7 +590,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
|
||||
myHolder.add(HighlightUtil.checkUnderscore(identifier, variable));
|
||||
myHolder.add(HighlightUtil.checkUnderscore(identifier, variable, myLanguageLevel));
|
||||
}
|
||||
else if (parent instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)parent;
|
||||
@@ -833,7 +833,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
PsiElement parent = list.getParent();
|
||||
if (parent instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)parent;
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCanHaveBody(method, myLanguageLevel,myFile));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCanHaveBody(method, myLanguageLevel));
|
||||
MethodSignatureBackedByPsiMethod methodSignature = MethodSignatureBackedByPsiMethod.create(method, PsiSubstitutor.EMPTY);
|
||||
if (!method.isConstructor()) {
|
||||
try {
|
||||
@@ -1378,7 +1378,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
|
||||
@Override
|
||||
public void visitSuperExpression(PsiSuperExpression expr) {
|
||||
myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier()));
|
||||
myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier(), myLanguageLevel));
|
||||
if (!myHolder.hasErrorResults()) visitExpression(expr);
|
||||
}
|
||||
|
||||
@@ -1396,7 +1396,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(PsiThisExpression expr) {
|
||||
myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier()));
|
||||
myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier(), myLanguageLevel));
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
myHolder.add(HighlightUtil.checkMemberReferencedBeforeConstructorCalled(expr, null, myFile));
|
||||
}
|
||||
@@ -1452,7 +1452,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
public void visitTypeCastExpression(PsiTypeCastExpression typeCast) {
|
||||
super.visitTypeCastExpression(typeCast);
|
||||
try {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIntersectionInTypeCast(typeCast));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIntersectionInTypeCast(typeCast, myLanguageLevel));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkInconvertibleTypeCast(typeCast));
|
||||
}
|
||||
catch (IndexNotReadyException ignore) {
|
||||
@@ -1498,7 +1498,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
@Override
|
||||
public void visitConditionalExpression(PsiConditionalExpression expression) {
|
||||
super.visitConditionalExpression(expression);
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(expression) && PsiPolyExpressionUtil.isPolyExpression(expression)) {
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) && PsiPolyExpressionUtil.isPolyExpression(expression)) {
|
||||
final PsiExpression thenExpression = expression.getThenExpression();
|
||||
final PsiExpression elseExpression = expression.getElseExpression();
|
||||
if (thenExpression != null && elseExpression != null) {
|
||||
|
||||
Reference in New Issue
Block a user