本文整理汇总了Java中com.intellij.openapi.util.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于com.intellij.openapi.util包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocalInspectionsAtCaret
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
private Pair<List<ProblemDescriptor>, Integer> getLocalInspectionsAtCaret(String filename, String content) {
PsiElement psiFile = myFixture.configureByText(filename, content);
int caretOffset = myFixture.getCaretOffset();
if(caretOffset <= 0) {
fail("Please provide <caret> tag");
}
ProblemsHolder problemsHolder = new ProblemsHolder(InspectionManager.getInstance(getProject()), psiFile.getContainingFile(), false);
for (LocalInspectionEP localInspectionEP : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
Object object = localInspectionEP.getInstance();
if(!(object instanceof LocalInspectionTool)) {
continue;
}
((LocalInspectionTool) object).buildVisitor(problemsHolder, false);
}
return new Pair<List<ProblemDescriptor>, Integer>(problemsHolder.getResults(), caretOffset);
}
示例2: getDejagnuParameters
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
/**
* Returns need runner parameters dependence current version runtest.
* @param version current version runtest
* @return list of need parameters
*/
@NotNull
@VisibleForTesting
static List<Pair<String, String>> getDejagnuParameters(@NotNull final String version){
final List<Pair<String, String>> params = new ArrayList<Pair<String, String>>();
params.add(new Pair<String, String>(HAS_RUNTEST_VAR, "1"));
if (VersionComparatorUtil.compare(version, "1.4.4") <= 0){
params.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all"));
return params;
}
if (VersionComparatorUtil.compare(version, "1.5.3") < 0){
params.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all --xml"));
return params;
}
params.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all --xml=\"testresults.xml\""));
return params;
}
示例3: getDejagnuParametersTest
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
@Test
public void getDejagnuParametersTest(){
final Collection<Pair<String, String>> answer = new ArrayList<Pair<String, String>>();
answer.add(new Pair<String, String>(HAS_RUNTEST_VAR, "1"));
answer.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all"));
Assert.assertEquals(RuntestToolProvider.getDejagnuParameters("1.4.4"), answer,"for version 1.4.4");
answer.clear();
answer.add(new Pair<String, String>(HAS_RUNTEST_VAR, "1"));
answer.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all --xml"));
Assert.assertEquals(RuntestToolProvider.getDejagnuParameters("1.5.1"), answer, "for version 1.5.1");
answer.clear();
answer.add(new Pair<String, String>(HAS_RUNTEST_VAR, "1"));
//answer.add(new Pair<String, String>(MY_RUNTESTFLAGS, "'--all --xml'"));
answer.add(new Pair<String, String>(MY_RUNTESTFLAGS, "RUNTESTFLAGS=--all --xml=\"testresults.xml\""));
Assert.assertEquals(RuntestToolProvider.getDejagnuParameters("1.5.3"), answer, "for version 1.5.3");
Assert.assertEquals(RuntestToolProvider.getDejagnuParameters("1.6"), answer, "for version 1.6");
}
示例4: onDownload
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
@Override
public Pair<Boolean, List<File>> onDownload(@NotNull ClassEntity[] classEntities, @NotNull File outputFolder) {
String newUrl = null;
try {
newUrl = androidOnlineSearch(classEntities[0]);
} catch (ConnectException | UnknownHostException e1) {
if (timeoutListener != null) {
timeoutListener.run();
}
} catch (Exception e) {
Log.e(e);
}
if (!Utils.isEmpty(newUrl)) {
for (ClassEntity entity : classEntities) {
entity.setDownloadUrl(newUrl);
}
Log.debug("SearchDownload => " + newUrl);
return new XrefDownload().onDownload(classEntities, outputFolder);
}
return Pair.create(false, Collections.<File>emptyList());
}
示例5: addShortcut
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
private void addShortcut(@NotNull final String actionIdString, @NotNull final String[] shortcuts) {
KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
for (Keymap keymap : keymapManager.getAllKeymaps()) {
List<Pair<String, String>> pairs = myDeletedShortcuts.get(keymap);
if (pairs == null) {
pairs = new ArrayList<>();
myDeletedShortcuts.put(keymap, pairs);
}
for (String shortcutString : shortcuts) {
Shortcut studyActionShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
String[] actionsIds = keymap.getActionIds(studyActionShortcut);
for (String actionId : actionsIds) {
pairs.add(Pair.create(actionId, shortcutString));
keymap.removeShortcut(actionId, studyActionShortcut);
}
keymap.addShortcut(actionIdString, studyActionShortcut);
}
}
}
示例6: projectClosed
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
@Override
public void projectClosed() {
final Course course = StudyTaskManager.getInstance(myProject).getCourse();
if (course != null) {
final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
if (toolWindow != null) {
toolWindow.getContentManager().removeAllContents(false);
}
KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
for (Keymap keymap : keymapManager.getAllKeymaps()) {
List<Pair<String, String>> pairs = myDeletedShortcuts.get(keymap);
if (pairs != null && !pairs.isEmpty()) {
for (Pair<String, String> actionShortcut : pairs) {
keymap.addShortcut(actionShortcut.first, new KeyboardShortcut(KeyStroke.getKeyStroke(actionShortcut.second), null));
}
}
}
}
myListener = null;
}
示例7: updateCourseProgress
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
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);
}
}
示例8: countProgressAsOneTaskWithSubtasks
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
/**
* Counts current progress for course which consists of only on task with subtasks
* In this case we count each subtasks as task
* @return Pair (number of solved tasks, number of tasks) or null if lessons can't be interpreted as one task with subtasks
*/
@Nullable
private static Pair<Integer, Integer> countProgressAsOneTaskWithSubtasks(List<Lesson> lessons) {
if (lessons.size() == 1 && lessons.get(0).getTaskList().size() == 1) {
final Lesson lesson = lessons.get(0);
final Task task = lesson.getTaskList().get(0);
if (task instanceof TaskWithSubtasks) {
final int lastSubtaskIndex = ((TaskWithSubtasks)task).getLastSubtaskIndex();
final int activeSubtaskIndex = ((TaskWithSubtasks)task).getActiveSubtaskIndex();
int taskNum = lastSubtaskIndex + 1;
boolean isLastSubtaskSolved = activeSubtaskIndex == lastSubtaskIndex && task.getStatus() == StudyStatus.Solved;
return Pair.create(isLastSubtaskSolved ? taskNum : activeSubtaskIndex, taskNum);
}
}
return null;
}
示例9: drawAnswerPlaceholder
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder,
@NotNull final JBColor color) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
EffectType.BOXED, Font.PLAIN);
textAttributes.setEffectColor(color);
int startOffset = placeholder.getOffset();
if (startOffset == -1) {
return;
}
final int length =
placeholder.isActive() ? placeholder.getRealLength() : placeholder.getVisibleLength(placeholder.getActiveSubtaskIndex());
Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
startOffset = offsets.first;
int endOffset = offsets.second;
if (placeholder.isActive()) {
drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, PLACEHOLDERS_LAYER);
}
else if (!placeholder.getUseLength() && length != 0) {
drawAnswerPlaceholderFromPrevStep(editor, startOffset, endOffset);
}
}
示例10: createGuardedBlocks
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) {
Document document = editor.getDocument();
if (document instanceof DocumentImpl) {
DocumentImpl documentImpl = (DocumentImpl)document;
List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument());
Integer start = offsets.first;
Integer end = offsets.second;
if (start != 0) {
createGuardedBlock(editor, blocks, start - 1, start);
}
if (end != document.getTextLength()) {
createGuardedBlock(editor, blocks, end, end + 1);
}
}
}
示例11: doTest
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
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);
}
}
示例12: checkByFile
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
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));
}
}
}
示例13: findSelectedBreakpoint
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
@NotNull
public static Pair<GutterIconRenderer, Object> findSelectedBreakpoint(@NotNull final Project project, @NotNull final Editor editor) {
int offset = editor.getCaretModel().getOffset();
Document editorDocument = editor.getDocument();
DebuggerSupport[] debuggerSupports = DebuggerSupport.getDebuggerSupports();
for (DebuggerSupport debuggerSupport : debuggerSupports) {
final BreakpointPanelProvider<?> provider = debuggerSupport.getBreakpointPanelProvider();
final int textLength = editor.getDocument().getTextLength();
if (offset > textLength) {
offset = textLength;
}
Object breakpoint = provider.findBreakpoint(project, editorDocument, offset);
if (breakpoint != null) {
final GutterIconRenderer iconRenderer = provider.getBreakpointGutterIconRenderer(breakpoint);
return Pair.create(iconRenderer, breakpoint);
}
}
return Pair.create(null, null);
}
示例14: isProperAssignmentStatementFound
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
private static Pair<Boolean, PsiNewExpression> isProperAssignmentStatementFound(PsiLocalVariable localVariable, PsiMethodCallExpression addAllExpression) {
PsiStatement currentStatement = PsiTreeUtil.getParentOfType(addAllExpression, PsiStatement.class);
final PsiStatement localVariableDefinitionStatement = PsiTreeUtil.getParentOfType(localVariable, PsiStatement.class);
while (currentStatement != null) {
currentStatement = PsiTreeUtil.getPrevSiblingOfType(currentStatement, PsiStatement.class);
if (currentStatement == localVariableDefinitionStatement) {
return Pair.create(true, null);
}
for (PsiAssignmentExpression expression : PsiTreeUtil.findChildrenOfType(currentStatement, PsiAssignmentExpression.class)) {
final PsiExpression lExpression = expression.getLExpression();
if (lExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)lExpression).isReferenceTo(localVariable)) {
final PsiExpression rExpression = expression.getRExpression();
final boolean isValid = checkLocalVariableAssignmentOrInitializer(rExpression);
return Pair.create(isValid, isValid ? (PsiNewExpression)rExpression : null);
}
}
}
return Pair.create(true, null);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:CollectionAddAllCanBeReplacedWithConstructorInspection.java
示例15: initComboBox
import com.intellij.openapi.util.Pair; //导入依赖的package包/类
static JComboBox initComboBox(final JComboBox comboBox, final Condition<String> validity) {
comboBox.setEditable(false);
comboBox.setPrototypeDisplayValue(new ComboBoxItem("A", null));
comboBox.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final Pair<String, Icon> pair = (Pair<String, Icon>)value;
final String text = pair == null ? null : pair.first;
setText(text);
final Dimension dimension = getPreferredSize();
if (!validity.value(text)) {
setFont(getFont().deriveFont(Font.ITALIC));
setForeground(JBColor.RED);
}
setIcon(pair == null ? null : pair.second);
setPreferredSize(new Dimension(-1, dimension.height));
return this;
}
});
return comboBox;
}