Java Code Examples for com.intellij.openapi.util.Pair

The following examples show how to use com.intellij.openapi.util.Pair. These examples are extracted from open source projects. 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 Project: lsp4intellij   Source File: LSPReferencesAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (editor != null) {
        EditorEventManager eventManager = EditorEventManagerBase.forEditor(editor);
        if (eventManager == null) {
            return;
        }
        List<PsiElement2UsageTargetAdapter> targets = new ArrayList<>();
        Pair<List<PsiElement>, List<VirtualFile>> references = eventManager
                .references(editor.getCaretModel().getCurrentCaret().getOffset());
        if (references.first != null && references.second != null) {
            references.first.forEach(element -> targets.add(new PsiElement2UsageTargetAdapter(element)));
        }
        showReferences(editor, targets, editor.getCaretModel().getCurrentCaret().getLogicalPosition());
    }
}
 
Example 2
Source Project: idea-gitignore   Source File: GeneratorDialog.java    License: MIT License 6 votes vote down vote up
/**
 * Updates editor's content depending on the selected {@link TreePath}.
 *
 * @param path selected tree path
 */
private void updateDescriptionPanel(@NotNull TreePath path) {
    final TemplateTreeNode node = (TemplateTreeNode) path.getLastPathComponent();
    final Resources.Template template = node.getTemplate();

    ApplicationManager.getApplication().runWriteAction(
            () -> CommandProcessor.getInstance().runUndoTransparentAction(() -> {
                String content = template != null ?
                        StringUtil.notNullize(template.getContent()).replace('\r', '\0') : "";
                previewDocument.replaceString(0, previewDocument.getTextLength(), content);

                List<Pair<Integer, Integer>> pairs =
                        getFilterRanges(profileFilter.getTextEditor().getText(), content);
                highlightWords(pairs);
            })
    );
}
 
Example 3
Source Project: consulo   Source File: ShowIntentionsPass.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean markActionInvoked(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull IntentionAction action) {
  final int offset = ((EditorEx)editor).getExpectedCaretOffset();

  List<HighlightInfo> infos = new ArrayList<>();
  DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new CommonProcessors.CollectProcessor<>(infos));
  boolean removed = false;
  for (HighlightInfo info : infos) {
    if (info.quickFixActionMarkers != null) {
      for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
        HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
        if (actionInGroup.getAction() == action) {
          // no CME because the list is concurrent
          removed |= info.quickFixActionMarkers.remove(pair);
        }
      }
    }
  }
  return removed;
}
 
Example 4
@Override
protected final void doExecute(@NotNull final Editor editor, @Nullable final Caret caret, final DataContext dataContext) {
    MyApplicationComponent.setAction(actionClass);

    final Pair<Boolean, T> additionalParameter = beforeWriteAction(editor, dataContext);
    if (!additionalParameter.first) {
        return;
    }

    final Runnable runnable = () -> executeWriteAction(editor, caret, dataContext, additionalParameter.second);
    new EditorWriteActionHandler(false) {
        @Override
        public void executeWriteAction(Editor editor1, @Nullable Caret caret1, DataContext dataContext1) {
            runnable.run();
        }
    }.doExecute(editor, caret, dataContext);
}
 
Example 5
Source Project: consulo   Source File: TabbedShowHistoryAction.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Pair<FilePath, VirtualFile> getPathAndParentFile(@Nonnull VcsContext context) {
  if (context.getSelectedFilesStream().findAny().isPresent()) {
    VirtualFile file = getIfSingle(context.getSelectedFilesStream());
    return file != null ? Pair.create(VcsUtil.getFilePath(file), file) : Pair.empty();
  }

  File[] ioFiles = context.getSelectedIOFiles();
  if (ioFiles != null && ioFiles.length > 0) {
    for (File ioFile : ioFiles) {
      VirtualFile parent = getParentVirtualFile(ioFile);
      if (parent != null) return Pair.create(VcsUtil.getFilePath(parent, ioFile.getName()), parent);
    }
  }

  return Pair.empty();
}
 
Example 6
Source Project: consulo   Source File: TypoTolerantMatcher.java    License: Apache License 2.0 6 votes vote down vote up
private boolean processErrors(int start, int end, Processor<? super Pair<Integer, Error>> processor) {
  if (myBase != null && start < myDeriveIndex) {
    if (!myBase.processErrors(start, myDeriveIndex, processor)) {
      return false;
    }
  }

  if (myErrors != null) {
    for (Pair<Integer, Error> error : myErrors) {
      if (start <= error.first && error.first < end) {
        if (!processor.process(error)) {
          return false;
        }
      }
    }
  }

  return true;
}
 
Example 7
Source Project: consulo   Source File: ComponentStoreImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void save(@Nonnull List<Pair<StateStorage.SaveSession, File>> readonlyFiles) {
  ExternalizationSession externalizationSession = myComponents.isEmpty() ? null : getStateStorageManager().startExternalization();
  if (externalizationSession != null) {
    String[] names = ArrayUtil.toStringArray(myComponents.keySet());
    Arrays.sort(names);
    for (String name : names) {
      StateComponentInfo<?> componentInfo = myComponents.get(name);

      commitComponentInsideSingleUIWriteThread(componentInfo, externalizationSession);
    }
  }

  for (SettingsSavingComponent settingsSavingComponent : mySettingsSavingComponents) {
    try {
      settingsSavingComponent.save();
    }
    catch (Throwable e) {
      LOG.error(e);
    }
  }

  doSave(externalizationSession == null ? null : externalizationSession.createSaveSessions(), readonlyFiles);
}
 
Example 8
Source Project: consulo   Source File: ShowIntentionActionsHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static Pair<PsiFile, Editor> chooseBetweenHostAndInjected(@Nonnull PsiFile hostFile,
                                                                 @Nonnull Editor hostEditor,
                                                                 @Nullable PsiFile injectedFile,
                                                                 @Nonnull PairProcessor<? super PsiFile, ? super Editor> predicate) {
  Editor editorToApply = null;
  PsiFile fileToApply = null;

  Editor injectedEditor = null;
  if (injectedFile != null) {
    injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
    if (predicate.process(injectedFile, injectedEditor)) {
      editorToApply = injectedEditor;
      fileToApply = injectedFile;
    }
  }

  if (editorToApply == null && hostEditor != injectedEditor && predicate.process(hostFile, hostEditor)) {
    editorToApply = hostEditor;
    fileToApply = hostFile;
  }
  if (editorToApply == null) return null;
  return Pair.create(fileToApply, editorToApply);
}
 
Example 9
Source Project: consulo   Source File: Messages.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Pair<String, Boolean> showInputDialogWithCheckBox(String message,
                                                                String title,
                                                                String checkboxText,
                                                                boolean checked,
                                                                boolean checkboxEnabled,
                                                                @Nullable Icon icon,
                                                                @NonNls String initialValue,
                                                                @Nullable InputValidator validator) {
  if (isApplicationInUnitTestOrHeadless()) {
    return new Pair<String, Boolean>(ourTestInputImplementation.show(message), checked);
  }
  else {
    InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(message, title, checkboxText, checked, checkboxEnabled, icon, initialValue, validator);
    dialog.show();
    return new Pair<String, Boolean>(dialog.getInputString(), dialog.isChecked());
  }
}
 
Example 10
Source Project: consulo   Source File: NamedScopeDescriptor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull PsiFile psiFile) {
  Pair<NamedScopesHolder, NamedScope> resolved = resolveScope(psiFile.getProject());
  if (resolved == null) {
    resolved = resolveScope(ProjectManager.getInstance().getDefaultProject());
  }
  if (resolved != null) {
    PackageSet fileSet = resolved.second.getValue();
    if (fileSet != null) {
      return fileSet.contains(psiFile, resolved.first);
    }
  }
  if (myFileSet != null) {
    NamedScopesHolder holder = DependencyValidationManager.getInstance(psiFile.getProject());
    return myFileSet.contains(psiFile, holder);
  }
  return false;
}
 
Example 11
Source Project: consulo   Source File: PersistentFSImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void applyCreateEventsInDirectory(@Nonnull VirtualDirectoryImpl parent, @Nonnull Collection<? extends VFileCreateEvent> createEvents) {
  int parentId = getFileId(parent);
  NewVirtualFile vf = findFileById(parentId);
  if (!(vf instanceof VirtualDirectoryImpl)) return;
  parent = (VirtualDirectoryImpl)vf;  // retain in myIdToDirCache at least for the duration of this block in order to subsequent findFileById() won't crash
  final NewVirtualFileSystem delegate = replaceWithNativeFS(getDelegate(parent));
  TIntHashSet parentChildrenIds = new TIntHashSet(createEvents.size());

  List<ChildInfo> childrenAdded = getOrCreateChildInfos(parent, createEvents, VFileCreateEvent::getChildName, parentChildrenIds, delegate, (createEvent, childId) -> {
    createEvent.resetCache();
    String name = createEvent.getChildName();
    Pair<FileAttributes, String> childData = getChildData(delegate, createEvent.getParent(), name, createEvent.getAttributes(), createEvent.getSymlinkTarget());
    if (childData == null) return null;
    childId = makeChildRecord(parentId, name, childData, delegate);
    return new ChildInfoImpl(childId, name, childData.first, createEvent.getChildren(), createEvent.getSymlinkTarget());
  });
  FSRecords.updateList(parentId, parentChildrenIds.toArray());
  parent.createAndAddChildren(childrenAdded, false, (__, ___) -> {
  });

  saveScannedChildrenRecursively(createEvents, delegate);
}
 
Example 12
Source Project: p4ic4idea   Source File: P4CommandUtil.java    License: Apache License 2.0 6 votes vote down vote up
public List<Pair<IFileSpec, IFileRevisionData>> getExactHistory(IOptionsServer server, List<IFileSpec> specs)
        throws P4JavaException {
    GetRevisionHistoryOptions opts = new GetRevisionHistoryOptions()
            .setMaxRevs(1)
            .setContentHistory(false)
            .setIncludeInherited(false)
            .setLongOutput(true)
            .setTruncatedLongOutput(false);
    Map<IFileSpec, List<IFileRevisionData>> res = server.getRevisionHistory(specs, opts);
    List<Pair<IFileSpec, IFileRevisionData>> ret = new ArrayList<>(res.size());
    for (Map.Entry<IFileSpec, List<IFileRevisionData>> entry: res.entrySet()) {
        // it can return empty values for a server message
        List<IFileRevisionData> value = entry.getValue();
        if (value != null && !value.isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Mapped " + entry.getKey().getDepotPath() + " to " + entry.getValue());
            }
            if (entry.getValue().size() != 1) {
                throw new IllegalStateException("Unexpected revision count for " + entry.getKey().getDepotPath());
            }
            ret.add(Pair.create(entry.getKey(), entry.getValue().get(0)));
        }
    }
    return ret;
}
 
Example 13
Source Project: consulo   Source File: PathsVerifier.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public Collection<FilePatch> filterBadFileTypePatches() {
  List<Pair<VirtualFile, ApplyTextFilePatch>> failedTextPatches =
          ContainerUtil.findAll(myTextPatches, new Condition<Pair<VirtualFile, ApplyTextFilePatch>>() {
            @Override
            public boolean value(Pair<VirtualFile, ApplyTextFilePatch> textPatch) {
              final VirtualFile file = textPatch.getFirst();
              if (file.isDirectory()) return false;
              return !isFileTypeOk(file);
            }
          });
  myTextPatches.removeAll(failedTextPatches);
  return ContainerUtil.map(failedTextPatches, new Function<Pair<VirtualFile, ApplyTextFilePatch>, FilePatch>() {
    @Override
    public FilePatch fun(Pair<VirtualFile, ApplyTextFilePatch> patchInfo) {
      return patchInfo.getSecond().getPatch();
    }
  });
}
 
Example 14
Source Project: consulo   Source File: VcsLogGraphTable.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private Pair<TIntHashSet, Integer> findRowsToSelectAndScroll(@Nonnull GraphTableModel model,
                                                             @Nonnull VisibleGraph<Integer> visibleGraph) {
  TIntHashSet rowsToSelect = new TIntHashSet();

  if (model.getRowCount() == 0) {
    // this should have been covered by facade.getVisibleCommitCount,
    // but if the table is empty (no commits match the filter), the GraphFacade is not updated, because it can't handle it
    // => it has previous values set.
    return Pair.create(rowsToSelect, null);
  }

  Integer rowToScroll = null;
  for (int row = 0;
       row < visibleGraph.getVisibleCommitCount() && (rowsToSelect.size() < mySelectedCommits.size() || rowToScroll == null);
       row++) { //stop iterating if found all hashes
    int commit = visibleGraph.getRowInfo(row).getCommit();
    if (mySelectedCommits.contains(commit)) {
      rowsToSelect.add(row);
    }
    if (myVisibleSelectedCommit != null && myVisibleSelectedCommit == commit) {
      rowToScroll = row;
    }
  }
  return Pair.create(rowsToSelect, rowToScroll);
}
 
Example 15
Source Project: p4ic4idea   Source File: JreSettingsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void getProperty() {
    Properties props = System.getProperties();
    for (String key : props.stringPropertyNames()) {
        JreSettings.setOverrides((Map<String, String>) null);
        String value = props.getProperty(key);
        assertEquals(value, JreSettings.getProperty(key));
        JreSettings.setOverrides(new Pair<>(key, "--" + value));
        assertEquals("--" + value, JreSettings.getProperty(key));
        JreSettings.setOverrides(new Pair<>(key, null));
        assertNull(JreSettings.getProperty(key));
        assertEquals("abc", JreSettings.getProperty(key, "abc"));
    }

    JreSettings.setOverrides((Map<String, String>) null);

    int i = 0;
    String notExist;
    do {
        i++;
        notExist = "not-exist-" + i;
    } while (props.getProperty(notExist) != null);
    assertNull(JreSettings.getProperty(notExist));
    assertEquals("abc", JreSettings.getProperty(notExist, "abc"));
}
 
Example 16
@RequiredReadAction
public MsilPropertyAsCSharpPropertyDeclaration(PsiElement parent, MsilPropertyEntry variable, List<Pair<DotNetXAccessor, MsilMethodEntry>> pairs)
{
	super(parent, getAdditionalModifiers(variable, pairs), variable);
	myAccessors = buildAccessors(this, pairs);

	myTypeForImplementValue = NullableLazyValue.of(() ->
	{
		String nameFromBytecode = getVariable().getNameFromBytecode();
		String typeBeforeDot = StringUtil.getPackageName(nameFromBytecode);
		SomeType someType = SomeTypeParser.parseType(typeBeforeDot, nameFromBytecode);
		if(someType != null)
		{
			return new DummyType(getProject(), MsilPropertyAsCSharpPropertyDeclaration.this, someType);
		}
		return null;
	});
}
 
Example 17
Source Project: consulo   Source File: CachedIntentions.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
IntentionActionWithTextCaching wrapAction(@Nonnull HighlightInfo.IntentionActionDescriptor descriptor,
                                          @Nonnull PsiElement element,
                                          @Nonnull PsiFile containingFile,
                                          @Nullable Editor containingEditor) {
  IntentionActionWithTextCaching cachedAction = new IntentionActionWithTextCaching(descriptor, (cached, action) -> {
    if (action instanceof QuickFixWrapper) {
      // remove only inspection fixes after invocation,
      // since intention actions might be still available
      removeActionFromCached(cached);
      markInvoked(action);
    }
  });
  final List<IntentionAction> options = descriptor.getOptions(element, containingEditor);
  if (options == null) return cachedAction;
  for (IntentionAction option : options) {
    Editor editor = ObjectUtils.chooseNotNull(myEditor, containingEditor);
    if (editor == null) continue;
    Pair<PsiFile, Editor> availableIn = ShowIntentionActionsHandler.chooseBetweenHostAndInjected(myFile, editor, containingFile, (f, e) -> ShowIntentionActionsHandler.availableFor(f, e, option));
    if (availableIn == null) continue;
    IntentionActionWithTextCaching textCaching = new IntentionActionWithTextCaching(option);
    boolean isErrorFix = myErrorFixes.contains(textCaching);
    if (isErrorFix) {
      cachedAction.addErrorFix(option);
    }
    boolean isInspectionFix = myInspectionFixes.contains(textCaching);
    if (isInspectionFix) {
      cachedAction.addInspectionFix(option);
    }
    else {
      cachedAction.addIntention(option);
    }
  }
  return cachedAction;
}
 
Example 18
Source Project: consulo   Source File: ParameterInfoController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returned Point is in layered pane coordinate system.
 * Second value is a {@link HintManager.PositionFlags position flag}.
 */
static Pair<Point, Short> chooseBestHintPosition(Editor editor, VisualPosition pos, LightweightHint hint, short preferredPosition, boolean showLookupHint) {
  if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) return Pair.pair(new Point(), HintManager.DEFAULT);

  HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  Dimension hintSize = hint.getComponent().getPreferredSize();
  JComponent editorComponent = editor.getComponent();
  JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();

  Point p1;
  Point p2;
  if (showLookupHint) {
    p1 = hintManager.getHintPosition(hint, editor, HintManager.UNDER);
    p2 = hintManager.getHintPosition(hint, editor, HintManager.ABOVE);
  }
  else {
    p1 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.UNDER);
    p2 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE);
  }

  boolean p1Ok = p1.y + hintSize.height < layeredPane.getHeight();
  boolean p2Ok = p2.y >= 0;

  if (!showLookupHint) {
    if (preferredPosition != HintManager.DEFAULT) {
      if (preferredPosition == HintManager.ABOVE) {
        if (p2Ok) return new Pair<>(p2, HintManager.ABOVE);
      }
      else if (preferredPosition == HintManager.UNDER) {
        if (p1Ok) return new Pair<>(p1, HintManager.UNDER);
      }
    }
  }
  if (p1Ok) return new Pair<>(p1, HintManager.UNDER);
  if (p2Ok) return new Pair<>(p2, HintManager.ABOVE);

  int underSpace = layeredPane.getHeight() - p1.y;
  int aboveSpace = p2.y;
  return aboveSpace > underSpace ? new Pair<>(new Point(p2.x, 0), HintManager.UNDER) : new Pair<>(p1, HintManager.ABOVE);
}
 
Example 19
Source Project: consulo   Source File: ComponentStoreImpl.java    License: Apache License 2.0 5 votes vote down vote up
protected static void executeSave(@Nonnull SaveSession session, @Nonnull List<Pair<SaveSession, File>> readonlyFiles) {
  try {
    session.save();
  }
  catch (ReadOnlyModificationException e) {
    readonlyFiles.add(Pair.create(session, e.getFile()));
  }
}
 
Example 20
Source Project: consulo   Source File: VfsImplUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static NewVirtualFile refreshAndFindFileByPath(@Nonnull NewVirtualFileSystem vfs, @Nonnull String path) {
  Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path);
  if (data == null) return null;

  NewVirtualFile file = data.first;
  for (String pathElement : data.second) {
    if (pathElement.isEmpty() || ".".equals(pathElement)) continue;
    if ("..".equals(pathElement)) {
      if (file.is(VFileProperty.SYMLINK)) {
        final String canonicalPath = file.getCanonicalPath();
        final NewVirtualFile canonicalFile = canonicalPath != null ? refreshAndFindFileByPath(vfs, canonicalPath) : null;
        file = canonicalFile != null ? canonicalFile.getParent() : null;
      }
      else {
        file = file.getParent();
      }
    }
    else {
      file = file.refreshAndFindChild(pathElement);
    }

    if (file == null) return null;
  }

  return file;
}
 
Example 21
Source Project: consulo   Source File: BlockUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Pair<List<DataLanguageBlockWrapper>, List<DataLanguageBlockWrapper>> splitBlocksByRightBound(@Nonnull Block parent, @Nonnull TextRange bounds) {
  final List<Block> subBlocks = parent.getSubBlocks();
  if (subBlocks.size() == 0) return new Pair<List<DataLanguageBlockWrapper>, List<DataLanguageBlockWrapper>>(Collections.<DataLanguageBlockWrapper>emptyList(), Collections.<DataLanguageBlockWrapper>emptyList());
  final ArrayList<DataLanguageBlockWrapper> before = new ArrayList<DataLanguageBlockWrapper>(subBlocks.size() / 2);
  final ArrayList<DataLanguageBlockWrapper> after = new ArrayList<DataLanguageBlockWrapper>(subBlocks.size() / 2);
  splitByRightBoundAndCollectBlocks(subBlocks, before, after, bounds);
  return new Pair<List<DataLanguageBlockWrapper>, List<DataLanguageBlockWrapper>>(before, after);
}
 
Example 22
Source Project: consulo   Source File: ExternalSystemFacadeManager.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Nonnull
private RemoteExternalSystemFacade doGetFacade(@Nonnull IntegrationKey key, @Nonnull Project project) throws Exception {
  final boolean currentInProcess = ExternalSystemApiUtil.isInProcessMode(key.getExternalSystemId());
  final ExternalSystemCommunicationManager myCommunicationManager = currentInProcess ? myInProcessCommunicationManager : myRemoteCommunicationManager;
  
  ExternalSystemManager manager = ExternalSystemApiUtil.getManager(key.getExternalSystemId());
  if (project.isDisposed() || manager == null) {
    return RemoteExternalSystemFacade.NULL_OBJECT;
  }
  Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings> pair = myRemoteFacades.get(key);
  if (pair != null && prepare(myCommunicationManager, project, key, pair)) {
    return pair.first;
  }
  
  myLock.lock();
  try {
    pair = myRemoteFacades.get(key);
    if (pair != null && prepare(myCommunicationManager, project, key, pair)) {
      return pair.first;
    }
    if (pair != null) {
      myFacadeWrappers.clear();
      myRemoteFacades.clear();
    }
    return doCreateFacade(key, project, myCommunicationManager);
  }
  finally {
    myLock.unlock();
  }
}
 
Example 23
Source Project: azure-devops-intellij   Source File: DiffCompareInfoProvider.java    License: MIT License 5 votes vote down vote up
private GitCommitCompareInfo getCompareInfo(final Project project, final GitRepository gitRepository,
                                            final String source, final String target)
        throws VcsException {
    final VirtualFile root = gitRepository.getRoot();
    final List<GitCommit> commits1 = getUtilWrapper().history(project, root, ".." + target);
    final List<GitCommit> commits2 = getUtilWrapper().history(project, root, target + "..");

    final Collection<Change> diff = getUtilWrapper().getDiff(project, root, target, source);
    final GitCommitCompareInfo info = new GitCommitCompareInfo(GitCommitCompareInfo.InfoType.BRANCH_TO_HEAD);

    info.put(gitRepository, diff);
    info.put(gitRepository, new Pair<List<GitCommit>, List<GitCommit>>(commits1, commits2));

    return info;
}
 
Example 24
Source Project: consulo   Source File: XDebuggerTreePanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Pair<Image, Point> createDraggedImage(final DnDAction action, final Point dragOrigin) {
  XValueNodeImpl[] nodes = getNodesToDrag();
  if (nodes.length == 1) {
    return DnDAwareTree.getDragImage(myTree, nodes[0].getPath(), dragOrigin);
  }
  return DnDAwareTree.getDragImage(myTree, XDebuggerBundle.message("xdebugger.drag.text.0.elements", nodes.length), dragOrigin);
}
 
Example 25
Source Project: consulo   Source File: VirtualFilePointerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String getPresentableUrl() {
  FilePointerPartNode node = checkDisposed(myNode);
  if (node == null) return "";
  Pair<VirtualFile, String> result = node.update();
  return result == null ? "" : PathUtil.toPresentableUrl(result.second);
}
 
Example 26
Source Project: consulo   Source File: CreateFromTemplatePanel.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public Map<String, Object> getVariables(Map<String, Object> predefinedProperties) {
  Map<String, Object> result = new HashMap<>(predefinedProperties);
  for (Pair<String, JTextField> pair : myAttributes) {
    result.put(pair.first, pair.second.getText());
  }
  return result;
}
 
Example 27
Source Project: consulo   Source File: NamedScopeDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
private Pair<NamedScopesHolder, NamedScope> resolveScope(@Nonnull Project project) {
  NamedScopesHolder holder = DependencyValidationManager.getInstance(project);
  NamedScope scope = holder.getScope(myScopeName);
  if (scope == null) {
    holder = NamedScopeManager.getInstance(project);
    scope = holder.getScope(myScopeName);
  }
  return scope != null ? Pair.create(holder, scope) : null;
}
 
Example 28
Source Project: consulo   Source File: ShowParameterInfoHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, ParameterInfoHandler handler, boolean requestFocus) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus, false);
  component.update(false);

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ParameterInfoController.chooseBestHintPosition(editor, null, hint, HintManager.DEFAULT, true);
  ApplicationManager.getApplication().invokeLater(() -> {
    if (!EditorActivityManager.getInstance().isVisible(editor)) return;
    hintManager.showEditorHint(hint, editor, pos.getFirst(), HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_LOOKUP_ITEM_CHANGE | HintManager.UPDATE_BY_SCROLLING, 0, false, pos.getSecond());
  });
}
 
Example 29
Source Project: consulo   Source File: ControlBinder.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void reset() {
  for (Pair<ControlValueAccessor, BeanValueAccessor> binding : myBindings) {
    if (!binding.first.isEnabled()) {
      continue;
    }
    Object value = binding.second.getValue();
    try {
      value = convert(value, binding.first.getType());
      binding.first.setValue(value);
    }
    catch (IllegalArgumentException e) {
      LOG.debug(e);
    }
  }
}
 
Example 30
Source Project: consulo   Source File: DumpLookupElementWeights.java    License: Apache License 2.0 5 votes vote down vote up
public static List<String> getLookupElementWeights(LookupImpl lookup, boolean hideSingleValued) {
  final Map<LookupElement, List<Pair<String, Object>>> weights = lookup.getRelevanceObjects(lookup.getItems(), hideSingleValued);
  return ContainerUtil.map(weights.entrySet(), new Function<Map.Entry<LookupElement, List<Pair<String, Object>>>, String>() {
    @Override
    public String fun(Map.Entry<LookupElement, List<Pair<String, Object>>> entry) {
      return entry.getKey().getLookupString() + "\t" + StringUtil.join(entry.getValue(), new Function<Pair<String, Object>, String>() {
        @Override
        public String fun(Pair<String, Object> pair) {
          return pair.first + "=" + pair.second;
        }
      }, ", ");
    }
  });
}