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

The following are Jave code examples for showing how to use getSecond() of the com.intellij.openapi.util.Pair class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: educational-plugin   File: StudyToolWindow.java   Source Code and License Vote up 6 votes
public void updateCourseProgress(@NotNull final Project project) {
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course != null) {
    List<Lesson> lessons = course.getLessons();

    Pair<Integer, Integer> progress = countProgressAsOneTaskWithSubtasks(lessons);
    if (progress == null) {
      progress = countProgressWithoutSubtasks(lessons);
    }

    int taskSolved = progress.getFirst();
    int taskNum = progress.getSecond();
    String completedTasks = String.format("%d of %d tasks completed", taskSolved, taskNum);
    double percent = (taskSolved * 100.0) / taskNum;

    myStatisticLabel.setText(completedTasks);
    myStudyProgressBar.setFraction(percent / 100);
  }
}
 
Example 2
Project: educational-plugin   File: CCShowPreviewTest.java   Source Code and License Vote up 6 votes
private void doTest(String name) {
  VirtualFile file = configureByTaskFile(name + CCTestsUtil.BEFORE_POSTFIX);
  CCShowPreview action = new CCShowPreview();
  TestActionEvent e = getActionEvent(action,PsiManager.getInstance(getProject()).findFile(file));
  action.beforeActionPerformedUpdate(e);
  assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
  action.actionPerformed(e);
  Editor editor = EditorFactory.getInstance().getAllEditors()[1];
  try {
    Pair<Document, List<AnswerPlaceholder>> pair = getPlaceholders(name + CCTestsUtil.AFTER_POSTFIX);
    assertEquals("Files don't match", pair.getFirst().getText(), editor.getDocument().getText());
    for (AnswerPlaceholder placeholder : pair.getSecond()) {
      assertNotNull("No highlighter for placeholder:" + CCTestsUtil.getPlaceholderPresentation(placeholder),
                    getHighlighter(editor.getMarkupModel(), placeholder));
    }
  }
  finally {
    EditorFactory.getInstance().releaseEditor(editor);
  }
}
 
Example 3
Project: educational-plugin   File: CCTestCase.java   Source Code and License Vote up 6 votes
public void checkByFile(TaskFile taskFile, String fileName, boolean useLength) {
  Pair<Document, List<AnswerPlaceholder>> placeholders = getPlaceholders(fileName, useLength, true);
  String message = "Placeholders don't match";
  if (taskFile.getActivePlaceholders().size() != placeholders.second.size()) {
    throw new ComparisonFailure(message,
                                CCTestsUtil.getPlaceholdersPresentation(taskFile.getActivePlaceholders()),
                                CCTestsUtil.getPlaceholdersPresentation(placeholders.second));
  }
  for (AnswerPlaceholder answerPlaceholder : placeholders.getSecond()) {
    AnswerPlaceholder placeholder = taskFile.getAnswerPlaceholder(answerPlaceholder.getOffset());
    if (!CCTestsUtil.comparePlaceholders(placeholder, answerPlaceholder)) {
      throw new ComparisonFailure(message,
                                  CCTestsUtil.getPlaceholdersPresentation(taskFile.getActivePlaceholders()),
                                  CCTestsUtil.getPlaceholdersPresentation(placeholders.second));
    }
  }
}
 
Example 4
Project: lua-for-idea   File: ControlFlowBuilder.java   Source Code and License Vote up 6 votes
private void addPendingEdge(LuaPsiElement scopeWhenAdded, InstructionImpl instruction) {
    if (instruction == null) {
        return;
    }

    int i = 0;
    if (scopeWhenAdded != null) {
        for (; i < myPending.size(); i++) {
            Pair<InstructionImpl, LuaPsiElement> pair = myPending.get(i);

            final LuaPsiElement currScope = pair.getSecond();
            if (currScope == null) {
                continue;
            }
            if (!PsiTreeUtil.isAncestor(currScope, scopeWhenAdded, true)) {
                break;
            }
        }
    }
    myPending.add(i, new Pair<InstructionImpl, LuaPsiElement>(instruction, scopeWhenAdded));
}
 
Example 5
Project: intellij-ce-playground   File: DeclarationConflictChecker.java   Source Code and License Vote up 6 votes
/**
 * Shows a panel with name redefinition conflicts, if needed.
 * @param project
 * @param conflicts what {@link #findDefinitions} would return
 * @param obscured name or its topmost qualifier that is obscured, used at top of pane.
 * @param name full name (maybe qualified) to show as obscured and display as qualifier in "would be" chunks.
 * @return true iff conflicts is not empty and the panel is shown.
 */
public static boolean showConflicts(Project project, List<Pair<PsiElement, PsiElement>> conflicts, String obscured, @Nullable String name) {
  if (conflicts.size() > 0) {
    Usage[] usages = new Usage[conflicts.size()];
    int i = 0;
    for (Pair<PsiElement, PsiElement> pair : conflicts) {
      usages[i] = new NameUsage(pair.getFirst(), pair.getSecond(), name != null? name : obscured, name != null);
      i += 1;
    }
    UsageViewPresentation prsnt = new UsageViewPresentation();
    prsnt.setTabText(PyBundle.message("CONFLICT.name.$0.obscured", obscured));
    prsnt.setCodeUsagesString(PyBundle.message("CONFLICT.name.$0.obscured.cannot.convert", obscured));
    prsnt.setUsagesWord(PyBundle.message("CONFLICT.occurrence.sing"));
    prsnt.setUsagesString(PyBundle.message("CONFLICT.occurrence.pl"));
    UsageViewManager.getInstance(project).showUsages(UsageTarget.EMPTY_ARRAY, usages, prsnt);
    return true;
  }
  return false;
}
 
Example 6
Project: intellij-ce-playground   File: AbstractProjectImportErrorHandler.java   Source Code and License Vote up 6 votes
@NotNull
public ExternalSystemException createUserFriendlyError(@NotNull String msg, @Nullable String location, @NotNull String... quickFixes) {
  String newMsg = msg;
  if (!newMsg.isEmpty() && Character.isLowerCase(newMsg.charAt(0))) {
    // Message starts with lower case letter. Sentences should start with uppercase.
    newMsg = "Cause: " + newMsg;
  }

  if (!StringUtil.isEmpty(location)) {
    Pair<String, Integer> pair = getErrorLocation(location);
    if (pair != null) {
      return new LocationAwareExternalSystemException(newMsg, pair.first, pair.getSecond(), quickFixes);
    }
  }
  return new ExternalSystemException(newMsg, null, quickFixes);
}
 
Example 7
Project: intellij-ce-playground   File: TopAnomaliesAction.java   Source Code and License Vote up 6 votes
@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 8
Project: educational-plugin   File: PyStudySmartChecker.java   Source Code and License Vote up 5 votes
static void runSmartTestProcess(@NotNull final VirtualFile taskDir,
                                       @NotNull final PyStudyTestRunner testRunner,
                                       @NotNull final String taskFileName,
                                       @NotNull final TaskFile taskFile,
                                       @NotNull final Project project) {
  final VirtualFile virtualFile = taskDir.findFileByRelativePath(taskFileName);
  if (virtualFile == null) {
    return;
  }
  Pair<VirtualFile, TaskFile> pair = getCopyWithAnswers(taskDir, virtualFile, taskFile);
  if (pair == null) {
    return;
  }
  VirtualFile answerFile = pair.getFirst();
  TaskFile answerTaskFile = pair.getSecond();
  try {
    for (final AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
      final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
      if (document == null) {
        continue;
      }
      smartCheck(answerPlaceholder, project, answerFile, answerTaskFile, taskFile, testRunner,
                 virtualFile, document);
    }
  }
  finally {
    StudyUtils.deleteFile(answerFile);
  }
}
 
Example 9
Project: intellij-ce-playground   File: TreeChangeImpl.java   Source Code and License Vote up 5 votes
private int getOptimizedNodeOldOffset(ASTNode child, ChangeInfo changeInfo) {
  // we usually add / remove ranges so old offset can be tried to calculate from change with previous sibling
  ASTNode prevSibling = child.getTreePrev();
  if (prevSibling != null) {
    if (mySortedChanges.size() > 0) {
      Pair<ASTNode, Integer> pair = mySortedChanges.get(mySortedChanges.size() - 1);

      if (pair.getFirst() == prevSibling) {
        ChangeInfo prevSiblingChange = myChanges.get(prevSibling);
        if ((prevSiblingChange.getChangeType() == ChangeInfo.REMOVED &&
             changeInfo.getChangeType() == ChangeInfo.REMOVED
            ) ||
            (prevSiblingChange.getChangeType() == ChangeInfo.ADD &&
             changeInfo.getChangeType() == ChangeInfo.ADD
            )
           ) {
          int optimizedResult = pair.getSecond() + prevSiblingChange.getOldLength();
          if (ourDoChecks && !ourReportedDifferentOptimizedNodeOldOffset) {
            int oldOffset = calculateOldOffsetLinearly(child);
            if (optimizedResult != oldOffset) {
              LOG.error("Failed optimized node old offset check:"+changeInfo + ", previous:" + prevSibling + "," + prevSiblingChange);
              ourReportedDifferentOptimizedNodeOldOffset = true;
              optimizedResult = oldOffset;
            }
          }
          return optimizedResult;
        }
      }
    }
  }
  return haveNotCalculated;
}
 
Example 10
Project: intellij-ce-playground   File: SdkComponentsStep.java   Source Code and License Vote up 5 votes
private void setupControl(JTable table, Object value, boolean isSelected, boolean hasFocus) {
  myPanel.setBorder(getCellBorder(table, isSelected && hasFocus));
  Color foreground;
  Color background;
  if (isSelected) {
    background = table.getSelectionBackground();
    foreground = table.getSelectionForeground();
  }
  else {
    background = table.getBackground();
    foreground = table.getForeground();
  }
  myPanel.setBackground(background);
  myCheckBox.setForeground(foreground);
  myPanel.remove(myCheckBox);
  //noinspection unchecked
  Pair<ComponentTreeNode, Integer> pair = (Pair<ComponentTreeNode, Integer>)value;
  int indent = 0;
  if (pair != null) {
    ComponentTreeNode node = pair.getFirst();
    myCheckBox.setEnabled(isOptional(node));
    myCheckBox.setText(node.getLabel());
    myCheckBox.setSelected(node.isChecked());
    indent = pair.getSecond();
  }
  myPanel.add(myCheckBox,
              new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
                                  GridConstraints.SIZEPOLICY_FIXED, null, null, null, indent * 2));
}
 
Example 11
Project: intellij-ce-playground   File: MoveInstanceMembersUtil.java   Source Code and License Vote up 5 votes
private static void getThisClassesToMembers(final PsiElement scope, final Map<PsiClass, Set<PsiMember>> map, final PsiMember refMember) {
  if (scope instanceof PsiExpression) {
    final PsiExpression expression = (PsiExpression)scope;
    if (!(scope instanceof PsiReferenceExpression) || !((PsiReferenceExpression)scope).isReferenceTo(refMember)) {
      final Pair<PsiMember, PsiClass> pair = getMemberAndClassReferencedByThis(expression);
      if (pair != null) {
        PsiClass refClass = pair.getSecond();
        PsiMember member = pair.getFirst();
        if (refClass != null) {
          boolean inherited = false;
          PsiClass parentClass = PsiTreeUtil.getParentOfType(scope, PsiClass.class, true);
          while (parentClass != null && PsiTreeUtil.isAncestor(refMember, parentClass, false)) {
            if (parentClass == refClass || parentClass.isInheritor(refClass, true)) {
              inherited = true;
              break;
            }
            parentClass = PsiTreeUtil.getParentOfType(parentClass, PsiClass.class, true);
          }
          if (!inherited && !PsiTreeUtil.isAncestor(refMember, member, false)) {
            addReferencedMember(map, refClass, member);
          }
        }
      }

      if (expression instanceof PsiThisExpression) {
        final PsiJavaCodeReferenceElement thisQualifier = ((PsiThisExpression)expression).getQualifier();
        PsiClass thisClass = thisQualifier == null ? PsiTreeUtil.getParentOfType(expression, PsiClass.class, true) : ((PsiClass)thisQualifier.resolve());
        if (thisClass != null && !PsiTreeUtil.isAncestor( refMember,thisClass, false)) {
          addReferencedMember(map, thisClass, null);
        }
      }
    }
  }

  final PsiElement[] children = scope.getChildren();
  for (PsiElement child : children) {
    getThisClassesToMembers(child, map, refMember);
  }
}
 
Example 12
Project: intellij-ce-playground   File: RemoteRevisionsStateCache.java   Source Code and License Vote up 5 votes
public void minus(Pair<String, AbstractVcs> pair) {
  final VirtualFile root = getRootForPath(pair.getFirst());
  if (root == null) return;
  synchronized (myLock) {
    final VcsRoot key = new VcsRoot(pair.getSecond(), root);
    if (myQueries.containsKey(key)) {
      myQueries.remove(key, pair.getFirst());
    }
    myChanged.remove(pair.getFirst());
  }
}
 
Example 13
Project: intellij-ce-playground   File: PyDocumentationBuilder.java   Source Code and License Vote up 5 votes
@Nullable
private PsiElement resolveToDocStringOwner() {
  // here the ^Q target is already resolved; the resolved element may point to intermediate assignments
  if (myElement instanceof PyTargetExpression) {
    final String targetName = myElement.getText();
    myReassignmentChain.addWith(TagSmall, $(PyBundle.message("QDOC.assigned.to.$0", targetName)).addItem(BR));
    final PyExpression assignedValue = ((PyTargetExpression)myElement).findAssignedValue();
    if (assignedValue instanceof PyReferenceExpression) {
      final PsiElement resolved = resolveWithoutImplicits((PyReferenceExpression)assignedValue);
      if (resolved != null) {
        return resolved;
      }
    }
    return assignedValue;
  }
  if (myElement instanceof PyReferenceExpression) {
    myReassignmentChain.addWith(TagSmall, $(PyBundle.message("QDOC.assigned.to.$0", myElement.getText())).addItem(BR));
    return resolveWithoutImplicits((PyReferenceExpression)myElement);
  }
  // it may be a call to a standard wrapper
  if (myElement instanceof PyCallExpression) {
    final PyCallExpression call = (PyCallExpression)myElement;
    final Pair<String, PyFunction> wrapInfo = PyCallExpressionHelper.interpretAsModifierWrappingCall(call, myOriginalElement);
    if (wrapInfo != null) {
      final String wrapperName = wrapInfo.getFirst();
      final PyFunction wrappedFunction = wrapInfo.getSecond();
      myReassignmentChain.addWith(TagSmall, $(PyBundle.message("QDOC.wrapped.in.$0", wrapperName)).addItem(BR));
      return wrappedFunction;
    }
  }
  return myElement;
}
 
Example 14
Project: intellij-ce-playground   File: ExternalSystemTaskActivator.java   Source Code and License Vote up 5 votes
private boolean runTasksQueue(final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue) {
  final Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings> pair = tasksQueue.poll();
  if (pair == null) return true;

  final ProjectSystemId systemId = pair.first;
  final ExternalSystemTaskExecutionSettings executionSettings = pair.getSecond();

  final Semaphore targetDone = new Semaphore();
  targetDone.down();
  final Ref<Boolean> result = new Ref<Boolean>(false);
  ExternalSystemUtil.runTask(executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, systemId,
                             new TaskCallback() {
                               @Override
                               public void onSuccess() {
                                 result.set(runTasksQueue(tasksQueue));
                                 targetDone.up();
                               }

                               @Override
                               public void onFailure() {
                                 targetDone.up();
                               }
                             },
                             ProgressExecutionMode.IN_BACKGROUND_ASYNC);
  targetDone.waitFor();
  return result.get();
}
 
Example 15
Project: intellij-ce-playground   File: GitConfig.java   Source Code and License Vote up 5 votes
/**
 * Creates an instance of GitConfig by reading information from the specified {@code .git/config} file.
 * <p/>
 * If some section is invalid, it is skipped, and a warning is reported.
 */
@NotNull
static GitConfig read(@NotNull GitPlatformFacade platformFacade, @NotNull File configFile) {
  GitConfig emptyConfig = new GitConfig(Collections.<Remote>emptyList(), Collections.<Url>emptyList(),
                                        Collections.<BranchConfig>emptyList());
  if (!configFile.exists()) {
    LOG.info("No .git/config file at " + configFile.getPath());
    return emptyConfig;
  }

  Ini ini = new Ini();
  ini.getConfig().setMultiOption(true);  // duplicate keys (e.g. url in [remote])
  ini.getConfig().setTree(false);        // don't need tree structure: it corrupts url in section name (e.g. [url "http://github.com/"]
  try {
    ini.load(configFile);
  }
  catch (IOException e) {
    LOG.warn("Couldn't load .git/config file at " + configFile.getPath(), e);
    return emptyConfig;
  }

  IdeaPluginDescriptor plugin = platformFacade.getPluginByClassName(GitConfig.class.getName());
  ClassLoader classLoader = plugin == null ?
                            GitConfig.class.getClassLoader() :   // null e.g. if IDEA is started from IDEA
                            plugin.getPluginClassLoader();

  Pair<Collection<Remote>, Collection<Url>> remotesAndUrls = parseRemotes(ini, classLoader);
  Collection<BranchConfig> trackedInfos = parseTrackedInfos(ini, classLoader);

  return new GitConfig(remotesAndUrls.getFirst(), remotesAndUrls.getSecond(), trackedInfos);
}
 
Example 16
Project: intellij-ce-playground   File: MigrationNode.java   Source Code and License Vote up 5 votes
@NotNull
public Collection<? extends AbstractTreeNode> getChildren() {
  if (myCachedChildren == null) {
    myCachedChildren = new ArrayList<MigrationNode>();
    
    final PsiElement element = myInfo.getElement();
    if (element != null) {
      myLabeler.setCurrentRoot(myInfo);

      try {
        myLabeler.migrateRoot(element, myMigrationType, myLabeler.markRootUsages(element, myMigrationType));
      }
      catch (TypeMigrationLabeler.MigrateException e) {
        //skip warning
      }

      final HashSet<Pair<TypeMigrationUsageInfo, PsiType>> roots = myLabeler.getRootsTree().get(myInfo);
      if (roots != null) {
        for (Pair<TypeMigrationUsageInfo, PsiType> root : roots) {

          final TypeMigrationUsageInfo info = root.getFirst();

          if (myParents.contains(info)) continue;
          final HashSet<TypeMigrationUsageInfo> parents = new HashSet<TypeMigrationUsageInfo>(myParents);
          parents.add(info);

          final MigrationNode migrationNode =
              new MigrationNode(getProject(), info, root.getSecond(), myLabeler, myBuilder, parents, myProcessed);

          if (myInfo.isExcluded()) {
            info.setExcluded(true);
          }

          myCachedChildren.add(migrationNode);
        }
      }
    }
  }
  return myCachedChildren;
}
 
Example 17
Project: intellij-ce-playground   File: FormReferenceProvider.java   Source Code and License Vote up 5 votes
public static void setGUIComponentType(PsiPlainTextFile file, String fieldName, String typeText) {
  final Map<String, Pair<PsiType, TextRange>> fieldNameToTypeMap = getCachedData(file).myFieldNameToTypeMap;
  final Pair<PsiType, TextRange> typeRangePair = fieldNameToTypeMap.get(fieldName);
  if (typeRangePair != null) {
    final TextRange range = typeRangePair.getSecond();
    if (range != null) {
      PsiDocumentManager.getInstance(file.getProject()).getDocument(file).replaceString(range.getStartOffset(), range.getEndOffset(), typeText);
    }
  }
}
 
Example 18
Project: intellij-ce-playground   File: MakeTypeGenericAction.java   Source Code and License Vote up 5 votes
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
  Pair<PsiVariable, PsiType> pair = findVariable(element);
  if (pair == null) return;
  PsiVariable variable = pair.getFirst();
  PsiType type = pair.getSecond();

  variable.getTypeElement().replace(JavaPsiFacade.getInstance(variable.getProject()).getElementFactory().createTypeElement(type));
}
 
Example 19
Project: intellij-ce-playground   File: TrafficProgressPanel.java   Source Code and License Vote up 5 votes
private void rebuildPassesProgress(@NotNull TrafficLightRenderer.DaemonCodeAnalyzerStatus status) {
  myPassStatuses.removeAll();
  myPassStatuses.setLayout(new GridBagLayout());
  GridBagConstraints c = new GridBagConstraints();
  c.gridy = 0;
  c.fill = GridBagConstraints.HORIZONTAL;
  for (ProgressableTextEditorHighlightingPass pass : status.passStati) {
    JLabel label = new JLabel(pass.getPresentableName() + ": ");
    label.setHorizontalTextPosition(SwingConstants.RIGHT);

    Pair<JProgressBar, JLabel> pair = myTrafficLightRenderer.passes.get(pass);
    JProgressBar progressBar = pair.getFirst();
    progressBar.putClientProperty("JComponent.sizeVariant", "mini");
    JLabel percLabel = pair.getSecond();
    myProgressToText.put(progressBar, percLabel);
    c.gridx = 0;
    myPassStatuses.add(label, c);
    c.gridx = 1;
    myPassStatuses.add(progressBar, c);
    c.gridx = 2;
    c.weightx = 1;
    myPassStatuses.add(percLabel, c);

    c.gridy++;
  }

  myHintHint.initStyle(myPassStatuses, true);
}
 
Example 20
Project: intellij-ce-playground   File: XsltRunConfiguration.java   Source Code and License Vote up 4 votes
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    DefaultJDOMExternalizer.writeExternal(this, element);

    Element e = new Element("XsltFile");
    if (myXsltFile != null) {
        e.setAttribute("url", myXsltFile.getUrl());
        element.addContent(e);
    }
    e = new Element("XmlFile");
    if (myXmlInputFile != null) {
        e.setAttribute("url", myXmlInputFile.getUrl());
        element.addContent(e);
    }

    final Element params = new Element("parameters");
    element.addContent(params);
    for (Pair<String, String> pair : myParameters) {
        final Element p = new Element("param");
        params.addContent(p);
        p.setAttribute("name", pair.getFirst());

        final String value = pair.getSecond();
        if (value != null) {
            p.setAttribute("value", value);
        }
    }

    final Element type = new Element("OutputType");
    type.setAttribute("value", myOutputType.name());
    type.setAttribute("save-to-file", String.valueOf(mySaveToFile));
    element.addContent(type);

    final Element fileType = new Element("FileType");
    if (myFileType != null) {
      fileType.setAttribute("name", myFileType.getName());
    }
    element.addContent(fileType);

    final Element choice = new Element("JdkChoice");
    choice.setAttribute("value", myJdkChoice.name());
    element.addContent(choice);
}
 
Example 21
Project: intellij-ce-playground   File: RunnerLayout.java   Source Code and License Vote up 4 votes
@NotNull
public LayoutAttractionPolicy getAttractionPolicy(@NotNull String condition) {
  final Pair<String, LayoutAttractionPolicy> pair = myDefaultFocus.get(condition);
  return pair == null ? new LayoutAttractionPolicy.FocusOnce() : pair.getSecond();
}
 
Example 22
Project: intellij-ce-playground   File: JsonLineMover.java   Source Code and License Vote up 4 votes
@Override
public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) {
  myShouldAddComma = false;

  if (!(file instanceof JsonFile) || !super.checkAvailable(editor, file, info, down)) {
    return false;
  }

  Pair<PsiElement, PsiElement> movedElementRange = getElementRange(editor, file, info.toMove);
  if (!isValidElementRange(movedElementRange)) {
    return false;
  }

  // Tweak range to move if it's necessary
  movedElementRange = expandCommentsInRange(movedElementRange);
  info.toMove = new LineRange(movedElementRange.getFirst(), movedElementRange.getSecond());

  // Adjust destination range to prevent illegal offsets
  final int lineCount = editor.getDocument().getLineCount();
  if (down) {
    info.toMove2 = new LineRange(info.toMove.endLine, Math.min(info.toMove.endLine + 1, lineCount));
  }
  else {
    info.toMove2 = new LineRange(Math.max(info.toMove.startLine - 1, 0), info.toMove.startLine);
  }

  if (movedElementRange.getFirst() instanceof PsiComment && movedElementRange.getSecond() instanceof PsiComment) {
    return true;
  }

  // Check whether additional comma is needed
  final Pair<PsiElement, PsiElement> destElementRange = getElementRange(editor, file, info.toMove2);
  if (isValidElementRange(destElementRange) && movedElementRange.getFirst().getParent() == destElementRange.getSecond().getParent()) {
    final PsiElement commonParent = movedElementRange.getFirst().getParent();
    final PsiElement lowerRightElement = down ? destElementRange.getSecond() : movedElementRange.getSecond();
    // Destination rightmost element is not closing brace or bracket
    if (lowerRightElement instanceof JsonElement) {
      if (commonParent instanceof JsonArray && notFollowedByNextElementOrComma(lowerRightElement, JsonValue.class) ||
          commonParent instanceof JsonObject && notFollowedByNextElementOrComma(lowerRightElement, JsonProperty.class)) {
        myShouldAddComma = true;
      }
    }
  }
  return true;
}
 
Example 23
Project: intellij-ce-playground   File: DebuggerTreeCreatorImpl.java   Source Code and License Vote up 4 votes
@NotNull
@Override
public String getTitle(@NotNull Pair<NodeDescriptorImpl, String> descriptor) {
  return descriptor.getSecond();
}
 
Example 24
Project: intellij-ce-playground   File: XDebuggerInstanceTreeCreator.java   Source Code and License Vote up 4 votes
@NotNull
@Override
public String getTitle(@NotNull Pair<XInstanceEvaluator, String> descriptor) {
  return descriptor.getSecond();
}