public static boolean processChildDeclarations(PsiElement element, PsiScopeProcessor processor, ResolveState substitutor, PsiElement lastParent, PsiElement place) { PsiElement run = (lastParent == null) ? element.getLastChild() : lastParent.getPrevSibling(); while (run != null) { if (!run.processDeclarations(processor, substitutor, null, place)) { return false; } run = run.getPrevSibling(); } return true; }
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState resolveState, PsiElement lastParent, @NotNull PsiElement place) { if ((lastParent != null) && (lastParent.getParent() == this)) { final LuaParameter[] params = getParameters().getLuaParameters(); for (LuaParameter param : params) { if (!processor.execute(param, resolveState)) { return false; } } } return true; }
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState resolveState, PsiElement lastParent, @NotNull PsiElement place) { PsiElement parent = place.getParent(); while(parent != null && !(parent instanceof LuaPsiFile)) { if (parent == getBlock() ) { LuaExpression[] names = getIndices(); for (LuaExpression name : names) { if (!processor.execute(name, resolveState)) return false; } } parent = parent.getParent(); } return true; }
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState resolveState, PsiElement lastParent, @NotNull PsiElement place) { PsiElement parent = place.getParent(); while (parent != null && !(parent instanceof LuaPsiFile)) { if (parent == getBlock()) { if (!processor.execute(getIndex(), resolveState)) return false; } parent = parent.getParent(); } return true; }
@Override public void process(@NotNull List<String> methodCallInfo, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { if (methodCallInfo.isEmpty() || methodCallInfo.size() < 3 || !"repositories".equals(methodCallInfo.get(2)) || !"maven".equals(methodCallInfo.get(1))) { return; } GroovyPsiManager psiManager = GroovyPsiManager.getInstance(place.getProject()); GradleResolverUtil.processDeclarations( psiManager, processor, state, place, GradleCommonClassNames.GRADLE_API_ARTIFACTS_REPOSITORIES_MAVEN_ARTIFACT_REPOSITORY); PsiClass contributorClass = psiManager.findClassWithCache( GradleCommonClassNames.GRADLE_API_ARTIFACTS_REPOSITORIES_MAVEN_ARTIFACT_REPOSITORY, place.getResolveScope()); if (contributorClass == null) return; GradleResolverUtil.processMethod(methodCallInfo.get(0), contributorClass, processor, state, place); }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { if (isAncestor(place)) { return true; } if (isStatic() && lastParent instanceof GrImportStatement) return true; if (isOnDemand()) { if (!processDeclarationsForMultipleElements(processor, lastParent, place, state)) return false; } else { if (!processDeclarationsForSingleElement(processor, lastParent, place, state)) return false; } return true; }
public static boolean categoryIteration(GrClosableBlock place, final PsiScopeProcessor processor, ResolveState state) { final ClassHint classHint = processor.getHint(ClassHint.KEY); if (classHint != null && !classHint.shouldProcess(ClassHint.ResolveKind.METHOD)) return true; final GrMethodCall call = checkMethodCall(place, USE); if (call == null) return true; final GrClosableBlock[] closures = call.getClosureArguments(); GrExpression[] args = call.getExpressionArguments(); if (!(placeEqualsSingleClosureArg(place, closures) || placeEqualsLastArg(place, args))) return true; if (!(call.resolveMethod() instanceof GrGdkMethod)) return true; state = state.put(ClassHint.RESOLVE_CONTEXT, call); if ((args.length == 1 || args.length == 2 && placeEqualsLastArg(place, args))) { PsiType type = args[0].getType(); if (type instanceof GrTupleType) { return processTypesFromTuple((GrTupleType)type, processor, state, place); } } return processTypesFomArgs(args, processor, state, place); }
public static boolean walkChildrenScopes(@NotNull PsiElement thisElement, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, PsiElement place) { PsiElement child = null; if (lastParent != null && lastParent.getParent() == thisElement) { child = lastParent.getPrevSibling(); if (child == null) return true; // first element } if (child == null) { child = thisElement.getLastChild(); } while (child != null) { if (!child.processDeclarations(processor, state, null, place)) return false; child = child.getPrevSibling(); } return true; }
@NotNull public static List<PyImportElement> getVisibleImports(@NotNull ScopeOwner owner) { final List<PyImportElement> visibleImports = new ArrayList<PyImportElement>(); PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() { @Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { if (element instanceof PyImportElement) { visibleImports.add((PyImportElement)element); } return true; } @Nullable @Override public <T> T getHint(@NotNull Key<T> hintKey) { return null; } @Override public void handleEvent(@NotNull Event event, @Nullable Object associated) { } }, owner, null, null); return visibleImports; }
@Override public boolean processClassLevelDeclarations(@NotNull PsiScopeProcessor processor) { final PyClassStub stub = getStub(); if (stub != null) { final List<StubElement> children = stub.getChildrenStubs(); for (StubElement child : children) { if (!processor.execute(child.getPsi(), ResolveState.initial())) { return false; } } } else { PyResolveUtil.scopeCrawlUp(processor, this, null, this); } return true; }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this); PsiElement[] decls = getDeclaredElements(); for (PsiElement decl : decls) { if (decl != lastParent) { if (!processor.execute(decl, state)) return false; } else { final ElementClassHint hint = processor.getHint(ElementClassHint.KEY); if (lastParent instanceof PsiClass) { if (hint == null || hint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) { if (!processor.execute(lastParent, state)) return false; } } } } return true; }
public static boolean processStaticImports(@NotNull PsiScopeProcessor resolver, @NotNull PsiFile file, @NotNull ResolveState state, @NotNull PsiElement place) { if (!shouldProcessMethods(resolver.getHint(ClassHint.KEY))) return true; return file.processDeclarations(new GrDelegatingScopeProcessorWithHints(resolver, null, ClassHint.RESOLVE_KINDS_METHOD) { @Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState _state) { if (_state.get(RESOLVE_CONTEXT) instanceof GrImportStatement) { super.execute(element, _state); } return true; } }, state, null, place); }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { if (!ResolveUtil.shouldProcessProperties(processor.getHint(ClassHint.KEY))) return true; if (lastParent != null && !(getParent() instanceof GrTypeDefinitionBody) && lastParent == getTupleInitializer()) { return true; } for (final GrVariable variable : getVariables()) { if (lastParent == variable) break; if (lastParent instanceof GrMethod && !(variable instanceof GrField)) break; if (!ResolveUtil.processElement(processor, variable, state)) return false; } return true; }
private static void resolveToMethodWithClosure(PsiElement place, PsiElement resolveToElement, String closureTypeFqcn, PsiScopeProcessor processor, ResolveState state, GroovyPsiManager psiManager) { if (place.getParent() instanceof GrMethodCallExpression) { GrLightMethodBuilder methodWithClosure = GradleResolverUtil.createMethodWithClosure(place.getText(), closureTypeFqcn, null, place, psiManager); if (methodWithClosure != null) { processor.execute(methodWithClosure, state); methodWithClosure.setNavigationElement(resolveToElement); } } else if (place.getParent() instanceof GrReferenceExpression) { GrLightVariable variable = new GrLightVariable(place.getManager(), place.getText(), closureTypeFqcn, place); processor.execute(variable, state); } }
@Override public boolean processDeclarations(@NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { assert isValid(); if (processor instanceof ClassResolverProcessor && isPhysical() && (getUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING) == Boolean.TRUE || myResolveCache.hasUpToDateValue())) { final ClassResolverProcessor hint = (ClassResolverProcessor)processor; String name = hint.getName(state); MostlySingularMultiMap<String, SymbolCollectingProcessor.ResultWithContext> cache = myResolveCache.getValue(); MyResolveCacheProcessor cacheProcessor = new MyResolveCacheProcessor(processor, state); return name != null ? cache.processForKey(name, cacheProcessor) : cache.processAllValues(cacheProcessor); } return processDeclarationsNoGuess(processor, state, lastParent, place); }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { if (lastParent instanceof PsiExpressionList) return true; final PsiClassStub stub = getStub(); if (stub != null) { // no tree is loaded // that means we could not have come from resolving something inside anonymous class, we just resolving the base class reference // so skip the (very expensive) getBaseClassReference() call which would load tree return true; } if (lastParent != null/* IMPORTANT: do not call getBaseClassReference() for lastParent == null and lastParent which is not under our node - loads tree!*/ && lastParent.getParent() == this && lastParent == getBaseClassReference()) { return true; } return super.processDeclarations(processor, state, lastParent, place); }
public static boolean doTreeWalkUp(@NotNull final PsiElement place, @NotNull final PsiElement originalPlace, @NotNull final PsiScopeProcessor processor, @Nullable final PsiScopeProcessor nonCodeProcessor, @NotNull final ResolveState state) { final GrClosableBlock maxScope = nonCodeProcessor != null ? PsiTreeUtil.getParentOfType(place, GrClosableBlock.class, true, PsiFile.class) : null; return PsiTreeUtil.treeWalkUp(place, maxScope, new PairProcessor<PsiElement, PsiElement>() { @Override public boolean process(PsiElement scope, PsiElement lastParent) { ProgressManager.checkCanceled(); if (!doProcessDeclarations(originalPlace, lastParent, scope, substituteProcessor(processor, scope), nonCodeProcessor, state)) { return false; } issueLevelChangeEvents(processor, scope); return true; } }); }
@Override public boolean processInstanceLevelDeclarations(@NotNull PsiScopeProcessor processor, @Nullable PsiElement location) { Map<String, PyTargetExpression> declarationsInMethod = new HashMap<String, PyTargetExpression>(); PyFunction instanceMethod = PsiTreeUtil.getParentOfType(location, PyFunction.class); final PyClass containingClass = instanceMethod != null ? instanceMethod.getContainingClass() : null; if (instanceMethod != null && containingClass != null && CompletionUtil.getOriginalElement(containingClass) == this) { collectInstanceAttributes(instanceMethod, declarationsInMethod); for (PyTargetExpression targetExpression : declarationsInMethod.values()) { if (!processor.execute(targetExpression, ResolveState.initial())) { return false; } } } for (PyTargetExpression expr : getInstanceAttributes()) { if (declarationsInMethod.containsKey(expr.getName())) { continue; } if (!processor.execute(expr, ResolveState.initial())) return false; } return true; }
@Override public void processDynamicElements(@NotNull PsiType qualifierType, @Nullable PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { if (aClass == null) { return; } if (!GRADLE_API_CONFIGURATION_CONTAINER.equals(aClass.getQualifiedName())) { return; } // Assuming that the method call is equivalent to calling ConfigurationContainer.getByName() processConfigurationAddition(aClass, processor, state, place); }
@Override public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { PsiElement pomElement = aClass.getContainingFile().getContext(); if (pomElement == null) return; PsiFile pomFile = pomElement.getContainingFile(); if (!(pomFile instanceof XmlFile)) return; DomManager domManager = DomManager.getDomManager(pomElement.getProject()); if (!(domManager.getDomFileDescription((XmlFile)pomFile) instanceof MavenDomProjectModelDescription)) { return; } DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE); }
private boolean processChildrenScopes(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { final StubElement<?> stub = getStub(); if (stub != null) { return true; // only local usages are traversed here. Having a stub means the clients are outside and won't see our variables } PsiElement run = lastParent == null ? getLastChild() : lastParent.getPrevSibling(); while (run != null) { if (shouldProcess(lastParent, run) && !run.processDeclarations(processor, state, null, place)) { return false; } run = run.getPrevSibling(); } return true; }
public static void processDeclarations(@Nullable String methodName, @NotNull GroovyPsiManager psiManager, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place, @NotNull String... fqNames) { for (String fqName : fqNames) { if(fqName == null) continue; PsiClass psiClass = psiManager.findClassWithCache(fqName, place.getResolveScope()); if (psiClass != null) { psiClass.processDeclarations(processor, state, null, place); if (methodName != null) { processMethod(methodName, psiClass, processor, state, place); } } } }
private boolean processParameters(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { if (!ResolveUtil.shouldProcessProperties(processor.getHint(ClassHint.KEY))) return true; if (hasParametersSection()) { for (GrParameter parameter : getParameters()) { if (!ResolveUtil.processElement(processor, parameter, state)) return false; } } else if (!isItAlreadyDeclared(place)) { GrParameter[] synth = getSyntheticItParameter(); if (synth.length > 0) { if (!ResolveUtil.processElement(processor, synth[0], state.put(ClassHint.RESOLVE_CONTEXT, this))) return false; } } return true; }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { return AppleScriptPsiElementImpl.processDeclarationsImpl(this, processor, state, lastParent, place) && super.processDeclarations(processor, state, lastParent, place); }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { return processDeclarationsImpl(this, processor, state, lastParent, place) && super.processDeclarations(processor, state, lastParent, place); }
public static boolean treeWalkUp(PsiElement place, PsiScopeProcessor processor) { PsiElement lastParent = null; PsiElement run = place; while (run != null) { if (!run.processDeclarations(processor, ResolveState.initial(), lastParent, place)) return false; lastParent = run; run = run.getContext(); //same as getParent } return true; }
public static boolean processChildren(PsiElement element, PsiScopeProcessor processor, ResolveState substitutor, PsiElement lastParent, PsiElement place) { PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling(); while (run != null) { if (PsiTreeUtil.findCommonParent(place, run) != run && !run.processDeclarations(processor, substitutor, lastParent, place)) return false; run = run.getPrevSibling(); } return true; }
static PsiScopeProcessor substituteProcessor(PsiScopeProcessor processor, PsiElement scope) { //hack for walking up in java code //java's processDeclarations don't check names so we should do it manually if (scope.getLanguage() != GroovyLanguage.INSTANCE && processor.getHint(NameHint.KEY) != null) { return new JavaResolverProcessor(processor); } return processor; }
@Override public boolean processDeclarations(PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place) { PsiElement run = lastParent == null ? getLastChild() : lastParent.getPrevSibling(); if (run != null && run.getParent() != this) run = null; while (run != null) { if (!run.processDeclarations(processor, state, null, place)) return false; run = run.getPrevSibling(); } return true; }
private boolean processImportsOnDemand(PsiScopeProcessor processor, ResolveState state, PsiElement parent, PsiElement place) { for (GrImportStatement anImport : myOnDemandImports) { if (!anImport.processDeclarations(processor, state, parent, place)) { return false; } } return true; }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) { return myWrappee.processDeclarations(processor, state, lastParent, place); }
@Override public void processDynamicElements(@NotNull PsiType qualifierType, @NotNull PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { processDynamicElements(qualifierType, processor, place, state); }
public static void processTypeDeclarations(PsiType type, PsiElement place, PsiScopeProcessor processor) { if (type instanceof PsiArrayType) { LanguageLevel languageLevel = PsiUtil.getLanguageLevel(place); final PsiClass arrayClass = JavaPsiFacade.getInstance(place.getProject()).getElementFactory().getArrayClass(languageLevel); final PsiTypeParameter[] arrayTypeParameters = arrayClass.getTypeParameters(); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; if (arrayTypeParameters.length > 0) { substitutor = substitutor.put(arrayTypeParameters[0], ((PsiArrayType)type).getComponentType()); } arrayClass.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, substitutor), arrayClass, place); } else if (type instanceof PsiIntersectionType) { for (PsiType psiType : ((PsiIntersectionType)type).getConjuncts()) { processTypeDeclarations(psiType, place, processor); } } else if (type instanceof PsiDisjunctionType) { final PsiType lub = ((PsiDisjunctionType)type).getLeastUpperBound(); processTypeDeclarations(lub, place, processor); } else { final JavaResolveResult result = PsiUtil.resolveGenericsClassInType(type); final PsiClass clazz = (PsiClass)result.getElement(); if (clazz != null) { clazz.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, result.getSubstitutor()), clazz, place); } } }
static void issueLevelChangeEvents(PsiScopeProcessor processor, PsiElement run) { processor.handleEvent(JavaScopeProcessorEvent.CHANGE_LEVEL, null); if (run instanceof GrClosableBlock && GrClosableBlock.OWNER_NAME.equals(getNameHint(processor)) || run instanceof PsiClass && !(run instanceof PsiAnonymousClass) || run instanceof GrMethod && run.getParent() instanceof GroovyFile) { processor.handleEvent(DECLARATION_SCOPE_PASSED, run); } }
public static void processImplicitDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place) { if (!place.getText().equals("resources")) { GroovyPsiManager psiManager = GroovyPsiManager.getInstance(place.getProject()); GradleResolverUtil.processDeclarations(psiManager, processor, state, place, GRADLE_API_PROJECT); } }
@Nullable public static String getNameHint(PsiScopeProcessor processor) { NameHint nameHint = processor.getHint(NameHint.KEY); if (nameHint == null) { return null; } return nameHint.getName(ResolveState.initial()); }
@Override public void processDynamicElements(@NotNull final PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull final PsiElement place, @NotNull ResolveState state) { if (isInAnnotation(place)) return; final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType); if (aClass == null) return; final PsiModifierList modifierList = aClass.getModifierList(); if (modifierList == null) return; List<PsiClass> mixins = new ArrayList<PsiClass>(); for (PsiAnnotation annotation : getAllMixins(modifierList)) { final PsiAnnotationMemberValue value = annotation.findAttributeValue("value"); if (value instanceof GrAnnotationArrayInitializer) { final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer)value).getInitializers(); for (GrAnnotationMemberValue initializer : initializers) { addMixin(initializer, mixins); } } else if (value instanceof GrExpression) { addMixin((GrExpression)value, mixins); } } final MixinProcessor delegate = new MixinProcessor(processor, qualifierType, place); for (PsiClass mixin : mixins) { if (!mixin.processDeclarations(delegate, state, null, place)) { return; } } }
public static void addImplicitVariable(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement element, @NotNull String type) { PsiVariable myPsi = new GrImplicitVariableImpl(element.getManager(), element.getText(), type, element); processor.execute(myPsi, state); }
@Nullable private static PsiMethod findAndProcessContributingMethod(String symbol, PsiScopeProcessor processor, ResolveState state, PsiElement place, PsiClass contributorClass, GroovyPsiManager psiManager) { PsiMethod method = getContributingMethod(place, contributorClass, symbol); if (method == null) { return null; } ParametrizedTypeExtractor typeExtractor = getTypeExtractor(method); if (typeExtractor != null && !typeExtractor.hasNamedDomainObjectContainer() && typeExtractor.isClosure()) { // method takes a closure argument String clz = typeExtractor.getClosureType(); if (clz == null) { clz = CommonClassNames.JAVA_LANG_OBJECT; } if (ourDslForClassMap.containsKey(clz)) { clz = ourDslForClassMap.get(clz); } resolveToMethodWithClosure(place, method, clz, processor, state, psiManager); } else { GrLightMethodBuilder builder = new GrLightMethodBuilder(place.getManager(), method.getName()); PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getManager().getProject()); PsiType type = new PsiArrayType(factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope())); builder.addParameter(new GrLightParameter("param", type, builder)); PsiClassType retType = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope()); builder.setReturnType(retType); processor.execute(builder, state); builder.setNavigationElement(method); } return method; }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this); final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY); if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) { final PsiClass[] classes = getClasses(); for (PsiClass aClass : classes) { if (!processor.execute(aClass, state)) return false; } } return true; }