Search in sources :

Example 11 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)

Example 12 with Trinity

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

the class MxmlUtil method computeEffectiveClass.

static Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> computeEffectiveClass(final PsiElement element, final PsiElement declaration, final ProjectComponentReferenceCounter projectComponentReferenceCounter, final boolean computePropertyFilter) throws InvalidPropertyException {
    PsiFile psiFile = declaration.getContainingFile();
    VirtualFile virtualFile = psiFile.getVirtualFile();
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
    LOG.assertTrue(virtualFile != null);
    if (!projectFileIndex.isInSourceContent(virtualFile)) {
        return NON_PROJECT_CLASS;
    }
    if (psiFile instanceof XmlFile) {
        return new Trinity<>(DocumentFactoryManager.getInstance().getId(virtualFile, (XmlFile) psiFile, projectComponentReferenceCounter), null, null);
    }
    final Set<PsiFile> filteredFiles;
    if (computePropertyFilter) {
        filteredFiles = new THashSet<>();
        filteredFiles.add(psiFile);
    } else {
        filteredFiles = null;
    }
    final JSClass aClass = (JSClass) declaration;
    JSClass[] classes;
    while ((classes = aClass.getSuperClasses()).length > 0) {
        JSClass parentClass = classes[0];
        PsiFile containingFile = parentClass.getContainingFile();
        //noinspection ConstantConditions
        if (!projectFileIndex.isInSourceContent(containingFile.getVirtualFile())) {
            return new Trinity<>(-1, parentClass.getQualifiedName(), computePropertyFilter ? new CustomComponentPropertyFilter(filteredFiles) : null);
        } else if (computePropertyFilter) {
            filteredFiles.add(containingFile);
        }
    }
    // well, it must be at least mx.core.UIComponent or spark.primitives.supportClasses.GraphicElement
    throw new InvalidPropertyException(element, "unresolved.class", aClass.getQualifiedName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Trinity(com.intellij.openapi.util.Trinity) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 13 with Trinity

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

the class PackageFileWorker method packageFile.

public static void packageFile(@NotNull VirtualFile file, @NotNull Project project, final Artifact[] artifacts, final boolean packIntoArchives) throws IOException {
    LOG.debug("Start packaging file: " + file.getPath());
    final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts);
    File ioFile = VfsUtilCore.virtualToIoFile(file);
    for (Trinity<Artifact, PackagingElementPath, String> item : items) {
        final Artifact artifact = item.getFirst();
        final String outputPath = artifact.getOutputPath();
        if (!StringUtil.isEmpty(outputPath)) {
            PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird(), packIntoArchives);
            LOG.debug(" package to " + outputPath);
            worker.packageFile(outputPath, item.getSecond().getParents());
        }
    }
}
Also used : Trinity(com.intellij.openapi.util.Trinity) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 14 with Trinity

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

the class JsonSchemaWalker method extractSchemaVariants.

public static void extractSchemaVariants(@NotNull final Project project, @NotNull final CompletionSchemesConsumer consumer, @NotNull VirtualFile rootSchemaFile, @NotNull JsonSchemaObject rootSchema, boolean isName, List<Step> position, boolean acceptAdditionalPropertiesSchemas) {
    final Set<Trinity<JsonSchemaObject, VirtualFile, List<Step>>> control = new HashSet<>();
    final JsonSchemaServiceEx serviceEx = JsonSchemaServiceEx.Impl.getEx(project);
    final ArrayDeque<Trinity<JsonSchemaObject, VirtualFile, List<Step>>> queue = new ArrayDeque<>();
    queue.add(Trinity.create(rootSchema, rootSchemaFile, position));
    while (!queue.isEmpty()) {
        final Trinity<JsonSchemaObject, VirtualFile, List<Step>> trinity = queue.removeFirst();
        if (!control.add(trinity))
            break;
        final JsonSchemaObject object = trinity.getFirst();
        final VirtualFile schemaFile = trinity.getSecond();
        final List<Step> path = trinity.getThird();
        if (path.isEmpty()) {
            consumer.consume(isName, object, schemaFile, path);
            continue;
        }
        final DefinitionsResolver definitionsResolver = new DefinitionsResolver(path);
        extractSchemaVariants(definitionsResolver, object, path, acceptAdditionalPropertiesSchemas);
        if (definitionsResolver.isFound()) {
            final List<JsonSchemaObject> matchedSchemas = definitionsResolver.getSchemaObjects();
            matchedSchemas.forEach(matchedSchema -> {
                final List<JsonSchemaObject> list = gatherSchemas(matchedSchema);
                for (JsonSchemaObject schemaObject : list) {
                    if (schemaObject.getDefinitionAddress() != null && !schemaObject.getDefinitionAddress().startsWith("#/")) {
                        final List<Step> steps = new ArrayList<>();
                        if (!isName)
                            steps.add(new Step(StateType._value, null));
                        visitSchemaByDefinitionAddress(serviceEx, queue, schemaFile, schemaObject.getDefinitionAddress(), steps);
                    }
                }
            });
            if (matchedSchemas.size() == 1)
                consumer.consume(isName, matchedSchemas.get(0), schemaFile, path);
            else {
                if (definitionsResolver.isOneOf()) {
                    consumer.oneOf(isName, matchedSchemas, schemaFile, path);
                } else {
                    consumer.anyOf(isName, matchedSchemas, schemaFile, path);
                }
            }
        } else {
            final List<Pair<JsonSchemaObject, List<Step>>> variants = definitionsResolver.getVariants();
            for (Pair<JsonSchemaObject, List<Step>> variant : variants) {
                if (variant.getFirst().getDefinitionAddress() == null)
                    continue;
                visitSchemaByDefinitionAddress(serviceEx, queue, schemaFile, variant.getFirst().getDefinitionAddress(), variant.getSecond());
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Trinity(com.intellij.openapi.util.Trinity) Pair(com.intellij.openapi.util.Pair)

Example 15 with Trinity

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

the class ShowRunningListAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null || project.isDisposed())
        return;
    final Ref<Pair<? extends JComponent, String>> stateRef = new Ref<>();
    final Ref<Balloon> balloonRef = new Ref<>();
    final Timer timer = UIUtil.createNamedTimer("runningLists", 250);
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            Balloon balloon = balloonRef.get();
            if (project.isDisposed() || (balloon != null && balloon.isDisposed())) {
                timer.stop();
                return;
            }
            ArrayList<Project> projects = new ArrayList<>(Arrays.asList(ProjectManager.getInstance().getOpenProjects()));
            //List should begin with current project
            projects.remove(project);
            projects.add(0, project);
            Pair<? extends JComponent, String> state = getCurrentState(projects);
            Pair<? extends JComponent, String> prevState = stateRef.get();
            if (prevState != null && prevState.getSecond().equals(state.getSecond()))
                return;
            stateRef.set(state);
            BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(state.getFirst());
            builder.setShowCallout(false).setTitle(ExecutionBundle.message("show.running.list.balloon.title")).setBlockClicksThroughBalloon(true).setDialogMode(true).setHideOnKeyOutside(false);
            IdeFrame frame = IdeFrame.KEY.getData(e.getDataContext());
            if (frame == null) {
                frame = WindowManagerEx.getInstanceEx().getFrame(project);
            }
            if (balloon != null) {
                balloon.hide();
            }
            builder.setClickHandler(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (e.getSource() instanceof MouseEvent) {
                        MouseEvent mouseEvent = (MouseEvent) e.getSource();
                        Component component = mouseEvent.getComponent();
                        component = SwingUtilities.getDeepestComponentAt(component, mouseEvent.getX(), mouseEvent.getY());
                        Object value = ((JComponent) component).getClientProperty(KEY);
                        if (value instanceof Trinity) {
                            Project aProject = (Project) ((Trinity) value).first;
                            JFrame aFrame = WindowManager.getInstance().getFrame(aProject);
                            if (aFrame != null && !aFrame.isActive()) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(aFrame, true);
                                });
                            }
                            ExecutionManagerImpl.getInstance(aProject).getContentManager().toFrontRunContent((Executor) ((Trinity) value).second, (RunContentDescriptor) ((Trinity) value).third);
                        }
                    }
                }
            }, false);
            balloon = builder.createBalloon();
            balloonRef.set(balloon);
            JComponent component = frame.getComponent();
            RelativePoint point = new RelativePoint(component, new Point(component.getWidth(), 0));
            balloon.show(point, Balloon.Position.below);
        }
    };
    timer.addActionListener(actionListener);
    timer.setInitialDelay(0);
    timer.start();
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) IdeFrame(com.intellij.openapi.wm.IdeFrame) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder) Executor(com.intellij.execution.Executor) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RelativePoint(com.intellij.ui.awt.RelativePoint) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener)

Aggregations

Trinity (com.intellij.openapi.util.Trinity)24 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 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 Language (com.intellij.lang.Language)3 FileType (com.intellij.openapi.fileTypes.FileType)3 TextRange (com.intellij.openapi.util.TextRange)3 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)2 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 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2