Search in sources :

Example 76 with Pair

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();
}
Also used : TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) XDebuggerTreeNode(com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode) Pair(com.intellij.openapi.util.Pair)

Example 77 with Pair

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);
}
Also used : MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) MethodResolverProcessor(com.intellij.psi.scope.processor.MethodResolverProcessor) MethodProcessorSetupFailedException(com.intellij.psi.scope.MethodProcessorSetupFailedException) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with Pair

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);
}
Also used : ChangeSuperClassFix(com.intellij.codeInspection.inheritance.ChangeSuperClassFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) HashSet(com.intellij.util.containers.HashSet) Pair(com.intellij.openapi.util.Pair)

Example 79 with Pair

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()]);
}
Also used : Language(com.intellij.lang.Language) java.util(java.util) ColorUtil(com.intellij.ui.ColorUtil) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) StringUtil(com.intellij.openapi.util.text.StringUtil) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) SchemeMetaInfo(com.intellij.openapi.options.SchemeMetaInfo) ContainerUtil(com.intellij.util.containers.ContainerUtil) com.intellij.openapi.editor.colors(com.intellij.openapi.editor.colors) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) DefaultLanguageHighlighterColors(com.intellij.openapi.editor.DefaultLanguageHighlighterColors) Contract(org.jetbrains.annotations.Contract) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pair(com.intellij.openapi.util.Pair) PsiElement(com.intellij.psi.PsiElement) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) UIBundle(com.intellij.ui.UIBundle) NotNull(org.jetbrains.annotations.NotNull) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with Pair

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;
}
Also used : IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) FileViewProvider(com.intellij.psi.FileViewProvider) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Pair (com.intellij.openapi.util.Pair)391 NotNull (org.jetbrains.annotations.NotNull)131 ArrayList (java.util.ArrayList)83 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 Project (com.intellij.openapi.project.Project)60 Nullable (org.jetbrains.annotations.Nullable)59 PsiElement (com.intellij.psi.PsiElement)47 TextRange (com.intellij.openapi.util.TextRange)43 File (java.io.File)42 List (java.util.List)37 Module (com.intellij.openapi.module.Module)34 ContainerUtil (com.intellij.util.containers.ContainerUtil)26 PsiFile (com.intellij.psi.PsiFile)25 StringUtil (com.intellij.openapi.util.text.StringUtil)20 IOException (java.io.IOException)19 java.util (java.util)19 ApplicationManager (com.intellij.openapi.application.ApplicationManager)18 THashSet (gnu.trove.THashSet)17 Map (java.util.Map)17 Document (com.intellij.openapi.editor.Document)15