Java Code Examples for com.intellij.openapi.util.Comparing#equal()

The following examples show how to use com.intellij.openapi.util.Comparing#equal() . 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: CSharpMsilStubIndexer.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void indexClass(@Nonnull MsilClassEntryStub stub, @Nonnull IndexSink indexSink)
{
	String name = stub.getName();
	if(StringUtil.isEmpty(name))
	{
		return;
	}

	if(stub.isNested())
	{
		return;
	}

	List<StubElement> childrenStubs = stub.getChildrenStubs();
	for(StubElement childrenStub : childrenStubs)
	{
		if(childrenStub instanceof MsilCustomAttributeStub && Comparing.equal(((MsilCustomAttributeStub) childrenStub).getTypeRef(), DotNetTypes.System.Runtime.CompilerServices
				.ExtensionAttribute))
		{
			indexSink.occurrence(CSharpIndexKeys.TYPE_WITH_EXTENSION_METHODS_INDEX, DotNetNamespaceStubUtil.getIndexableNamespace(stub.getNamespace()));
			break;
		}
	}
}
 
Example 2
Source File: GeneratedParserUtilBase.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public static int nextTokenIsFast(PsiBuilder builder, String tokenText, boolean caseSensitive) {
    CharSequence sequence = builder.getOriginalText();
    int offset = builder.getCurrentOffset();
    int endOffset = offset + tokenText.length();
    CharSequence subSequence = sequence.subSequence(offset, Math.min(endOffset, sequence.length()));

    if (!Comparing.equal(subSequence, tokenText, caseSensitive)) return 0;

    int count = 0;
    while (true) {
        int nextOffset = builder.rawTokenTypeStart(++count);
        if (nextOffset > endOffset) {
            return -count;
        }
        else if (nextOffset == endOffset) {
            break;
        }
    }
    return count;
}
 
Example 3
Source File: ActionsTreeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Condition<AnAction> isActionFiltered(final ActionManager actionManager,
                                                   final Keymap keymap,
                                                   final KeyboardShortcut keyboardShortcut) {
  return new Condition<AnAction>() {
    public boolean value(final AnAction action) {
      if (keyboardShortcut == null) return true;
      if (action == null) return false;
      final Shortcut[] actionShortcuts =
        keymap.getShortcuts(action instanceof ActionStub ? ((ActionStub)action).getId() : actionManager.getId(action));
      for (Shortcut shortcut : actionShortcuts) {
        if (shortcut instanceof KeyboardShortcut) {
          final KeyboardShortcut keyboardActionShortcut = (KeyboardShortcut)shortcut;
          if (Comparing.equal(keyboardActionShortcut, keyboardShortcut)) {
            return true;
          }
        }
      }
      return false;
    }
  };
}
 
Example 4
Source File: AbstractElementSignatureProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected static <T extends PsiNamedElement> T restoreElementInternal(@Nonnull PsiElement parent,
                                                                      String name,
                                                                      int index,
                                                                      @Nonnull Class<T> hisClass)
{
  PsiElement[] children = parent.getChildren();

  for (PsiElement child : children) {
    if (ReflectionUtil.isAssignable(hisClass, child.getClass())) {
      T namedChild = hisClass.cast(child);
      final String childName = namedChild.getName();

      if (Comparing.equal(name, childName)) {
        if (index == 0) {
          return namedChild;
        }
        index--;
      }
    }
  }

  return null;
}
 
Example 5
Source File: CSharpReferenceExpressionImplUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private static boolean isReferenceTo(@Nonnull ResolveResult resolveResult, PsiElement element)
{
	PsiElement psiElement = resolveResult.getElement();
	if(element instanceof DotNetNamespaceAsElement && psiElement instanceof DotNetNamespaceAsElement)
	{
		if(Comparing.equal(((DotNetNamespaceAsElement) psiElement).getPresentableQName(), ((DotNetNamespaceAsElement) element).getPresentableQName()))
		{
			return true;
		}
	}

	if(element.getManager().areElementsEquivalent(element, psiElement))
	{
		return true;
	}
	return false;
}
 
Example 6
Source File: UnmarkRootAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean canUnmark(AnActionEvent e) {
  Module module = e.getData(LangDataKeys.MODULE);
  VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  if (module == null || vFiles == null) {
    return false;
  }
  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
  final ContentEntry[] contentEntries = moduleRootManager.getContentEntries();

  for (VirtualFile vFile : vFiles) {
    if (!vFile.isDirectory()) {
      continue;
    }

    for (ContentEntry contentEntry : contentEntries) {
      for (ContentFolder contentFolder : contentEntry.getFolders(ContentFolderScopes.all())) {
        if (Comparing.equal(contentFolder.getFile(), vFile)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example 7
Source File: LocalSearchScope.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean equals(Object o) {
  if (this == o) return true;
  if (!(o instanceof LocalSearchScope)) return false;

  final LocalSearchScope localSearchScope = (LocalSearchScope)o;

  if (localSearchScope.myIgnoreInjectedPsi != myIgnoreInjectedPsi) return false;
  if (localSearchScope.myScope.length != myScope.length) return false;
  for (final PsiElement scopeElement : myScope) {
    final PsiElement[] thatScope = localSearchScope.myScope;
    for (final PsiElement thatScopeElement : thatScope) {
      if (!Comparing.equal(scopeElement, thatScopeElement)) return false;
    }
  }


  return true;
}
 
Example 8
Source File: XBreakpointBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setLogExpressionObject(@Nullable XExpression expression) {
  if (!Comparing.equal(myLogExpression, expression)) {
    myLogExpression = expression;
    fireBreakpointChanged();
  }
}
 
Example 9
Source File: UsagePreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void resetEditor(@Nonnull final List<? extends UsageInfo> infos) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  PsiElement psiElement = infos.get(0).getElement();
  if (psiElement == null) return;
  PsiFile psiFile = psiElement.getContainingFile();
  if (psiFile == null) return;

  PsiLanguageInjectionHost host = InjectedLanguageManager.getInstance(myProject).getInjectionHost(psiFile);
  if (host != null) {
    psiFile = host.getContainingFile();
    if (psiFile == null) return;
  }

  final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
  if (document == null) return;
  if (myEditor == null || document != myEditor.getDocument()) {
    releaseEditor();
    removeAll();
    myEditor = createEditor(psiFile, document);
    if (myEditor == null) return;
    myLineHeight = myEditor.getLineHeight();
    myEditor.setBorder(null);
    add(myEditor.getComponent(), BorderLayout.CENTER);

    invalidate();
    validate();
  }

  if (!Comparing.equal(infos, myCachedSelectedUsageInfos)
      // avoid moving viewport
      || !UsageViewPresentation.arePatternsEqual(myCachedSearchPattern, myPresentation.getSearchPattern()) || !UsageViewPresentation.arePatternsEqual(myCachedReplacePattern, myPresentation.getReplacePattern())) {
    highlight(infos, myEditor, myProject, true, HighlighterLayer.ADDITIONAL_SYNTAX);
    myCachedSelectedUsageInfos = infos;
    myCachedSearchPattern = myPresentation.getSearchPattern();
    myCachedReplacePattern = myPresentation.getReplacePattern();
  }
}
 
Example 10
Source File: EditChangelistDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void doOKAction() {
  String oldName = myList.getName();
  String oldComment = myList.getComment();

  if (!Comparing.equal(oldName, myPanel.getChangeListName()) && ChangeListManager.getInstance(myProject).findChangeList(myPanel.getChangeListName()) != null) {
    Messages.showErrorDialog(myPanel.getContent(),
                             VcsBundle.message("changes.dialog.editchangelist.error.already.exists", myPanel.getChangeListName()),
                             VcsBundle.message("changes.dialog.editchangelist.title"));
    return;
  }

  if (!Comparing.equal(oldName, myPanel.getChangeListName(), true) || !Comparing.equal(oldComment, myPanel.getDescription(), true)) {
    final ChangeListManager clManager = ChangeListManager.getInstance(myProject);

    final String newName = myPanel.getChangeListName();
    if (! myList.getName().equals(newName)) {
      clManager.editName(myList.getName(), newName);
    }
    final String newDescription = myPanel.getDescription();
    if (! myList.getComment().equals(newDescription)) {
      clManager.editComment(myList.getName(), newDescription);
    }
  }
  if (!myList.isDefault() && myPanel.getMakeActiveCheckBox().isSelected()) {
    ChangeListManager.getInstance(myProject).setDefaultChangeList(myList);  
  }
  myPanel.changelistCreatedOrChanged(myList);
  super.doOKAction();
}
 
Example 11
Source File: PersistentFSImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean namesEqual(@Nonnull VirtualFileSystem fs, @Nonnull CharSequence n1, @Nonnull CharSequence n2) {
  return Comparing.equal(n1, n2, fs.isCaseSensitive());
}
 
Example 12
Source File: PopupListElementRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void customizeComponent(JList<? extends E> list, E value, boolean isSelected) {
  ListPopupStep<Object> step = myPopup.getListStep();
  boolean isSelectable = step.isSelectable(value);
  myTextLabel.setEnabled(isSelectable);
  if (step instanceof BaseListPopupStep) {
    Color bg = ((BaseListPopupStep<E>)step).getBackgroundFor(value);
    Color fg = ((BaseListPopupStep<E>)step).getForegroundFor(value);
    if (!isSelected && fg != null) myTextLabel.setForeground(fg);
    if (!isSelected && bg != null) UIUtil.setBackgroundRecursively(myComponent, bg);
    if (bg != null && mySeparatorComponent.isVisible() && myCurrentIndex > 0) {
      E prevValue = list.getModel().getElementAt(myCurrentIndex - 1);
      // separator between 2 colored items shall get color too
      if (Comparing.equal(bg, ((BaseListPopupStep<E>)step).getBackgroundFor(prevValue))) {
        myRendererComponent.setBackground(bg);
      }
    }
  }

  if (step.isMnemonicsNavigationEnabled()) {
    MnemonicNavigationFilter<Object> filter = step.getMnemonicNavigationFilter();
    int pos = filter == null ? -1 : filter.getMnemonicPos(value);
    if (pos != -1) {
      String text = myTextLabel.getText();
      text = text.substring(0, pos) + text.substring(pos + 1);
      myTextLabel.setText(text);
      myTextLabel.setDisplayedMnemonicIndex(pos);
    }
  }
  else {
    myTextLabel.setDisplayedMnemonicIndex(-1);
  }

  if (step.hasSubstep(value) && isSelectable) {
    myNextStepLabel.setVisible(true);
    final boolean isDark = ColorUtil.isDark(UIUtil.getListSelectionBackground());
    myNextStepLabel.setIcon(isSelected ? isDark ? AllIcons.Icons.Ide.NextStepInverted : AllIcons.Icons.Ide.NextStep : AllIcons.Icons.Ide.NextStepGrayed);
  }
  else {
    myNextStepLabel.setVisible(false);
    //myNextStepLabel.setIcon(PopupIcons.EMPTY_ICON);
  }

  setSelected(myComponent, isSelected && isSelectable);
  setSelected(myTextLabel, isSelected && isSelectable);
  setSelected(myNextStepLabel, isSelected && isSelectable);

  if (myShortcutLabel != null) {
    myShortcutLabel.setEnabled(isSelectable);
    myShortcutLabel.setText("");
    if (value instanceof ShortcutProvider) {
      ShortcutSet set = ((ShortcutProvider)value).getShortcut();
      if (set != null) {
        Shortcut shortcut = ArrayUtil.getFirstElement(set.getShortcuts());
        if (shortcut != null) {
          myShortcutLabel.setText("     " + KeymapUtil.getShortcutText(shortcut));
        }
      }
    }
    setSelected(myShortcutLabel, isSelected && isSelectable);
    myShortcutLabel.setForeground(isSelected && isSelectable ? UIManager.getColor("MenuItem.acceleratorSelectionForeground") : UIManager.getColor("MenuItem.acceleratorForeground"));
  }
}
 
Example 13
Source File: QuickListsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isModified() {
  QuickList[] storedLists = QuickListsManager.getInstance().getAllQuickLists();
  QuickList[] modelLists = getCurrentQuickListIds();
  return !Comparing.equal(storedLists, modelLists);
}
 
Example 14
Source File: VcsLimitHistoryConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isModified() {
  if (myHighlightRecentlyChanged.isSelected() != myConfiguration.LIMIT_HISTORY) return true;
  if (! Comparing.equal(myHighlightInterval.getValue(), myConfiguration.MAXIMUM_HISTORY_ROWS)) return true;
  return false;
}
 
Example 15
Source File: EditorColorsSchemeImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void setColor(ColorKey key, Color color) {
  if (!Comparing.equal(color, getColor(key))) {
    myColorsMap.put(key, color);
  }
}
 
Example 16
Source File: AttributesFlyweight.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public AttributesFlyweight withErrorStripeColor(Color stripeColor) {
  return Comparing.equal(stripeColor, myErrorStripeColor) ? this : create(myForeground, myBackground, myFontType, myEffectColor, myEffectType, myAdditionalEffects, stripeColor);
}
 
Example 17
Source File: AddAccessModifierFix.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
private static boolean equal(CSharpModifier[] modifiers, CSharpModifier... required)
{
	return Comparing.equal(modifiers, required);
}
 
Example 18
Source File: XQueryRunConfigurationProducer.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private boolean isForTheSameModule(Location location, XQueryRunConfiguration appConfiguration) {
    final Module configurationModule = appConfiguration.getConfigurationModule().getModule();
    return Comparing.equal(location.getModule(), configurationModule)
            || Comparing.equal(getPredefinedModule(location), configurationModule);
}
 
Example 19
Source File: EditorHistoryManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public synchronized boolean hasBeenOpen(@Nonnull VirtualFile f) {
  for (HistoryEntry each : myEntriesList) {
    if (Comparing.equal(each.getFile(), f)) return true;
  }
  return false;
}
 
Example 20
Source File: AttributesFlyweight.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public AttributesFlyweight withEffectColor(Color effectColor) {
  return Comparing.equal(effectColor, myEffectColor) ? this : create(myForeground, myBackground, myFontType, effectColor, myEffectType, myAdditionalEffects, myErrorStripeColor);
}