Java Code Examples for com.intellij.openapi.util.Pair#getSecond()

The following examples show how to use com.intellij.openapi.util.Pair#getSecond() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
public void actionPerformed(AnActionEvent event) {
    Project project = event.getProject();
    if(project == null) {
        return;
    }

    Editor editor = event.getData(PlatformDataKeys.EDITOR);

    Component applicationWindow = IdeHelper.getWindowComponentFromProject(event.getProject());
    if(applicationWindow == null) {
        return;
    }

    Pair<PsiFile, PhpClass> pair = findPhpClass(event);
    if(pair == null) {
        return;
    }

    if(pair.getSecond() == null) {
        SymfonyCreateService.create(applicationWindow, project, pair.getFirst(), editor);
        return;
    }

    SymfonyCreateService.create(applicationWindow, project, pair.getFirst(), pair.getSecond(), editor);
}
 
Example 2
Source Project: consulo   File: Switcher.java    License: Apache License 2.0 6 votes vote down vote up
void setShowOnlyEditedFiles(boolean onlyEdited) {
  if (myShowOnlyEditedFilesCheckBox.isSelected() != onlyEdited) {
    myShowOnlyEditedFilesCheckBox.setSelected(onlyEdited);
  }

  final boolean listWasSelected = files.getSelectedIndex() != -1;

  final Pair<List<FileInfo>, Integer> filesAndSelection = getFilesToShowAndSelectionIndex(project, collectFiles(project, onlyEdited), toolWindows.getModel().getSize(), isPinnedMode());
  final int selectionIndex = filesAndSelection.getSecond();

  ListModel<FileInfo> model = files.getModel();
  files.clearSelection(); // workaround JDK-7108280
  ListUtil.removeAllItems(model);
  ListUtil.addAllItems(model, filesAndSelection.getFirst());

  if (selectionIndex > -1 && listWasSelected) {
    files.setSelectedIndex(selectionIndex);
  }
  files.revalidate();
  files.repaint();
}
 
Example 3
/**
 * Increases how many synthetic rbraces the remapper should consume.
 */
boolean increaseRbraceDebt(int offset) {
    if (maxRbraceDebt < 1) return false;

    Pair<Integer,Integer> oldValue = ContainerUtil.getOrCreate(debtPoints, offset, INIT_KEY);
    Pair<Integer,Integer> newValue;

    Integer snd = oldValue.getSecond();

    if (oldValue.getFirst() == 0) {
        newValue = Pair.create(maxRbraceDebt, maxRbraceDebt - 1);
    } else {
        newValue = Pair.create(oldValue.getFirst(), --snd);
    }
    rbraceDebt++;
    maxRbraceDebt--;
    debtPoints.put(offset, newValue);
    return true;
}
 
Example 4
/**
 * Returns the number of stealable braces (=open braces - 1) in the parsing lexer at a
 * given line/column.
 */
private static int findBraces(LinkedList<Pair<Pair<Integer, Integer>, Integer>> l, int offs, int line, int lineStart) {
    int i = l.size() - 1;
    Pair<Pair<Integer, Integer>, Integer> last;
    if (i == 0) return 0;

    Pair<Pair<Integer, Integer>, Integer> e = last = l.get(i--);
    while (e != null) {
        if (e.getFirst().getFirst() > line ||
                e.getFirst().getFirst() == line
                && e.getFirst().getSecond() > offs - lineStart) {
            e = last;
            break;
        }
        last = e;
        e = l.get(i--);
    }
    // Comepnsate if we are looking for the last element.
    if (e == null) {
        e = last;
    }
    return e != null ? e.getSecond() - 1 : -1;
}
 
Example 5
Source Project: GitToolBox   File: BlamePopup.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private Pair<? extends CommittedChangeList, FilePath> findAffectedFiles(
    @NotNull CommittedChangesProvider<?, ?> changesProvider) {
  try {
    Pair<? extends CommittedChangeList, FilePath> pair = changesProvider.getOneList(file,
        revisionInfo.getRevisionNumber());
    if (pair != null && pair.getFirst() != null) {
      if (pair.getSecond() != null) {
        pair = Pair.create(pair.getFirst(), VcsUtil.getFilePath(file));
      }
      return pair;
    }
    return null;
  } catch (VcsException e) {
    LOG.warn("Failed to find affected files for path " + file, e);
    return null;
  }
}
 
Example 6
Source Project: consulo   File: TopAnomaliesAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Pair<?, Integer> o1, Pair<?, Integer> o2) {
  int i = o2.getSecond() - o1.getSecond();
  if (i != 0) {
    return i;
  }
  int h1 = o1.hashCode();
  int h2 = o2.hashCode();
  if (h1 > h2) {
    return 1;
  }
  if (h1 < h2) {
    return -1;
  }
  return 0;
}
 
Example 7
Source Project: consulo   File: PathMacroTable.java    License: Apache License 2.0 6 votes vote down vote up
public void editMacro() {
  if (getSelectedRowCount() != 1) {
    return;
  }
  final int selectedRow = getSelectedRow();
  final Pair<String, String> pair = myMacros.get(selectedRow);
  final String title = ApplicationBundle.message("title.edit.variable");
  final String macroName = pair.getFirst();
  final PathMacroEditor macroEditor = new PathMacroEditor(title, macroName, pair.getSecond(), new EditValidator());
  macroEditor.show();
  if (macroEditor.isOK()) {
    myMacros.remove(selectedRow);
    myMacros.add(Pair.create(macroEditor.getName(), macroEditor.getValue()));
    Collections.sort(myMacros, MACRO_COMPARATOR);
    myTableModel.fireTableDataChanged();
  }
}
 
Example 8
private void fullDirRefresh(@Nonnull VirtualDirectoryImpl dir, @Nonnull RefreshContext refreshContext) {
  while (true) {
    // obtaining directory snapshot
    Pair<String[], VirtualFile[]> result = getDirectorySnapshot(refreshContext.persistence, dir);
    if (result == null) return;
    String[] persistedNames = result.getFirst();
    VirtualFile[] children = result.getSecond();

    RefreshingFileVisitor refreshingFileVisitor = new RefreshingFileVisitor(dir, refreshContext, null, Arrays.asList(children));
    refreshingFileVisitor.visit(dir);
    if (myCancelled) {
      addAllEventsFrom(refreshingFileVisitor);
      break;
    }

    // generating events unless a directory was changed in between
    boolean hasEvents = ReadAction.compute(() -> {
      if (ApplicationManager.getApplication().isDisposed()) {
        return true;
      }
      if (!Arrays.equals(persistedNames, refreshContext.persistence.list(dir)) || !Arrays.equals(children, dir.getChildren())) {
        if (LOG.isDebugEnabled()) LOG.debug("retry: " + dir);
        return false;
      }

      addAllEventsFrom(refreshingFileVisitor);
      return true;
    });
    if (hasEvents) {
      break;
    }
  }
}
 
Example 9
Source Project: consulo   File: VirtualFilePointerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String getUrl() {
  FilePointerPartNode node = myNode;
  if (node == null) return "";
  // optimization: when file is null we shouldn't try to do expensive findFileByUrl() just to return the url
  Pair<VirtualFile, String> fileAndUrl = node.myFileAndUrl;
  if (fileAndUrl != null && fileAndUrl.getFirst() == null) {
    return fileAndUrl.getSecond();
  }
  Pair<VirtualFile, String> result = node.update();
  return result == null ? "" : result.second;
}
 
Example 10
Source Project: consulo   File: ExistingLibraryEditor.java    License: Apache License 2.0 5 votes vote down vote up
private LibraryType detectType() {
  if (!myDetectedTypeComputed) {
    final Pair<LibraryType<?>,LibraryProperties<?>> pair = LibraryDetectionManager.getInstance().detectType(Arrays.asList(getFiles(
            BinariesOrderRootType.getInstance())));
    if (pair != null) {
      myDetectedType = pair.getFirst();
      myDetectedLibraryProperties = pair.getSecond();
    }
    myDetectedTypeComputed = true;
  }
  return myDetectedType;
}
 
Example 11
Source Project: consulo   File: PathMacroTable.java    License: Apache License 2.0 5 votes vote down vote up
public void commit() {
  myPathMacros.removeAllMacros();
  for (Pair<String, String> pair : myMacros) {
    final String value = pair.getSecond();
    if (value != null && value.trim().length() > 0) {
      String path = value.replace(File.separatorChar, '/');
      if (path.endsWith("/")) path = path.substring(0, path.length() - 1);
      myPathMacros.setMacro(pair.getFirst(), path);
    }
  }
}
 
Example 12
private static void annotateCompilationExpression(PsiElement node, AnnotationHolder holder) {
  final Set<String> definitions = HaxeProjectSettings.getInstance(node.getProject()).getUserCompilerDefinitionsAsSet();
  final String nodeText = node.getText();
  for (Pair<String, Integer> pair : HaxeStringUtil.getWordsWithOffset(nodeText)) {
    final String word = pair.getFirst();
    final int offset = pair.getSecond();
    final int absoluteOffset = node.getTextOffset() + offset;
    final TextRange range = new TextRange(absoluteOffset, absoluteOffset + word.length());
    final Annotation annotation = holder.createInfoAnnotation(range, null);
    final String attributeName = definitions.contains(word) ? HaxeSyntaxHighlighterColors.HAXE_DEFINED_VAR
                                                            : HaxeSyntaxHighlighterColors.HAXE_UNDEFINED_VAR;
    annotation.setTextAttributes(TextAttributesKey.find(attributeName));
    annotation.registerFix(new HaxeDefineIntention(word, definitions.contains(word)), range);
  }
}
 
Example 13
Source Project: consulo   File: FileTypeAssocTable.java    License: Apache License 2.0 5 votes vote down vote up
boolean isAssociatedWith(@Nonnull T type, @Nonnull FileNameMatcher matcher) {
  if (matcher instanceof ExtensionFileNameMatcher || matcher instanceof ExactFileNameMatcher) {
    return findAssociatedFileType(matcher) == type;
  }

  for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) {
    if (matcher.equals(mapping.getFirst()) && type == mapping.getSecond()) return true;
  }

  return false;
}
 
Example 14
@RequiredReadAction
@Nullable
@Override
public IElementType getOperatorElementType()
{
	Pair<String, IElementType> pair = ourOperatorNames.get(myOriginal.getName());
	if(pair == null)
	{
		return null;
	}
	return pair.getSecond();
}
 
Example 15
@Override
public void collect(@NotNull TwigFileVariableCollectorParameter parameter, @NotNull Map<String, Set<String>> variables) {
    ASTNode macroStatement = TreeUtil.findParent(parameter.getElement().getNode(), TwigElementTypes.MACRO_STATEMENT);
    if(macroStatement == null) {
        return;
    }

    PsiElement psiElement = macroStatement.getPsi();
    if(psiElement == null) {
        return;
    }

    PsiElement marcoTag = psiElement.getFirstChild();
    if(marcoTag == null) {
        return;
    }

    Pair<String, String> pair = TwigUtil.getTwigMacroNameAndParameter(marcoTag);
    if(pair == null || pair.getSecond() == null) {
        return;
    }

    // strip braces "(foobar, foo)"
    String args = StringUtils.stripStart(pair.getSecond(), "( ");
    args = StringUtils.stripEnd(args, ") ");

    for (String s : args.split("\\s*,\\s*")) {
        variables.put(s, Collections.emptySet());
    }
}
 
Example 16
Source Project: consulo   File: ShowDiffFromAnnotation.java    License: Apache License 2.0 5 votes vote down vote up
private DiffNavigationContext createDiffNavigationContext(final int actualLine) {
  final ContentsLines contentsLines = new ContentsLines(myFileAnnotation.getAnnotatedContent());

  final Pair<Integer, String> pair = correctActualLineIfTextEmpty(contentsLines, actualLine);
  return new DiffNavigationContext(new Iterable<String>() {
    @Override
    public Iterator<String> iterator() {
      return new CacheOneStepIterator<String>(new ContextLineIterator(contentsLines, myFileAnnotation, pair.getFirst()));
    }
  }, pair.getSecond());
}
 
Example 17
Source Project: idea-php-symfony2-plugin   File: EntityHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Search for a repository class of a model
 *
 * @param project Current project
 * @param shortcutName "\Class\Name" or "FooBundle:Name"
 */
@Nullable
public static PhpClass getEntityRepositoryClass(@NotNull Project project, @NotNull String shortcutName) {
    PhpClass phpClass = resolveShortcutName(project, shortcutName);
    if(phpClass == null) {
        return null;
    }

    String presentableFQN = phpClass.getPresentableFQN();
    PhpClass classRepository = DoctrineMetadataUtil.getClassRepository(project, presentableFQN);
    if(classRepository != null) {
        return classRepository;
    }

    // search on annotations
    PhpDocComment docAnnotation = phpClass.getDocComment();
    if(docAnnotation != null) {
        // search for repositoryClass="Foo\Bar\RegisterRepository"; repositoryClass=Foo\Bar\RegisterRepository::class
        // @MongoDB\Document; @ORM\Entity
        Collection<Pair<String, String>> classRepositoryPair = DoctrineUtil.getClassRepositoryPair(docAnnotation);
        if (!classRepositoryPair.isEmpty()) {
            Pair<String, String> next = classRepositoryPair.iterator().next();
            if (next.getSecond() != null) {
                return PhpElementsUtil.getClassInterface(project, next.getSecond());
            }
        }
    }

    SymfonyBundle symfonyBundle = new SymfonyBundleUtil(project).getContainingBundle(phpClass);
    if(symfonyBundle != null) {
        PhpClass repositoryClass = getEntityRepositoryClass(project, symfonyBundle, presentableFQN);
        if(repositoryClass != null) {
            return repositoryClass;
        }
    }

    // old __CLASS__ Repository type
    // @TODO remove this fallback when we implemented all cases
    return resolveShortcutName(project, shortcutName + "Repository");
}
 
Example 18
Source Project: consulo   File: RunnerLayout.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public LayoutAttractionPolicy getAttractionPolicy(@Nonnull String condition) {
  final Pair<String, LayoutAttractionPolicy> pair = myDefaultFocus.get(condition);
  return pair == null ? new LayoutAttractionPolicy.FocusOnce() : pair.getSecond();
}
 
Example 19
Source Project: consulo   File: Functions.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object fun(Pair<?, ?> pair) {
  return Pair.getSecond(pair);
}
 
Example 20
Source Project: consulo   File: ArchivesBuilder.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void buildArchive(final ArchivePackageInfo archive) throws IOException {
  if (archive.getPackedFiles().isEmpty() && archive.getPackedArchives().isEmpty()) {
    myContext.addMessage(CompilerMessageCategory.WARNING, "Archive '" + archive.getPresentableDestination() + "' has no files so it won't be created", null,
                         -1, -1);
    return;
  }

  myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.building.0", archive.getPresentableDestination()));
  File tempFile = File.createTempFile("artifactCompiler", "tmp");

  myBuiltArchives.put(archive, tempFile);

  FileUtil.createParentDirs(tempFile);

  ArchivePackageWriter<T> packageWriter = (ArchivePackageWriter<T>)archive.getPackageWriter();

  T archiveFile;

  if (packageWriter instanceof ArchivePackageWriterEx) {
    archiveFile = ((ArchivePackageWriterEx<T>)packageWriter).createArchiveObject(tempFile, archive);
  }
  else {
    archiveFile = packageWriter.createArchiveObject(tempFile);
  }

  try {
    final THashSet<String> writtenPaths = new THashSet<>();
    for (Pair<String, VirtualFile> pair : archive.getPackedFiles()) {
      final VirtualFile sourceFile = pair.getSecond();
      if (sourceFile.isInLocalFileSystem()) {
        File file = VfsUtil.virtualToIoFile(sourceFile);
        addFileToArchive(archiveFile, packageWriter, file, pair.getFirst(), writtenPaths);
      }
      else {
        extractFileAndAddToArchive(archiveFile, packageWriter, sourceFile, pair.getFirst(), writtenPaths);
      }
    }

    for (Pair<String, ArchivePackageInfo> nestedArchive : archive.getPackedArchives()) {
      File nestedArchiveFile = myBuiltArchives.get(nestedArchive.getSecond());
      if (nestedArchiveFile != null) {
        addFileToArchive(archiveFile, packageWriter, nestedArchiveFile, nestedArchive.getFirst(), writtenPaths);
      }
      else {
        LOGGER.debug("nested archive file " + nestedArchive.getFirst() + " for " + archive.getPresentableDestination() + " not found");
      }
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  finally {
    packageWriter.close(archiveFile);
  }
}