Search in sources :

Example 46 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class Client method writeDocumentFactory.

/**
   * You must rollback block out if this method returns false
   */
private boolean writeDocumentFactory(DocumentInfo documentInfo, Module module, XmlFile psiFile, ProblemsHolder problemsHolder) throws IOException {
    final AccessToken token = ReadAction.start();
    final int flags;
    try {
        final JSClass jsClass = XmlBackedJSClassFactory.getXmlBackedClass(psiFile);
        assert jsClass != null;
        out.writeAmfUtf(jsClass.getQualifiedName());
        if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.SPARK_APPLICATION) || ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.MX_APPLICATION)) {
            flags = 1;
        } else if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.IUI_COMPONENT)) {
            flags = 0;
        } else {
            flags = 2;
        }
    } finally {
        token.finish();
    }
    out.write(flags);
    Pair<ProjectComponentReferenceCounter, List<RangeMarker>> result = new MxmlWriter(out, problemsHolder, registeredModules.getInfo(module).getFlexLibrarySet().assetCounterInfo.demanded).write(psiFile);
    if (result == null) {
        return false;
    }
    blockOut.end();
    documentInfo.setRangeMarkers(result.second);
    return result.first.unregistered.isEmpty() || registerDocumentReferences(result.first.unregistered, module, problemsHolder);
}
Also used : ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) MxmlWriter(com.intellij.flex.uiDesigner.mxml.MxmlWriter) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 47 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class FlexAutoImportsTest method getIntentions.

private List<IntentionAction> getIntentions(final String fileName, final String hint) throws Throwable {
    List<IntentionAction> list = ContainerUtil.findAll(myFixture.getAvailableIntentions(fileName), intentionAction -> intentionAction.getText().startsWith(hint));
    final AccessToken l = ReadAction.start();
    try {
        Document document = myFixture.getEditor().getDocument();
        int offset = myFixture.getEditor().getCaretModel().getOffset();
        int line = document.getLineNumber(offset);
        boolean hasHint = !DaemonCodeAnalyzerEx.processHighlights(document, getProject(), HighlightSeverity.ERROR, document.getLineStartOffset(line), document.getLineEndOffset(line), info -> !info.hasHint());
        if (!hasHint) {
            fail("Auto import fix not found: " + DaemonCodeAnalyzerImpl.getHighlights(document, HighlightSeverity.INFORMATION, getProject()));
        }
    } finally {
        l.finish();
    }
    return list;
}
Also used : VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) JSTestOption(com.intellij.lang.javascript.JSTestOption) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) ContainerUtil(com.intellij.util.containers.ContainerUtil) DaemonCodeAnalyzerEx(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx) ReadAction(com.intellij.openapi.application.ReadAction) FlexModuleFixtureBuilderImpl(com.intellij.flex.util.FlexModuleFixtureBuilderImpl) AccessToken(com.intellij.openapi.application.AccessToken) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) JSUnresolvedVariableInspection(com.intellij.lang.javascript.inspections.JSUnresolvedVariableInspection) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) FlexModuleFixtureBuilder(com.intellij.flex.util.FlexModuleFixtureBuilder) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) CodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) List(java.util.List) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) AccessToken(com.intellij.openapi.application.AccessToken) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) Document(com.intellij.openapi.editor.Document)

Example 48 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class MxmlWriter method write.

@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
    document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
    final AccessToken token = ReadAction.start();
    try {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        problemsHolder.setCurrentFile(virtualFile);
        XmlTag tag = psiFile.getRootTag();
        XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
        final ClassBackedElementDescriptor descriptor;
        if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
            descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
        } else {
            return null;
        }
        final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
        try {
            PsiElement declaration = descriptor.getDeclaration();
            if (declaration == null) {
                return null;
            }
            effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
        } catch (InvalidPropertyException e) {
            problemsHolder.add(e);
            return null;
        }
        if (effectiveClassInfo.first == -1) {
            out.write(Amf3Types.OBJECT);
            writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
        } else {
            writer.documentReference(effectiveClassInfo.first);
            out.allocateClearShort();
        }
        processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
        writer.endObject();
        if (stateWriter != null) {
            stateWriter.write();
            hasStates = false;
        } else {
            out.write(0);
        }
        injectedASWriter.write();
        writer.writeMessageHeader(projectComponentReferenceCounter);
        return Pair.create(projectComponentReferenceCounter, rangeMarkers);
    } finally {
        token.finish();
        problemsHolder.setCurrentFile(null);
        writer.resetAfterMessage();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Condition(com.intellij.openapi.util.Condition) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class XSourcePositionImpl method createByOffset.

/**
   * do not call this method from plugins, use {@link XDebuggerUtil#createPositionByOffset(VirtualFile, int)} instead
   */
@Nullable
public static XSourcePositionImpl createByOffset(@Nullable VirtualFile file, final int offset) {
    if (file == null)
        return null;
    AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        Document document = FileDocumentManager.getInstance().getDocument(file);
        if (document == null) {
            return null;
        }
        int line = DocumentUtil.isValidOffset(offset, document) ? document.getLineNumber(offset) : -1;
        return new XSourcePositionImpl(file, line, offset);
    } finally {
        lock.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.

the class RefreshWorker method fullDirRefresh.

private void fullDirRefresh(NewVirtualFileSystem fs, PersistentFS persistence, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
    while (true) {
        // obtaining directory snapshot
        String[] currentNames;
        VirtualFile[] children;
        AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            currentNames = persistence.list(dir);
            children = dir.getChildren();
        } finally {
            token.finish();
        }
        // reading children attributes
        String[] upToDateNames = VfsUtil.filterNames(fs.list(dir));
        Set<String> newNames = newTroveSet(strategy, upToDateNames);
        ContainerUtil.removeAll(newNames, currentNames);
        Set<String> deletedNames = newTroveSet(strategy, currentNames);
        ContainerUtil.removeAll(deletedNames, upToDateNames);
        OpenTHashSet<String> actualNames = null;
        if (!fs.isCaseSensitive()) {
            actualNames = new OpenTHashSet<>(strategy, upToDateNames);
        }
        if (LOG.isTraceEnabled())
            LOG.trace("current=" + Arrays.toString(currentNames) + " +" + newNames + " -" + deletedNames);
        List<Pair<String, FileAttributes>> addedMap = ContainerUtil.newArrayListWithCapacity(newNames.size());
        for (String name : newNames) {
            checkCancelled(dir);
            addedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
        }
        List<Pair<VirtualFile, FileAttributes>> updatedMap = ContainerUtil.newArrayListWithCapacity(children.length);
        for (VirtualFile child : children) {
            if (deletedNames.contains(child.getName()))
                continue;
            checkCancelled(dir);
            updatedMap.add(pair(child, fs.getAttributes(child)));
        }
        // generating events unless a directory was changed in between
        token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            if (!Arrays.equals(currentNames, persistence.list(dir)) || !Arrays.equals(children, dir.getChildren())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("retry: " + dir);
                continue;
            }
            for (String name : deletedNames) {
                scheduleDeletion(dir.findChild(name));
            }
            for (Pair<String, FileAttributes> pair : addedMap) {
                String name = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    scheduleCreation(dir, name, childAttributes.isDirectory(), false);
                } else {
                    LOG.warn("[+] fs=" + fs + " dir=" + dir + " name=" + name);
                }
            }
            for (Pair<VirtualFile, FileAttributes> pair : updatedMap) {
                VirtualFile child = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    checkAndScheduleChildRefresh(dir, child, childAttributes);
                    checkAndScheduleFileNameChange(actualNames, child);
                } else {
                    LOG.warn("[x] fs=" + fs + " dir=" + dir + " name=" + child.getName());
                    scheduleDeletion(child);
                }
            }
            break;
        } finally {
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Pair(com.intellij.openapi.util.Pair)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)89 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)12 Document (com.intellij.openapi.editor.Document)10 Project (com.intellij.openapi.project.Project)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)8 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 PsiFile (com.intellij.psi.PsiFile)3 List (java.util.List)3 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2