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;
}
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();
});
}
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();
}
}
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;
}
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();
}
}
}
Aggregations