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;
}
use of com.intellij.psi.scope.ElementClassHint in project android by JetBrains.
the class LightBindingClass method processDeclarations.
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
boolean continueProcessing = super.processDeclarations(processor, state, lastParent, place);
if (!continueProcessing) {
return false;
}
List<PsiDataBindingResourceItem> imports = myInfo.getItems(DataBindingResourceType.IMPORT);
if (imports.isEmpty()) {
return true;
}
final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (classHint != null && classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
final NameHint nameHint = processor.getHint(NameHint.KEY);
final String name = nameHint != null ? nameHint.getName(state) : null;
for (PsiDataBindingResourceItem imp : imports) {
String alias = imp.getExtra(SdkConstants.ATTR_ALIAS);
if (alias != null) {
// aliases are pre-resolved in {@linkplain #replaceImportAliases}
continue;
}
String qName = imp.getExtra(SdkConstants.ATTR_TYPE);
if (qName == null) {
continue;
}
if (name != null && !qName.endsWith("." + name)) {
continue;
}
Module module = myInfo.getModule();
if (module == null) {
// this should not really happen but just to be safe
return true;
}
PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qName, module.getModuleWithDependenciesAndLibrariesScope(true));
if (aClass != null) {
if (!processor.execute(aClass, state)) {
// found it!
return false;
}
}
}
}
return true;
}
use of com.intellij.psi.scope.ElementClassHint in project intellij-elixir by KronicDeth.
the class BeamFileImpl method processDeclarations.
/**
* Passes the declarations contained in this PSI element and its children
* for processing to the specified scope processor.
*
* @param processor the processor receiving the declarations.
* @param lastParent the child of this element has been processed during the previous
* step of the tree up walk (declarations under this element do not need
* to be processed again)
* @param place the original element from which the tree up walk was initiated. @return true if the declaration processing should continue or false if it should be stopped.
*/
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
boolean keepProcessing = true;
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
for (CanonicallyNamed modular : modulars()) {
if (!processor.execute(modular, state)) {
keepProcessing = false;
break;
}
}
}
return keepProcessing;
}
Aggregations