From dc5a17e4be2aa06ac1e1d440c6313ec76bec543e Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Wed, 21 Mar 2018 20:27:33 +0300 Subject: [PATCH] Cleanup PyPropertyAccessInspection (PY-28206) Cache is dropped because PyClass caches properties --- .../PyPropertyAccessInspection.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyPropertyAccessInspection.java b/python/src/com/jetbrains/python/inspections/PyPropertyAccessInspection.java index f2a6d746f9d0..df0b6a585495 100644 --- a/python/src/com/jetbrains/python/inspections/PyPropertyAccessInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyPropertyAccessInspection.java @@ -17,10 +17,8 @@ package com.jetbrains.python.inspections; import com.intellij.codeInspection.LocalInspectionToolSession; import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; -import java.util.HashMap; import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.quickfix.PyCreatePropertyQuickFix; import com.jetbrains.python.psi.*; @@ -35,6 +33,7 @@ import org.jetbrains.annotations.NotNull; * User: dcheryasov */ public class PyPropertyAccessInspection extends PyInspection { + @Nls @NotNull @Override @@ -42,21 +41,15 @@ public class PyPropertyAccessInspection extends PyInspection { return PyBundle.message("INSP.NAME.property.access"); } - @Override - public boolean isEnabledByDefault() { - return true; - } - @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) { return new Visitor(holder, session); } - public static class Visitor extends PyInspectionVisitor { - private final HashMap, Property> myPropertyCache = new HashMap<>(); + private static class Visitor extends PyInspectionVisitor { - public Visitor(@NotNull final ProblemsHolder holder, LocalInspectionToolSession session) { + public Visitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) { super(holder, session); } @@ -80,15 +73,7 @@ public class PyPropertyAccessInspection extends PyInspection { final PyClass cls = ((PyClassType)type).getPyClass(); final String name = node.getName(); if (name != null) { - final Pair key = Pair.create(cls, name); - final Property property; - if (myPropertyCache.containsKey(key)) { - property = myPropertyCache.get(key); - } - else { - property = cls.findProperty(name, true, myTypeEvalContext); - } - myPropertyCache.put(key, property); // we store nulls, too, to know that a property does not exist + final Property property = cls.findProperty(name, true, myTypeEvalContext); if (property != null) { final AccessDirection dir = AccessDirection.of(node); checkAccessor(node, name, dir, property); @@ -104,7 +89,10 @@ public class PyPropertyAccessInspection extends PyInspection { } } - private void checkAccessor(PyExpression node, String name, AccessDirection dir, Property property) { + private void checkAccessor(@NotNull PyExpression node, + @NotNull String name, + @NotNull AccessDirection dir, + @NotNull Property property) { final Maybe accessor = property.getByDirection(dir); if (accessor.isDefined() && accessor.value() == null) { final String message;