Search in sources :

Example 1 with DocumentInfo

use of com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo in project intellij-plugins by JetBrains.

the class Client method renderDocumentAndDependents.

public AsyncResult<List<DocumentInfo>> renderDocumentAndDependents(@Nullable List<DocumentInfo> infos, THashMap<ModuleInfo, List<LocalStyleHolder>> outdatedLocalStyleHolders, final AsyncResult<List<DocumentInfo>> result) {
    if ((infos == null || infos.isEmpty()) && outdatedLocalStyleHolders.isEmpty()) {
        result.setDone(infos);
        return result;
    }
    final ActionCallback callback = new ActionCallback("renderDocumentAndDependents");
    boolean hasError = true;
    try {
        beginMessage(ClientMethod.renderDocumentsAndDependents, callback, result, () -> {
            final int[] ids;
            try {
                ids = SocketInputHandler.getInstance().getReader().readIntArray();
            } catch (IOException e) {
                LogMessageUtil.processInternalError(e);
                return;
            }
            DocumentFactoryManager documentFactoryManager = DocumentFactoryManager.getInstance();
            List<DocumentInfo> rendered = new ArrayList<>(ids.length);
            for (int id : ids) {
                rendered.add(documentFactoryManager.getInfo(id));
            }
            result.setDone(rendered);
        });
        out.writeUInt29(outdatedLocalStyleHolders.size());
        outdatedLocalStyleHolders.forEachKey(moduleInfo -> {
            out.writeUInt29(moduleInfo.getId());
            return true;
        });
        out.write(infos);
        hasError = false;
    } finally {
        finalizeMessageAndFlush(hasError, callback);
    }
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 2 with DocumentInfo

use of com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo in project intellij-plugins by JetBrains.

the class Client method registerDocumentFactoryIfNeed.

private int registerDocumentFactoryIfNeed(Module module, XmlFile psiFile, VirtualFile virtualFile, boolean force, ProblemsHolder problemsHolder) {
    final DocumentFactoryManager documentFactoryManager = DocumentFactoryManager.getInstance();
    final boolean registered = !force && documentFactoryManager.isRegistered(virtualFile);
    final DocumentInfo documentInfo = documentFactoryManager.get(virtualFile, null, null);
    if (!registered) {
        boolean hasError = true;
        try {
            beginMessage(ClientMethod.registerDocumentFactory);
            writeId(module);
            out.writeShort(documentInfo.getId());
            writeVirtualFile(virtualFile, out);
            hasError = !writeDocumentFactory(documentInfo, module, psiFile, problemsHolder);
        } catch (Throwable e) {
            LogMessageUtil.processInternalError(e, virtualFile);
        } finally {
            try {
                if (hasError) {
                    blockOut.rollback();
                    //noinspection ReturnInsideFinallyBlock
                    return -1;
                }
            } finally {
                outLock.unlock();
            }
        }
    }
    return documentInfo.getId();
}
Also used : DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 3 with DocumentInfo

use of com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo in project intellij-plugins by JetBrains.

the class AppTest method applicationLaunchedAndInitialized.

@Override
protected void applicationLaunchedAndInitialized() {
    ((MySocketInputHandler) SocketInputHandler.getInstance()).fail = fail;
    ((MySocketInputHandler) SocketInputHandler.getInstance()).semaphore = semaphore;
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(myModule);
    connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {

        @Override
        public void documentRendered(DocumentInfo info) {
            semaphore.up();
        }

        @Override
        public void errorOccurred() {
            fail.set(true);
            semaphore.up();
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 4 with DocumentInfo

use of com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo in project intellij-plugins by JetBrains.

the class DesignerApplicationManager method renderIfNeed.

public void renderIfNeed(@NotNull XmlFile psiFile, @Nullable final Consumer<DocumentInfo> handler, @Nullable ActionCallback renderRejectedCallback, final boolean debug) {
    boolean needInitialRender = isApplicationClosed();
    DocumentInfo documentInfo = null;
    if (!needInitialRender) {
        Document[] unsavedDocuments = FileDocumentManager.getInstance().getUnsavedDocuments();
        if (unsavedDocuments.length > 0) {
            renderDocumentsAndCheckLocalStyleModification(unsavedDocuments);
        }
        documentInfo = DocumentFactoryManager.getInstance().getNullableInfo(psiFile);
        needInitialRender = documentInfo == null;
    }
    if (!needInitialRender) {
        if (handler == null) {
            return;
        }
        Application app = ApplicationManager.getApplication();
        if (app.isDispatchThread()) {
            final DocumentInfo finalDocumentInfo = documentInfo;
            app.executeOnPooledThread(() -> handler.consume(finalDocumentInfo));
        } else {
            handler.consume(documentInfo);
        }
        return;
    }
    synchronized (initialRenderQueue) {
        AsyncResult<DocumentInfo> renderResult = initialRenderQueue.findResult(psiFile);
        if (renderResult == null) {
            renderResult = new AsyncResult<>();
            if (renderRejectedCallback != null) {
                renderResult.notifyWhenRejected(renderRejectedCallback);
            }
            initialRenderQueue.add(new RenderAction<AsyncResult<DocumentInfo>>(psiFile.getProject(), psiFile.getViewProvider().getVirtualFile(), renderResult) {

                @Override
                protected boolean isNeedEdt() {
                    // ProgressManager requires dispatch thread
                    return true;
                }

                @Override
                protected void doRun() {
                    assert project != null;
                    if (project.isDisposed()) {
                        return;
                    }
                    assert file != null;
                    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
                    if (!(psiFile instanceof XmlFile)) {
                        return;
                    }
                    Module module = ModuleUtilCore.findModuleForFile(file, project);
                    if (module != null) {
                        renderDocument(module, (XmlFile) psiFile, debug, result);
                    }
                }
            });
        }
        if (handler != null) {
            renderResult.doWhenDone(handler);
        }
        renderResult.doWhenDone(createDocumentRenderedNotificationDoneHandler(false));
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Application(com.intellij.openapi.application.Application) AsyncResult(com.intellij.openapi.util.AsyncResult) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 5 with DocumentInfo

use of com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo in project intellij-plugins by JetBrains.

the class IncrementalDocumentSynchronizer method incrementalSync.

private boolean incrementalSync(final DocumentInfo info) {
    final XmlElementValueProvider valueProvider = findSupportedTarget();
    if (valueProvider == null) {
        return false;
    }
    XmlTag tag = (XmlTag) valueProvider.getElement().getParent();
    if (!(tag.getDescriptor() instanceof ClassBackedElementDescriptor)) {
        return false;
    }
    int componentId = info.rangeMarkerIndexOf(tag);
    if (componentId == -1) {
        return false;
    }
    final AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) valueProvider.getPsiMetaData();
    assert descriptor != null;
    final String typeName = descriptor.getTypeName();
    final String type = descriptor.getType();
    if (type == null) {
        return !typeName.equals(FlexAnnotationNames.EFFECT);
    } else if (type.equals(JSCommonTypeNames.FUNCTION_CLASS_NAME) || typeName.equals(FlexAnnotationNames.EVENT)) {
        return true;
    }
    final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter();
    //noinspection IOResourceOpenedButNotSafelyClosed
    final PrimitiveAmfOutputStream dataOut = new PrimitiveAmfOutputStream(new ByteArrayOutputStreamEx(16));
    PrimitiveWriter writer = new PrimitiveWriter(dataOut, stringWriter);
    boolean needRollbackStringWriter = true;
    try {
        if (descriptor.isAllowsPercentage()) {
            String value = valueProvider.getTrimmed();
            final boolean hasPercent;
            if (value.isEmpty() || ((hasPercent = value.endsWith("%")) && value.length() == 1)) {
                return true;
            }
            final String name;
            if (hasPercent) {
                name = descriptor.getPercentProxy();
                value = value.substring(0, value.length() - 1);
            } else {
                name = descriptor.getName();
            }
            stringWriter.write(name, dataOut);
            dataOut.writeAmfDouble(value);
        } else {
            stringWriter.write(descriptor.getName(), dataOut);
            if (!writer.writeIfApplicable(valueProvider, dataOut, descriptor)) {
                needRollbackStringWriter = false;
                stringWriter.rollback();
                return false;
            }
        }
        needRollbackStringWriter = false;
    } catch (InvalidPropertyException ignored) {
        return true;
    } catch (NumberFormatException ignored) {
        return true;
    } finally {
        if (needRollbackStringWriter) {
            stringWriter.rollback();
        }
    }
    Client.getInstance().updatePropertyOrStyle(info.getId(), componentId, stream -> {
        stringWriter.writeTo(stream);
        stream.write(descriptor.isStyle());
        dataOut.writeTo(stream);
    }).doWhenDone(() -> DesignerApplicationManager.createDocumentRenderedNotificationDoneHandler(true).consume(info));
    return true;
}
Also used : VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) FlexAnnotationNames(com.intellij.javascript.flex.FlexAnnotationNames) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) ByteArrayOutputStreamEx(com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx) XmlElementValueProvider(com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) FlexReferenceContributor(com.intellij.javascript.flex.FlexReferenceContributor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PrimitiveWriter(com.intellij.flex.uiDesigner.mxml.PrimitiveWriter) Nullable(org.jetbrains.annotations.Nullable) Update(com.intellij.util.ui.update.Update) JSCommonTypeNames(com.intellij.lang.javascript.psi.JSCommonTypeNames) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) com.intellij.psi(com.intellij.psi) XmlAttributeValueProvider(com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) XmlElementValueProvider(com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider) ByteArrayOutputStreamEx(com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) PrimitiveWriter(com.intellij.flex.uiDesigner.mxml.PrimitiveWriter) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)7 XmlFile (com.intellij.psi.xml.XmlFile)3 Document (com.intellij.openapi.editor.Document)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 AsyncResult (com.intellij.openapi.util.AsyncResult)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 StylesheetFile (com.intellij.psi.css.StylesheetFile)2 ByteArrayOutputStreamEx (com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx)1 PrimitiveAmfOutputStream (com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)1 StringRegistry (com.intellij.flex.uiDesigner.io.StringRegistry)1 MxmlUtil (com.intellij.flex.uiDesigner.mxml.MxmlUtil)1 PrimitiveWriter (com.intellij.flex.uiDesigner.mxml.PrimitiveWriter)1 XmlAttributeValueProvider (com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider)1 XmlElementValueProvider (com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 FlexAnnotationNames (com.intellij.javascript.flex.FlexAnnotationNames)1 FlexPredefinedTagNames (com.intellij.javascript.flex.FlexPredefinedTagNames)1 FlexReferenceContributor (com.intellij.javascript.flex.FlexReferenceContributor)1 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)1 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)1