Example #1
0
    @Override
    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
      if (element instanceof PsiMethod && ((PsiMethod) element).isConstructor()) return true;
      if (element instanceof PsiNamedElement) {

        PsiNamedElement namedElement = (PsiNamedElement) element;

        boolean isAccessible = isAccessible(namedElement);
        final PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
        final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
        boolean isStaticsOK =
            isStaticsOK(namedElement, resolveContext, myParameters.getInvocationCount() <= 1);

        PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
        if (substitutor == null) substitutor = PsiSubstitutor.EMPTY;
        if (element instanceof PsiMethod) {
          substitutor =
              mySubstitutorComputer.obtainSubstitutor(substitutor, (PsiMethod) element, state);
        }

        consume(
            new GroovyResolveResultImpl(
                namedElement, resolveContext, spreadState, substitutor, isAccessible, isStaticsOK));
      }
      return true;
    }
Example #2
0
 private void getVariantsFromQualifierType(
     @NotNull PsiType qualifierType, @NotNull Project project) {
   final ResolveState state = ResolveState.initial();
   if (qualifierType instanceof PsiClassType) {
     PsiClassType.ClassResolveResult result = ((PsiClassType) qualifierType).resolveGenerics();
     PsiClass qualifierClass = result.getElement();
     if (qualifierClass != null) {
       qualifierClass.processDeclarations(
           myProcessor, state.put(PsiSubstitutor.KEY, result.getSubstitutor()), null, myRefExpr);
     }
   } else if (qualifierType instanceof PsiArrayType) {
     final GrTypeDefinition arrayClass =
         GroovyPsiManager.getInstance(project)
             .getArrayClass(((PsiArrayType) qualifierType).getComponentType());
     if (arrayClass != null) {
       if (!arrayClass.processDeclarations(myProcessor, state, null, myRefExpr)) return;
     }
   } else if (qualifierType instanceof PsiIntersectionType) {
     for (PsiType conjunct : ((PsiIntersectionType) qualifierType).getConjuncts()) {
       getVariantsFromQualifierType(conjunct, project);
     }
     return;
   }
   ResolveUtil.processNonCodeMembers(qualifierType, myProcessor, myRefExpr, state);
 }
Example #3
0
 public static boolean processElement(PsiScopeProcessor processor, PsiNamedElement namedElement) {
   if (namedElement == null) return true;
   NameHint nameHint = processor.getHint(NameHint.KEY);
   String name = nameHint == null ? null : nameHint.getName(ResolveState.initial());
   if (name == null || name.equals(namedElement.getName())) {
     return processor.execute(namedElement, ResolveState.initial());
   }
   return true;
 }
  @Override
  public boolean processDeclarations(
      @NotNull PsiScopeProcessor processor,
      @NotNull ResolveState state,
      PsiElement lastParent,
      @NotNull PsiElement place) {
    // System.out.println ("XqyVarNameElementImpl.processDeclarations: " + toString() + "/" +
    // getName());

    if (!(place instanceof XqyRefVarName)) {
      return true;
    }

    if (getText().equals(place.getText())) {
      // System.out.println ("  candidate VarName: " + toString() + "/" + getText());
      return processor.execute(this, ResolveState.initial());
    }

    // TODO: Suppress vars with same name in wider scope
    if (state == XqyReferenceImpl.variantResolveState) {
      processor.execute(this, null);
    }

    return true;
  }
    @Override
    public boolean execute(PsiElement element, ResolveState state) {
      if (element instanceof PsiMethod || element instanceof PsiField) {
        String propertyName;
        PsiType type;

        if (element instanceof PsiMethod) {
          PsiMethod method = (PsiMethod) element;
          if (!GroovyPropertyUtils.isSimplePropertySetter(method)) return true;

          propertyName = GroovyPropertyUtils.getPropertyNameBySetter(method);
          if (propertyName == null) return true;

          type = method.getParameterList().getParameters()[0].getType();
        } else {
          type = ((PsiField) element).getType();
          propertyName = ((PsiField) element).getName();
        }

        if (((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC)) return true;

        if (myResult.containsKey(propertyName) || propertyName.equals(METACLASS)) return true;

        PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
        if (substitutor != null) {
          type = substitutor.substitute(type);
        }

        myResult.put(propertyName, new TypeCondition(type, element));
      }

      return true;
    }
 @Override
 public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
   if (element == member) {
     subst.set(state.get(PsiSubstitutor.KEY));
   }
   return true;
 }
  private static boolean processMethod(
      @NotNull GrTypeDefinition grType,
      @NotNull PsiScopeProcessor processor,
      @NotNull ResolveState state,
      @NotNull PsiElement place,
      boolean processInstanceMethods,
      @NotNull PsiSubstitutor substitutor,
      @NotNull PsiElementFactory factory,
      @NotNull LanguageLevel level,
      boolean placeGroovy,
      @NotNull CandidateInfo info) {
    PsiMethod method = (PsiMethod) info.getElement();
    if (!processInstanceMember(processInstanceMethods, method)
        || isSameDeclaration(place, method)
        || !isMethodVisible(placeGroovy, method)) {
      return true;
    }
    LOG.assertTrue(method.getContainingClass() != null);
    final PsiSubstitutor finalSubstitutor =
        PsiClassImplUtil.obtainFinalSubstitutor(
            method.getContainingClass(),
            info.getSubstitutor(),
            grType,
            substitutor,
            factory,
            level);

    return processor.execute(method, state.put(PsiSubstitutor.KEY, finalSubstitutor));
  }
  private boolean processDeclarationsForMultipleElements(
      @NotNull final PsiScopeProcessor processor,
      @Nullable PsiElement lastParent,
      @NotNull PsiElement place,
      @NotNull ResolveState state) {
    GrCodeReferenceElement ref = getImportReference();
    if (ref == null) return true;

    if (isStatic()) {
      final PsiElement resolved = ref.resolve();
      if (resolved instanceof PsiClass) {
        state = state.put(ClassHint.RESOLVE_CONTEXT, this);
        final PsiClass clazz = (PsiClass) resolved;
        for (final PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
          if (!clazz.processDeclarations(
              new DelegatingScopeProcessor(each) {
                @Override
                public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
                  if (element instanceof PsiMember
                      && ((PsiMember) element).hasModifierProperty(PsiModifier.STATIC)) {
                    return super.execute(element, state);
                  }
                  return true;
                }
              },
              state,
              lastParent,
              place)) return false;
        }
      }
    } else {
      if (ResolveUtil.shouldProcessClasses(processor.getHint(ElementClassHint.KEY))) {
        String qName = PsiUtil.getQualifiedReferenceText(ref);
        if (qName != null) {
          PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(qName);
          if (aPackage != null
              && !((GroovyFile) getContainingFile())
                  .getPackageName()
                  .equals(aPackage.getQualifiedName())) {
            state = state.put(ClassHint.RESOLVE_CONTEXT, this);
            if (!aPackage.processDeclarations(processor, state, lastParent, place)) return false;
          }
        }
      }
    }
    return true;
  }
  private JavaResolveResult advancedResolveInner(final PsiElement psiElement, final String qName) {
    final PsiManager manager = psiElement.getManager();
    final GlobalSearchScope scope = getScope();
    if (myIndex == myJavaClassReferenceSet.getReferences().length - 1) {
      final PsiClass aClass =
          JavaPsiFacade.getInstance(manager.getProject()).findClass(qName, scope);
      if (aClass != null) {
        return new ClassCandidateInfo(aClass, PsiSubstitutor.EMPTY, false, psiElement);
      } else {
        if (!JavaClassReferenceProvider.ADVANCED_RESOLVE.getBooleanValue(getOptions())) {
          return JavaResolveResult.EMPTY;
        }
      }
    }
    PsiElement resolveResult = JavaPsiFacade.getInstance(manager.getProject()).findPackage(qName);
    if (resolveResult == null) {
      resolveResult = JavaPsiFacade.getInstance(manager.getProject()).findClass(qName, scope);
    }
    if (myInStaticImport && resolveResult == null) {
      resolveResult = resolveMember(qName, manager, getElement().getResolveScope());
    }
    if (resolveResult == null) {
      PsiFile containingFile = psiElement.getContainingFile();

      if (containingFile instanceof PsiJavaFile) {
        if (containingFile instanceof JspFile) {
          containingFile = containingFile.getViewProvider().getPsi(StdLanguages.JAVA);
          if (containingFile == null) return JavaResolveResult.EMPTY;
        }

        final ClassResolverProcessor processor =
            new ClassResolverProcessor(getCanonicalText(), psiElement);
        containingFile.processDeclarations(processor, ResolveState.initial(), null, psiElement);

        if (processor.getResult().length == 1) {
          final JavaResolveResult javaResolveResult = processor.getResult()[0];

          if (javaResolveResult != JavaResolveResult.EMPTY && getOptions() != null) {
            final Boolean value =
                JavaClassReferenceProvider.RESOLVE_QUALIFIED_CLASS_NAME.getValue(getOptions());
            final PsiClass psiClass = (PsiClass) javaResolveResult.getElement();
            if (value != null && value.booleanValue() && psiClass != null) {
              final String qualifiedName = psiClass.getQualifiedName();

              if (!qName.equals(qualifiedName)) {
                return JavaResolveResult.EMPTY;
              }
            }
          }

          return javaResolveResult;
        }
      }
    }
    return resolveResult != null
        ? new CandidateInfo(resolveResult, PsiSubstitutor.EMPTY, false, false, psiElement)
        : JavaResolveResult.EMPTY;
  }
  @NotNull
  private PsiSubstitutor inferSubstitutor(@NotNull PsiMethod method, @NotNull ResolveState state) {
    PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
    if (substitutor == null) substitutor = PsiSubstitutor.EMPTY;

    return myByShape
        ? substitutor
        : mySubstitutorComputer.obtainSubstitutor(substitutor, method, state);
  }
 @Override
 public boolean processResolveVariants(@NotNull GoScopeProcessor processor) {
   Collection<GoLabelDefinition> defs = getLabelDefinitions();
   for (GoLabelDefinition def : defs) {
     if (!processor.execute(def, ResolveState.initial())) {
       return false;
     }
   }
   return true;
 }
 public boolean satisfies(@NotNull PsiElement element, @NotNull ResolveState state) {
   final String name = PsiUtilCore.getName(element);
   if (StringUtil.isNotEmpty(name) && (myMatcher == null || myMatcher.value(name))) {
     if (myFilter.isClassAcceptable(element.getClass())
         && myFilter.isAcceptable(
             new CandidateInfo(element, state.get(PsiSubstitutor.KEY)), myElement)) {
       return true;
     }
   }
   return false;
 }
Example #13
0
 @Nullable
 public static PsiElement resolveMixin(@NotNull PsiElement base, @NotNull String name) {
   CssResolveProcessor processor = CssPluginsFacade.getMixinProcessor(base, name);
   if (processor.executeInScope(base)) {
     processFile(
         base.getContainingFile(),
         processor,
         ResolveState.initial().put(PROCESSED_PATHS, new HashSet<String>()));
   }
   return processor.getResult();
 }
  @Override
  public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
    if (myStopExecuting) {
      return false;
    }
    if (element instanceof PsiMethod) {
      PsiMethod method = (PsiMethod) element;

      if (method.isConstructor() != myIsConstructor) return true;

      PsiSubstitutor substitutor = inferSubstitutor(method, state);

      PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
      final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);

      boolean isAccessible = isAccessible(method);
      boolean isStaticsOK = isStaticsOK(method, resolveContext, false);
      boolean isApplicable =
          PsiUtil.isApplicable(myArgumentTypes, method, substitutor, myPlace, myByShape);
      boolean isValidResult = isStaticsOK && isAccessible && isApplicable;

      GroovyResolveResultImpl candidate =
          new GroovyResolveResultImpl(
              method,
              resolveContext,
              spreadState,
              substitutor,
              isAccessible,
              isStaticsOK,
              false,
              isValidResult);

      if (!myAllVariants && isValidResult) {
        addCandidate(candidate);
      } else {
        addInapplicableCandidate(candidate);
      }
    }

    return true;
  }
 public static void processClass(
     @NotNull GrCall call,
     PsiClassType type,
     @Nullable String argumentName,
     Map<String, ArgumentDescriptor> result) {
   if (argumentName == null) {
     ResolveUtil.processAllDeclarations(
         type, new MyPsiScopeProcessor(result, call), ResolveState.initial(), call);
   } else {
     ResolveUtil.processAllDeclarations(
         type,
         new MyPsiScopeProcessor(argumentName, true, result, call),
         ResolveState.initial(),
         call);
     ResolveUtil.processAllDeclarations(
         type,
         new MyPsiScopeProcessor(argumentName, false, result, call),
         ResolveState.initial(),
         call);
   }
 }
Example #16
0
  public static boolean treeWalkUp(PsiElement place, PsiScopeProcessor processor) {
    PsiElement lastParent = null;
    PsiElement run = place;
    while (run != null) {
      if (!run.processDeclarations(processor, ResolveState.initial(), lastParent, place))
        return false;
      lastParent = run;
      run = run.getContext(); // same as getParent
    }

    return true;
  }
 private static boolean processSuperTypes(
     @NotNull PsiClass aClass,
     @NotNull PsiScopeProcessor processor,
     @Nullable Set<PsiClass> visited,
     PsiElement last,
     @NotNull PsiElement place,
     @NotNull ResolveState state,
     boolean isRaw,
     @NotNull PsiElementFactory factory,
     @NotNull LanguageLevel languageLevel) {
   boolean resolved = false;
   for (final PsiClassType superType : aClass.getSuperTypes()) {
     final PsiClassType.ClassResolveResult superTypeResolveResult = superType.resolveGenerics();
     PsiClass superClass = superTypeResolveResult.getElement();
     if (superClass == null) continue;
     PsiSubstitutor finalSubstitutor =
         obtainFinalSubstitutor(
             superClass,
             superTypeResolveResult.getSubstitutor(),
             aClass,
             state.get(PsiSubstitutor.KEY),
             factory,
             languageLevel);
     if (aClass instanceof PsiTypeParameter
         && PsiUtil.isRawSubstitutor(superClass, finalSubstitutor)) {
       finalSubstitutor = PsiSubstitutor.EMPTY;
     }
     if (!processDeclarationsInClass(
         superClass,
         processor,
         state.put(PsiSubstitutor.KEY, finalSubstitutor),
         visited,
         last,
         place,
         isRaw)) {
       resolved = true;
     }
   }
   return !resolved;
 }
Example #18
0
 private void getVariantsFromQualifier(@NotNull GrExpression qualifier) {
   Project project = qualifier.getProject();
   PsiType qualifierType = qualifier.getType();
   final ResolveState state = ResolveState.initial();
   if (qualifierType == null || qualifierType == PsiType.VOID) {
     if (qualifier instanceof GrReferenceExpression) {
       PsiElement resolved = ((GrReferenceExpression) qualifier).resolve();
       if (resolved instanceof PsiPackage || resolved instanceof PsiVariable) {
         resolved.processDeclarations(myProcessor, state, null, myRefExpr);
         return;
       }
     }
     getVariantsFromQualifierType(TypesUtil.getJavaLangObject(qualifier), project);
   } else if (qualifierType instanceof PsiIntersectionType) {
     for (PsiType conjunct : ((PsiIntersectionType) qualifierType).getConjuncts()) {
       getVariantsFromQualifierType(conjunct, project);
     }
   } else if (qualifierType instanceof GrTraitType) {
     GrTypeDefinition definition = ((GrTraitType) qualifierType).getMockTypeDefinition();
     if (definition != null) {
       PsiClassType classType = JavaPsiFacade.getElementFactory(project).createType(definition);
       getVariantsFromQualifierType(classType, project);
     } else {
       getVariantsFromQualifierType(((GrTraitType) qualifierType).getExprType(), project);
       for (PsiClassType traitType : ((GrTraitType) qualifierType).getTraitTypes()) {
         getVariantsFromQualifierType(traitType, project);
       }
     }
   } else {
     getVariantsFromQualifierType(qualifierType, project);
     if (qualifier instanceof GrReferenceExpression
         && !PsiUtil.isSuperReference(qualifier)
         && !PsiUtil.isInstanceThisRef(qualifier)) {
       PsiElement resolved = ((GrReferenceExpression) qualifier).resolve();
       if (resolved instanceof PsiClass) { // //omitted .class
         GlobalSearchScope scope = myRefExpr.getResolveScope();
         PsiClass javaLangClass = PsiUtil.getJavaLangClass(resolved, scope);
         if (javaLangClass != null) {
           PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
           PsiTypeParameter[] typeParameters = javaLangClass.getTypeParameters();
           if (typeParameters.length == 1) {
             substitutor = substitutor.put(typeParameters[0], qualifierType);
           }
           PsiType javaLangClassType =
               JavaPsiFacade.getElementFactory(myRefExpr.getProject())
                   .createType(javaLangClass, substitutor);
           ResolveUtil.processAllDeclarations(javaLangClassType, myProcessor, state, myRefExpr);
         }
       }
     }
   }
 }
  @Override
  public boolean execute(@NotNull PsiElement element, ResolveState state) {
    DotNetGenericExtractor extractor = state.get(CSharpResolveUtil.EXTRACTOR);
    assert extractor != null;

    for (PsiElement psiElement : OverrideUtil.getAllMembers(element, myScope, extractor, true)) {
      if (!ExecuteTargetUtil.isMyElement(this, psiElement)) {
        continue;
      }
      addElement(psiElement);
    }
    return true;
  }
 public static boolean treeWalkUp(
     @Nullable PsiElement place, @NotNull PsiScopeProcessor processor) {
   PsiElement lastParent = null;
   PsiElement run = place;
   while (run != null) {
     if (place != run
         && !run.processDeclarations(processor, ResolveState.initial(), lastParent, place))
       return false;
     lastParent = run;
     run = run.getParent();
   }
   return true;
 }
Example #21
0
  public PsiElement resolve() {
    final String varName = getName();
    if (varName == null) {
      return null;
    }

    BashVarProcessor processor = new BashVarProcessor(this, true);
    if (!BashPsiUtils.varResolveTreeWalkUp(
        processor, this, getContainingFile(), ResolveState.initial())) {
      return processor.getBestResult(false, this);
    }

    return null;
  }
Example #22
0
  private void getVariantsImpl() {
    GrExpression qualifier = myRefExpr.getQualifierExpression();
    if (qualifier == null) {
      ResolveUtil.treeWalkUp(myRefExpr, myProcessor, true);

      for (PsiElement e = myRefExpr.getParent(); e != null; e = e.getParent()) {
        if (e instanceof GrClosableBlock) {
          ResolveState state = ResolveState.initial().put(ClassHint.RESOLVE_CONTEXT, e);
          for (ClosureMissingMethodContributor contributor :
              ClosureMissingMethodContributor.EP_NAME.getExtensions()) {
            contributor.processMembers((GrClosableBlock) e, myProcessor, myRefExpr, state);
          }
        }
      }

      GrExpression runtimeQualifier = PsiImplUtil.getRuntimeQualifier(myRefExpr);
      if (runtimeQualifier != null) {
        getVariantsFromQualifier(runtimeQualifier);
      }

      getBindings();
    } else {
      if (myRefExpr.getDotTokenType() != GroovyTokenTypes.mSPREAD_DOT) {
        getVariantsFromQualifier(qualifier);

        if (qualifier instanceof GrReferenceExpression
            && ("class".equals(((GrReferenceExpression) qualifier).getReferenceName())
                || PsiUtil.isThisReference(qualifier) && !PsiUtil.isInstanceThisRef(qualifier))) {
          processIfJavaLangClass(qualifier.getType());
        }
      } else {
        getVariantsFromQualifierForSpreadOperator(qualifier);
      }
    }
    ResolveUtil.processCategoryMembers(myRefExpr, myProcessor, ResolveState.initial());
  }
  private PsiElement internalResolve() {
    final String referencedName = getReferencedName();
    if (referencedName == null) {
      return null;
    }

    final BashFunctionProcessor processor = new BashFunctionProcessor(referencedName);

    boolean walkOn =
        PsiTreeUtil.treeWalkUp(processor, this, getContainingFile(), ResolveState.initial());
    if (!walkOn) {
      return processor.hasResults() ? processor.getBestResult(true, this) : null;
    }

    return null;
  }
Example #24
0
 private static boolean pushPath(@NotNull PsiFile file, @NotNull ResolveState state) {
   synchronized (LOCK) {
     if (!CssUtils.isDynamicCssLanguage(file)) {
       return false;
     }
     Collection<String> paths = state.get(PROCESSED_PATHS);
     if (paths == null) {
       return false;
     }
     VirtualFile virtualFile = file.getVirtualFile();
     if (virtualFile != null && paths.add(virtualFile.getPath())) {
       return true;
     }
     return false;
   }
 }
  @Override
  public PsiElement resolve() {
    ErlangVarProcessor processor = new ErlangVarProcessor(myElement.getText(), myElement);
    ErlangListComprehension lc =
        PsiTreeUtil.getParentOfType(myElement, ErlangListComprehension.class);
    ErlangCompositeElement place = lc != null ? lc.getLcExprs() : myElement;
    ResolveUtil.treeWalkUp(place, processor);
    ErlangQVar result = processor.getResult();
    if (result != null) return result;

    ErlangModule module = getModule(myElement.getContainingFile());
    if (module == null) return null;
    module.processDeclarations(processor, ResolveState.initial(), module, module);

    return processor.getResult();
  }
  @Override
  public boolean execute(@NotNull PsiElement element, ResolveState state) {
    if (!(element instanceof PsiClass)) return true;
    final PsiClass aClass = (PsiClass) element;
    final String name = aClass.getName();
    if (!myClassName.equals(name)) {
      return true;
    }
    boolean accessible = myPlace == null || checkAccessibility(aClass);
    if (myCandidates == null) {
      myCandidates = new SmartList<ClassCandidateInfo>();
    } else {
      String fqName = aClass.getQualifiedName();
      if (fqName != null) {
        for (int i = myCandidates.size() - 1; i >= 0; i--) {
          ClassCandidateInfo info = myCandidates.get(i);

          Domination domination =
              dominates(aClass, accessible && isAccessible(aClass), fqName, info);
          if (domination == Domination.DOMINATED_BY) {
            return true;
          } else if (domination == Domination.DOMINATES) {
            myCandidates.remove(i);
          }
        }
      }
    }

    myHasAccessibleCandidate |= accessible;
    myHasInaccessibleCandidate |= !accessible;
    myCandidates.add(
        new ClassCandidateInfo(
            aClass, state.get(PsiSubstitutor.KEY), !accessible, myCurrentFileContext));
    myResult = null;
    if (!accessible) return true;
    if (aClass.hasModifierProperty(PsiModifier.PRIVATE)) {
      final PsiClass containingPlaceClass =
          PsiTreeUtil.getParentOfType(myPlace, PsiClass.class, false);
      if (containingPlaceClass != null
          && !PsiTreeUtil.isAncestor(containingPlaceClass, aClass, true)) {
        return true;
      }
    }
    return myCurrentFileContext instanceof PsiImportStatementBase;
  }
  public boolean processNestedElements(PsiScopeProcessor processor) {
    final AntIntrospector introspector = AntDomExtender.getIntrospector(myAntClass);
    if (introspector != null) {
      String expectedName = ResolveUtil.getNameHint(processor);
      final PsiType stringType = getParameterList().getParameters()[1].getType();
      final PsiType closureType = getParameterList().getParameters()[2].getType();

      for (String name : Collections.list(introspector.getNestedElements())) {
        if (expectedName == null || expectedName.equals(name)) {
          final AntBuilderMethod method =
              new AntBuilderMethod(
                  myPlace, name, closureType, introspector.getElementType(name), stringType);
          if (!processor.execute(method, ResolveState.initial())) return false;
        }
      }
    }
    return true;
  }
  @org.jetbrains.annotations.NotNull
  public Object[] getVariants() {
    List<Object> variants = Lists.newArrayList();

    BashFunctionVariantsProcessor processor = new BashFunctionVariantsProcessor();
    PsiTreeUtil.treeWalkUp(processor, this, this.getContainingFile(), ResolveState.initial());

    variants.addAll(processor.getFunctionDefs());

    if (BashProjectSettings.storedSettings(getProject()).isAutocompleteBuiltinCommands()) {
      variants.addAll(LanguageBuiltins.commands);
    }

    if (BashProjectSettings.storedSettings(getProject()).isSupportBash4()) {
      variants.addAll(LanguageBuiltins.commands_v4);
    }

    return variants.toArray();
  }
  private boolean processSingleClassImport(
      @NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
    if (!ResolveUtil.shouldProcessClasses(processor.getHint(ElementClassHint.KEY))) return true;

    GrCodeReferenceElement ref = getImportReference();
    if (ref == null) return true;

    final PsiElement resolved = ref.resolve();
    if (!(resolved instanceof PsiClass)) {
      return true;
    }

    if (!isAliasedImport() && isFromSamePackage((PsiClass) resolved)) {
      return true; // don't process classes from the same package because such import statements are
                   // ignored by compiler
    }

    return processor.execute(resolved, state.put(ClassHint.RESOLVE_CONTEXT, this));
  }
  @NotNull
  @Override
  public Collection<StructureViewTreeElement> getChildrenBase() {
    final NavigatablePsiElement element = getElement();
    final List<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>();

    if (element instanceof DartFile || element instanceof DartEmbeddedContent) {
      THashSet<DartComponentName> componentNames = new THashSet<DartComponentName>();
      DartPsiCompositeElementImpl.processDeclarationsImpl(
          element, new ComponentNameScopeProcessor(componentNames), ResolveState.initial(), null);
      for (DartComponentName componentName : componentNames) {
        PsiElement parent = componentName.getParent();
        if (parent instanceof DartComponent) {
          result.add(new DartStructureViewElement((DartComponent) parent));
        }
      }
    } else if (element instanceof DartClass) {
      for (DartComponent subNamedComponent :
          DartResolveUtil.getNamedSubComponents((DartClass) element)) {
        result.add(new DartStructureViewElement(subNamedComponent));
      }
    }

    Collections.sort(
        result,
        new Comparator<StructureViewTreeElement>() {
          @Override
          public int compare(StructureViewTreeElement o1, StructureViewTreeElement o2) {
            PsiElement element1, element2;
            if (o1 instanceof DartStructureViewElement
                && o2 instanceof DartStructureViewElement
                && (element1 = ((DartStructureViewElement) o1).getElement()) != null
                && (element2 = ((DartStructureViewElement) o2).getElement()) != null) {
              return element1.getTextRange().getStartOffset()
                  - element2.getTextRange().getStartOffset();
            }
            return 0;
          }
        });

    return result;
  }