Search in sources :

Example 11 with AccessToken

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

the class SpringLoadedPositionManagerFactory method usesSpringLoaded.

private static boolean usesSpringLoaded(@NotNull final DebugProcess process) {
    Boolean force = process.getProcessHandler().getUserData(FORCE_SPRINGLOADED);
    if (force == Boolean.TRUE)
        return true;
    try (AccessToken ignored = ApplicationManager.getApplication().acquireReadActionLock()) {
        JavaPsiFacade facade = JavaPsiFacade.getInstance(process.getProject());
        if (facade.findPackage("com.springsource.loaded") != null || facade.findPackage("org.springsource.loaded") != null) {
            return true;
        }
    }
    // Check spring loaded for remote process
    VirtualMachineProxy proxy = process.getVirtualMachineProxy();
    return !proxy.classesByName("com.springsource.loaded.agent.SpringLoadedAgent").isEmpty() || !proxy.classesByName("org.springsource.loaded.agent.SpringLoadedAgent").isEmpty();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) VirtualMachineProxy(com.intellij.debugger.engine.jdi.VirtualMachineProxy) AccessToken(com.intellij.openapi.application.AccessToken)

Example 12 with AccessToken

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

the class PsiVisitors method visit.

/**
   * Read action will be taken automatically
   */
public static <RESULT> RESULT visit(@NotNull XSourcePosition position, @NotNull Project project, @NotNull Visitor<RESULT> visitor, RESULT defaultResult) {
    AccessToken token = ReadAction.start();
    try {
        Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
        PsiFile file = document == null || document.getTextLength() == 0 ? null : PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (file == null) {
            return defaultResult;
        }
        int positionOffset;
        int column = position instanceof SourceInfo ? Math.max(((SourceInfo) position).getColumn(), 0) : 0;
        try {
            positionOffset = column == 0 ? DocumentUtil.getFirstNonSpaceCharOffset(document, position.getLine()) : document.getLineStartOffset(position.getLine()) + column;
        } catch (IndexOutOfBoundsException ignored) {
            return defaultResult;
        }
        PsiElement element = file.findElementAt(positionOffset);
        return element == null ? defaultResult : visitor.visit(position, element, positionOffset, document);
    } finally {
        token.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Document(com.intellij.openapi.editor.Document) ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement)

Example 13 with AccessToken

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

the class PluginBuildConfiguration method setManifestPath.

public void setManifestPath(@Nullable String manifestPath) {
    if (StringUtil.isEmpty(manifestPath)) {
        myManifestFilePointer = null;
        return;
    }
    VirtualFile manifest = LocalFileSystem.getInstance().findFileByPath(manifestPath);
    if (manifest == null) {
        Messages.showErrorDialog(myModule.getProject(), DevKitBundle.message("error.file.not.found.message", manifestPath), DevKitBundle.message("error.file.not.found"));
        AccessToken token = ReadAction.start();
        try {
            myManifestFilePointer = VirtualFilePointerManager.getInstance().create(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(manifestPath)), myModule, null);
        } finally {
            token.finish();
        }
    } else {
        AccessToken token = ReadAction.start();
        try {
            myManifestFilePointer = VirtualFilePointerManager.getInstance().create(manifest, myModule, null);
        } finally {
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AccessToken(com.intellij.openapi.application.AccessToken)

Example 14 with AccessToken

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

the class XSourcePositionImpl method create.

/**
   * do not call this method from plugins, use {@link XDebuggerUtil#createPosition(VirtualFile, int, int)} instead
   */
@Nullable
public static XSourcePositionImpl create(@Nullable VirtualFile file, int line, int column) {
    if (file == null) {
        return null;
    }
    AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        int offset;
        if (file instanceof LightVirtualFile || file instanceof HttpVirtualFile) {
            offset = -1;
        } else {
            Document document = file.isValid() ? FileDocumentManager.getInstance().getDocument(file) : null;
            if (document == null) {
                return null;
            }
            if (line < 0) {
                line = 0;
            }
            if (column < 0) {
                column = 0;
            }
            offset = line < document.getLineCount() ? document.getLineStartOffset(line) + column : -1;
            if (offset >= document.getTextLength()) {
                offset = document.getTextLength() - 1;
            }
        }
        return new XSourcePositionImpl(file, line, offset);
    } finally {
        lock.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with AccessToken

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

the class MigrateCvsRootAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final VcsContext context = CvsContextWrapper.createInstance(event);
    final VirtualFile selectedFile = context.getSelectedFile();
    final Project project = context.getProject();
    final MigrateRootDialog dialog = new MigrateRootDialog(project, selectedFile);
    if (!dialog.showAndGet()) {
        return;
    }
    final File directory = dialog.getSelectedDirectory();
    final boolean shouldReplaceAllRoots = dialog.shouldReplaceAllRoots();
    final List<File> rootFiles = new ArrayList<>();
    try {
        if (shouldReplaceAllRoots) {
            collectRootFiles(directory, null, rootFiles);
        } else {
            collectRootFiles(directory, dialog.getCvsRoot(), rootFiles);
        }
    } catch (IOException e) {
        LOG.error(e);
        return;
    }
    final CvsRootConfiguration cvsConfiguration = dialog.getSelectedCvsConfiguration();
    final String cvsRoot = cvsConfiguration.getCvsRootAsString();
    for (final File file : rootFiles) {
        try {
            FileUtils.writeLine(file, cvsRoot);
        } catch (IOException e) {
            LOG.error(e);
            break;
        }
    }
    final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        for (File file : rootFiles) {
            CvsVfsUtil.findFileByIoFile(file).refresh(true, false);
        }
    } finally {
        token.finish();
    }
    StatusBar.Info.set("Finished migrating CVS root to " + cvsRoot, project);
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) MigrateRootDialog(com.intellij.cvsSupport2.ui.MigrateRootDialog) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) CvsRootConfiguration(com.intellij.cvsSupport2.config.CvsRootConfiguration)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 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 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3