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

The following examples show how to use com.intellij.util.ThreeState#UNSURE . 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: 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 2
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 3
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 4
Source File: UnityPlayerService.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public void bindAndRun(@Nonnull Project project, @Nonnull Runnable runnable)
{
	switch(myBindState)
	{
		case YES:
			runnable.run();
			break;
		case UNSURE:
			// nothing
			break;
		default:
			myBindState = ThreeState.UNSURE;

			new Task.Backgroundable(project, "Preparing network listeners...")
			{
				@Override
				public void run(@Nonnull ProgressIndicator progressIndicator)
				{
					bind(progressIndicator);
				}

				@RequiredUIAccess
				@Override
				public void onFinished()
				{
					myBindState = ThreeState.YES;

					runUpdateTask();

					runnable.run();
				}
			}.queue();
			break;
	}
}
 
Example 5
Source File: PhpParameterStringCompletionConfidence.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
    if (!Symfony2ProjectComponent.isEnabled(contextElement)) {
        return ThreeState.UNSURE;
    }

    if(!(psiFile instanceof PhpFile)) {
        return ThreeState.UNSURE;
    }

    PsiElement context = contextElement.getContext();
    if(!(context instanceof StringLiteralExpression)) {
        return ThreeState.UNSURE;
    }

    // $test == "";
    if(context.getParent() instanceof BinaryExpression) {
        return ThreeState.NO;
    }

    // $this->container->get("");
    PsiElement stringContext = context.getContext();
    if(stringContext instanceof ParameterList) {
        return ThreeState.NO;
    }

    // $this->method(... array('foo'); array('bar' => 'foo') ...);
    ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(context);
    if(arrayCreationExpression != null && arrayCreationExpression.getContext() instanceof ParameterList) {
        return ThreeState.NO;
    }

    // $array['value']
    if(PlatformPatterns.psiElement().withSuperParent(2, ArrayIndex.class).accepts(contextElement)) {
        return ThreeState.NO;
    }

    return ThreeState.UNSURE;
}
 
Example 6
Source File: PhpParameterStringCompletionConfidence.java    From idea-php-advanced-autocomplete with MIT License 5 votes vote down vote up
@NotNull
    @Override
    public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {

        if (!(psiFile instanceof PhpFile)) {
            return ThreeState.UNSURE;
        }

        PsiElement context = contextElement.getContext();
        if (!(context instanceof StringLiteralExpression)) {
            return ThreeState.UNSURE;
        }

//        // $test == "";
//        if(context.getParent() instanceof BinaryExpression) {
//            return ThreeState.NO;
//        }

        // $object->method("");
        PsiElement stringContext = context.getContext();
        if (stringContext instanceof ParameterList) {
            return ThreeState.NO;
        }

//        // $object->method(... array('foo'); array('bar' => 'foo') ...);
//        ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(context);
//        if(arrayCreationExpression != null && arrayCreationExpression.getContext() instanceof ParameterList) {
//            return ThreeState.NO;
//        }

//        // $array['value']
//        if(PlatformPatterns.psiElement().withSuperParent(2, ArrayIndex.class).accepts(contextElement)) {
//            return ThreeState.NO;
//        }

        return ThreeState.UNSURE;
    }
 
Example 7
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 8
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 9
Source File: Invoker.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Invoker(@Nonnull String prefix, @Nonnull Disposable parent, @Nonnull ThreeState useReadAction) {
  StringBuilder sb = new StringBuilder().append(UID.getAndIncrement()).append(".Invoker.").append(prefix);
  if (useReadAction != ThreeState.UNSURE) {
    sb.append(".ReadAction=").append(useReadAction);
  }
  description = sb.append(": ").append(parent).toString();
  this.useReadAction = useReadAction;
  register(parent, this);
}
 
Example 10
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 11
Source File: GradleDslSimpleExpression.java    From ok-gradle with Apache License 2.0 4 votes vote down vote up
/**
 * Tells the expression that the value has changed, this sets this element to modified and resets the cycle detection state.
 */
protected void valueChanged() {
  myHasCycle = ThreeState.UNSURE;
  setModified();
}
 
Example 12
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 13
Source File: StartedActivated.java    From consulo with Apache License 2.0 4 votes vote down vote up
public MySection(final ThrowableRunnable<VcsException> start, final ThrowableRunnable<VcsException> stop) {
  myStart = start;
  myStop = stop;
  myState = ThreeState.UNSURE;
}
 
Example 14
Source File: Invoker.java    From consulo with Apache License 2.0 4 votes vote down vote up
public EDT(@Nonnull Disposable parent) {
  super("EDT", parent, ThreeState.UNSURE);
}
 
Example 15
Source File: SuppressIntentionActionFromFix.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ThreeState isShouldBeAppliedToInjectionHost() {
  return myFix instanceof InjectionAwareSuppressQuickFix
         ? ((InjectionAwareSuppressQuickFix)myFix).isShouldBeAppliedToInjectionHost()
         : ThreeState.UNSURE;
}
 
Example 16
Source File: DiffTreeTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public ThreeState deepEqual(@Nonnull final Node node, @Nonnull final Node node1) {
  return ThreeState.UNSURE;
}
 
Example 17
Source File: PhpAnnotationCompletionConfidence.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {

    if(!(psiFile instanceof PhpFile)) {
        return ThreeState.UNSURE;
    }

    PsiElement context = contextElement.getContext();
    if(context instanceof StringLiteralExpression) {

        // foo="<|>"
        if(PhpPatterns.psiElement(PhpDocElementTypes.phpDocString).accepts(context)) {
            return ThreeState.NO;
        }

    } else if(context instanceof PhpDocComment) {

        // * <|>
        if(PhpPatterns.psiElement().afterLeafSkipping(
            PhpPatterns.psiElement(PsiWhiteSpace.class),
            PhpPatterns.psiElement(PhpDocTokenTypes.DOC_LEADING_ASTERISK)
        ).accepts(contextElement)) {
            return ThreeState.NO;
        }

    } else if(context instanceof PhpPsiElementImpl) {

        // @Foo(<|>)
        if(PhpPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList).accepts(context)) {
            return ThreeState.NO;
        }

        // @<|>
        if(PhpPatterns.psiElement(PhpDocElementTypes.phpDocTag).accepts(context)) {
            return ThreeState.NO;
        }

    }

    return ThreeState.UNSURE;
}
 
Example 18
Source File: PhpParameterStringCompletionConfidence.java    From idea-php-laravel-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {

    if(!(psiFile instanceof PhpFile)) {
        return ThreeState.UNSURE;
    }

    Project project = contextElement.getProject();
    if(!LaravelProjectComponent.isEnabled(project) || !LaravelSettings.getInstance(project).useAutoPopup) {
        return ThreeState.UNSURE;
    }

    PsiElement context = contextElement.getContext();
    if(!(context instanceof StringLiteralExpression)) {
        return ThreeState.UNSURE;
    }

    // $test == "";
    if(context.getParent() instanceof BinaryExpression) {
        return ThreeState.NO;
    }

    // $this->container->get("");
    PsiElement stringContext = context.getContext();
    if(stringContext instanceof ParameterList) {
        return ThreeState.NO;
    }

    // $this->method(... array('foo'); array('bar' => 'foo') ...);
    ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(context);
    if(arrayCreationExpression != null && arrayCreationExpression.getContext() instanceof ParameterList) {
        return ThreeState.NO;
    }

    // $array['value']
    if(PlatformPatterns.psiElement().withSuperParent(2, ArrayIndex.class).accepts(contextElement)) {
        return ThreeState.NO;
    }

    return ThreeState.UNSURE;
}
 
Example 19
Source File: XValue.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Provide inline debugger data, return ability to provide, use
 * {@link ThreeState#UNSURE} if unsupported (default platform implementation will be used),
 * {@link ThreeState#YES} if applicable
 * {@link ThreeState#NO} if not applicable
 */
@Nonnull
public ThreeState computeInlineDebuggerData(@Nonnull XInlineDebuggerDataCallback callback) {
  return ThreeState.UNSURE;
}
 
Example 20
Source File: AbstractVcs.java    From consulo with Apache License 2.0 2 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)
 */
@CalledInAwt
@Nonnull
public ThreeState mayRemoveChangeList(@Nonnull LocalChangeList list, boolean explicitly) {
  return ThreeState.UNSURE;
}