use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class CustomFieldInplaceEditor method doOKAction.
@Override
public void doOKAction() {
List<Pair<String, TextWithImports>> children = getRendererChildren();
TextWithImports newText = TextWithImportsImpl.fromXExpression(myExpressionEditor.getExpression());
if (myDescriptor == null) {
children.add(0, Pair.create("", newText));
} else {
int index = myDescriptor.getEnumerationIndex();
children.set(index, Pair.create(children.get(index).first, newText));
}
myTree.putClientProperty(XDebuggerTreeRestorer.SELECTION_PATH_PROPERTY, createDummySelectionTreePath(newText.getText(), (XDebuggerTreeNode) myNode.getParent()));
XDebuggerUtilImpl.rebuildTreeAndViews(myTree);
super.doOKAction();
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class ExceptionUtil method getUnhandledExceptions.
@NotNull
public static List<PsiClassType> getUnhandledExceptions(@NotNull final PsiCallExpression methodCall, @Nullable final PsiElement topElement, final boolean includeSelfCalls) {
//exceptions only influence the invocation type after overload resolution is complete
if (MethodCandidateInfo.isOverloadCheck()) {
return Collections.emptyList();
}
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(methodCall.getArgumentList());
final JavaResolveResult result = properties != null ? properties.getInfo() : InferenceSession.getResolveResult(methodCall);
final PsiElement element = result.getElement();
final PsiMethod method = element instanceof PsiMethod ? (PsiMethod) element : null;
if (method == null) {
return Collections.emptyList();
}
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class);
if (!includeSelfCalls && method == containingMethod) {
return Collections.emptyList();
}
if (properties != null) {
PsiUtilCore.ensureValid(method);
}
final PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes();
if (thrownExceptions.length == 0) {
return Collections.emptyList();
}
final PsiSubstitutor substitutor = result.getSubstitutor();
if (!isArrayClone(method, methodCall) && methodCall instanceof PsiMethodCallExpression) {
final PsiFile containingFile = (containingMethod == null ? methodCall : containingMethod).getContainingFile();
final MethodResolverProcessor processor = new MethodResolverProcessor((PsiMethodCallExpression) methodCall, containingFile);
try {
PsiScopesUtil.setupAndRunProcessor(processor, methodCall, false);
final List<Pair<PsiMethod, PsiSubstitutor>> candidates = ContainerUtil.mapNotNull(processor.getResults(), info -> {
PsiElement element1 = info.getElement();
if (info instanceof MethodCandidateInfo && MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod) element1) && !MethodSignatureUtil.isSuperMethod((PsiMethod) element1, method)) {
return Pair.create((PsiMethod) element1, ((MethodCandidateInfo) info).getSubstitutor(false));
}
return null;
});
if (candidates.size() > 1) {
GlobalSearchScope scope = methodCall.getResolveScope();
final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions, scope);
for (Pair<PsiMethod, PsiSubstitutor> pair : candidates) {
final PsiClassType[] exceptions = pair.first.getThrowsList().getReferencedTypes();
if (exceptions.length == 0) {
return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, PsiClassType.EMPTY_ARRAY);
}
retainExceptions(ex, collectSubstituted(pair.second, exceptions, scope));
}
return getUnhandledExceptions(methodCall, topElement, PsiSubstitutor.EMPTY, ex.toArray(new PsiClassType[ex.size()]));
}
} catch (MethodProcessorSetupFailedException ignore) {
return Collections.emptyList();
}
}
return getUnhandledExceptions(method, methodCall, topElement, substitutor);
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class SuperClassHasFrequentlyUsedInheritorsInspectionTest method doTest.
private void doTest(final int expectedSize) {
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.enableInspections(SuperClassHasFrequentlyUsedInheritorsInspection.class);
final Set<Pair<String, Integer>> actualSet = new HashSet<Pair<String, Integer>>();
for (IntentionAction intentionAction : myFixture.getAvailableIntentions()) {
if (intentionAction instanceof QuickFixWrapper) {
ChangeSuperClassFix changeSuperClassFix = getQuickFixFromWrapper((QuickFixWrapper) intentionAction);
if (changeSuperClassFix != null) {
actualSet.add(Pair.create(changeSuperClassFix.getNewSuperClass().getQualifiedName(), changeSuperClassFix.getPercent()));
}
}
}
assertSize(expectedSize, actualSet);
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class RainbowHighlighter method generateColors.
@NotNull
private static Color[] generateColors(@NotNull TextAttributesScheme colorsScheme, boolean withCorrectionAndCaching) {
List<Color> stopRainbowColors = ContainerUtil.map(RAINBOW_COLOR_KEYS, key -> getRainbowColorFromAttribute(colorsScheme.getAttributes(key)));
List<Color> rainbowColors = ColorGenerator.generateLinearColorSequence(stopRainbowColors, RAINBOW_COLORS_BETWEEN);
if (withCorrectionAndCaching && (colorsScheme instanceof EditorColorsScheme)) {
final EditorColorPalette palette = EditorColorPaletteFactory.getInstance().getPalette((EditorColorsScheme) colorsScheme, Language.ANY).collectColorsWithFilter(attr -> getRainbowColorFromAttribute(attr), true);
final List<Pair<Color, Double>> colorCircles = new ArrayList<>();
final Color background = ((EditorColorsScheme) colorsScheme).getDefaultBackground();
final boolean schemeIsDark = ColorUtil.isDark(background);
final double minDistanceWithOrdinal = schemeIsDark ? 0.06 : 0.10;
final double minDistanceWithDiagnostic = schemeIsDark ? 0.12 : 0.20;
colorCircles.add(Pair.create(background, 0.24));
palette.getEntries().forEach(entry -> colorCircles.add(Pair.create(entry.getKey(), Collections.disjoint(CODE_INSIGHT_CONFLICT_KEYS, entry.getValue()) ? minDistanceWithOrdinal : minDistanceWithDiagnostic)));
rainbowColors = ContainerUtil.map(rainbowColors, rainbowColor -> resolveConflict(colorCircles, rainbowColor, 0));
final Map<TextAttributesKey, TextAttributes> cache = getGeneratedTextAttributesCache(colorsScheme);
if (cache != null) {
cache.entrySet().removeIf(entry -> isRainbowTempKey(entry.getKey()));
int i = 0;
for (Color rainbowColor : rainbowColors) {
TextAttributesKey key = createRainbowKey(i++, rainbowColor);
cache.put(key, key.getDefaultAttributes());
}
}
}
return rainbowColors.toArray(new Color[rainbowColors.size()]);
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class PsiFileStubImpl method getStubRoots.
@NotNull
@Override
public PsiFileStub[] getStubRoots() {
if (myStubRoots != null)
return myStubRoots;
final T psi = getPsi();
if (psi == null) {
return new PsiFileStub[] { this };
}
final FileViewProvider viewProvider = psi.getViewProvider();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
StubTree baseTree = getOrCalcStubTree(stubBindingRoot);
if (baseTree != null) {
final List<PsiFileStub> roots = new SmartList<>(baseTree.getRoot());
final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = StubTreeBuilder.getStubbedRoots(viewProvider);
for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) {
if (stubbedRoot.second == stubBindingRoot)
continue;
final StubTree secondaryStubTree = getOrCalcStubTree(stubbedRoot.second);
if (secondaryStubTree != null) {
final PsiFileStub root = secondaryStubTree.getRoot();
roots.add(root);
}
}
final PsiFileStub[] rootsArray = roots.toArray(new PsiFileStub[roots.size()]);
for (PsiFileStub root : rootsArray) {
if (root instanceof PsiFileStubImpl) {
((PsiFileStubImpl) root).setStubRoots(rootsArray);
}
}
myStubRoots = rootsArray;
return rootsArray;
}
return PsiFileStub.EMPTY_ARRAY;
}
Aggregations