Looks like I've optimized some code, that we don't need at all. refElement.getPsiElement(), which is slow is only used to get it's file to check if it belongs to search scope.

This commit is contained in:
Maxim Shafirov
2012-04-10 21:08:44 +04:00
parent b7bbb9bcbf
commit 5d8433e70f
3 changed files with 14 additions and 11 deletions
@@ -343,11 +343,12 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
final RefElementImpl refElement = (RefElementImpl)refEntity;
if (!refElement.isSuspicious()) return;
final PsiElement element = refElement.getElement();
if (element == null) return;
PsiFile file = refElement.getContainingFile();
if (file == null) return;
final boolean isSuppressed = refElement.isSuppressed(getShortName());
if (!getContext().isToCheckMember(element, UnusedDeclarationInspection.this) || isSuppressed) {
if (isSuppressed || !scope.contains(element)) {
if (!getContext().isToCheckFile(file, UnusedDeclarationInspection.this) || isSuppressed) {
if (isSuppressed || !scope.contains(file)) {
getEntryPointsManager().addEntryPoint(refElement, false);
}
return;
@@ -71,7 +71,10 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class GlobalInspectionContextImpl extends UserDataHolderBase implements GlobalInspectionContext {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.GlobalInspectionContextImpl");
@@ -346,16 +349,15 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
public boolean isToCheckMember(@NotNull RefElement owner, InspectionProfileEntry tool) {
final PsiElement element = owner.getElement();
return isToCheckMember(element, tool) && !((RefElementImpl)owner).isSuppressed(tool.getShortName());
return isToCheckFile(((RefElementImpl)owner).getContainingFile(), tool) && !((RefElementImpl)owner).isSuppressed(tool.getShortName());
}
public boolean isToCheckMember(final PsiElement element, final InspectionProfileEntry tool) {
public boolean isToCheckFile(PsiFile file, final InspectionProfileEntry tool) {
final Tools tools = myTools.get(tool.getShortName());
if (tools != null) {
for (ScopeToolState state : tools.getTools()) {
final NamedScope namedScope = state.getScope(element.getProject());
if (namedScope == null || namedScope.getValue().contains(element.getContainingFile(), getCurrentProfile().getProfileManager().getScopesManager())) {
final NamedScope namedScope = state.getScope(file.getProject());
if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) {
if (state.isEnabled()) {
final InspectionProfileEntry entry = state.getTool();
if (entry instanceof InspectionToolWrapper && ((InspectionToolWrapper)entry).getTool() == tool) return true;
@@ -145,7 +145,7 @@ public class DuplicatePropertyInspection extends GlobalSimpleInspectionTool {
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextImpl context, final RefManager refManager, final ProblemDescriptionsProcessor processor) {
if (!(file instanceof PropertiesFile)) return;
if (!context.isToCheckMember(file, this)) return;
if (!context.isToCheckFile(file, this)) return;
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
final PropertiesFile propertiesFile = (PropertiesFile)file;
final List<IProperty> properties = propertiesFile.getProperties();