mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
optimization: dequadratisation (Prefer to resolve first, traverse up later to avoid performance drop in deep hierarchies)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -209,13 +209,17 @@ public class JavaSuppressionUtil {
|
||||
return statement;
|
||||
}
|
||||
|
||||
PsiVariable local = PsiTreeUtil.getParentOfType(place, PsiVariable.class, false);
|
||||
if (local != null && getAnnotationMemberSuppressedIn(local, toolId) != null) {
|
||||
PsiModifierList modifierList = local.getModifierList();
|
||||
return modifierList != null ? modifierList.findAnnotation(SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null;
|
||||
PsiModifierListOwner up = PsiTreeUtil.getNonStrictParentOfType(place, PsiVariable.class, PsiDocCommentOwner.class);
|
||||
if (up instanceof PsiVariable) {
|
||||
PsiVariable local = (PsiVariable)up;
|
||||
if (getAnnotationMemberSuppressedIn(local, toolId) != null) {
|
||||
PsiModifierList modifierList = local.getModifierList();
|
||||
return modifierList != null ? modifierList.findAnnotation(SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null;
|
||||
}
|
||||
}
|
||||
|
||||
PsiDocCommentOwner container = PsiTreeUtil.getNonStrictParentOfType(place, PsiDocCommentOwner.class);
|
||||
PsiDocCommentOwner container = up == null || up instanceof PsiDocCommentOwner
|
||||
? (PsiDocCommentOwner)up : PsiTreeUtil.getNonStrictParentOfType(up, PsiDocCommentOwner.class);
|
||||
while (true) {
|
||||
if (!(container instanceof PsiTypeParameter)) break;
|
||||
container = PsiTreeUtil.getParentOfType(container, PsiDocCommentOwner.class);
|
||||
|
||||
@@ -501,7 +501,12 @@ public class AnnotationUtil {
|
||||
}
|
||||
|
||||
public static boolean isInsideAnnotation(PsiElement element) {
|
||||
return PsiTreeUtil.getParentOfType(element, PsiNameValuePair.class, PsiArrayInitializerMemberValue.class) != null;
|
||||
for (int level = 0; level<4; level++) {
|
||||
if (element instanceof PsiNameValuePair) return true;
|
||||
element = element.getParent();
|
||||
if (element == null) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isInferredAnnotation(@NotNull PsiAnnotation annotation) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -143,16 +143,18 @@ public class PsiPrimitiveType extends PsiType.Stub {
|
||||
*/
|
||||
@Nullable
|
||||
public PsiClassType getBoxedType(PsiElement context) {
|
||||
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(context);
|
||||
PsiFile file = context.getContainingFile();
|
||||
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(file);
|
||||
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) return null;
|
||||
|
||||
String boxedQName = getBoxedTypeName();
|
||||
//[ven]previous call returns null for NULL, VOID
|
||||
if (boxedQName == null) return null;
|
||||
PsiClass aClass = JavaPsiFacade.getInstance(context.getProject()).findClass(boxedQName, context.getResolveScope());
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(file.getProject());
|
||||
PsiClass aClass = facade.findClass(boxedQName, context.getResolveScope());
|
||||
if (aClass == null) return null;
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
|
||||
PsiElementFactory factory = facade.getElementFactory();
|
||||
return factory.createType(aClass, PsiSubstitutor.EMPTY, languageLevel, getAnnotations());
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -82,9 +82,6 @@ public class AssignmentToStaticFieldFromInstanceMethodInspection
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return;
|
||||
}
|
||||
if (isInStaticMethod(expression)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement referent = ((PsiReference)expression).resolve();
|
||||
if (referent == null) {
|
||||
return;
|
||||
@@ -93,9 +90,13 @@ public class AssignmentToStaticFieldFromInstanceMethodInspection
|
||||
return;
|
||||
}
|
||||
final PsiField fieldReferenced = (PsiField)referent;
|
||||
if (fieldReferenced.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
registerError(expression);
|
||||
if (!fieldReferenced.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
if (isInStaticMethod(expression)) {
|
||||
return;
|
||||
}
|
||||
registerError(expression);
|
||||
}
|
||||
|
||||
private static boolean isInStaticMethod(PsiElement element) {
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,10 +77,6 @@ public class AssignmentToSuperclassFieldInspection extends BaseInspection {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiClass.class, PsiLambdaExpression.class);
|
||||
if (method == null || !method.isConstructor()) {
|
||||
return;
|
||||
}
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
|
||||
final PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
|
||||
if (qualifierExpression != null &&
|
||||
@@ -96,6 +92,10 @@ public class AssignmentToSuperclassFieldInspection extends BaseInspection {
|
||||
if (fieldClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiClass.class, PsiLambdaExpression.class);
|
||||
if (method == null || !method.isConstructor()) {
|
||||
return;
|
||||
}
|
||||
final PsiClass assignmentClass = method.getContainingClass();
|
||||
final String name = fieldClass.getQualifiedName();
|
||||
if (name == null || !InheritanceUtil.isInheritor(assignmentClass, true, name)) {
|
||||
|
||||
+3
-3
@@ -26,9 +26,6 @@ class NonFinalStaticVariableUsedInClassInitializationVisitor extends BaseInspect
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
if (!isInClassInitialization(expression)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement referent = expression.resolve();
|
||||
if (!(referent instanceof PsiField)) {
|
||||
return;
|
||||
@@ -40,6 +37,9 @@ class NonFinalStaticVariableUsedInClassInitializationVisitor extends BaseInspect
|
||||
if (field.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return;
|
||||
}
|
||||
if (!isInClassInitialization(expression)) {
|
||||
return;
|
||||
}
|
||||
registerError(expression, field);
|
||||
}
|
||||
|
||||
|
||||
+14
-13
@@ -18,6 +18,7 @@ package com.siyeh.ig.j2me;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -25,7 +26,6 @@ import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -161,6 +161,15 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldInspect(PsiFile file) {
|
||||
if (FileTypeUtils.isInServerPageFile(file)) {
|
||||
// disable for jsp files IDEADEV-12957
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new PrivateMemberAccessFromInnerClassVisitor();
|
||||
@@ -171,9 +180,6 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(PsiNewExpression expression) {
|
||||
if (FileTypeUtils.isInServerPageFile(expression)) {
|
||||
return;
|
||||
}
|
||||
super.visitNewExpression(expression);
|
||||
final PsiClass containingClass =
|
||||
getContainingContextClass(expression);
|
||||
@@ -215,21 +221,12 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
@Override
|
||||
public void visitReferenceExpression(
|
||||
@NotNull PsiReferenceExpression expression) {
|
||||
if (FileTypeUtils.isInServerPageFile(expression)) {
|
||||
// disable for jsp files IDEADEV-12957
|
||||
return;
|
||||
}
|
||||
super.visitReferenceExpression(expression);
|
||||
final PsiElement referenceNameElement =
|
||||
expression.getReferenceNameElement();
|
||||
if (referenceNameElement == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement containingClass =
|
||||
getContainingContextClass(expression);
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement element = expression.resolve();
|
||||
if (!(element instanceof PsiMethod || element instanceof PsiField)) {
|
||||
return;
|
||||
@@ -238,6 +235,10 @@ public class PrivateMemberAccessBetweenOuterAndInnerClassInspection
|
||||
if (!member.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement containingClass = getContainingContextClass(expression);
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiClass memberClass = ClassUtils.getContainingClass(member);
|
||||
if (memberClass == null || memberClass.equals(containingClass) ||
|
||||
(!PsiTreeUtil.isAncestor(containingClass, memberClass, true) && !PsiTreeUtil.isAncestor(memberClass, containingClass, true))) {
|
||||
|
||||
+22
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -83,25 +83,6 @@ public class AccessToNonThreadSafeStaticFieldFromInstanceInspectionBase extends
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
final PsiModifierListOwner parent =
|
||||
PsiTreeUtil.getParentOfType(expression, PsiField.class, PsiMethod.class, PsiClassInitializer.class);
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (parent instanceof PsiMethod || parent instanceof PsiClassInitializer) {
|
||||
if (parent.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
|
||||
return;
|
||||
}
|
||||
final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(expression, PsiSynchronizedStatement.class);
|
||||
if (synchronizedStatement != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (parent instanceof PsiField || parent instanceof PsiClassInitializer) {
|
||||
if (parent.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (expression.getQualifierExpression() != null) {
|
||||
return;
|
||||
}
|
||||
@@ -126,6 +107,27 @@ public class AccessToNonThreadSafeStaticFieldFromInstanceInspectionBase extends
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiModifierListOwner parent =
|
||||
PsiTreeUtil.getParentOfType(expression, PsiField.class, PsiMethod.class, PsiClassInitializer.class);
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (parent instanceof PsiMethod || parent instanceof PsiClassInitializer) {
|
||||
if (parent.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
|
||||
return;
|
||||
}
|
||||
final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(expression, PsiSynchronizedStatement.class);
|
||||
if (synchronizedStatement != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (parent instanceof PsiField || parent instanceof PsiClassInitializer) {
|
||||
if (parent.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (deepCheck) {
|
||||
final PsiExpression initializer = field.getInitializer();
|
||||
if (initializer == null) {
|
||||
|
||||
+27
-26
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,6 +49,29 @@ public class AccessToStaticFieldLockedOnInstanceInspectionBase extends BaseInspe
|
||||
@Override
|
||||
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
final PsiElement target = expression.resolve();
|
||||
if (!(target instanceof PsiField)) {
|
||||
return;
|
||||
}
|
||||
final PsiField lockedField = (PsiField)target;
|
||||
if (!lockedField.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtils.isConstant(lockedField)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = lockedField.getContainingClass();
|
||||
if (!PsiTreeUtil.isAncestor(containingClass, expression, false)) {
|
||||
return;
|
||||
}
|
||||
if (!ignoredClasses.isEmpty()) {
|
||||
final PsiType type = lockedField.getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
if (aClass != null && ignoredClasses.contains(aClass.getQualifiedName())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLockedOnInstance = false;
|
||||
boolean isLockedOnClass = false;
|
||||
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
|
||||
@@ -73,9 +96,9 @@ public class AccessToStaticFieldLockedOnInstanceInspectionBase extends BaseInspe
|
||||
final PsiExpression lockExpression = synchronizedStatement.getLockExpression();
|
||||
if (lockExpression instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression reference = (PsiReferenceExpression)lockExpression;
|
||||
final PsiElement target = reference.resolve();
|
||||
if (target instanceof PsiField) {
|
||||
final PsiField lockField = (PsiField)target;
|
||||
final PsiElement lockTarget = reference.resolve();
|
||||
if (lockTarget instanceof PsiField) {
|
||||
final PsiField lockField = (PsiField)lockTarget;
|
||||
if (lockField.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
isLockedOnClass = true;
|
||||
}
|
||||
@@ -95,28 +118,6 @@ public class AccessToStaticFieldLockedOnInstanceInspectionBase extends BaseInspe
|
||||
if (!isLockedOnInstance || isLockedOnClass) {
|
||||
return;
|
||||
}
|
||||
final PsiElement target = expression.resolve();
|
||||
if (!(target instanceof PsiField)) {
|
||||
return;
|
||||
}
|
||||
final PsiField lockedField = (PsiField)target;
|
||||
if (!lockedField.hasModifierProperty(PsiModifier.STATIC) || ExpressionUtils.isConstant(lockedField)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = lockedField.getContainingClass();
|
||||
if (!PsiTreeUtil.isAncestor(containingClass, expression, false)) {
|
||||
return;
|
||||
}
|
||||
if (!ignoredClasses.isEmpty()) {
|
||||
final PsiType type = lockedField.getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
if (aClass != null && ignoredClasses.contains(aClass.getQualifiedName())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
registerError(expression);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-5
@@ -100,10 +100,6 @@ public class AmbiguousFieldAccessInspection extends BaseInspection {
|
||||
if (expression.isQualified()) {
|
||||
return;
|
||||
}
|
||||
PsiClass containingClass = ClassUtils.getContainingClass(expression);
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElement target = expression.resolve();
|
||||
if (target == null) {
|
||||
return;
|
||||
@@ -113,7 +109,14 @@ public class AmbiguousFieldAccessInspection extends BaseInspection {
|
||||
}
|
||||
final PsiField field = (PsiField)target;
|
||||
final PsiClass fieldClass = field.getContainingClass();
|
||||
if (fieldClass == null || !containingClass.isInheritor(fieldClass, true)) {
|
||||
if (fieldClass == null) {
|
||||
return;
|
||||
}
|
||||
PsiClass containingClass = ClassUtils.getContainingClass(expression);
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!containingClass.isInheritor(fieldClass, true)) {
|
||||
return;
|
||||
}
|
||||
final PsiElement parent = containingClass.getParent();
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class ParameterHidingMemberVariableInspectionBase extends BaseInspection
|
||||
if (variableName == null) {
|
||||
return null;
|
||||
}
|
||||
PsiClass aClass = ClassUtils.getContainingClass(variable);
|
||||
PsiClass aClass = ClassUtils.getContainingClass(method);
|
||||
while (aClass != null) {
|
||||
PsiField field = aClass.findFieldByName(variableName, true);
|
||||
if (field != null) {
|
||||
|
||||
+19
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.intellij.uiDesigner.inspections;
|
||||
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -58,24 +57,28 @@ public class BoundFieldAssignmentInspection extends BaseJavaLocalInspectionTool
|
||||
return new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
|
||||
if (expression.getLExpression() instanceof PsiReferenceExpression) {
|
||||
PsiExpression lExpression = expression.getLExpression();
|
||||
if (lExpression instanceof PsiReferenceExpression) {
|
||||
PsiReferenceExpression lExpr = (PsiReferenceExpression)lExpression;
|
||||
PsiElement lElement = lExpr.resolve();
|
||||
if (!(lElement instanceof PsiField)) {
|
||||
return;
|
||||
}
|
||||
PsiField field = (PsiField) lElement;
|
||||
PsiReference formReference = FormReferenceProvider.getFormReference(field);
|
||||
if (!(formReference instanceof FieldFormReference)) {
|
||||
return;
|
||||
}
|
||||
FieldFormReference ref = (FieldFormReference) formReference;
|
||||
if (ref.isCustomCreate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
|
||||
if (method != null && AsmCodeGenerator.SETUP_METHOD_NAME.equals(method.getName())) {
|
||||
return;
|
||||
}
|
||||
PsiReferenceExpression lExpr = (PsiReferenceExpression) expression.getLExpression();
|
||||
PsiElement lElement = lExpr.resolve();
|
||||
if (lElement instanceof PsiField) {
|
||||
PsiField field = (PsiField) lElement;
|
||||
PsiReference formReference = FormReferenceProvider.getFormReference(field);
|
||||
if (formReference instanceof FieldFormReference) {
|
||||
FieldFormReference ref = (FieldFormReference) formReference;
|
||||
if (!ref.isCustomCreate()) {
|
||||
holder.registerProblem(expression, UIDesignerBundle.message("inspection.bound.field.message"),
|
||||
new LocalQuickFix[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
holder.registerProblem(expression, UIDesignerBundle.message("inspection.bound.field.message"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user