Search in sources :

Example 1 with ScopeVariable

use of org.jetbrains.plugins.ruby.ruby.codeInsight.resolve.scope.ScopeVariable in project intellij-plugins by JetBrains.

the class MotionDebuggerTypesHelper method resolveToDeclaration.

@Override
public PsiElement resolveToDeclaration(XSourcePosition position, LLValue var) {
    final String name = var.getName();
    final VirtualFile file = position.getFile();
    final int offset = position.getOffset();
    final PsiFile psiFile = PsiManager.getInstance(myProcess.getProject()).findFile(file);
    if (psiFile == null)
        return null;
    final PsiElement element = RubyPsiUtil.getSignificantLeafToTheRight(psiFile.findElementAt(offset));
    final RContainer container = element != null ? RubyPsiUtil.getParentContainerOrSelf(element) : null;
    if (container == null)
        return null;
    ScopeVariable variable = null;
    for (ScopeVariable scopeVariable : container.getScope().getAllDeclaredVariables()) {
        if (name.equals(scopeVariable.getName())) {
            variable = scopeVariable;
            break;
        }
    }
    if (variable == null)
        return null;
    final RPsiElement item = ContainerUtil.getFirstItem(variable.getDeclarations());
    if (item == null)
        return null;
    return item;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RPsiElement(org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement) RContainer(org.jetbrains.plugins.ruby.ruby.lang.psi.holders.RContainer) ScopeVariable(org.jetbrains.plugins.ruby.ruby.codeInsight.resolve.scope.ScopeVariable) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) RPsiElement(org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 ScopeVariable (org.jetbrains.plugins.ruby.ruby.codeInsight.resolve.scope.ScopeVariable)1 RPsiElement (org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement)1 RContainer (org.jetbrains.plugins.ruby.ruby.lang.psi.holders.RContainer)1