java resolve: don't check for staticness in processors that don't care (IDEA-233325)

GitOrigin-RevId: f6122e80a30e7613eab234422982e3be4f8ac3cb
This commit is contained in:
Peter Gromov
2020-03-13 22:35:15 +01:00
committed by intellij-monorepo-bot
parent ad18ae6f93
commit 81762901e8
7 changed files with 33 additions and 25 deletions

View File

@@ -100,7 +100,7 @@ public class JavaCompletionProcessor implements PsiScopeProcessor, ElementClassH
@Override
public void handleEvent(@NotNull Event event, Object associated){
if(event == JavaScopeProcessorEvent.START_STATIC){
if (JavaScopeProcessorEvent.isEnteringStaticScope(event, associated)) {
myStatic = true;
}
if(event == JavaScopeProcessorEvent.CHANGE_LEVEL){

View File

@@ -15,6 +15,12 @@
*/
package com.intellij.psi.scope;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author yole
*/
@@ -23,6 +29,23 @@ public class JavaScopeProcessorEvent implements PsiScopeProcessor.Event {
}
public static final JavaScopeProcessorEvent START_STATIC = new JavaScopeProcessorEvent();
/**
* An event issued by {@link com.intellij.psi.scope.util.PsiScopesUtil#treeWalkUp}
* after {@link com.intellij.psi.PsiElement#processDeclarations} was called,
* for each element in the hierarchy defined by a chain of {@link PsiElement#getContext()} calls.
* The associated object is the {@link PsiElement} whose declarations have been processed.
*/
public static final JavaScopeProcessorEvent EXIT_LEVEL = new JavaScopeProcessorEvent();
public static final JavaScopeProcessorEvent CHANGE_LEVEL = new JavaScopeProcessorEvent();
public static final JavaScopeProcessorEvent SET_CURRENT_FILE_CONTEXT = new JavaScopeProcessorEvent();
public static boolean isEnteringStaticScope(@NotNull PsiScopeProcessor.Event event, @Nullable Object associated) {
if (event == START_STATIC) return true;
return event == EXIT_LEVEL &&
associated instanceof PsiModifierListOwner &&
((PsiModifierListOwner)associated).hasModifierProperty(PsiModifier.STATIC);
}
}

View File

@@ -3,16 +3,12 @@
package com.intellij.codeInsight.completion.proc;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiVariable;
import com.intellij.psi.ResolveState;
import com.intellij.psi.*;
import com.intellij.psi.scope.ElementClassHint;
import com.intellij.psi.scope.JavaScopeProcessorEvent;
import com.intellij.psi.scope.PsiScopeProcessor;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -25,11 +21,6 @@ public class VariablesProcessor implements PsiScopeProcessor, ElementClassHint{
private final boolean myStaticSensitiveFlag;
private final List<? super PsiVariable> myResultList;
/** Collecting _all_ variables in scope */
public VariablesProcessor(String _prefix, boolean staticSensitiveFlag){
this(_prefix, staticSensitiveFlag, new ArrayList<>());
}
/** Collecting _all_ variables in scope */
public VariablesProcessor(String _prefix, boolean staticSensitiveFlag, List<? super PsiVariable> lst){
myPrefix = _prefix;
@@ -60,8 +51,9 @@ public class VariablesProcessor implements PsiScopeProcessor, ElementClassHint{
@Override
public final void handleEvent(@NotNull Event event, Object associated){
if(event == JavaScopeProcessorEvent.START_STATIC)
if (JavaScopeProcessorEvent.isEnteringStaticScope(event, associated)) {
myStaticScopeFlag = true;
}
}
/** sometimes it is important to get results as array */

View File

@@ -72,7 +72,7 @@ public class VariableResolverProcessor extends ConflictFilterProcessor implement
@Override
public final void handleEvent(@NotNull PsiScopeProcessor.Event event, Object associated) {
super.handleEvent(event, associated);
if(event == JavaScopeProcessorEvent.START_STATIC){
if (JavaScopeProcessorEvent.isEnteringStaticScope(event, associated)) {
myStaticScopeFlag = true;
}
else if (JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT.equals(event)) {

View File

@@ -69,7 +69,7 @@ public abstract class MethodsProcessor extends ConflictFilterProcessor implement
@Override
public void handleEvent(@NotNull Event event, Object associated) {
if (event == JavaScopeProcessorEvent.START_STATIC) {
if (JavaScopeProcessorEvent.isEnteringStaticScope(event, associated)) {
myStaticScopeFlag = true;
}
else if (JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT.equals(event)) {

View File

@@ -53,8 +53,9 @@ public abstract class VariablesProcessor implements PsiScopeProcessor, ElementCl
@Override
public final void handleEvent(@NotNull Event event, Object associated){
if(event == JavaScopeProcessorEvent.START_STATIC)
if (JavaScopeProcessorEvent.isEnteringStaticScope(event, associated)) {
myStaticScopeFlag = true;
}
}
public int size(){

View File

@@ -71,19 +71,11 @@ public class PsiScopesUtil {
return false; // resolved
}
PsiElement context = scope.getContext();
if (scope instanceof PsiModifierListOwner &&
!(scope instanceof PsiParameter/* important for not loading tree! */) &&
!(context instanceof PsiFile)) { // avoid calling hasModifierProperty (it's expensive in Lombok) at least on top-level classes
PsiModifierList modifierList = ((PsiModifierListOwner)scope).getModifierList();
if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC)) {
processor.handleEvent(JavaScopeProcessorEvent.START_STATIC, null);
}
}
if (scope == maxScope) break;
prevParent = scope;
scope = context;
processor.handleEvent(JavaScopeProcessorEvent.EXIT_LEVEL, scope);
processor.handleEvent(JavaScopeProcessorEvent.CHANGE_LEVEL, null);
scope = scope.getContext();
}
return true;