com.intellij.psi.ResolveState#put ( )源码实例Demo

下面列出了com.intellij.psi.ResolveState#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@RequiredReadAction
private static CSharpFieldDeclaration findField(CSharpTypeDeclaration owner, String name)
{
	AsPsiElementProcessor psiElementProcessor = new AsPsiElementProcessor();
	MemberResolveScopeProcessor memberResolveScopeProcessor = new MemberResolveScopeProcessor(owner, psiElementProcessor, new ExecuteTarget[]{ExecuteTarget.FIELD}, OverrideProcessor.ALWAYS_TRUE);

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

	CSharpResolveUtil.walkChildren(memberResolveScopeProcessor, owner, false, true, state);
	for(PsiElement element : psiElementProcessor.getElements())
	{
		if(element instanceof CSharpFieldDeclaration)
		{
			return (CSharpFieldDeclaration) element;
		}
	}
	return null;
}
 
@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);
}
 
@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);
}
 
源代码4 项目: consulo-csharp   文件: CSharpSearchUtil.java
@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;
}
 
@RequiredReadAction
private static DotNetMethodDeclaration findMethodByName(@Nonnull String name, PsiElement owner)
{
	AsPsiElementProcessor psiElementProcessor = new AsPsiElementProcessor();
	MemberResolveScopeProcessor memberResolveScopeProcessor = new MemberResolveScopeProcessor(owner, psiElementProcessor, new ExecuteTarget[]{ExecuteTarget.ELEMENT_GROUP}, OverrideProcessor
			.ALWAYS_TRUE);

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

	CSharpResolveUtil.walkChildren(memberResolveScopeProcessor, owner, false, true, state);

	for(PsiElement psiElement : psiElementProcessor.getElements())
	{
		if(psiElement instanceof CSharpElementGroup)
		{
			for(PsiElement element : ((CSharpElementGroup<?>) psiElement).getElements())
			{
				if(element instanceof DotNetMethodDeclaration)
				{
					return (DotNetMethodDeclaration) element;
				}
			}
		}
	}
	return null;
}
 
源代码6 项目: BashSupport   文件: BashResolveUtil.java
public static PsiElement resolve(BashVar bashVar, boolean dumbMode, ResolveProcessor processor) {
    if (bashVar == null || !bashVar.isPhysical()) {
        return null;
    }

    final String varName = bashVar.getReferenceName();
    if (varName == null) {
        return null;
    }

    PsiFile psiFile = BashPsiUtils.findFileContext(bashVar);
    VirtualFile virtualFile = psiFile.getVirtualFile();

    String filePath = virtualFile != null ? virtualFile.getPath() : null;
    Project project = bashVar.getProject();

    ResolveState resolveState = ResolveState.initial();

    GlobalSearchScope fileScope = GlobalSearchScope.fileScope(psiFile);

    Collection<BashVarDef> varDefs;
    if (dumbMode || isScratchFile(virtualFile) || isNotIndexedFile(project, virtualFile)) {
        varDefs = PsiTreeUtil.collectElementsOfType(psiFile, BashVarDef.class);
    } else {
        varDefs = StubIndex.getElements(BashVarDefIndex.KEY, varName, project, fileScope, BashVarDef.class);
    }

    for (BashVarDef varDef : varDefs) {
        ProgressManager.checkCanceled();

        processor.execute(varDef, resolveState);
    }

    if (!dumbMode && filePath != null) {
        Collection<BashIncludeCommand> includeCommands = StubIndex.getElements(BashIncludeCommandIndex.KEY, filePath, project, fileScope, BashIncludeCommand.class);
        if (!includeCommands.isEmpty()) {
            boolean varIsInFunction = BashPsiUtils.findNextVarDefFunctionDefScope(bashVar) != null;

            for (BashIncludeCommand command : includeCommands) {
                ProgressManager.checkCanceled();

                boolean includeIsInFunction = BashPsiUtils.findNextVarDefFunctionDefScope(command) != null;

                //either one of var or include command is in a function or the var is used after the include command
                if (varIsInFunction || includeIsInFunction || (BashPsiUtils.getFileTextOffset(bashVar) > BashPsiUtils.getFileTextEndOffset(command))) {
                    try {
                        resolveState = resolveState.put(Keys.resolvingIncludeCommand, command);

                        command.processDeclarations(processor, resolveState, command, bashVar);
                    } finally {
                        resolveState = resolveState.put(Keys.resolvingIncludeCommand, null);
                    }
                }
            }
        }
    }

    processor.prepareResults();

    return processor.getBestResult(false, bashVar);
}
 
源代码7 项目: consulo-csharp   文件: OverrideUtil.java
@Nonnull
@RequiredReadAction
public static Collection<DotNetVirtualImplementOwner> collectOverridingMembers(final DotNetVirtualImplementOwner target)
{
	PsiElement parent = target.getParent();
	if(parent == null)
	{
		return Collections.emptyList();
	}
	OverrideProcessor.Collector overrideProcessor = new OverrideProcessor.Collector();

	MemberResolveScopeProcessor processor = new MemberResolveScopeProcessor(parent, CommonProcessors.<ResolveResult>alwaysTrue(), new ExecuteTarget[]{
			ExecuteTarget.MEMBER,
			ExecuteTarget.ELEMENT_GROUP
	}, overrideProcessor);

	ResolveState state = ResolveState.initial();
	if(target instanceof CSharpIndexMethodDeclaration)
	{
		state = state.put(CSharpResolveUtil.SELECTOR, StaticResolveSelectors.INDEX_METHOD_GROUP);
	}
	else
	{
		String name = ((PsiNamedElement) target).getName();
		if(name == null)
		{
			return Collections.emptyList();
		}
		state = state.put(CSharpResolveUtil.SELECTOR, new MemberByNameSelector(name));
	}

	CSharpResolveUtil.walkChildren(processor, parent, false, true, state);

	List<DotNetVirtualImplementOwner> results = overrideProcessor.getResults();

	// need filter result due it ill return all elements with target selector
	ListIterator<DotNetVirtualImplementOwner> listIterator = results.listIterator();
	while(listIterator.hasNext())
	{
		ProgressManager.checkCanceled();

		DotNetVirtualImplementOwner next = listIterator.next();
		if(!CSharpElementCompareUtil.isEqual(next, target, CSharpElementCompareUtil.CHECK_RETURN_TYPE, target))
		{
			listIterator.remove();
		}
	}
	return results;
}
 
@RequiredReadAction
@Override
public void process(@Nonnull CSharpResolveOptions options,
		@Nonnull DotNetGenericExtractor defaultExtractor,
		@Nullable PsiElement forceQualifierElement,
		@Nonnull Processor<ResolveResult> processor)
{
	PsiElement element = options.getElement();

	DotNetTypeRef resolvedTypeRef = null;

	CSharpFieldOrPropertySetBlock block = PsiTreeUtil.getParentOfType(element, CSharpFieldOrPropertySetBlock.class);
	if(block != null)
	{
		PsiElement parent = block.getParent();
		if(parent instanceof CSharpShortObjectInitializerExpressionImpl)
		{
			resolvedTypeRef = ((CSharpShortObjectInitializerExpressionImpl) parent).toTypeRef(true);
		}
	}

	if(resolvedTypeRef == null)
	{
		CSharpCallArgumentListOwner callArgumentListOwner = PsiTreeUtil.getParentOfType(element, CSharpCallArgumentListOwner.class);

		if(callArgumentListOwner instanceof CSharpNewExpression)
		{
			resolvedTypeRef = ((CSharpNewExpression) callArgumentListOwner).toTypeRef(false);
		}
		else if(callArgumentListOwner instanceof DotNetAttribute)
		{
			resolvedTypeRef = ((DotNetAttribute) callArgumentListOwner).toTypeRef();
		}
		else
		{
			resolvedTypeRef = DotNetTypeRef.ERROR_TYPE;
		}
	}

	if(resolvedTypeRef == DotNetTypeRef.ERROR_TYPE)
	{
		return;
	}

	DotNetTypeResolveResult typeResolveResult = resolvedTypeRef.resolve();

	PsiElement typeElement = typeResolveResult.getElement();
	if(typeElement == null)
	{
		return;
	}

	DotNetGenericExtractor genericExtractor = typeResolveResult.getGenericExtractor();

	StubScopeProcessor scopeProcessor = CSharpReferenceExpressionImplUtil.createMemberProcessor(options, processor);

	ResolveState state = ResolveState.initial();
	state = state.put(CSharpResolveUtil.EXTRACTOR, genericExtractor);
	state = state.put(CSharpResolveUtil.SELECTOR, options.getSelector());
	CSharpResolveUtil.walkChildren(scopeProcessor, typeElement, false, true, state);
}
 
源代码9 项目: consulo-csharp   文件: CSharpSearchUtil.java
@Nullable
@RequiredReadAction
public static DotNetMethodDeclaration findMethodByName(@Nonnull final String name,
		@Nonnull PsiElement owner,
		@Nullable String parentQName,
		@Nonnull DotNetGenericExtractor extractor,
		final int parameterSize)
{
	//TODO [VISTALL] some hack until we dont make override more powerfull
	if(parentQName != null)
	{
		if(owner instanceof DotNetMemberOwner)
		{
			for(DotNetNamedElement dotNetNamedElement : ((DotNetMemberOwner) owner).getMembers())
			{
				if(dotNetNamedElement instanceof CSharpMethodDeclaration && ((CSharpMethodDeclaration) dotNetNamedElement).getParameters().length == 0 &&
						name.equals(dotNetNamedElement.getName()))
				{
					DotNetTypeRef typeRefForImplement = ((CSharpMethodDeclaration) dotNetNamedElement).getTypeRefForImplement();
					if(DotNetTypeRefUtil.isVmQNameEqual(typeRefForImplement, owner, parentQName))
					{
						return (DotNetMethodDeclaration) GenericUnwrapTool.extract(dotNetNamedElement, extractor);
					}
				}
			}
		}
	}

	AsPsiElementProcessor psiElementProcessor = new AsPsiElementProcessor();
	MemberResolveScopeProcessor memberResolveScopeProcessor = new MemberResolveScopeProcessor(owner, psiElementProcessor, new ExecuteTarget[]{ExecuteTarget.ELEMENT_GROUP},
			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 psiElement : psiElementProcessor.getElements())
	{
		if(psiElement instanceof CSharpElementGroup)
		{
			for(PsiElement element : ((CSharpElementGroup<?>) psiElement).getElements())
			{
				//TODO [VISTALL] parameter handling
				if(element instanceof DotNetMethodDeclaration &&
						((DotNetMethodDeclaration) element).getParameters().length == parameterSize &&
						isMyElement(element, parentQName))
				{
					return (DotNetMethodDeclaration) element;
				}
			}
		}
	}
	return null;
}
 
源代码10 项目: consulo-csharp   文件: CSharpResolveUtil.java
@RequiredReadAction
public static boolean walkChildren(@Nonnull final PsiScopeProcessor processor, @Nonnull final PsiElement entrance, boolean walkParent, boolean walkDeep, @Nonnull ResolveState state)
{
	if(walkDeep)
	{
		state = state.put(WALK_DEEP, Boolean.TRUE);
	}

	ProgressIndicatorProvider.checkCanceled();
	GlobalSearchScope resolveScope = entrance.getResolveScope();
	if(entrance instanceof CSharpTypeDeclaration)
	{
		if(!processor.execute(entrance, state))
		{
			return false;
		}

		if(walkParent)
		{
			PsiElement parent = entrance.getContext();
			if(parent == null)
			{
				return true;
			}

			if(!walkChildren(processor, parent, walkParent, walkDeep, state))
			{
				return false;
			}
		}
	}
	else if(entrance instanceof CSharpTypeDefStatement)
	{
		DotNetTypeRef dotNetTypeRef = ((CSharpTypeDefStatement) entrance).toTypeRef();

		DotNetTypeResolveResult typeResolveResult = dotNetTypeRef.resolve();

		PsiElement element = typeResolveResult.getElement();
		if(element == null)
		{
			return true;
		}

		CSharpResolveSelector selector = state.get(SELECTOR);
		ResolveState newState = ResolveState.initial().put(SELECTOR, selector).put(EXTRACTOR, typeResolveResult.getGenericExtractor());
		return walkChildren(processor, element, walkParent, walkDeep, newState);
	}
	else if(entrance instanceof DotNetGenericParameter)
	{
		if(!processor.execute(entrance, state))
		{
			return false;
		}
	}
	else if(entrance instanceof DotNetNamespaceAsElement)
	{
		state = state.put(BaseDotNetNamespaceAsElement.RESOLVE_SCOPE, resolveScope);
		state = state.put(BaseDotNetNamespaceAsElement.FILTER, DotNetNamespaceAsElement.ChildrenFilter.NONE);

		if(!processor.execute(entrance, state))
		{
			return false;
		}

		String parentQName = ((DotNetNamespaceAsElement) entrance).getPresentableParentQName();
		// dont go to root namespace
		if(StringUtil.isEmpty(parentQName))
		{
			return true;
		}

		if(walkParent)
		{
			DotNetNamespaceAsElement parentNamespace = DotNetPsiSearcher.getInstance(entrance.getProject()).findNamespace(parentQName, resolveScope);
			if(parentNamespace != null && !walkChildren(processor, parentNamespace, walkParent, walkDeep, state))
			{
				return false;
			}
		}
	}
	else if(entrance instanceof DotNetNamespaceDeclaration)
	{
		String presentableQName = ((DotNetNamespaceDeclaration) entrance).getPresentableQName();
		if(presentableQName == null)
		{
			return true;
		}

		state = state.put(BaseDotNetNamespaceAsElement.RESOLVE_SCOPE, resolveScope);
		state = state.put(BaseDotNetNamespaceAsElement.FILTER, DotNetNamespaceAsElement.ChildrenFilter.NONE);

		DotNetNamespaceAsElement namespace = DotNetPsiSearcher.getInstance(entrance.getProject()).findNamespace(presentableQName, resolveScope);
		if(namespace != null && !walkChildren(processor, namespace, walkParent, walkDeep, state))
		{
			return false;
		}
	}
	return true;
}
 
 同类方法