Search in sources :

Example 81 with AccessToken

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

the class PyClassInheritorsSearchExecutor method processDirectInheritors.

private static boolean processDirectInheritors(final PyClass superClass, final Processor<PyClass> consumer, final boolean checkDeep, final Set<PyClass> processed) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        final String superClassName = superClass.getName();
        // we don't want to look for inheritors of overly general classes
        if (superClassName == null || IGNORED_BASES.contains(superClassName))
            return true;
        if (processed.contains(superClass))
            return true;
        processed.add(superClass);
        Project project = superClass.getProject();
        final Collection<PyClass> candidates = StubIndex.getElements(PySuperClassIndex.KEY, superClassName, project, ProjectScope.getAllScope(project), PyClass.class);
        for (PyClass candidate : candidates) {
            final PyClass[] classes = candidate.getSuperClasses(null);
            for (PyClass superClassCandidate : classes) {
                if (superClassCandidate.isEquivalentTo(superClass)) {
                    if (!consumer.process(candidate)) {
                        return false;
                    }
                    if (checkDeep && !processDirectInheritors(candidate, consumer, checkDeep, processed))
                        return false;
                    break;
                }
            }
        }
    } finally {
        accessToken.finish();
    }
    return true;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken)

Example 82 with AccessToken

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

the class StartBrowserPanel method virtualFileToUrl.

@Nullable
private static Url virtualFileToUrl(@NotNull VirtualFile file, @NotNull Project project) {
    PsiFile psiFile;
    AccessToken token = ReadAction.start();
    try {
        psiFile = PsiManager.getInstance(project).findFile(file);
    } finally {
        token.finish();
    }
    return WebBrowserServiceImpl.getDebuggableUrl(psiFile);
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with AccessToken

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

the class VfsTestUtil method createFileOrDir.

private static VirtualFile createFileOrDir(VirtualFile root, String relativePath, String text, boolean dir) {
    try {
        AccessToken token = WriteAction.start();
        try {
            VirtualFile parent = root;
            Assert.assertNotNull(parent);
            StringTokenizer parents = new StringTokenizer(PathUtil.getParentPath(relativePath), "/");
            while (parents.hasMoreTokens()) {
                String name = parents.nextToken();
                VirtualFile child = parent.findChild(name);
                if (child == null || !child.isValid()) {
                    child = parent.createChildDirectory(VfsTestUtil.class, name);
                }
                parent = child;
            }
            VirtualFile file;
            //need this to ensure that fileCreated event is fired
            parent.getChildren();
            if (dir) {
                file = parent.createChildDirectory(VfsTestUtil.class, PathUtil.getFileName(relativePath));
            } else {
                file = parent.findFileByRelativePath(relativePath);
                if (file == null) {
                    file = parent.createChildData(VfsTestUtil.class, PathUtil.getFileName(relativePath));
                }
                VfsUtil.saveText(file, text);
            }
            return file;
        } finally {
            token.finish();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringTokenizer(com.intellij.util.text.StringTokenizer) AccessToken(com.intellij.openapi.application.AccessToken) IOException(java.io.IOException)

Example 84 with AccessToken

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

the class ExternalSystemImportingTestCase method getModule.

@Override
protected Module getModule(String name) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        Module m = ModuleManager.getInstance(myProject).findModuleByName(name);
        assertNotNull("Module " + name + " not found", m);
        return m;
    } finally {
        accessToken.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 85 with AccessToken

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

the class PyDebugProcess method runToPosition.

@Override
public void runToPosition(@NotNull final XSourcePosition position, @Nullable XSuspendContext context) {
    dropFrameCaches();
    if (isConnected() && !mySuspendedThreads.isEmpty()) {
        final PySourcePosition pyPosition = myPositionConverter.convertToPython(position);
        String type = PyLineBreakpointType.ID;
        AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            final Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
            if (document != null) {
                for (XBreakpointType breakpointType : Extensions.getExtensions(XBreakpointType.EXTENSION_POINT_NAME)) {
                    if (breakpointType instanceof PyBreakpointType && ((PyBreakpointType) breakpointType).canPutInDocument(getSession().getProject(), document)) {
                        type = breakpointType.getId();
                        break;
                    }
                }
            }
        } finally {
            lock.finish();
        }
        myDebugger.setTempBreakpoint(type, pyPosition.getFile(), pyPosition.getLine());
        passToCurrentThread(context, ResumeOrStepCommand.Mode.RESUME);
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Document(com.intellij.openapi.editor.Document)

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