com.intellij.psi.ResolveState Java Examples

The following examples show how to use com.intellij.psi.ResolveState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSharpForStatementImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement
		place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(DotNetVariable dotNetVariable : getVariables())
	{
		if(!processor.execute(dotNetVariable, state))
		{
			return false;
		}
	}
	return true;
}
 
Example #2
Source File: GenericFromParentKindProcessor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull CSharpResolveOptions options,
		@Nonnull DotNetGenericExtractor defaultExtractor,
		@Nullable PsiElement forceQualifierElement,
		@Nonnull Processor<ResolveResult> processor)
{
	PsiElement element = options.getElement();

	DotNetGenericParameterListOwner genericParameterListOwner = CSharpReferenceExpressionImplUtil.findParentOrNextIfDoc(element,
			DotNetGenericParameterListOwner.class);
	if(genericParameterListOwner == null)
	{
		return;
	}

	SimpleNamedScopeProcessor scopeProcessor = new SimpleNamedScopeProcessor(processor, options.isCompletion(), ExecuteTarget.GENERIC_PARAMETER);
	ResolveState state = ResolveState.initial();
	state = state.put(CSharpResolveUtil.SELECTOR, options.getSelector());
	genericParameterListOwner.processDeclarations(scopeProcessor, state, null, element);
}
 
Example #3
Source File: CSharpBinaryExpressionImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	DotNetExpression leftExpression = getLeftExpression();
	if(leftExpression != null && !leftExpression.processDeclarations(processor, state, lastParent, place))
	{
		return false;
	}

	DotNetExpression rightExpression = getRightExpression();
	if(rightExpression != null && !rightExpression.processDeclarations(processor, state, lastParent, place))
	{
		return false;
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #4
Source File: CSharpSearchUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static DotNetPropertyDeclaration findPropertyByName(@Nonnull final String name, @Nonnull PsiElement owner, @Nullable String parentQName, @Nonnull DotNetGenericExtractor extractor)
{
	AsPsiElementProcessor psiElementProcessor = new AsPsiElementProcessor();
	MemberResolveScopeProcessor memberResolveScopeProcessor = new MemberResolveScopeProcessor(owner, psiElementProcessor, new ExecuteTarget[]{ExecuteTarget.PROPERTY},
			OverrideProcessor.ALWAYS_TRUE);

	ResolveState state = ResolveState.initial();
	state = state.put(CSharpResolveUtil.EXTRACTOR, extractor);
	state = state.put(CSharpResolveUtil.SELECTOR, new MemberByNameSelector(name));

	CSharpResolveUtil.walkChildren(memberResolveScopeProcessor, owner, false, true, state);
	for(PsiElement element : psiElementProcessor.getElements())
	{
		if(isMyElement(element, parentQName))
		{
			return (DotNetPropertyDeclaration) element;
		}
	}
	return null;
}
 
Example #5
Source File: ParameterFromParentKindProcessor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull CSharpResolveOptions options,
		@Nonnull DotNetGenericExtractor defaultExtractor,
		@Nullable PsiElement forceQualifierElement,
		@Nonnull Processor<ResolveResult> processor)
{
	PsiElement element = options.getElement();

	DotNetParameterListOwner parameterListOwner = CSharpReferenceExpressionImplUtil.findParentOrNextIfDoc(element, DotNetParameterListOwner
			.class);
	if(parameterListOwner == null)
	{
		return;
	}

	SimpleNamedScopeProcessor scopeProcessor = new SimpleNamedScopeProcessor(processor, options.isCompletion(),
			ExecuteTarget.LOCAL_VARIABLE_OR_PARAMETER_OR_LOCAL_METHOD);
	ResolveState state = ResolveState.initial();
	state = state.put(CSharpResolveUtil.SELECTOR, options.getSelector());

	parameterListOwner.processDeclarations(scopeProcessor, state, null, element);
}
 
Example #6
Source File: CSharpLinqExpressionImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(PsiElement psiElement : getChildren())
	{
		if(!psiElement.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #7
Source File: CSharpForeachStatementImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}
	CSharpLocalVariable variable = getVariable();
	if(variable != null)
	{
		if(!processor.execute(variable, state))
		{
			return false;
		}
	}
	return true;
}
 
Example #8
Source File: DumbFunctionReference.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiElement resolveInner() {
    final String referencedName = cmd.getReferencedCommandName();
    if (referencedName == null) {
        return null;
    }


    // in dumb mode the current is the only one searched for function definitions
    List<BashFunctionDef> functionDefs = cmd.getContainingFile().allFunctionDefinitions();

    ResolveState initial = ResolveState.initial();

    ResolveProcessor processor = new BashFunctionProcessor(referencedName);
    for (BashFunctionDef functionDef : functionDefs) {
        processor.execute(functionDef, initial);
    }

    processor.prepareResults();

    return processor.hasResults() ? processor.getBestResult(true, cmd) : null;
}
 
Example #9
Source File: CSharpFixedStatementImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(DotNetVariable dotNetVariable : getVariables())
	{
		if(!processor.execute(dotNetVariable, state))
		{
			return false;
		}
	}
	return true;
}
 
Example #10
Source File: GLSLFunctionDefinitionImpl.java    From glsl4idea with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (lastParent == null) {
        // Do not show declarations of parameters to outside scopes
        return true;
    }

    for (GLSLParameterDeclaration parameter : getParameters()) {
        if (parameter == lastParent) // TODO(jp): sloppy, parameter is probably not direct child, so this will fail
            continue;

        if (!parameter.processDeclarations(processor, state, lastParent, place)) return false;
    }

    return true;
}
 
Example #11
Source File: CSharpLinqJoinClauseImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	CSharpLinqVariableImpl variable = getVariable();
	if(variable != null)
	{
		if(!processor.execute(variable, state))
		{
			return false;
		}
	}

	CSharpLinqIntoClauseImpl intoClause = getIntoClause();
	if(intoClause != null)
	{
		if(!intoClause.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return true;
}
 
Example #12
Source File: CSharpLinqQueryBodyImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(lastParent == null || !PsiTreeUtil.isAncestor(this, lastParent, false))
	{
		return true;
	}

	for(PsiElement psiElement : getChildren())
	{
		if(!psiElement.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #13
Source File: GLSLCompoundStatement.java    From glsl4idea with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state,
                                   @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (lastParent == null) {
        // Do not show declarations of nested variables to outside scopes
        return true;
    }

    for (GLSLStatement statement : getStatements()) {
        if (statement == null)
            continue;
        if (!statement.processDeclarations(processor, state, lastParent, place)) return false;
    }

    return true;
}
 
Example #14
Source File: CSharpCasePatternStatementImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredReadAction
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	DotNetVariable variable = getVariable();
	if(!processor.execute(variable, state))
	{
		return false;
	}

	DotNetExpression whenExpression = getWhenExpression();
	if(whenExpression != null && !whenExpression.processDeclarations(processor, state, lastParent, place))
	{
		return false;
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #15
Source File: CSharpNewExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	CSharpCallArgument[] callArguments = getCallArguments();
	for(CSharpCallArgument callArgument : callArguments)
	{
		if(!callArgument.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #16
Source File: CSharpXAccessorImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor,
		@Nonnull ResolveState state,
		PsiElement lastParent,
		@Nonnull PsiElement place)
{
	if(ExecuteTargetUtil.canProcess(processor, ExecuteTarget.LOCAL_VARIABLE_OR_PARAMETER_OR_LOCAL_METHOD))
	{
		PsiElement parent = getParent();
		if(!parent.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}

		Kind accessorKind = getAccessorKind();
		if(accessorKind == Kind.SET || accessorKind == Kind.ADD || accessorKind == Kind.REMOVE)
		{
			Pair<DotNetTypeRef, DotNetQualifiedElement> pair = getTypeRefOfParent();
			if(pair.getSecond() == null)
			{
				return true;
			}

			CSharpLightLocalVariableBuilder builder = new CSharpLightLocalVariableBuilder(pair.getSecond()).withName(VALUE).withParent(this)
					.withTypeRef(pair.getFirst());

			builder.putUserData(CSharpResolveUtil.ACCESSOR_VALUE_VARIABLE_OWNER, pair.getSecond());

			if(!processor.execute(builder, state))
			{
				return false;
			}
		}
	}
	return true;
}
 
Example #17
Source File: CSharpElementGroupImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	for(T element : myElements)
	{
		ProgressManager.checkCanceled();

		if(!processor.execute(element, state))
		{
			return false;
		}
	}
	return true;
}
 
Example #18
Source File: CSharpPrefixExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	DotNetExpression expression = getExpression();
	if(expression != null && !expression.processDeclarations(processor, state, lastParent, place))
	{
		return false;
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #19
Source File: SimpleNamedScopeProcessor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public boolean execute(@Nonnull PsiElement element, ResolveState state)
{
	if(!(element instanceof PsiNamedElement) || !ExecuteTargetUtil.isMyElement(this, element))
	{
		return true;
	}

	String name = ((PsiNamedElement) element).getName();
	if(name == null)
	{
		return true;
	}

	if(myCompletion)
	{
		return myCompletionProcessor.process(new CSharpResolveResult(element));
	}
	else
	{
		CSharpResolveSelector selector = state.get(CSharpResolveUtil.SELECTOR);
		if(!(selector instanceof CSharpNamedResolveSelector))
		{
			return true;
		}

		if(((CSharpNamedResolveSelector) selector).isNameEqual(name))
		{
			myCompletionProcessor.process(new CSharpResolveResult(element));
			return false;
		}
	}
	return true;
}
 
Example #20
Source File: MemberResolveScopeProcessor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public boolean execute(@Nonnull PsiElement element, ResolveState state)
{
	CSharpResolveSelector selector = state.get(CSharpResolveUtil.SELECTOR);
	if(selector == null)
	{
		return true;
	}

	DotNetGenericExtractor extractor = state.get(CSharpResolveUtil.EXTRACTOR);
	assert extractor != null;

	CSharpResolveContext context = CSharpResolveContextUtil.createContext(extractor, myResolveScope, element);

	Collection<PsiElement> psiElements = selector.doSelectElement(context, state.get(CSharpResolveUtil.WALK_DEEP) == Boolean.TRUE);
	psiElements = applyTypeArguments(psiElements);
	psiElements = CSharpCompositeTypeDeclaration.wrapPartialTypes(myResolveScope, myScopeElement.getProject(), psiElements);

	for(PsiElement psiElement : OverrideUtil.filterOverrideElements(this, myScopeElement, psiElements, myOverrideProcessor))
	{
		ProgressManager.checkCanceled();

		if(!ExecuteTargetUtil.isMyElement(this, psiElement))
		{
			continue;
		}

		final CSharpResolveResult result = new CSharpResolveResult(psiElement);
		result.setProvider(element);
		result.setAssignable(myScopeElement);

		if(!myResultProcessor.process(result))
		{
			return false;
		}
	}
	return true;
}
 
Example #21
Source File: CSharpOutRefVariableExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	DotNetVariable variable = getVariable();
	if(!processor.execute(variable, state))
	{
		return false;
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example #22
Source File: HaxeMacroUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static Set<HaxeComponentName> findVariables(@Nullable PsiElement at) {
  if (at == null) {
    return Collections.emptySet();
  }
  final Set<HaxeComponentName> result = new THashSet<HaxeComponentName>();
  PsiTreeUtil.treeWalkUp(new PsiScopeProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, ResolveState state) {
      if (element instanceof HaxeNamedComponent) {
        final HaxeNamedComponent haxeNamedComponent = (HaxeNamedComponent)element;
        if (haxeNamedComponent.getComponentName() != null && HaxeComponentType.isVariable(HaxeComponentType.typeOf(haxeNamedComponent))) {
          result.add(haxeNamedComponent.getComponentName());
        }
      }
      return true;
    }

    @Override
    public <T> T getHint(@NotNull Key<T> hintKey) {
      return null;
    }

    @Override
    public void handleEvent(Event event, @Nullable Object associated) {
    }
  }, at, null, ResolveState.initial());
  return result;
}
 
Example #23
Source File: ResolveUtil.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public static <T extends XQueryPsiElement> boolean processChildren(PsiElement element, PsiScopeProcessor processor,
        ResolveState substitutor, PsiElement lastParent, PsiElement place, Class<T>... childClassesToSkip) {
    PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
    while (run != null) {
        if (!isAnyOf(run, childClassesToSkip) &&PsiTreeUtil.findCommonParent(place, run) != run && !run.processDeclarations(processor, substitutor,
                null, place)) {
            return false;
        }
        run = run.getPrevSibling();
    }

    return true;
}
 
Example #24
Source File: ExpectedUsingInfo.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private boolean isUsedNamespace(String namespace, PsiElement target, PsiElement element)
{
	return !CSharpResolveUtil.walkUsing(new BaseScopeProcessor()
	{
		@Override
		@RequiredReadAction
		public boolean execute(@Nonnull PsiElement psiElement, ResolveState resolveState)
		{
			if(psiElement instanceof CSharpUsingTypeStatement)
			{
				DotNetTypeResolveResult typeResolveResult = ((CSharpUsingTypeStatement) psiElement).getTypeRef().resolve();
				if(target.isEquivalentTo(typeResolveResult.getElement()))
				{
					return false;
				}
			}
			else if(psiElement instanceof CSharpUsingNamespaceStatement)
			{
				String referenceText = ((CSharpUsingNamespaceStatement) psiElement).getReferenceText();
				if(Objects.equals(namespace, referenceText))
				{
					return false;
				}
			}
			return true;
		}
	}, element, null, ResolveState.initial());
}
 
Example #25
Source File: XQueryXmlNamespaceReference.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private XQueryAttrLocalName getReferenceFromXmlUpInTheHierarchy() {
    XmlTagNamespaceReferenceScopeProcessor processor = new XmlTagNamespaceReferenceScopeProcessor<T>(myElement);
    PsiTreeUtil.treeWalkUp(processor, myElement, null, ResolveState.initial());
    if (processor.getResult() != null) {
        return processor.getResult();
    } else {
        return null;
    }
}
 
Example #26
Source File: CSharpLinqLetClauseImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent,
		@Nonnull PsiElement place)
{
	CSharpLinqVariableImpl variable = getVariable();
	if(variable != null)
	{
		if(!processor.execute(variable, state))
		{
			return false;
		}
	}
	return true;
}
 
Example #27
Source File: HaxeRefactoringUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static Set<String> collectUsedNames(HaxePsiCompositeElement context) {
  final Set<HaxeComponentName> usedComponentNames = new THashSet<HaxeComponentName>();
  PsiTreeUtil.treeWalkUp(new ComponentNameScopeProcessor(usedComponentNames), context, null, new ResolveState());
  return new THashSet<String>(ContainerUtil.map(usedComponentNames, new Function<HaxeComponentName, String>() {
    @Nullable
    @Override
    public String fun(HaxeComponentName componentName) {
      return componentName.getName();
    }
  }));
}
 
Example #28
Source File: GLSLFile.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (lastParent == null) {
        return true;
    }
    PsiElement child = lastParent.getPrevSibling();
    while (child != null) {
        if (!child.processDeclarations(processor, state, lastParent, place)) return false;
        child = child.getPrevSibling();
    }
    return true;
}
 
Example #29
Source File: PsiScopesUtilCore.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean treeWalkUp(@Nonnull final PsiScopeProcessor processor,
                                 @Nonnull final PsiElement entrance,
                                 @Nullable final PsiElement maxScope,
                                 @Nonnull final ResolveState state) {
  if (!entrance.isValid()) {
    LOGGER.error(new PsiInvalidElementAccessException(entrance));
  }
  PsiElement prevParent = entrance;
  PsiElement scope = entrance;

  while (scope != null) {
    ProgressIndicatorProvider.checkCanceled();

    if (!scope.processDeclarations(processor, state, prevParent, entrance)) {
      return false; // resolved
    }


    if (scope == maxScope) break;
    prevParent = scope;
    scope = prevParent.getContext();
    if (scope != null && scope != prevParent.getParent() && !scope.isValid()) {
      break;
    }

  }

  return true;
}
 
Example #30
Source File: GLSLReferenceBase.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
public Object[] getVariants() {
    List<PsiNamedElement> elements = new ArrayList<>();
    NamedElementCollector collector = new NamedElementCollector(elements);
    PsiTreeUtil.treeWalkUp(collector, source, null, ResolveState.initial());
    return elements.toArray();
}