Java Code Examples for com.intellij.psi.ResolveState#initial()
The following examples show how to use
com.intellij.psi.ResolveState#initial() .
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: DumbFunctionReference.java From BashSupport with Apache License 2.0 | 6 votes |
@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 2
Source File: Unity3dSceneCSharpFieldReference.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: ParameterFromParentKindProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@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 4
Source File: GenericFromParentKindProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@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 5
Source File: CSharpSearchUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@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 6
Source File: Unity3dEventMethodReference.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@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; }
Example 7
Source File: BashResolveUtil.java From BashSupport with Apache License 2.0 | 4 votes |
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); }
Example 8
Source File: SmartFunctionReference.java From BashSupport with Apache License 2.0 | 4 votes |
@Nullable @Override public PsiElement resolveInner() { final String referencedName = cmd.getReferencedCommandName(); if (referencedName == null) { return null; } final ResolveProcessor processor = new BashFunctionProcessor(referencedName); Project project = cmd.getProject(); PsiFile currentFile = cmd.getContainingFile(); GlobalSearchScope allFiles = FileInclusionManager.includedFilesUnionScope(currentFile); Collection<BashFunctionDef> functionDefs = StubIndex.getElements(BashFunctionNameIndex.KEY, referencedName, project, allFiles, BashFunctionDef.class); ResolveState initial = ResolveState.initial(); for (BashFunctionDef functionDef : functionDefs) { processor.execute(functionDef, initial); } //find include commands which are relevant for the start element if (!processor.hasResults()) { Set<BashFile> includingFiles = FileInclusionManager.findIncluders(project, currentFile); List<GlobalSearchScope> scopes = Lists.newLinkedList(); for (BashFile file : includingFiles) { scopes.add(GlobalSearchScope.fileScope(file)); } if (!scopes.isEmpty()) { GlobalSearchScope scope = GlobalSearchScope.union(scopes.toArray(new GlobalSearchScope[scopes.size()])); functionDefs = StubIndex.getElements(BashFunctionNameIndex.KEY, referencedName, project, scope, BashFunctionDef.class); for (BashFunctionDef def : functionDefs) { processor.execute(def, initial); } } } processor.prepareResults(); return processor.hasResults() ? processor.getBestResult(true, cmd) : null; }
Example 9
Source File: OverrideUtil.java From consulo-csharp with Apache License 2.0 | 4 votes |
@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; }
Example 10
Source File: FieldOrPropertyKindProcessor.java From consulo-csharp with Apache License 2.0 | 4 votes |
@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); }
Example 11
Source File: CSharpSearchUtil.java From consulo-csharp with Apache License 2.0 | 4 votes |
@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; }