Java Code Examples for com.intellij.util.ThreeState#YES

The following examples show how to use com.intellij.util.ThreeState#YES . 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: MyDeviceChooser.java    From ADB-Duang with MIT License 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  if (!(value instanceof LaunchCompatibility)) {
    return;
  }

  LaunchCompatibility compatibility = (LaunchCompatibility)value;
  ThreeState compatible = compatibility.isCompatible();
  if (compatible == ThreeState.YES) {
    append("Yes");
  } else {
    if (compatible == ThreeState.NO) {
      append("No", SimpleTextAttributes.ERROR_ATTRIBUTES);
    } else {
      append("Maybe");
    }
    String reason = compatibility.getReason();
    if (reason != null) {
      append(", ");
      append(reason);
    }
  }
}
 
Example 2
Source File: MyDeviceChooser.java    From ADBWIFI with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  if (!(value instanceof LaunchCompatibility)) {
    return;
  }

  LaunchCompatibility compatibility = (LaunchCompatibility)value;
  ThreeState compatible = compatibility.isCompatible();
  if (compatible == ThreeState.YES) {
    append("Yes");
  } else {
    if (compatible == ThreeState.NO) {
      append("No", SimpleTextAttributes.ERROR_ATTRIBUTES);
    } else {
      append("Maybe");
    }
    String reason = compatibility.getReason();
    if (reason != null) {
      append(", ");
      append(reason);
    }
  }
}
 
Example 3
Source File: CompletionPhase.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean shouldSkipAutoPopup(Editor editor, PsiFile psiFile) {
  int offset = editor.getCaretModel().getOffset();
  int psiOffset = Math.max(0, offset - 1);

  PsiElement elementAt = psiFile.findElementAt(psiOffset);
  if (elementAt == null) return true;

  Language language = PsiUtilCore.findLanguageFromElement(elementAt);

  for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
    final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset);
    if (result != ThreeState.UNSURE) {
      LOG.debug(confidence + " has returned shouldSkipAutopopup=" + result);
      return result == ThreeState.YES;
    }
  }
  return false;
}
 
Example 4
Source File: SmartSerializer.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SmartSerializer(boolean trackSerializedNames, boolean useSkipEmptySerializationFilter) {
  mySerializedAccessorNameTracker = trackSerializedNames ? new LinkedHashSet<String>() : null;

  mySerializationFilter = useSkipEmptySerializationFilter ?
                          new SkipEmptySerializationFilter() {
                            @Override
                            protected ThreeState accepts(@Nonnull String name, @Nonnull Object beanValue) {
                              return mySerializedAccessorNameTracker != null && mySerializedAccessorNameTracker.contains(name) ? ThreeState.YES : ThreeState.UNSURE;
                            }
                          } :
                          new SkipDefaultValuesSerializationFilters() {
                            @Override
                            public boolean accepts(@Nonnull Accessor accessor, @Nonnull Object bean) {
                              if (mySerializedAccessorNameTracker != null && mySerializedAccessorNameTracker.contains(accessor.getName())) {
                                return true;
                              }
                              return super.accepts(accessor, bean);
                            }
                          };
}
 
Example 5
Source File: SkipAutopopupInStrings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ThreeState shouldSkipAutopopup(@Nonnull PsiElement contextElement, @Nonnull PsiFile psiFile, int offset) {
  if (isInStringLiteral(contextElement)) {
    return ThreeState.YES;
  }

  return ThreeState.UNSURE;
}
 
Example 6
Source File: ShowIntentionActionsHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean availableFor(@Nonnull PsiFile psiFile, @Nonnull Editor editor, @Nonnull IntentionAction action) {
  if (!psiFile.isValid()) return false;

  try {
    Project project = psiFile.getProject();
    action = IntentionActionDelegate.unwrap(action);
    if (action instanceof SuppressIntentionActionFromFix) {
      final ThreeState shouldBeAppliedToInjectionHost = ((SuppressIntentionActionFromFix)action).isShouldBeAppliedToInjectionHost();
      if (editor instanceof EditorWindow && shouldBeAppliedToInjectionHost == ThreeState.YES) {
        return false;
      }
      if (!(editor instanceof EditorWindow) && shouldBeAppliedToInjectionHost == ThreeState.NO) {
        return false;
      }
    }

    if (action instanceof PsiElementBaseIntentionAction) {
      PsiElementBaseIntentionAction psiAction = (PsiElementBaseIntentionAction)action;
      if (!psiAction.checkFile(psiFile)) {
        return false;
      }
      PsiElement leaf = psiFile.findElementAt(editor.getCaretModel().getOffset());
      if (leaf == null || !psiAction.isAvailable(project, editor, leaf)) {
        return false;
      }
    }
    else if (!action.isAvailable(project, editor, psiFile)) {
      return false;
    }
  }
  catch (IndexNotReadyException e) {
    return false;
  }
  return true;
}
 
Example 7
Source File: StartedActivated.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void start(final List<ThrowableRunnable<VcsException>> callList) {
  if (myMaster != null) {
    myMaster.start(callList);
  }
  if (! ThreeState.YES.equals(myState)) {
    myState = ThreeState.YES;
    callList.add(myStart);
  }
}
 
Example 8
Source File: ASTShallowComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hashCodesEqual(@Nonnull final ASTNode n1, @Nonnull final ASTNode n2) {
  if (n1 instanceof LeafElement && n2 instanceof LeafElement) {
    return textMatches(n1, n2) == ThreeState.YES;
  }

  if (n1 instanceof PsiErrorElement && n2 instanceof PsiErrorElement) {
    final PsiErrorElement e1 = (PsiErrorElement)n1;
    final PsiErrorElement e2 = (PsiErrorElement)n2;
    if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription())) return false;
  }

  return ((TreeElement)n1).hc() == ((TreeElement)n2).hc();
}
 
Example 9
Source File: ASTShallowComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ThreeState textMatches(ASTNode oldNode, ASTNode newNode) {
  myIndicator.checkCanceled();
  String oldText = TreeUtil.isCollapsedChameleon(oldNode) ? oldNode.getText() : null;
  String newText = TreeUtil.isCollapsedChameleon(newNode) ? newNode.getText() : null;
  if (oldText != null && newText != null) return oldText.equals(newText) ? ThreeState.YES : ThreeState.UNSURE;

  if (oldText != null) {
    return compareTreeToText((TreeElement)newNode, oldText) ? ThreeState.YES : ThreeState.UNSURE;
  }
  if (newText != null) {
    return compareTreeToText((TreeElement)oldNode, newText) ? ThreeState.YES : ThreeState.UNSURE;
  }

  if (oldNode instanceof ForeignLeafPsiElement) {
    return newNode instanceof ForeignLeafPsiElement && oldNode.getText().equals(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }

  if (newNode instanceof ForeignLeafPsiElement) return ThreeState.NO;

  if (oldNode instanceof LeafElement) {
    return ((LeafElement)oldNode).textMatches(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }
  if (newNode instanceof LeafElement) {
    return ((LeafElement)newNode).textMatches(oldNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }

  if (oldNode instanceof PsiErrorElement && newNode instanceof PsiErrorElement) {
    final PsiErrorElement e1 = (PsiErrorElement)oldNode;
    final PsiErrorElement e2 = (PsiErrorElement)newNode;
    if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription())) return ThreeState.NO;
  }

  return ThreeState.UNSURE;
}
 
Example 10
Source File: DiffTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private CompareResult looksEqual(@Nonnull ShallowNodeComparator<OT, NT> comparator, OT oldChild1, NT newChild1) {
  if (oldChild1 == null || newChild1 == null) {
    return oldChild1 == newChild1 ? CompareResult.EQUAL : CompareResult.NOT_EQUAL;
  }
  if (!comparator.typesEqual(oldChild1, newChild1)) return CompareResult.NOT_EQUAL;
  ThreeState ret = comparator.deepEqual(oldChild1, newChild1);
  if (ret == ThreeState.YES) return CompareResult.EQUAL;
  if (ret == ThreeState.UNSURE) return CompareResult.DRILL_DOWN_NEEDED;
  return CompareResult.TYPE_ONLY;
}
 
Example 11
Source File: GradleDslSimpleExpression.java    From ok-gradle with Apache License 2.0 5 votes vote down vote up
/**
 * Works out whether or not this GradleDslSimpleExpression has a cycle.
 */
public boolean hasCycle() {
  if (myHasCycle != ThreeState.UNSURE) {
    return myHasCycle == ThreeState.YES;
  }
  return hasCycle(this, new HashSet<>(), new HashSet<>());
}
 
Example 12
Source File: SkipAutopopupInComments.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ThreeState shouldSkipAutopopup(@Nonnull PsiElement contextElement, @Nonnull PsiFile psiFile, int offset) {
  if (PsiTreeUtil.getNonStrictParentOfType(contextElement, PsiComment.class) != null) {
    return ThreeState.YES;
  }

  return ThreeState.UNSURE;
}
 
Example 13
Source File: P4Vcs.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when a changelist is deleted explicitly by user or implicitly (e.g. after default changelist switch
 * when the previous one was empty).
 * @param list change list that's about to be removed
 * @param explicitly whether it's a result of explicit Delete action, or just after switching the active changelist.
 * @return UNSURE if the VCS has nothing to say about this changelist.
 * YES or NO if the changelist has to be removed or not, and no further confirmations are needed about this changelist
 * (in particular, the VCS can show a confirmation to the user by itself)
 */
@Override
// @CalledInAwt
@NotNull
public ThreeState mayRemoveChangeList(@NotNull LocalChangeList list, boolean explicitly) {
    if (!explicitly || ChangeListUtil.isDefaultChangelist(list)) {
        return ThreeState.NO;
    }
    return ThreeState.YES;
}
 
Example 14
Source File: BuildFileCompletionConfidence.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public ThreeState shouldSkipAutopopup(PsiElement contextElement, PsiFile psiFile, int offset) {
  if (contextElement.getParent() instanceof IntegerLiteral) {
    return ThreeState.YES;
  }
  return super.shouldSkipAutopopup(contextElement, psiFile, offset);
}
 
Example 15
Source File: SkipDefaultsSerializationFilter.java    From consulo with Apache License 2.0 4 votes vote down vote up
boolean equal(@Nullable Binding binding, @Nullable Object currentValue, @Nullable Object defaultValue) {
  if (defaultValue instanceof Element && currentValue instanceof Element) {
    return JDOMUtil.areElementsEqual((Element)currentValue, (Element)defaultValue);
  }
  else {
    if (currentValue == defaultValue) {
      return true;
    }
    if (currentValue == null || defaultValue == null) {
      return false;
    }

    if (binding instanceof BasePrimitiveBinding) {
      Binding referencedBinding = ((BasePrimitiveBinding)binding).myBinding;
      if (referencedBinding instanceof BeanBinding) {
        BeanBinding classBinding = (BeanBinding)referencedBinding;
        ThreeState compareByFields = classBinding.hasEqualMethod;
        if (compareByFields == ThreeState.UNSURE) {
          try {
            classBinding.myBeanClass.getDeclaredMethod("equals", Object.class);
            compareByFields = ThreeState.NO;
          }
          catch (NoSuchMethodException ignored) {
            compareByFields = ThreeState.YES;
          }
          catch (Exception e) {
            Binding.LOG.warn(e);
          }

          classBinding.hasEqualMethod = compareByFields;
        }

        if (compareByFields == ThreeState.YES) {
          return classBinding.equalByFields(currentValue, defaultValue, this);
        }
      }
    }

    return Comparing.equal(currentValue, defaultValue);
  }
}
 
Example 16
Source File: Invoker.java    From consulo with Apache License 2.0 4 votes vote down vote up
public BackgroundThread(@Nonnull Disposable parent) {
  super("Background.Thread", parent, ThreeState.YES);
  executor = AppExecutorUtil.createBoundedScheduledExecutorService(toString(), 1);
}
 
Example 17
Source File: Invoker.java    From consulo with Apache License 2.0 4 votes vote down vote up
public BackgroundPool(@Nonnull Disposable parent) {
  super("Background.Pool", parent, ThreeState.YES);
}
 
Example 18
Source File: Invoker.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @param task    a task to execute on the valid thread
 * @param promise an object to control task processing
 * @param attempt an attempt to run the specified task
 */
private void invokeSafely(@Nonnull Runnable task, @Nonnull AsyncPromise<?> promise, int attempt) {
  try {
    if (canInvoke(task, promise)) {
      if (getApplication() == null) {
        task.run(); // is not interruptible in tests without application
      }
      else if (useReadAction != ThreeState.YES || isDispatchThread()) {
        ProgressManager.getInstance().runProcess(task, indicator(promise));
      }
      else if (getApplication().isReadAccessAllowed()) {
        if (((ApplicationEx)getApplication()).isWriteActionPending()) {
          offerRestart(task, promise, attempt);
          return;
        }
        ProgressManager.getInstance().runProcess(task, indicator(promise));
      }
      else {
        // try to execute a task until it stops throwing ProcessCanceledException
        while (!ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(task, indicator(promise))) {
          if (!is("invoker.can.yield.to.pending.write.actions")) {
            offerRestart(task, promise, attempt);
            return;
          }
          if (!canInvoke(task, promise)) return; // stop execution of obsolete task
          ProgressIndicatorUtils.yieldToPendingWriteActions();
          if (!canRestart(task, promise, attempt)) return;
          LOG.debug("Task is restarted");
          attempt++;
        }
      }
      promise.setResult(null);
    }
  }
  catch (ProcessCanceledException | IndexNotReadyException exception) {
    offerRestart(task, promise, attempt);
  }
  catch (Throwable throwable) {
    try {
      LOG.error(throwable);
    }
    finally {
      promise.setError(throwable);
    }
  }
  finally {
    count.decrementAndGet();
  }
}
 
Example 19
Source File: CppCompletionConfidence.java    From CppTools with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
  return ThreeState.YES;
}
 
Example 20
Source File: Invoker.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the invoker of user read actions on background threads.
 *
 * @param parent     a disposable parent object
 * @param maxThreads the number of threads used for parallel calculation,
 *                   where 1 guarantees sequential calculation,
 *                   which allows not to use additional synchronization
 */
public Background(@Nonnull Disposable parent, int maxThreads) {
  this(parent, ThreeState.YES, maxThreads);
}