private static void getImplementListsInner(
      GrTypeDefinition grType, List<PsiClassType> result, Set<PsiClass> visited) {
    if (!visited.add(grType)) return;

    final PsiClassType[] implementsTypes = getReferenceListTypes(grType.getImplementsClause());
    List<PsiClassType> fromDelegates = getImplementsFromDelegate(grType, visited);
    if (fromDelegates != null) {
      result.addAll(fromDelegates);
    }
    result.addAll(Arrays.asList(implementsTypes));

    if (!grType.isInterface()
        && !ContainerUtil.or(implementsTypes, IS_GROOVY_OBJECT)
        && !ContainerUtil.or(getReferenceListTypes(grType.getExtendsClause()), IS_GROOVY_OBJECT)) {
      result.add(getGroovyObjectType(grType));
    }
  }
 public TransferableFileEditorStateSupport(
     @NotNull DiffSettingsHolder.DiffSettings settings,
     @NotNull List<BinaryEditorHolder> holders,
     @NotNull Disposable disposable) {
   mySettings = settings;
   myHolders = holders;
   mySupported = ContainerUtil.or(myHolders, IS_SUPPORTED);
   new MySynchronizer(ContainerUtil.filter(myHolders, IS_SUPPORTED)).install(disposable);
 }
  public static CompletionResultSet addJavaSorting(
      final CompletionParameters parameters, CompletionResultSet result) {
    final PsiElement position = parameters.getPosition();
    final ExpectedTypeInfo[] expectedTypes =
        PsiJavaPatterns.psiElement()
                .beforeLeaf(PsiJavaPatterns.psiElement().withText("."))
                .accepts(position)
            ? ExpectedTypeInfo.EMPTY_ARRAY
            : JavaSmartCompletionContributor.getExpectedTypes(parameters);
    final CompletionType type = parameters.getCompletionType();
    final boolean smart = type == CompletionType.SMART;
    final boolean afterNew = JavaSmartCompletionContributor.AFTER_NEW.accepts(position);

    List<LookupElementWeigher> afterProximity = new ArrayList<>();
    afterProximity.add(new PreferContainingSameWords(expectedTypes));
    afterProximity.add(new PreferShorter(expectedTypes));

    CompletionSorter sorter = CompletionSorter.defaultSorter(parameters, result.getPrefixMatcher());
    if (!smart && afterNew) {
      sorter = sorter.weighBefore("liftShorter", new PreferExpected(true, expectedTypes, position));
    } else if (PsiTreeUtil.getParentOfType(position, PsiReferenceList.class) == null) {
      sorter =
          ((CompletionSorterImpl) sorter)
              .withClassifier("liftShorterClasses", true, new LiftShorterClasses(position));
    }
    if (smart) {
      sorter =
          sorter.weighAfter("priority", new PreferDefaultTypeWeigher(expectedTypes, parameters));
    }

    List<LookupElementWeigher> afterPrefix = ContainerUtil.newArrayList();
    afterPrefix.add(new PreferByKindWeigher(type, position, expectedTypes));
    if (!smart) {
      ContainerUtil.addIfNotNull(afterPrefix, preferStatics(position, expectedTypes));
      if (!afterNew) {
        afterPrefix.add(new PreferExpected(false, expectedTypes, position));
      }
    }
    ContainerUtil.addIfNotNull(afterPrefix, recursion(parameters, expectedTypes));
    afterPrefix.add(new PreferSimilarlyEnding(expectedTypes));
    if (ContainerUtil.or(expectedTypes, info -> !info.getType().equals(PsiType.VOID))) {
      afterPrefix.add(new PreferNonGeneric());
    }
    Collections.addAll(afterPrefix, new PreferAccessible(position), new PreferSimple());

    sorter =
        sorter.weighAfter(
            "prefix", afterPrefix.toArray(new LookupElementWeigher[afterPrefix.size()]));
    sorter =
        sorter.weighAfter(
            "proximity", afterProximity.toArray(new LookupElementWeigher[afterProximity.size()]));
    return result.withRelevanceSorter(sorter);
  }
  private boolean hasSwitchedRoots() {
    final File currentRoot = myMergeContext.getWcInfo().getRootInfo().getIoFile();

    return ContainerUtil.or(
        myMergeContext.getVcs().getAllWcInfos(),
        new Condition<WCInfo>() {
          @Override
          public boolean value(WCInfo info) {
            return NestedCopyType.switched.equals(info.getType())
                && FileUtil.isAncestor(currentRoot, info.getRootInfo().getIoFile(), true);
          }
        });
  }
 @Override
 public boolean isStartMatch(LookupElement element) {
   if (super.isStartMatch(element)) {
     return true;
   }
   if (element.isCaseSensitive()) {
     return false;
   }
   return ContainerUtil.or(
       element.getAllLookupStrings(),
       new Condition<String>() {
         @Override
         public boolean value(String s) {
           return myCaseInsensitiveMatcher.isStartMatch(s);
         }
       });
 }
  private static boolean isFlagCheck(PsiElement element) {
    PsiStatement statement = PsiTreeUtil.getParentOfType(element, PsiStatement.class);
    if (!(statement instanceof PsiIfStatement)) return false;

    PsiExpression condition = ((PsiIfStatement) statement).getCondition();
    if (!PsiTreeUtil.isAncestor(condition, element, false)) return false;

    if (isCompileTimeFlagReference(condition)) return true;

    Collection<PsiReferenceExpression> refs =
        PsiTreeUtil.findChildrenOfType(condition, PsiReferenceExpression.class);
    return ContainerUtil.or(
        refs,
        new Condition<PsiReferenceExpression>() {
          @Override
          public boolean value(PsiReferenceExpression ref) {
            return isCompileTimeFlagReference(ref);
          }
        });
  }
예제 #7
0
  public void finishLookup(char completionChar, @Nullable final LookupElement item) {
    //noinspection deprecation,unchecked
    if (item == null
        || item instanceof EmptyLookupItem
        || item.getObject() instanceof DeferredUserLookupValue
            && item.as(LookupItem.CLASS_CONDITION_KEY) != null
            && !((DeferredUserLookupValue) item.getObject())
                .handleUserSelection(item.as(LookupItem.CLASS_CONDITION_KEY), myProject)) {
      doHide(false, true);
      fireItemSelected(null, completionChar);
      return;
    }

    if (myDisposed) { // DeferredUserLookupValue could close us in any way
      return;
    }

    final PsiFile file = getPsiFile();
    boolean writableOk =
        file == null || FileModificationService.getInstance().prepareFileForWrite(file);
    if (myDisposed) { // ensureFilesWritable could close us by showing a dialog
      return;
    }

    if (!writableOk) {
      doHide(false, true);
      fireItemSelected(null, completionChar);
      return;
    }

    final String prefix = itemPattern(item);
    boolean plainMatch =
        ContainerUtil.or(
            item.getAllLookupStrings(),
            new Condition<String>() {
              @Override
              public boolean value(String s) {
                return StringUtil.containsIgnoreCase(s, prefix);
              }
            });
    if (!plainMatch) {
      FeatureUsageTracker.getInstance()
          .triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CAMEL_HUMPS);
    }

    myFinishing = true;
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                myEditor.getDocument().startGuardedBlockChecking();
                try {
                  insertLookupString(item, getPrefixLength(item));
                } finally {
                  myEditor.getDocument().stopGuardedBlockChecking();
                }
              }
            });

    if (myDisposed) { // any document listeners could close us
      return;
    }

    doHide(false, true);

    fireItemSelected(item, completionChar);
  }