private boolean execute(@NotNull Match match, @NotNull ResolveState state) { /* ensure DECLARING_SCOPE is `true` to counter `DECLARING_SCOPE` being `false` for -> signature under `after` or `cond` */ ResolveState matchState = state.put(DECLARING_SCOPE, true); return execute((Infix) match, matchState); }
/** * Turns off any DECLARING_SCOPE because the {@link Infix} subclass can never be used to declare a variable in a * match. * * The rule is, if a lone variable by itself as an operand would declare that variable in a match then call, * {@link #execute(Infix, ResolveState)}; otherwise, call this method. */ private boolean executeNonDeclaringScopeInfix(@NotNull final Infix match, @NotNull ResolveState state) { return execute(match, state.put(DECLARING_SCOPE, false)); }
private boolean executeStrippedCallDefinitionHead(@NotNull Call strippedCallDefinitionHead, @NotNull ResolveState state) { boolean keepProcessing = true; PsiElement[] finalArguments = finalArguments(strippedCallDefinitionHead); if (finalArguments != null) { // set scope to declaring so that calls inside the arguments are treated as maybe macros keepProcessing = execute(finalArguments, state.put(DECLARING_SCOPE, true)); } return keepProcessing; }
@NotNull public static ResolveState createContextOnElement(@NotNull PsiElement element) { return ResolveState.initial().put(CONTEXT, SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element)); }
private boolean processGoType(@NotNull GoType type, @NotNull GoScopeProcessor processor, @NotNull ResolveState state) { Boolean result = RecursionManager.doPreventingRecursion(type, true, () -> { if (type instanceof GoParType) return processGoType(((GoParType)type).getActualType(), processor, state); if (!processExistingType(type, processor, state)) return false; if (type instanceof GoPointerType) { if (!processPointer((GoPointerType)type, processor, state.put(POINTER, true))) return false; GoType pointer = ((GoPointerType)type).getType(); if (pointer instanceof GoPointerType) { return processPointer((GoPointerType)pointer, processor, state.put(POINTER, true)); } } return processTypeRef(type, processor, state); }); return Boolean.TRUE.equals(result); }
private boolean processInTypeRef(@Nullable GoTypeReferenceExpression e, @NotNull GoScopeProcessor processor, @NotNull ResolveState state) { PsiElement resolve = e != null ? e.resolve() : null; if (resolve instanceof GoTypeOwner) { GoType type = ((GoTypeOwner)resolve).getGoType(state); if (type == null) return true; if (!processGoType(type, processor, state)) return false; if (type instanceof GoSpecType) { GoType inner = ((GoSpecType)type).getType(); if (inner instanceof GoPointerType && state.get(POINTER) != null) return true; if (inner != null && !processGoType(inner, processor, state.put(DONT_PROCESS_METHODS, true))) return false; } return true; } return true; }
@Nullable public static List<ResolveResult> resolveResultList(@NotNull String name, boolean incompleteCode, @NotNull PsiElement entrance, @NotNull ResolveState resolveState) { MultiResolve multiResolve = new MultiResolve(name, incompleteCode); ResolveState treeWalkUpResolveState = resolveState; if (treeWalkUpResolveState.get(ENTRANCE) == null) { treeWalkUpResolveState = treeWalkUpResolveState.put(ENTRANCE, entrance); } PsiTreeUtil.treeWalkUp( multiResolve, entrance, entrance.getContainingFile(), treeWalkUpResolveState ); return multiResolve.getResolveResultList(); }
@NotNull public static List<LookupElement> lookupElementList(@NotNull PsiElement entrance) { Variants variants = new Variants(); PsiTreeUtil.treeWalkUp( variants, entrance, entrance.getContainingFile(), ResolveState.initial().put(ENTRANCE, entrance) ); Collection<LookupElement> lookupElementCollection = variants.getLookupElementCollection(); List<LookupElement> lookupElementList; if (lookupElementCollection != null) { lookupElementList = new ArrayList<LookupElement>(lookupElementCollection); } else { lookupElementList = Collections.emptyList(); } return lookupElementList; }
protected boolean processImports(@NotNull GoFile file, @NotNull GoScopeProcessor processor, @NotNull ResolveState state, @NotNull GoCompositeElement element) { for (Map.Entry<String, Collection<GoImportSpec>> entry : file.getImportMap().entrySet()) { for (GoImportSpec o : entry.getValue()) { if (o.isForSideEffects()) continue; GoImportString importString = o.getImportString(); if (o.isDot()) { PsiDirectory implicitDir = importString.resolve(); boolean resolved = !processDirectory(implicitDir, file, null, processor, state, false); if (resolved && !processor.isCompletion()) { putIfAbsent(o, element); } if (resolved) return false; } else { if (o.getAlias() == null) { PsiDirectory resolve = importString.resolve(); if (resolve != null && !processor.execute(resolve, state.put(ACTUAL_NAME, entry.getKey()))) return false; } // todo: multi-resolve into appropriate package clauses if (!processor.execute(o, state.put(ACTUAL_NAME, entry.getKey()))) return false; } } } return true; }
resolveState = resolveState.put(BallerinaCompletionUtils.PUBLIC_DEFINITIONS_ONLY, "PUBLIC_DEFINITIONS_ONLY"); if (!processor.execute(child, resolveState)) {
private boolean execute(@NotNull InMatch match, @NotNull ResolveState state) { Operator operator = match.operator(); String operatorText = operator.getText(); boolean keepProcessing = true; if (operatorText.equals(DEFAULT_OPERATOR)) { PsiElement defaulted = match.leftOperand(); if (defaulted instanceof PsiNamedElement) { keepProcessing = executeOnVariable((PsiNamedElement) defaulted, state); } } else if (operatorText.equals("<-")) { PsiElement entrance = state.get(ENTRANCE); PsiElement rightOperand = match.rightOperand(); // variable on right of <- can't be declared on left because right expression generates left expression if (!PsiTreeUtil.isAncestor(rightOperand, entrance, false)) { // counter {@code state.put(DECLARING_SCOPE, false)} in #boolean(Call, Resolve) for {@code for} keepProcessing = executeLeftOperand(match, state.put(DECLARING_SCOPE, true)); } } return keepProcessing; }
if (!processCollectedRefs(interfaceRefs, processor, state.put(POINTER, null))) return false; if (!processCollectedRefs(structRefs, processor, state)) return false;
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { if (isScopingConstruct()) { // In a tree-up-walk, we only consider declarations of Module, Block, .. when we come from inside this Module. // Therefore, we need to check whether our last position was inside and if not, we don't consider the declarations // of this. if (lastParent == this.getHead() || lastParent.getParent() != this) { return true; } if (isScopingConstruct()) { state = state.put(SymbolResolveHint.RESOLVE_CONTEXT, this); state = state.put(SymbolResolveHint.LAST_PARENT, lastParent); return processor.execute(this, state); } } return true; }
state = state.put(visitedIncludeFiles, visitedFiles);