use of com.intellij.psi.scope.ElementClassHint in project intellij-community by JetBrains.
the class GroovyShellCodeFragment method processVariables.
private boolean processVariables(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (!ResolveUtil.shouldProcessMethods(classHint) && !ResolveUtil.shouldProcessProperties(classHint)) {
return true;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint != null ? nameHint.getName(state) : null;
if (name != null) {
final PsiVariable var = myVariables.get(name);
if (var != null) {
if (processor.execute(var, state)) {
return false;
}
}
} else {
for (PsiVariable var : myVariables.values()) {
if (!processor.execute(var, state)) {
return false;
}
}
}
return true;
}
use of com.intellij.psi.scope.ElementClassHint in project intellij-community by JetBrains.
the class GroovyShellCodeFragment method processTypeDefinitions.
private boolean processTypeDefinitions(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (!ResolveUtil.shouldProcessClasses(classHint)) {
return true;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint != null ? nameHint.getName(state) : null;
if (name != null) {
final GrTypeDefinition definition = myTypeDefinitions.get(name);
if (definition != null) {
if (processor.execute(definition, state)) {
return false;
}
}
} else {
for (GrTypeDefinition definition : myTypeDefinitions.values()) {
if (!processor.execute(definition, state)) {
return false;
}
}
}
return true;
}
use of com.intellij.psi.scope.ElementClassHint in project intellij-community by JetBrains.
the class PsiClassImplUtil method processDeclarationsInClassNotCached.
private static boolean processDeclarationsInClassNotCached(@NotNull PsiClass aClass, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, @Nullable Set<PsiClass> visited, final PsiElement last, @NotNull final PsiElement place, final boolean isRaw, @NotNull final LanguageLevel languageLevel, @NotNull final GlobalSearchScope resolveScope) {
if (visited == null)
visited = new THashSet<>();
if (!visited.add(aClass))
return true;
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final NameHint nameHint = processor.getHint(NameHint.KEY);
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.FIELD)) {
if (nameHint != null) {
final PsiField fieldByName = aClass.findFieldByName(nameHint.getName(state), false);
if (fieldByName != null && !processor.execute(fieldByName, state))
return false;
} else {
final PsiField[] fields = aClass.getFields();
for (final PsiField field : fields) {
if (!processor.execute(field, state))
return false;
}
}
}
PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.METHOD)) {
PsiSubstitutor baseSubstitutor = state.get(PsiSubstitutor.KEY);
final PsiMethod[] methods = nameHint != null ? aClass.findMethodsByName(nameHint.getName(state), false) : aClass.getMethods();
for (final PsiMethod method : methods) {
PsiSubstitutor finalSubstitutor = checkRaw(isRaw, factory, method, baseSubstitutor);
ResolveState methodState = finalSubstitutor == baseSubstitutor ? state : state.put(PsiSubstitutor.KEY, finalSubstitutor);
if (!processor.execute(method, methodState))
return false;
}
}
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
if (last != null && last.getContext() == aClass) {
// Parameters
final PsiTypeParameterList list = aClass.getTypeParameterList();
if (list != null && !list.processDeclarations(processor, ResolveState.initial(), last, place))
return false;
}
if (!(last instanceof PsiReferenceList) && !(last instanceof PsiModifierList)) {
// Inners
if (nameHint != null) {
final PsiClass inner = aClass.findInnerClassByName(nameHint.getName(state), false);
if (inner != null) {
if (!processor.execute(inner, state))
return false;
}
} else {
final PsiClass[] inners = aClass.getInnerClasses();
for (final PsiClass inner : inners) {
if (!processor.execute(inner, state))
return false;
}
}
}
}
if (last instanceof PsiReferenceList)
return true;
final Set<PsiClass> visited1 = visited;
return processSuperTypes(aClass, state.get(PsiSubstitutor.KEY), factory, languageLevel, resolveScope, (superClass, finalSubstitutor) -> processDeclarationsInClass(superClass, processor, state.put(PsiSubstitutor.KEY, finalSubstitutor), visited1, last, place, languageLevel, isRaw, resolveScope));
}
use of com.intellij.psi.scope.ElementClassHint in project intellij-community by JetBrains.
the class SpockMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (ResolveUtil.shouldProcessProperties(classHint)) {
GrMethod method = PsiTreeUtil.getParentOfType(place, GrMethod.class);
if (method == null)
return;
if (aClass != method.getContainingClass())
return;
Map<String, SpockVariableDescriptor> cachedValue = SpockUtils.getVariableMap(method);
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
for (SpockVariableDescriptor spockVar : cachedValue.values()) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
} else {
SpockVariableDescriptor spockVar = cachedValue.get(nameHint);
if (spockVar != null && spockVar.getNavigationElement() != place) {
if (!processor.execute(spockVar.getVariable(), state))
return;
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
String nameHint = ResolveUtil.getNameHint(processor);
if (nameHint == null) {
nameHint = place instanceof GrReferenceExpression ? ((GrReferenceExpression) place).getReferenceName() : null;
if (nameHint != null)
nameHint = GroovyPropertyUtils.getGetterNameNonBoolean(nameHint);
}
if ("get_".equals(nameHint)) {
GrLightMethodBuilder m = new GrLightMethodBuilder(aClass.getManager(), "get_");
m.setReturnType(null);
if (!processor.execute(m, state))
return;
}
}
}
use of com.intellij.psi.scope.ElementClassHint in project intellij-community by JetBrains.
the class GroovyFileImpl method processDeclarationsNoGuess.
private boolean processDeclarationsNoGuess(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (myContext != null) {
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (!processChildrenScopes(processor, state, lastParent, place))
return false;
}
return true;
}
boolean processClasses = ResolveUtil.shouldProcessClasses(classHint);
GrImportStatement[] importStatements = getImportStatements();
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ALIAS, false))
return false;
GroovyScriptClass scriptClass = getScriptClass();
if (scriptClass != null && StringUtil.isJavaIdentifier(scriptClass.getName())) {
if (!(lastParent instanceof GrTypeDefinition)) {
if (!ResolveUtil.processClassDeclarations(scriptClass, processor, state, lastParent, place))
return false;
}
if (processClasses) {
if (!ResolveUtil.processElement(processor, scriptClass, state))
return false;
}
}
if (processClasses) {
for (GrTypeDefinition definition : getTypeDefinitions()) {
if (!ResolveUtil.processElement(processor, definition, state))
return false;
}
}
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (!processChildrenScopes(processor, state, lastParent, place))
return false;
}
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ALIAS, true))
return false;
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.SIMPLE, null))
return false;
if (!processDeclarationsInPackage(processor, state, lastParent, place))
return false;
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ON_DEMAND, null))
return false;
if (!ImplicitImportsKt.processImplicitImports(processor, state, lastParent, place, this))
return false;
if (ResolveUtil.shouldProcessPackages(classHint)) {
NameHint nameHint = processor.getHint(NameHint.KEY);
String expectedName = nameHint != null ? nameHint.getName(state) : null;
final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
if (expectedName != null) {
final PsiPackage pkg = facade.findPackage(expectedName);
if (pkg != null && !processor.execute(pkg, state)) {
return false;
}
} else {
PsiPackage defaultPackage = facade.findPackage("");
if (defaultPackage != null) {
for (PsiPackage subPackage : defaultPackage.getSubPackages(getResolveScope())) {
if (!ResolveUtil.processElement(processor, subPackage, state))
return false;
}
}
}
}
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (lastParent != null && !(lastParent instanceof GrTypeDefinition) && scriptClass != null) {
if (!ResolveUtil.processElement(processor, getSyntheticArgsParameter(), state))
return false;
}
}
return true;
}
Aggregations