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