Search in sources :

Example 1 with Trinity

use of com.intellij.openapi.util.Trinity in project kotlin by JetBrains.

the class FrameMap method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    if (myVarIndex.size() != myVarSizes.size()) {
        return "inconsistent";
    }
    List<Trinity<DeclarationDescriptor, Integer, Integer>> descriptors = Lists.newArrayList();
    for (Object descriptor0 : myVarIndex.keys()) {
        DeclarationDescriptor descriptor = (DeclarationDescriptor) descriptor0;
        int varIndex = myVarIndex.get(descriptor);
        int varSize = myVarSizes.get(descriptor);
        descriptors.add(Trinity.create(descriptor, varIndex, varSize));
    }
    Collections.sort(descriptors, new Comparator<Trinity<DeclarationDescriptor, Integer, Integer>>() {

        @Override
        public int compare(Trinity<DeclarationDescriptor, Integer, Integer> left, Trinity<DeclarationDescriptor, Integer, Integer> right) {
            return left.second - right.second;
        }
    });
    sb.append("size=").append(myMaxIndex);
    boolean first = true;
    for (Trinity<DeclarationDescriptor, Integer, Integer> t : descriptors) {
        if (!first) {
            sb.append(", ");
        }
        first = false;
        sb.append(t.first).append(",i=").append(t.second).append(",s=").append(t.third);
    }
    return sb.toString();
}
Also used : Trinity(com.intellij.openapi.util.Trinity) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor)

Example 2 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class MvcModuleStructureSynchronizer method scheduleRunActions.

private void scheduleRunActions() {
    if (myProject.isDisposed())
        return;
    final Application app = ApplicationManager.getApplication();
    if (app.isUnitTestMode()) {
        if (ourGrailsTestFlag && !myProject.isInitialized()) {
            runActions(computeRawActions(takeOrderSnapshot()));
        }
        return;
    }
    final Set<Pair<Object, SyncAction>> orderSnapshot = takeOrderSnapshot();
    ReadTask task = new ReadTask() {

        @Nullable
        @Override
        public Continuation performInReadAction(@NotNull final ProgressIndicator indicator) throws ProcessCanceledException {
            final Set<Trinity<Module, SyncAction, MvcFramework>> actions = isUpToDate() ? computeRawActions(orderSnapshot) : Collections.<Trinity<Module, SyncAction, MvcFramework>>emptySet();
            return new Continuation(() -> {
                if (isUpToDate()) {
                    runActions(actions);
                } else if (!indicator.isCanceled()) {
                    scheduleRunActions();
                }
            }, ModalityState.NON_MODAL);
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator indicator) {
            scheduleRunActions();
        }

        private boolean isUpToDate() {
            return !myProject.isDisposed() && orderSnapshot.equals(takeOrderSnapshot());
        }
    };
    GuiUtils.invokeLaterIfNeeded(() -> ProgressIndicatorUtils.scheduleWithWriteActionPriority(ourExecutor, task), ModalityState.NON_MODAL);
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull) Pair(com.intellij.openapi.util.Pair) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 3 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class AddAnnotationFixTest method testAnnotateLibrary.

public void testAnnotateLibrary() throws Throwable {
    addDefaultLibrary();
    myFixture.configureByFiles("lib/p/TestPrimitive.java", "content/anno/p/annotations.xml");
    myFixture.configureByFiles("lib/p/Test.java");
    final PsiFile file = myFixture.getFile();
    final Editor editor = myFixture.getEditor();
    // expecting other @Nullable annotations to be removed, and default @NotNull to be added
    List<Trinity<PsiModifierListOwner, String, Boolean>> expectedSequence = new ArrayList<>();
    for (String notNull : NullableNotNullManager.getInstance(myProject).getNullables()) {
        expectedSequence.add(Trinity.create(getOwner(), notNull, false));
    }
    expectedSequence.add(Trinity.create(getOwner(), AnnotationUtil.NOT_NULL, true));
    startListening(expectedSequence);
    myFixture.launchAction(myFixture.findSingleIntention("Annotate method 'get' as @NotNull"));
    FileDocumentManager.getInstance().saveAllDocuments();
    final PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset());
    assertNotNull(psiElement);
    final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psiElement, PsiModifierListOwner.class);
    assertNotNull(listOwner);
    assertNotNull(ExternalAnnotationsManager.getInstance(myProject).findExternalAnnotation(listOwner, AnnotationUtil.NOT_NULL));
    stopListeningAndCheckEvents();
    myFixture.checkResultByFile("content/anno/p/annotations.xml", "content/anno/p/annotationsAnnotateLibrary_after.xml", false);
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor)

Example 4 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class GroovyConstructorNamedArgumentProvider method processClass.

public static void processClass(@NotNull GrCall call, PsiClassType type, @Nullable String argumentName, final Map<String, NamedArgumentDescriptor> result) {
    if (argumentName == null) {
        final HashMap<String, Trinity<PsiType, PsiElement, PsiSubstitutor>> map = ContainerUtil.newHashMap();
        MyPsiScopeProcessor processor = new MyPsiScopeProcessor() {

            @Override
            protected void addNamedArgument(String propertyName, PsiType type, PsiElement element, PsiSubstitutor substitutor) {
                if (result.containsKey(propertyName))
                    return;
                Trinity<PsiType, PsiElement, PsiSubstitutor> pair = map.get(propertyName);
                if (pair != null) {
                    if (element instanceof PsiMethod && pair.second instanceof PsiField) {
                    // methods should override fields
                    } else {
                        return;
                    }
                }
                map.put(propertyName, Trinity.create(type, element, substitutor));
            }
        };
        processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_METHOD_PROPERTY);
        ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
        for (Map.Entry<String, Trinity<PsiType, PsiElement, PsiSubstitutor>> entry : map.entrySet()) {
            result.put(entry.getKey(), new TypeCondition(entry.getValue().first, entry.getValue().getSecond(), entry.getValue().getThird(), NamedArgumentDescriptor.Priority.AS_LOCAL_VARIABLE));
        }
    } else {
        MyPsiScopeProcessor processor = new MyPsiScopeProcessor() {

            @Override
            protected void addNamedArgument(String propertyName, PsiType type, PsiElement element, PsiSubstitutor substitutor) {
                if (result.containsKey(propertyName))
                    return;
                result.put(propertyName, new TypeCondition(type, element, substitutor, NamedArgumentDescriptor.Priority.AS_LOCAL_VARIABLE));
            }
        };
        processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_METHOD);
        processor.setNameHint(GroovyPropertyUtils.getSetterName(argumentName));
        ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
        processor.setResolveTargetKinds(ClassHint.RESOLVE_KINDS_PROPERTY);
        processor.setNameHint(argumentName);
        ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), call);
    }
}
Also used : Trinity(com.intellij.openapi.util.Trinity) TypeCondition(org.jetbrains.plugins.groovy.extensions.impl.TypeCondition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Trinity

use of com.intellij.openapi.util.Trinity in project intellij-community by JetBrains.

the class GdkMethodUtil method getClosureMixins.

private static Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> getClosureMixins(final GrStatement statement) {
    if (!(statement instanceof GrAssignmentExpression))
        return null;
    final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
    return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>>() {

        @Nullable
        @Override
        public Result<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>> compute() {
            Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
            if (original == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
            if (signatures == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final String name = signatures.second;
            final List<GrMethod> methods = ContainerUtil.newArrayList();
            final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
            if (closure == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            signatures.first.accept(new GrSignatureVisitor() {

                @Override
                public void visitClosureSignature(GrClosureSignature signature) {
                    super.visitClosureSignature(signature);
                    GrMethod method = createMethod(signature, name, assignment, closure);
                    methods.add(method);
                }
            });
            return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
        }
    });
}
Also used : Trinity(com.intellij.openapi.util.Trinity) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable) Pair(com.intellij.openapi.util.Pair)

Aggregations

Trinity (com.intellij.openapi.util.Trinity)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Pair (com.intellij.openapi.util.Pair)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 TextRange (com.intellij.openapi.util.TextRange)5 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 IElementType (com.intellij.psi.tree.IElementType)4 File (java.io.File)4 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 Language (com.intellij.lang.Language)3 FileType (com.intellij.openapi.fileTypes.FileType)3 ProcessHandler (com.intellij.execution.process.ProcessHandler)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)2 Module (com.intellij.openapi.module.Module)2