コード例 #1
0
 public void processInjectableElements(
     Collection<PsiElement> in, Processor<PsiElement> processor) {
   ClassMapCachingNulls<MultiHostInjector> map = getInjectorMap();
   for (PsiElement element : in) {
     if (map.get(element.getClass()) != null) processor.process(element);
   }
 }
コード例 #2
0
ファイル: JetPsiUtil.java プロジェクト: vijaykiran/kotlin
  // Delete given element and all the elements separating it from the neighboring elements of the
  // same class
  public static void deleteElementWithDelimiters(@NotNull PsiElement element) {
    PsiElement paramBefore = PsiTreeUtil.getPrevSiblingOfType(element, element.getClass());

    PsiElement from;
    PsiElement to;
    if (paramBefore != null) {
      from = paramBefore.getNextSibling();
      to = element;
    } else {
      PsiElement paramAfter = PsiTreeUtil.getNextSiblingOfType(element, element.getClass());

      from = element;
      to = paramAfter != null ? paramAfter.getPrevSibling() : element;
    }

    PsiElement parent = element.getParent();

    parent.deleteChildRange(from, to);
  }
コード例 #3
0
  @NotNull
  private static Couple<Collection<TextRange>> getUsages(
      @NotNull PsiElement target,
      PsiElement psiElement,
      boolean withDeclarations,
      boolean detectAccess) {
    List<TextRange> readRanges = new ArrayList<TextRange>();
    List<TextRange> writeRanges = new ArrayList<TextRange>();
    final ReadWriteAccessDetector detector =
        detectAccess ? ReadWriteAccessDetector.findDetector(target) : null;
    final FindUsagesManager findUsagesManager =
        ((FindManagerImpl) FindManager.getInstance(target.getProject())).getFindUsagesManager();
    final FindUsagesHandler findUsagesHandler =
        findUsagesManager.getFindUsagesHandler(target, true);
    final LocalSearchScope scope = new LocalSearchScope(psiElement);
    Collection<PsiReference> refs =
        findUsagesHandler != null
            ? findUsagesHandler.findReferencesToHighlight(target, scope)
            : ReferencesSearch.search(target, scope).findAll();
    for (PsiReference psiReference : refs) {
      if (psiReference == null) {
        LOG.error(
            "Null reference returned, findUsagesHandler="
                + findUsagesHandler
                + "; target="
                + target
                + " of "
                + target.getClass());
        continue;
      }
      List<TextRange> destination;
      if (detector == null
          || detector.getReferenceAccess(target, psiReference)
              == ReadWriteAccessDetector.Access.Read) {
        destination = readRanges;
      } else {
        destination = writeRanges;
      }
      HighlightUsagesHandler.collectRangesToHighlight(psiReference, destination);
    }

    if (withDeclarations) {
      final TextRange declRange =
          HighlightUsagesHandler.getNameIdentifierRange(psiElement.getContainingFile(), target);
      if (declRange != null) {
        if (detector != null && detector.isDeclarationWriteAccess(target)) {
          writeRanges.add(declRange);
        } else {
          readRanges.add(declRange);
        }
      }
    }

    return Couple.<Collection<TextRange>>of(readRanges, writeRanges);
  }
コード例 #4
0
 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;
 }
コード例 #5
0
    @Override
    public void visitCaseLabel(GrCaseLabel caseLabel) {
      final PsiElement parent = caseLabel.getParent().getParent();
      assert parent instanceof GrSwitchStatement : parent + " of class " + parent.getClass();
      final GrExpression condition = ((GrSwitchStatement) parent).getCondition();
      if (condition == null) return;

      final PsiType type = condition.getType();
      if (type == null) return;

      myResult = new TypeConstraint[] {SubtypeConstraint.create(type)};
    }
コード例 #6
0
  void processInPlaceInjectorsFor(@NotNull PsiElement element, @NotNull InjProcessor processor) {
    MultiHostInjector[] infos = getInjectorMap().get(element.getClass());
    if (infos != null) {
      final boolean dumb = myDumbService.isDumb();
      for (MultiHostInjector injector : infos) {
        if (dumb && !DumbService.isDumbAware(injector)) {
          continue;
        }

        if (!processor.process(element, injector)) return;
      }
    }
  }
コード例 #7
0
ファイル: CompletionData.java プロジェクト: jexp/idea2
  protected void completeReference(
      final PsiReference reference,
      final PsiElement position,
      final Set<LookupElement> set,
      final TailType tailType,
      final PsiFile file,
      final ElementFilter filter,
      final CompletionVariant variant) {
    if (reference instanceof PsiMultiReference) {
      for (PsiReference ref : getReferences((PsiMultiReference) reference)) {
        completeReference(ref, position, set, tailType, file, filter, variant);
      }
    } else if (reference instanceof PsiDynaReference) {
      for (PsiReference ref : ((PsiDynaReference<?>) reference).getReferences()) {
        completeReference(ref, position, set, tailType, file, filter, variant);
      }
    } else {
      final Object[] completions = reference.getVariants();
      if (completions == null) return;

      for (Object completion : completions) {
        if (completion == null) {
          LOG.assertTrue(
              false,
              "Position="
                  + position
                  + "\n;Reference="
                  + reference
                  + "\n;variants="
                  + Arrays.toString(completions));
        }
        if (completion instanceof PsiElement) {
          final PsiElement psiElement = (PsiElement) completion;
          if (filter.isClassAcceptable(psiElement.getClass())
              && filter.isAcceptable(psiElement, position)) {
            addLookupItem(set, tailType, completion, file, variant);
          }
        } else {
          if (completion instanceof LookupItem) {
            final Object o = ((LookupItem) completion).getObject();
            if (o instanceof PsiElement) {
              if (!filter.isClassAcceptable(o.getClass()) || !filter.isAcceptable(o, position))
                continue;
            }
          }
          addLookupItem(set, tailType, completion, file, variant);
        }
      }
    }
  }