Search in sources :

Example 31 with AccessToken

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

the class ExpressionBinding method resolveReferenceExpression.

@NotNull
private static PsiElement resolveReferenceExpression(JSReferenceExpression expression, boolean qualificatorSupported) throws InvalidPropertyException {
    if (!qualificatorSupported) {
        checkQualifier(expression);
    }
    final AccessToken token = ReadAction.start();
    final PsiElement element;
    try {
        element = expression.resolve();
    } finally {
        token.finish();
    }
    if (element == null) {
        throw new InvalidPropertyException(expression, "unresolved.variable.or.type", expression.getReferencedName());
    }
    return element;
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with AccessToken

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

the class SocketInputHandlerImpl method setProperty.

private void setProperty() throws IOException {
    final Project project = readProject();
    final DocumentFactoryManager.DocumentInfo info = DocumentFactoryManager.getInstance().getInfo(reader.readUnsignedShort());
    final XmlFile psiFile = virtualFileToXmlFile(project, info.getElement());
    final XmlTag rootTag = psiFile.getRootTag();
    assert rootTag != null;
    final int offset = info.getRangeMarker(reader.readInt()).getStartOffset() - rootTag.getStartOffsetInParent();
    final Document document = FileDocumentManager.getInstance().getDocument(info.getElement());
    assert document != null;
    final String name = reader.readUTF();
    final String value;
    switch(reader.read()) {
        case Amf3Types.TRUE:
            value = "true";
            break;
        case Amf3Types.FALSE:
            value = "false";
            break;
        case Amf3Types.STRING:
            value = reader.readUTF();
            break;
        default:
            throw new IllegalArgumentException("unknown value type");
    }
    final XmlTag tag;
    final AccessToken token = ReadAction.start();
    try {
        tag = PsiTreeUtil.getParentOfType(rootTag.findElementAt(offset), XmlTag.class);
        assert tag != null;
    } finally {
        token.finish();
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        WriteAction.run(() -> tag.setAttribute(name, value));
        info.documentModificationStamp = document.getModificationStamp();
    });
}
Also used : Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) AccessToken(com.intellij.openapi.application.AccessToken) Document(com.intellij.openapi.editor.Document) XmlTag(com.intellij.psi.xml.XmlTag)

Example 33 with AccessToken

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

the class MavenImportingTestCase method getModule.

protected Module getModule(final 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 34 with AccessToken

use of com.intellij.openapi.application.AccessToken in project sonarlint-intellij by SonarSource.

the class SonarLintAnalyzer method getInputFiles.

private List<ClientInputFile> getInputFiles(Module module, VirtualFileTestPredicate testPredicate, Collection<VirtualFile> filesToAnalyze) {
    List<ClientInputFile> inputFiles = new LinkedList<>();
    AccessToken token = app.acquireReadActionLock();
    try {
        for (VirtualFile f : filesToAnalyze) {
            boolean test = testPredicate.test(f);
            Charset charset = getEncoding(f);
            String relativePath = SonarLintUtils.getPortableRelativePath(module.getProject(), f);
            if (fileDocumentManager.isFileModified(f)) {
                inputFiles.add(new DefaultClientInputFile(f, relativePath, test, charset, fileDocumentManager.getDocument(f)));
            } else {
                inputFiles.add(new DefaultClientInputFile(f, relativePath, test, charset));
            }
        }
    } finally {
        token.finish();
    }
    return inputFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) Charset(java.nio.charset.Charset) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) LinkedList(java.util.LinkedList)

Example 35 with AccessToken

use of com.intellij.openapi.application.AccessToken in project sonarlint-intellij by SonarSource.

the class SonarClearIssuesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (project != null) {
        IssueManager issueManager = SonarLintUtils.get(project, IssueManager.class);
        DaemonCodeAnalyzer codeAnalyzer = SonarLintUtils.get(project, DaemonCodeAnalyzer.class);
        AccessToken token = ReadAction.start();
        try {
            issueManager.clear();
            // run annotator to remove highlighting of issues
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            VirtualFile[] openFiles = editorManager.getOpenFiles();
            Collection<PsiFile> psiFiles = findFiles(project, openFiles);
            psiFiles.forEach(codeAnalyzer::restart);
        } finally {
            // closeable only introduced in 2016.2
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) IssueManager(org.sonarlint.intellij.issue.IssueManager) AccessToken(com.intellij.openapi.application.AccessToken) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) PsiFile(com.intellij.psi.PsiFile)

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