private boolean processStructType(@NotNull GoScopeProcessor fieldProcessor, @Nullable GoType type) { return !(type instanceof GoStructType && !type.processDeclarations(fieldProcessor, ResolveState.initial(), null, myElement)); }
private void addToResolveResultList(@NotNull PsiElement element, ResolveState state, boolean validResult) { Boolean declaringScope = state.get(DECLARING_SCOPE); PsiElement lastBinding = state.get(LAST_BINDING_KEY); boolean added = false; expression, ResolveState .initial() .put(ENTRANCE, matchAncestor) .put(LAST_BINDING_KEY, element) );
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 PsiElement getContextElement(@Nullable ResolveState state) { SmartPsiElementPointer<PsiElement> context = state != null ? state.get(CONTEXT) : null; return context != null ? context.getElement() : null; }
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); }
@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; }
@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(); }
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { if (element.equals(o)) return !result.add(new PsiElementResolveResult(element)); String name = ObjectUtils.chooseNotNull(state.get(ACTUAL_NAME), element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName() : null); if (name != null && o.getIdentifier().textMatches(name)) { result.add(new PsiElementResolveResult(element)); return false; } return true; } };
/** * 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)); }
public boolean processResolveVariants(@NotNull BallerinaScopeProcessor processor) { return processor.execute(myElement, ResolveState.initial()); } }
boolean canProcessMethods = state.get(DONT_PROCESS_METHODS) == null; if (canProcessMethods && parent != null && !processNamedElements(processor, state, parent.getMethods(), localResolve, true)) return false; type.processDeclarations(delegate, ResolveState.initial(), null, myElement); List<GoTypeReferenceExpression> interfaceRefs = ContainerUtil.newArrayList(); List<GoTypeReferenceExpression> structRefs = ContainerUtil.newArrayList(); if (!processCollectedRefs(interfaceRefs, processor, state.put(POINTER, null))) return false; if (!processCollectedRefs(structRefs, processor, state)) return false; else if (state.get(POINTER) == null && type instanceof GoInterfaceType) { if (!processNamedElements(processor, state, ((GoInterfaceType)type).getMethods(), localResolve, true)) return false; if (!processCollectedRefs(((GoInterfaceType)type).getBaseTypesReferences(), processor, state)) return false;
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; }
protected boolean isInDeclaringScope(@NotNull Call call, @NotNull ResolveState state) { Boolean declaringScope = state.get(DECLARING_SCOPE); boolean inDeclaringScope; if (declaringScope != null) { inDeclaringScope = declaringScope; } else { inDeclaringScope = false; PsiElement maybeDeclaringScopeContext = PsiTreeUtil.getContextOfType( call, false, ElixirStabOperation.class, InMatch.class ); if (maybeDeclaringScopeContext != null) { if (maybeDeclaringScopeContext instanceof ElixirStabOperation) { ElixirStabOperation stabOperation = (ElixirStabOperation) maybeDeclaringScopeContext; PsiElement signature = stabOperation.leftOperand(); if (PsiTreeUtil.isAncestor(signature, call, false)) { inDeclaringScope = isDeclaringScope(stabOperation); } } else if (maybeDeclaringScopeContext instanceof InMatch) { InMatch inMatch = (InMatch) maybeDeclaringScopeContext; if (PsiTreeUtil.isAncestor(inMatch.leftOperand(), call, false)) { inDeclaringScope = true; } } } } return inDeclaringScope; }
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; }
public boolean processResolveVariants(@NotNull BallerinaScopeProcessor processor) { return processor.execute(myElement, ResolveState.initial()); } }
keepProcessing = execute(finalArguments[0], state.put(DECLARING_SCOPE, true)); PsiElement entrance = state.get(ENTRANCE); keepProcessing = execute(finalArgument, state.put(DECLARING_SCOPE, false)); state.put(DECLARING_SCOPE, false) ); ResolveState macroArgumentsState = state.put(DECLARING_SCOPE, true);
if (o instanceof GoNamedElement && !((GoNamedElement)o).isBlank() || o instanceof GoImportSpec && !((GoImportSpec)o).isDot()) { if (o instanceof GoImportSpec) { return GoCompletionUtil.createPackageLookupElement((GoImportSpec)o, state.get(GoReferenceBase.ACTUAL_NAME), vendoringEnabled);
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); }