use of com.intellij.psi.scope.NameHint in project intellij-community by JetBrains.
the class PsiCodeFragmentImpl method processDeclarations.
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
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;
if (name != null) {
String qNameImported = myPseudoImports.get(name);
if (qNameImported != null) {
PsiClass imported = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qNameImported, getResolveScope());
if (imported != null) {
if (!processor.execute(imported, state))
return false;
}
}
} else {
for (String qNameImported : myPseudoImports.values()) {
PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qNameImported, getResolveScope());
if (aClass != null) {
if (!processor.execute(aClass, state))
return false;
}
}
}
if (myContext == null) {
return JavaResolveUtil.processImplicitlyImportedPackages(processor, state, place, getManager());
}
}
IElementType i = myContentElementType;
if (i == JavaElementType.TYPE_WITH_CONJUNCTIONS_TEXT || i == JavaElementType.TYPE_WITH_DISJUNCTIONS_TEXT || i == JavaElementType.EXPRESSION_STATEMENT || i == JavaElementType.REFERENCE_TEXT) {
return true;
} else {
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
if (lastParent == null) {
// Parent element should not see our vars
return true;
}
return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
}
use of com.intellij.psi.scope.NameHint in project intellij-community by JetBrains.
the class PsiCodeBlockImpl method processDeclarations.
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
if (lastParent == null) {
// Parent element should not see our vars
return true;
}
Couple<Set<String>> pair = buildMaps();
boolean conflict = pair == null;
final Set<String> classesSet = conflict ? null : pair.getFirst();
final Set<String> variablesSet = conflict ? null : pair.getSecond();
final NameHint hint = processor.getHint(NameHint.KEY);
if (hint != null && !conflict) {
final ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
final String name = hint.getName(state);
if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) && classesSet.contains(name)) {
return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) && variablesSet.contains(name)) {
return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
} else {
return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
}
return true;
}
use of com.intellij.psi.scope.NameHint 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.NameHint in project intellij-community by JetBrains.
the class GrClassImplUtil method processDeclarations.
public static boolean processDeclarations(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (place instanceof GrCodeReferenceElement && lastParent instanceof GrModifierList) {
final PsiElement possibleAnnotation = PsiTreeUtil.skipParentsOfType(place, GrCodeReferenceElement.class);
if (possibleAnnotation instanceof GrAnnotation && possibleAnnotation.getParent() == lastParent) {
//don't process class members while resolving annotation which annotates current class
return true;
}
}
for (final PsiTypeParameter typeParameter : grType.getTypeParameters()) {
if (!ResolveUtil.processElement(processor, typeParameter, state))
return false;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint == null ? null : nameHint.getName(state);
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
boolean processInstanceMethods = (ResolveUtil.shouldProcessMethods(classHint) || ResolveUtil.shouldProcessProperties(classHint)) && shouldProcessInstanceMembers(grType, lastParent);
LanguageLevel level = PsiUtil.getLanguageLevel(place);
if (ResolveUtil.shouldProcessProperties(classHint)) {
Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
if (name != null) {
CandidateInfo fieldInfo = fieldsMap.get(name);
if (fieldInfo != null) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, fieldInfo)) {
return false;
}
} else if (grType.isTrait() && lastParent != null) {
PsiField field = findFieldByName(grType, name, false, true);
if (field != null && field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
} else {
for (CandidateInfo info : fieldsMap.values()) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, info)) {
return false;
}
}
if (grType.isTrait() && lastParent != null) {
for (PsiField field : CollectClassMembersUtil.getFields(grType, true)) {
if (field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
boolean isPlaceGroovy = place.getLanguage() == GroovyLanguage.INSTANCE;
if (name == null) {
for (List<CandidateInfo> list : methodsMap.values()) {
for (CandidateInfo info : list) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
} else {
List<CandidateInfo> byName = methodsMap.get(name);
if (byName != null) {
for (CandidateInfo info : byName) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
}
}
final GrTypeDefinitionBody body = grType.getBody();
if (body != null) {
if (ResolveUtil.shouldProcessClasses(classHint)) {
for (PsiClass innerClass : getInnerClassesForResolve(grType, lastParent, place)) {
if (name != null && !name.equals(innerClass.getName()))
continue;
if (!processor.execute(innerClass, state))
return false;
}
}
}
return true;
}
use of com.intellij.psi.scope.NameHint in project intellij-community by JetBrains.
the class PsiPackageImpl method processDeclarations.
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
GlobalSearchScope scope = place.getResolveScope();
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final Condition<String> nameCondition = processor.getHint(JavaCompletionHints.NAME_FILTER);
NameHint providedNameHint = processor.getHint(NameHint.KEY);
final String providedName = providedNameHint == null ? null : providedNameHint.getName(state);
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
if (providedName != null) {
final PsiClass[] classes = findClassByShortName(providedName, scope);
if (!processClasses(processor, state, classes, Conditions.alwaysTrue()))
return false;
} else {
PsiClass[] classes = getClasses(scope);
if (!processClasses(processor, state, classes, nameCondition != null ? nameCondition : Conditions.alwaysTrue()))
return false;
}
}
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)) {
if (providedName != null) {
PsiPackage aPackage = findSubPackageByName(providedName);
if (aPackage != null) {
if (!processor.execute(aPackage, state))
return false;
}
} else {
PsiPackage[] packs = getSubPackages(scope);
for (PsiPackage pack : packs) {
final String packageName = pack.getName();
if (packageName == null)
continue;
if (!PsiNameHelper.getInstance(myManager.getProject()).isIdentifier(packageName, PsiUtil.getLanguageLevel(this))) {
continue;
}
if (!processor.execute(pack, state)) {
return false;
}
}
}
}
return true;
}
Aggregations