com.intellij.openapi.util.Comparing Java Examples
The following examples show how to use
com.intellij.openapi.util.Comparing.
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: ChangesModuleGroupingPolicy.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nullable public ChangesBrowserNode getParentNodeFor(final StaticFilePath node, final ChangesBrowserNode rootNode) { if (myProject.isDefault()) return null; ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex(); VirtualFile vFile = node.getVf(); if (vFile == null) { vFile = LocalFileSystem.getInstance().findFileByIoFile(new File(node.getPath())); } boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files"); if (vFile != null && Comparing.equal(vFile, index.getContentRootForFile(vFile, hideExcludedFiles))) { Module module = index.getModuleForFile(vFile, hideExcludedFiles); return getNodeForModule(module, rootNode); } return null; }
Example #2
Source File: DeployToServerSettingsEditor.java From consulo with Apache License 2.0 | 6 votes |
private void onDeploymentSourceChanged(@javax.annotation.Nullable D configuration) { DeploymentSource selected = mySourceListModel.getSelectedItem(); if (Comparing.equal(selected, myLastSelection)) { if (configuration != null && myDeploymentSettingsEditor != null) { myDeploymentSettingsEditor.resetFrom(configuration); } return; } updateBeforeRunOptions(myLastSelection, false); updateBeforeRunOptions(selected, true); myDeploymentSettingsComponent.removeAll(); myDeploymentSettingsEditor = myDeploymentConfigurator.createEditor(selected); if (myDeploymentSettingsEditor != null) { Disposer.register(this, myDeploymentSettingsEditor); myDeploymentSettingsComponent.add(BorderLayout.CENTER, myDeploymentSettingsEditor.getComponent()); if (configuration != null) { myDeploymentSettingsEditor.resetFrom(configuration); } } myLastSelection = selected; }
Example #3
Source File: ArrayUtil.java From consulo with Apache License 2.0 | 6 votes |
@Contract(pure = true) public static <E> boolean startsWith(@Nonnull E[] array, @Nonnull E[] subArray) { //noinspection ArrayEquality if (array == subArray) { return true; } int length = subArray.length; if (array.length < length) { return false; } for (int i = 0; i < length; i++) { if (!Comparing.equal(array[i], subArray[i])) { return false; } } return true; }
Example #4
Source File: PsiCopyPasteManager.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public PsiElement[] getElements(boolean[] isCopied) { try { Object transferData = myCopyPasteManager.getContents(ourDataFlavor); if (!(transferData instanceof MyData)) { return null; } MyData dataProxy = (MyData)transferData; if (!Comparing.equal(dataProxy, myRecentData)) { return null; } if (isCopied != null) { isCopied[0] = myRecentData.isCopied(); } return myRecentData.getElements(); } catch (Exception e) { LOG.debug(e); return null; } }
Example #5
Source File: XBreakpointManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void updateBreakpointPresentation(@Nonnull XLineBreakpoint<?> breakpoint, @Nullable Image icon, @Nullable String errorMessage) { XLineBreakpointImpl lineBreakpoint = (XLineBreakpointImpl)breakpoint; CustomizedBreakpointPresentation presentation = lineBreakpoint.getCustomizedPresentation(); if (presentation == null) { if (icon == null && errorMessage == null) { return; } presentation = new CustomizedBreakpointPresentation(); } else if (Comparing.equal(presentation.getIcon(), icon) && Comparing.strEqual(presentation.getErrorMessage(), errorMessage)) { return; } presentation.setErrorMessage(errorMessage); presentation.setIcon(icon); lineBreakpoint.setCustomizedPresentation(presentation); myLineBreakpointManager.queueBreakpointUpdate(breakpoint); }
Example #6
Source File: PsiTestUtil.java From consulo with Apache License 2.0 | 6 votes |
public static ContentEntry addContentRoot(final Module module, final VirtualFile vDir) { final ModuleRootManager rootManager = ModuleRootManager.getInstance(module); new WriteCommandAction.Simple(module.getProject()) { @Override protected void run() throws Throwable { final ModifiableRootModel rootModel = rootManager.getModifiableModel(); rootModel.addContentEntry(vDir); rootModel.commit(); } }.execute().throwException(); for (ContentEntry entry : rootManager.getContentEntries()) { if (Comparing.equal(entry.getFile(), vDir)) { Assert.assertFalse(((ContentEntryImpl)entry).isDisposed()); return entry; } } return null; }
Example #7
Source File: JdkUtil.java From consulo with Apache License 2.0 | 6 votes |
public static boolean checkForJdk(final File homePath) { File binPath = new File(homePath.getAbsolutePath() + File.separator + "bin"); if (!binPath.exists()) return false; FileFilter fileFilter = new FileFilter() { @Override @SuppressWarnings({"HardCodedStringLiteral"}) public boolean accept(File f) { if (f.isDirectory()) return false; return Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javac") || Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javah"); } }; File[] children = binPath.listFiles(fileFilter); return children != null && children.length >= 2 && checkForRuntime(homePath.getAbsolutePath()); }
Example #8
Source File: ShowCoveringTestsAction.java From consulo with Apache License 2.0 | 6 votes |
private void extractTests(final File traceFile, final DataInputStream in, final Set<String> tests) throws IOException { long traceSize = in.readInt(); for (int i = 0; i < traceSize; i++) { final String className = in.readUTF(); final int linesSize = in.readInt(); for(int l = 0; l < linesSize; l++) { final int line = in.readInt(); if (Comparing.strEqual(className, myClassFQName)) { if (myLineData.getLineNumber() == line) { tests.add(FileUtil.getNameWithoutExtension(traceFile)); return; } } } } }
Example #9
Source File: ExtractSuperBaseProcessor.java From intellij-haxe with Apache License 2.0 | 6 votes |
@NotNull protected UsageInfo[] findUsages() { PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); final ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); detectTurnToSuperRefs(refs, result); final PsiPackage originalPackage = JavaDirectoryService.getInstance().getPackage(myClass.getContainingFile().getContainingDirectory()); if (Comparing.equal(JavaDirectoryService.getInstance().getPackage(myTargetDirectory), originalPackage)) { result.clear(); } for (final PsiReference ref : refs) { final PsiElement element = ref.getElement(); if (!canTurnToSuper(element) && !RefactoringUtil.inImportStatement(ref, element)) { result.add(new BindToOldUsageInfo(element, ref, myClass)); } } UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]); return UsageViewUtil.removeDuplicatedUsages(usageInfos); }
Example #10
Source File: AnchorElementInfo.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean pointsToTheSameElementAs(@Nonnull final SmartPointerElementInfo other, @Nonnull SmartPointerManagerImpl manager) { if (other instanceof AnchorElementInfo) { if (!getVirtualFile().equals(other.getVirtualFile())) return false; long packed1 = myStubElementTypeAndId; long packed2 = ((AnchorElementInfo)other).myStubElementTypeAndId; if (packed1 != -1 && packed2 != -1) { return packed1 == packed2; } if (packed1 != -1 || packed2 != -1) { return ReadAction.compute(() -> Comparing.equal(restoreElement(manager), other.restoreElement(manager))); } } return super.pointsToTheSameElementAs(other, manager); }
Example #11
Source File: ComboBoxFieldPanel.java From consulo with Apache License 2.0 | 6 votes |
public void addItemSetText(String text) { JComboBox comboBox = getComboBox(); int n = comboBox.getItemCount(); boolean found = false; for (int i = 0; i < n; i++) { String item = (String)comboBox.getItemAt(i); if (Comparing.strEqual(item, text)) { found = true; break; } } if (!found) { comboBox.addItem(text); } comboBox.getEditor().setItem(text); setText(text); }
Example #12
Source File: ModuleConfigurable.java From consulo with Apache License 2.0 | 6 votes |
@Override public void setDisplayName(String name) { name = name.trim(); final ModifiableModuleModel modifiableModuleModel = myConfigurator.getModuleModel(); if (StringUtil.isEmpty(name)) return; //empty string comes on double click on module node if (Comparing.strEqual(name, myModuleName)) return; //nothing changed try { modifiableModuleModel.renameModule(myModule, name); } catch (ModuleWithNameAlreadyExistsException ignored) { } myConfigurator.moduleRenamed(myModule, myModuleName, name); myModuleName = name; myConfigurator.setModified(!Comparing.strEqual(myModuleName, myModule.getName())); myContext.getDaemonAnalyzer().queueUpdateForAllElementsWithErrors(); }
Example #13
Source File: ExternalizablePropertyContainer.java From consulo with Apache License 2.0 | 6 votes |
public void writeExternal(@Nonnull Element element) { if (myExternalizers.isEmpty()) { return; } List<AbstractProperty> properties = new ArrayList<AbstractProperty>(myExternalizers.keySet()); Collections.sort(properties, AbstractProperty.NAME_COMPARATOR); for (AbstractProperty property : properties) { Externalizer externalizer = myExternalizers.get(property); if (externalizer == null) { continue; } Object propValue = property.get(this); if (!Comparing.equal(propValue, property.getDefault(this))) { Element child = new Element(property.getName()); externalizer.writeValue(child, propValue); if (!JDOMUtil.isEmpty(child)) { element.addContent(child); } } } }
Example #14
Source File: ActionsTreeUtil.java From consulo with Apache License 2.0 | 6 votes |
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 #15
Source File: RootModelImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean removeLayer(@Nonnull String name, boolean initDefault) { assertWritable(); ModuleRootLayerImpl removedLayer = myLayers.remove(name); if (removedLayer != null) { Disposer.dispose(removedLayer); if (initDefault && myLayers.isEmpty()) { initDefaultLayer(null); } if (Comparing.equal(myCurrentLayerName, name)) { setCurrentLayerSafe(myLayers.isEmpty() ? null : ContainerUtil.getFirstItem(myLayers.keySet())); } } return removedLayer != null; }
Example #16
Source File: ModulesAndLibrariesSourceItemsProvider.java From consulo with Apache License 2.0 | 6 votes |
private static Collection<? extends PackagingSourceItem> createModuleItems(ArtifactEditorContext editorContext, Artifact artifact, @Nonnull String[] groupPath) { final Module[] modules = editorContext.getModulesProvider().getModules(); final List<PackagingSourceItem> items = new ArrayList<PackagingSourceItem>(); Set<String> groups = new HashSet<String>(); for (Module module : modules) { String[] path = ModuleManager.getInstance(editorContext.getProject()).getModuleGroupPath(module); if (path == null) { path = ArrayUtil.EMPTY_STRING_ARRAY; } if (Comparing.equal(path, groupPath)) { items.add(new ModuleSourceItemGroup(module)); } else if (ArrayUtil.startsWith(path, groupPath)) { groups.add(path[groupPath.length]); } } for (String group : groups) { items.add(0, new ModuleGroupItem(ArrayUtil.append(groupPath, group))); } return items; }
Example #17
Source File: ChangeListsIndexes.java From consulo with Apache License 2.0 | 6 votes |
private void addChangeToIdx(final Change change, final VcsKey key) { final ContentRevision afterRevision = change.getAfterRevision(); final ContentRevision beforeRevision = change.getBeforeRevision(); if (afterRevision != null) { add(afterRevision.getFile(), change.getFileStatus(), key, beforeRevision == null ? VcsRevisionNumber.NULL : beforeRevision.getRevisionNumber()); } if (beforeRevision != null) { if (afterRevision != null) { if (! Comparing.equal(beforeRevision.getFile(), afterRevision.getFile())) { add(beforeRevision.getFile(), FileStatus.DELETED, key, beforeRevision.getRevisionNumber()); } } else { add(beforeRevision.getFile(), change.getFileStatus(), key, beforeRevision.getRevisionNumber()); } } }
Example #18
Source File: TooltipController.java From consulo with Apache License 2.0 | 6 votes |
public void showTooltip(@Nonnull Editor editor, @Nonnull Point p, @Nonnull TooltipRenderer tooltipRenderer, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintInfo) { if (myCurrentTooltip == null || !myCurrentTooltip.isVisible()) { myCurrentTooltipObject = null; } if (Comparing.equal(tooltipRenderer, myCurrentTooltipObject)) { IdeTooltipManager.getInstance().cancelAutoHide(); return; } if (myCurrentTooltipGroup != null && group.compareTo(myCurrentTooltipGroup) < 0) return; p = new Point(p); hideCurrentTooltip(); LightweightHint hint = tooltipRenderer.show(editor, p, alignToRight, group, hintInfo); myCurrentTooltipGroup = group; myCurrentTooltip = hint; myCurrentTooltipObject = tooltipRenderer; }
Example #19
Source File: ProjectSettingsPanel.java From consulo with Apache License 2.0 | 6 votes |
public boolean isModified() { final CopyrightProfile defaultCopyright = myManager.getDefaultCopyright(); final Object selected = myProfilesComboBox.getSelectedItem(); if (defaultCopyright != selected) { if (selected == null) return true; if (defaultCopyright == null) return true; if (!defaultCopyright.equals(selected)) return true; } final Map<String, String> map = myManager.getCopyrightsMapping(); if (map.size() != myScopeMappingModel.getItems().size()) return true; final Iterator<String> iterator = map.keySet().iterator(); for (ScopeSetting setting : myScopeMappingModel.getItems()) { final NamedScope scope = setting.getScope(); if (!iterator.hasNext()) return true; final String scopeName = iterator.next(); if (scope == null || !Comparing.strEqual(scopeName, scope.getName())) return true; final String profileName = map.get(scope.getName()); if (profileName == null) return true; if (!profileName.equals(setting.getProfileName())) return true; } return false; }
Example #20
Source File: AbstractTestTreeBuilder.java From consulo with Apache License 2.0 | 6 votes |
public void setStatisticsComparator(TestConsoleProperties properties, boolean sortByStatistics) { if (!sortByStatistics) { setTestsComparator(TestConsoleProperties.SORT_ALPHABETICALLY.value(properties)); } else { setNodeDescriptorComparator(new Comparator<NodeDescriptor>() { @Override public int compare(NodeDescriptor o1, NodeDescriptor o2) { if (o1.getParentDescriptor() == o2.getParentDescriptor() && o1 instanceof BaseTestProxyNodeDescriptor && o2 instanceof BaseTestProxyNodeDescriptor) { final Long d1 = ((BaseTestProxyNodeDescriptor)o1).getElement().getDuration(); final Long d2 = ((BaseTestProxyNodeDescriptor)o2).getElement().getDuration(); return Comparing.compare(d2, d1); } return 0; } }); } queueUpdate(); }
Example #21
Source File: CSharpPreprocessorReferenceExpressionImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public PsiElement resolve() { return ResolveCache.getInstance(getProject()).resolveWithCaching(this, (expression, incompleteCode) -> { Ref<CSharpPreprocessorVariable> ref = Ref.create(); collect(it -> { if(Comparing.equal(it.getName(), getElement().getText())) { ref.set(it); return false; } return true; }); return ref.get(); }, true, true); }
Example #22
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
@Override public int compare(UsageNode c1, UsageNode c2) { if (c1 instanceof StringNode) return 1; if (c2 instanceof StringNode) return -1; Usage o1 = c1.getUsage(); Usage o2 = c2.getUsage(); if (o1 == MORE_USAGES_SEPARATOR) return 1; if (o2 == MORE_USAGES_SEPARATOR) return -1; VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1); VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2); String name1 = v1 == null ? null : v1.getName(); String name2 = v2 == null ? null : v2.getName(); int i = Comparing.compare(name1, name2); if (i != 0) return i; if (o1 instanceof Comparable && o2 instanceof Comparable) { return ((Comparable) o1).compareTo(o2); } FileEditorLocation loc1 = o1.getLocation(); FileEditorLocation loc2 = o2.getLocation(); return Comparing.compare(loc1, loc2); }
Example #23
Source File: DirectoryNode.java From consulo with Apache License 2.0 | 5 votes |
private String getContentRootName(final VirtualFile baseDir, final String dirName) { if (baseDir != null) { if (!Comparing.equal(myVDirectory, baseDir)) { if (VfsUtil.isAncestor(baseDir, myVDirectory, false)) { return VfsUtilCore.getRelativePath(myVDirectory, baseDir, '/'); } else { return myVDirectory.getPresentableUrl(); } } } else { return myVDirectory.getPresentableUrl(); } return dirName; }
Example #24
Source File: JavaExtractSuperBaseDialog.java From intellij-haxe with Apache License 2.0 | 5 votes |
private PsiDirectory getDirUnderSameSourceRoot(final PsiDirectory[] directories) { final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile(); if (sourceFile != null) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile); if (sourceRoot != null) { for (PsiDirectory dir : directories) { if (Comparing.equal(fileIndex.getSourceRootForFile(dir.getVirtualFile()), sourceRoot)) { return dir; } } } } return directories[0]; }
Example #25
Source File: ToolsImpl.java From consulo with Apache License 2.0 | 5 votes |
public void enableTool(NamedScope namedScope, Project project) { if (myTools != null) { for (ScopeToolState state : myTools) { if (Comparing.equal(state.getScope(project), namedScope)) { state.setEnabled(true); } } } setEnabled(true); }
Example #26
Source File: TextEditorComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override public void propertyChanged(@Nonnull final VirtualFilePropertyEvent e) { if (VirtualFile.PROP_NAME.equals(e.getPropertyName())) { // File can be invalidated after file changes name (extension also // can changes). The editor should be removed if it's invalid. updateValidProperty(); if (Comparing.equal(e.getFile(), myFile) && (FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(e.getRequestor()) || !Comparing.equal(e.getOldValue(), e.getNewValue()))) { myEditorHighlighterUpdater.updateHighlighters(); } } }
Example #27
Source File: XQueryRunConfigurationProducer.java From intellij-xquery with Apache License 2.0 | 5 votes |
private boolean isForTheSameFile(PsiFile psiFile, XQueryRunConfiguration appConfiguration) { String checkedFilePath = FileUtil.toSystemIndependentName(psiFile.getVirtualFile().getCanonicalPath()); String existingConfigFilePath = ""; if (appConfiguration.getMainFileName() != null) existingConfigFilePath = FileUtil.toSystemIndependentName(appConfiguration.getMainFileName()); return Comparing.equal(checkedFilePath, existingConfigFilePath); }
Example #28
Source File: AbstractEditIntentionSettingsAction.java From consulo with Apache License 2.0 | 5 votes |
protected AbstractEditIntentionSettingsAction(@Nonnull IntentionAction action) { myFamilyName = action.getFamilyName(); // needed for checking errors in user written actions //noinspection ConstantConditions LOG.assertTrue(myFamilyName != null, "action " + action.getClass() + " family returned null"); myEnabled = !(action instanceof IntentionActionWrapper) || !Comparing.equal(action.getFamilyName(), ((IntentionActionWrapper)action).getFullFamilyName()); }
Example #29
Source File: ToolbarUpdater.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object obj) { if (!(obj instanceof MyUpdateRunnable)) return false; MyUpdateRunnable that = (MyUpdateRunnable)obj; if (myHash != that.myHash) return false; ToolbarUpdater updater1 = myUpdaterRef.get(); ToolbarUpdater updater2 = that.myUpdaterRef.get(); return Comparing.equal(updater1, updater2); }
Example #30
Source File: ModuleExtensionWithSdkOrderEntryImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isEquivalentTo(@Nonnull OrderEntry other) { if (other instanceof ModuleExtensionWithSdkOrderEntry) { String name1 = getSdkName(); String name2 = ((ModuleExtensionWithSdkOrderEntry)other).getSdkName(); return Comparing.strEqual(name1, name2); } return false; }