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

The following examples show how to use com.intellij.openapi.util.Trinity. 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
public void removeNotification(Notification notification) {
    synchronized (myNotifications) {
        myNotifications.remove(notification);
    }

    Runnable handler = removeHandlers.remove(notification);
    if (handler != null) {
        UIUtil.invokeLaterIfNeeded(handler);
    }

    Trinity<Notification, String, Long> oldStatus = getStatusMessage();
    if (oldStatus != null && notification == oldStatus.first) {
        setStatusToImportant();
    }
    fireModelChanged();
}
 
Example 2
Source Project: consulo   Source File: LogModel.java    License: Apache License 2.0 6 votes vote down vote up
void removeNotification(Notification notification) {
  synchronized (myNotifications) {
    myNotifications.remove(notification);
  }

  Runnable handler = removeHandlers.remove(notification);
  if (handler != null) {
    UIUtil.invokeLaterIfNeeded(handler);
  }

  Trinity<Notification, String, Long> oldStatus = getStatusMessage();
  if (oldStatus != null && notification == oldStatus.first) {
    setStatusToImportant();
  }
  fireModelChanged();
}
 
Example 3
Source Project: consulo   Source File: StubTreeBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()}
 */
@Nonnull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@Nonnull FileViewProvider viewProvider) {
  final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
  final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
  for (Language language : viewProvider.getLanguages()) {
    final PsiFile file = viewProvider.getPsi(language);
    if (file instanceof PsiFileImpl) {
      final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder();
      if (type != null) {
        roots.add(Trinity.create(language, (IStubFileElementType)type, file));
      }
    }
  }

  ContainerUtil.sort(roots, (o1, o2) -> {
    if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1;
    else if (o2.third == stubBindingRoot) return 1;
    else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
  });

  return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
 
Example 4
Source Project: consulo   Source File: CodeStyleBlankLinesPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void showCustomOption(Class<? extends CustomCodeStyleSettings> settingsClass,
                             String fieldName,
                             String title,
                             String groupName,
                             @Nullable OptionAnchor anchor,
                             @Nullable String anchorFieldName,
                             Object... options) {
  if (myIsFirstUpdate) {
    myCustomOptions.putValue(groupName, Trinity.create(settingsClass, fieldName, title));
  }

  for (IntOption option : myOptions) {
    if (option.myTarget.getName().equals(fieldName)) {
      option.myIntField.setEnabled(true);
    }
  }
}
 
Example 5
Source Project: consulo   Source File: TemplateKindCombo.java    License: Apache License 2.0 6 votes vote down vote up
public TemplateKindCombo() {
  getComboBox().setRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(@Nonnull JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof Trinity) {
        append((String)((Trinity)value).first);
        setIcon((Image)((Trinity)value).second);
      }
    }
  });

  new ComboboxSpeedSearch(getComboBox()) {
    @Override
    protected String getElementText(Object element) {
      if (element instanceof Trinity) {
        return (String)((Trinity)element).first;
      }
      return null;
    }
  };
  setButtonListener(null);
}
 
Example 6
Source Project: aem-ide-tooling-4-intellij   Source File: ConsoleLog.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static Trinity<Notification, String, Long> getStatusMessage(@Nullable Project project) {
    ConsoleLogModel model = getLogModel(project);
    if(model != null) {
        return model.getStatusMessage();
    }
    return null;
}
 
Example 7
void setStatusMessage(@Nullable Notification statusMessage, long stamp) {
    synchronized (myNotifications) {
        if (myStatusMessage != null && myStatusMessage.first == statusMessage) return;
        if (myStatusMessage == null && statusMessage == null) return;

        myStatusMessage = statusMessage == null ? null : Trinity.create(statusMessage, myStatuses.get(statusMessage), stamp);
    }
    StatusBar.Info.set("", myProject, ConsoleLog.LOG_REQUESTOR);
}
 
Example 8
@Nonnull
@RequiredReadAction
@Override
public Trinity<String, DotNetTypeRef, Boolean> getParameterInfo(@Nonnull DotNetParameter parameter)
{
	return Trinity.create(parameter.getName(), parameter.toTypeRef(true), parameter.hasModifier(CSharpModifier.OPTIONAL));
}
 
Example 9
@RequiredReadAction
@Nonnull
@Override
public Trinity<String, DotNetTypeRef, Boolean> getParameterInfo(@Nonnull CSharpSimpleParameterInfo parameter)
{
	return Trinity.create(parameter.getNotNullName(), parameter.getTypeRef(), parameter.isOptional());
}
 
Example 10
Source Project: consulo   Source File: TranslatingCompilerFilesMonitor.java    License: Apache License 2.0 5 votes vote down vote up
public abstract void collectFiles(CompileContext context,
TranslatingCompiler compiler,
Iterator<VirtualFile> scopeSrcIterator,
boolean forceCompile,
boolean isRebuild,
Collection<VirtualFile> toCompile,
Collection<Trinity<File, String, Boolean>> toDelete);
 
Example 11
Source Project: consulo   Source File: PackageFileWorker.java    License: Apache License 2.0 5 votes vote down vote up
public static void packageFile(@Nonnull VirtualFile file, @Nonnull Project project, final Artifact[] artifacts) throws IOException {
  LOG.debug("Start packaging file: " + file.getPath());
  final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
  File ioFile = VfsUtilCore.virtualToIoFile(file);
  for (Trinity<Artifact, PackagingElementPath, String> item : items) {
    final Artifact artifact = item.getFirst();
    final String outputPath = artifact.getOutputPath();
    if (!StringUtil.isEmpty(outputPath)) {
      PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird());
      LOG.debug(" package to " + outputPath);
      worker.packageFile(outputPath, item.getSecond().getParents());
    }
  }
}
 
Example 12
Source Project: consulo   Source File: LogModel.java    License: Apache License 2.0 5 votes vote down vote up
void setStatusMessage(@Nullable Notification statusMessage, long stamp) {
  synchronized (myNotifications) {
    if (myStatusMessage != null && myStatusMessage.first == statusMessage) return;
    if (myStatusMessage == null && statusMessage == null) return;

    myStatusMessage = statusMessage == null ? null : Trinity.create(statusMessage, EventLog.formatForLog(statusMessage, "").status, stamp);
  }
  StatusBar.Info.set("", myProject, EventLog.LOG_REQUESTOR);
}
 
Example 13
Source Project: consulo   Source File: ResolveCache.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private <TRef extends PsiReference, TResult> TResult resolve(@Nonnull final TRef ref,
                                                             @Nonnull final AbstractResolver<? super TRef, TResult> resolver,
                                                             boolean needToPreventRecursion,
                                                             final boolean incompleteCode,
                                                             boolean isPoly,
                                                             boolean isPhysical) {
  ProgressIndicatorProvider.checkCanceled();
  if (isPhysical) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
  }
  int index = getIndex(incompleteCode, isPoly);
  Map<TRef, TResult> map = getMap(isPhysical, index);
  TResult result = map.get(ref);
  if (result != null) {
    return result;
  }

  RecursionGuard.StackStamp stamp = RecursionManager.markStack();
  result = needToPreventRecursion
           ? RecursionManager.doPreventingRecursion(Trinity.create(ref, incompleteCode, isPoly), true, () -> resolver.resolve(ref, incompleteCode))
           : resolver.resolve(ref, incompleteCode);
  if (result instanceof ResolveResult) {
    ensureValidPsi((ResolveResult)result);
  }
  else if (result instanceof ResolveResult[]) {
    ensureValidResults((ResolveResult[])result);
  }
  else if (result instanceof PsiElement) {
    PsiUtilCore.ensureValid((PsiElement)result);
  }

  if (stamp.mayCacheNow()) {
    cache(ref, map, result);
  }
  return result;
}
 
Example 14
Source Project: consulo   Source File: LocalInspectionsPass.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Trinity<ProblemDescriptor, LocalInspectionToolWrapper, ProgressIndicator> trinity) {
  ProgressIndicator indicator = trinity.getThird();
  if (indicator.isCanceled()) {
    return false;
  }

  ProblemDescriptor descriptor = trinity.first;
  LocalInspectionToolWrapper tool = trinity.second;
  PsiElement psiElement = descriptor.getPsiElement();
  if (psiElement == null) return true;
  PsiFile file = psiElement.getContainingFile();
  Document thisDocument = documentManager.getDocument(file);

  HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();

  infos.clear();
  createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor, psiElement);
  for (HighlightInfo info : infos) {
    final EditorColorsScheme colorsScheme = getColorsScheme();
    UpdateHighlightersUtil
            .addHighlighterToEditorIncrementally(myProject, myDocument, getFile(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(),
                                                 info, colorsScheme, getId(), ranges2markersCache);
  }

  return true;
}
 
Example 15
Source Project: consulo   Source File: LocalInspectionsPass.java    License: Apache License 2.0 5 votes vote down vote up
private void addDescriptorIncrementally(@Nonnull final ProblemDescriptor descriptor,
                                        @Nonnull final LocalInspectionToolWrapper tool,
                                        @Nonnull final ProgressIndicator indicator) {
  if (myIgnoreSuppressed && SuppressionUtil.inspectionResultSuppressed(descriptor.getPsiElement(), tool.getTool())) {
    return;
  }
  myTransferToEDTQueue.offer(Trinity.create(descriptor, tool, indicator));
}
 
Example 16
Source Project: consulo   Source File: BraceMatcherBasedSelectioner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<TextRange> select(final PsiElement e, final CharSequence editorText, final int cursorOffset, final Editor editor) {
  final VirtualFile file = e.getContainingFile().getVirtualFile();
  final FileType fileType = file == null? null : file.getFileType();
  if (fileType == null) return super.select(e, editorText, cursorOffset, editor);
  final int textLength = editorText.length();
  final TextRange totalRange = e.getTextRange();
  final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(totalRange.getStartOffset());
  final BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);

  final ArrayList<TextRange> result = new ArrayList<TextRange>();
  final LinkedList<Trinity<Integer, Integer, IElementType>> stack = new LinkedList<Trinity<Integer, Integer, IElementType>>();
  while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) {
    final Trinity<Integer, Integer, IElementType> last;
    if (braceMatcher.isLBraceToken(iterator, editorText, fileType)) {
      stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType()));
    }
    else if (braceMatcher.isRBraceToken(iterator, editorText, fileType)
        && !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) {
      stack.removeLast();
      result.addAll(expandToWholeLine(editorText, new TextRange(last.first, iterator.getEnd())));
      int bodyStart = last.second;
      int bodyEnd = iterator.getStart();
      while (bodyStart < textLength && Character.isWhitespace(editorText.charAt(bodyStart))) bodyStart ++;
      while (bodyEnd > 0 && Character.isWhitespace(editorText.charAt(bodyEnd - 1))) bodyEnd --;
      result.addAll(expandToWholeLine(editorText, new TextRange(bodyStart, bodyEnd)));
    }
    iterator.advance();
  }
  result.add(e.getTextRange());
  return result;
}
 
Example 17
Source Project: consulo   Source File: PrattBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private TokenParser findParser() {
  final IElementType tokenType = getTokenType();
  for (final Trinity<Integer, PathPattern, TokenParser> trinity : myRegistry.getParsers(tokenType)) {
    if (trinity.first > myPriority && trinity.second.accepts(this)) {
      return trinity.third;
    }
  }
  return null;
}
 
Example 18
Source Project: consulo   Source File: CreateWithTemplatesDialogPanel.java    License: Apache License 2.0 5 votes vote down vote up
public CreateWithTemplatesDialogPanel(@Nonnull List<Trinity<String, Image, String>> templates, @Nullable String selectedItem) {
  super(templates, LIST_RENDERER);
  myTemplatesList.addListSelectionListener(e -> {
    Trinity<String, Image, String> selectedValue = myTemplatesList.getSelectedValue();
    if (selectedValue != null) {
      setTextFieldIcon(selectedValue.second);
    }
  });
  selectTemplate(selectedItem);
  setTemplatesListVisible(templates.size() > 1);
}
 
Example 19
Source Project: consulo   Source File: CreateWithTemplatesDialogPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void selectTemplate(@Nullable String selectedItem) {
  if (selectedItem == null) {
    myTemplatesList.setSelectedIndex(0);
    return;
  }

  ListModel<Trinity<String, Image, String>> model = myTemplatesList.getModel();
  for (int i = 0; i < model.getSize(); i++) {
    String templateID = model.getElementAt(i).getThird();
    if (selectedItem.equals(templateID)) {
      myTemplatesList.setSelectedIndex(i);
      return;
    }
  }
}
 
Example 20
Source Project: consulo   Source File: CreateDirectoryOrPackageAction.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  Project project = e.getData(CommonDataKeys.PROJECT);

  if (view == null || project == null) {
    return;
  }

  PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);

  if (directory == null) {
    return;
  }

  Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> info = getInfo(directory);

  boolean isDirectory = info.getThird() == ChildType.Directory;

  CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, isDirectory, info.getThird().getSeparator());

  String title = isDirectory ? IdeBundle.message("title.new.directory") : IdeBundle.message("title.new.package");

  createLightWeightPopup(validator, title, element -> {
    if (element != null) {
      view.selectElement(element);
    }
  }).showCenteredInCurrentWindow(project);
}
 
Example 21
Source Project: consulo   Source File: CreateDirectoryOrPackageAction.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredUIAccess
private static Trinity<ContentFolderTypeProvider, PsiDirectory, ChildType> getInfo(PsiDirectory d) {
  Project project = d.getProject();
  ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project);

  Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(d);
  if (moduleForPsiElement != null) {
    boolean isPackageSupported = false;
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForPsiElement);
    List<PsiPackageSupportProvider> extensions = PsiPackageSupportProvider.EP_NAME.getExtensionList();
    for (ModuleExtension moduleExtension : moduleRootManager.getExtensions()) {
      for (PsiPackageSupportProvider supportProvider : extensions) {
        if (supportProvider.isSupported(moduleExtension)) {
          isPackageSupported = true;
          break;
        }
      }
    }

    if (isPackageSupported) {
      ContentFolderTypeProvider contentFolderTypeForFile = projectFileIndex.getContentFolderTypeForFile(d.getVirtualFile());
      if (contentFolderTypeForFile != null) {
        Image childPackageIcon = contentFolderTypeForFile.getChildPackageIcon();
        return Trinity.create(contentFolderTypeForFile, d, childPackageIcon != null ? ChildType.Package : ChildType.Directory);
      }
    }
  }

  return Trinity.create(null, d, ChildType.Directory);
}
 
Example 22
Source Project: consulo   Source File: TemplateKindCombo.java    License: Apache License 2.0 5 votes vote down vote up
public String getSelectedName() {
  //noinspection unchecked
  final Trinity<String, Image, String> trinity = (Trinity<String, Image, String>)getComboBox().getSelectedItem();
  if (trinity == null) {
    // design time
    return null;
  }
  return trinity.third;
}
 
Example 23
Source Project: consulo   Source File: TemplateKindCombo.java    License: Apache License 2.0 5 votes vote down vote up
public void setSelectedName(@Nullable String name) {
  if (name == null) return;
  ComboBoxModel model = getComboBox().getModel();
  for (int i = 0, n = model.getSize(); i < n; i++) {
    Trinity<String, Image, String> trinity = (Trinity<String, Image, String>)model.getElementAt(i);
    if (name.equals(trinity.third)) {
      getComboBox().setSelectedItem(trinity);
      return;
    }
  }
}
 
Example 24
@Nullable
Trinity<Notification, String, Long> getStatusMessage() {
    synchronized (myNotifications) {
        return myStatusMessage;
    }
}
 
Example 25
Source Project: teamcity-vmware-plugin   Source File: FakeModel.java    License: Apache License 2.0 4 votes vote down vote up
public List<Trinity<String, String, Long>> getEvents() {
  return myEvents;
}
 
Example 26
Source Project: teamcity-vmware-plugin   Source File: FakeModel.java    License: Apache License 2.0 4 votes vote down vote up
public void publishEvent(String entityName, String actionName){
  myEvents.add(Trinity.create(entityName, actionName, System.currentTimeMillis()));
}
 
Example 27
Source Project: consulo   Source File: CompositeDependencyCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void syncOutDir(Trinity<File, String, Boolean> trinity) throws CacheCorruptedException {
  for (DependencyCache ourDependencyExtension : myDependencyCaches) {
    ourDependencyExtension.syncOutDir(trinity);
  }
}
 
Example 28
Source Project: consulo   Source File: LogModel.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
Trinity<Notification, String, Long> getStatusMessage() {
  synchronized (myNotifications) {
    return myStatusMessage;
  }
}
 
Example 29
Source Project: consulo   Source File: CodeStyleBlankLinesPanel.java    License: Apache License 2.0 4 votes vote down vote up
private void initCustomOptions(OptionGroup optionGroup, String groupName) {
  for (Trinity<Class<? extends CustomCodeStyleSettings>, String, String> each : myCustomOptions.get(groupName)) {
    doCreateOption(optionGroup, each.third, new IntOption(each.third, each.first, each.second), each.second);
  }
}
 
Example 30
Source Project: consulo   Source File: ExecutorRegistryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
private static Trinity<Project, String, String> createExecutionId(String executorId, @Nonnull ExecutionEnvironment environment) {
  return Trinity.create(environment.getProject(), executorId, environment.getRunner().getRunnerId());
}