Package com.intellij.openapi.application

Examples of com.intellij.openapi.application.AccessToken


  }

  @Override
  protected void moveOffsetAfter(boolean success) {
    RangeMarker exprMarker = getExprMarker();
    final AccessToken accessToken = WriteAction.start();
    try {
      Document document = myEditor.getDocument();
      // todo restore original expression if not success
      PsiDocumentManager.getInstance(myProject).commitDocument(document);
      if (exprMarker != null && exprMarker.isValid()) {
        myEditor.getCaretModel().moveToOffset(exprMarker.getStartOffset());
        myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
        exprMarker.dispose();
      }
    } finally {
      accessToken.finish();
    }
  }
View Full Code Here


                                                 final PsiElement[] elements,
                                                 final DartControlFlow controlFlow,
                                                 final Scope scope) {
    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
      public void run() {
        AccessToken l = WriteAction.start();
        try {
          doRefactoring(editor, elements, controlFlow, scope);
        }
        finally {
          l.finish();
        }
      }
    }, DartBundle.message("dart.extract.method"), null);
  }
View Full Code Here

    }
    return false;
  }

  private static Language getElementLanguage(final CompletionParameters parameters) {
    final AccessToken l = ReadAction.start();
    try {
      return PsiUtilCore.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset());
    } finally {
      l.finish();
    }
  }
View Full Code Here

    ProgressManager.getInstance().run(new Task.Modal(myRunConfiguration.getProject(), "Preparing bundles...", false) {
      @Override
      public void run(@NotNull ProgressIndicator progressIndicator) {
        progressIndicator.setIndeterminate(false);

        AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
          Set<SelectedBundle> selectedBundles = new HashSet<SelectedBundle>();
          // the bundles are module names, by now we try to find jar files in the output directory which we can then install
          ModuleManager moduleManager = ModuleManager.getInstance(myRunConfiguration.getProject());
          int bundleCount = myRunConfiguration.getBundlesToDeploy().size();
          for (int i = 0; i < bundleCount; i++) {
            progressIndicator.setFraction((double)i / bundleCount);

            SelectedBundle selectedBundle = myRunConfiguration.getBundlesToDeploy().get(i);
            if (selectedBundle.isModule()) {
              // use the output jar name if it is a module
              String name = selectedBundle.getName();
              Module module = moduleManager.findModuleByName(name);
              if (module == null) {
                throw new CantRunException("Module '" + name + "' no longer exists. Please check your run configuration.");
              }
              OsmorcFacet facet = OsmorcFacet.getInstance(module);
              if (facet == null) {
                throw new CantRunException("Module '" + name + "' has no OSGi facet. Please check your run configuration.");
              }
              selectedBundle.setBundlePath(facet.getConfiguration().getJarFileLocation());
              selectedBundles.add(selectedBundle);
              // add all the library dependencies of the bundle
              List<String> paths = new BundleCompiler().bundlifyLibraries(module, progressIndicator);
              for (String path : paths) {
                selectedBundles.add(new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "Dependency", path));
              }
            }
            else {
              if (selectedBundles.contains(selectedBundle)) {
                // if the user selected a dependency as runnable library, we need to replace the dependency with
                // the runnable library part
                selectedBundles.remove(selectedBundle);
              }
              selectedBundles.add(selectedBundle);
            }
          }

          // filter out bundles which have the same symbolic name
          Map<String, SelectedBundle> filteredBundles = new HashMap<String, SelectedBundle>();
          for (SelectedBundle selectedBundle : selectedBundles) {
            String path = selectedBundle.getBundlePath();
            if (path != null) {
              String name = CachingBundleInfoProvider.getBundleSymbolicName(path);
              String version = CachingBundleInfoProvider.getBundleVersion(path);
              String key = name + version;
              if (!filteredBundles.containsKey(key)) {
                filteredBundles.put(key, selectedBundle);
              }
            }
          }

          List<SelectedBundle> sortedBundles = ContainerUtil.newArrayList(filteredBundles.values());
          Collections.sort(sortedBundles, START_LEVEL_COMPARATOR);
          result.set(sortedBundles);
        }
        catch (CantRunException e) {
          error.set(e);
        }
        catch (OsgiBuildException e) {
          LOG.warn(e);
          error.set(new CantRunException(e.getMessage()));
        }
        catch (Throwable t) {
          LOG.error(t);
          error.set(new CantRunException("Internal error: " + t.getMessage()));
        }
        finally {
          token.finish();
        }
      }
    });

    if (!result.isNull()) {
View Full Code Here

    throw new NoDataException();
  }

  private int getLineNumber(PsiElement element, String parserClass, int currentLine) {
    int line = 0;
    AccessToken token = ReadAction.start();
    try {
      BnfRule rule = PsiTreeUtil.getParentOfType(element, BnfRule.class);
      PsiClass aClass = JavaPsiFacade.getInstance(myProcess.getProject()).findClass(parserClass, myProcess.getSearchScope());
      Document document = aClass != null? PsiDocumentManager.getInstance(myProcess.getProject()).getDocument(aClass.getContainingFile()) : null;
      if (rule != null && document != null) {
        return getLineNumber(aClass, document, currentLine, rule, element);
      }
    }
    finally {
      token.finish();
    }
    return line;
  }
View Full Code Here

    return myProcess.getRequestsManager().createClassPrepareRequest(requestor, getParserClass(position));
  }

  @NotNull
  private String getParserClass(SourcePosition classPosition) throws NoDataException {
    AccessToken token = ReadAction.start();
    try {
      BnfRule rule = getRuleAt(classPosition);
      String parserClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.PARSER_CLASS);
      if (StringUtil.isEmpty(parserClass)) throw new NoDataException();
      return parserClass;
    }
    finally {
      token.finish();
    }
  }
View Full Code Here

      final String prefix = docBuilder.toString();
      if (!ParserGeneratorUtil.Rule.isMeta(rule)) {
        updateDocPopup(rule, new Getter<String>() {
          @Override
          public String get() {
            AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
            try {
              return getUpdatedDocumentation(rule, prefix);
            }
            finally {
              accessToken.finish();
            }
          }
        });
      }
      return prefix;
View Full Code Here

    return "Create rule from usage";
  }

  @Override
  public void applyFix(final @NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final AccessToken token = WriteAction.start();
    try {
      final PsiElement element = descriptor.getPsiElement();
      final BnfRule rule = PsiTreeUtil.getParentOfType(element, BnfRule.class);
      if (rule == null) return;

      final BnfRule addedRule = BnfIntroduceRuleHandler.addNextRule(project, rule, "private " + myName + " ::= ");
      final FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor(rule.getContainingFile().getVirtualFile());
      if (selectedEditor instanceof TextEditor) {
        final Editor editor = ((TextEditor)selectedEditor).getEditor();
        editor.getCaretModel().moveToOffset(addedRule.getTextRange().getEndOffset() - (BnfIntroduceRuleHandler.endsWithSemicolon(addedRule)? 1 : 0));
        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
      }
    }
    finally {
      token.finish();
    }
  }
View Full Code Here

      VfsRootAccess.allowRootAccess(absolutePath);
    }
    else {
      VfsRootAccess.disallowRootAccess(absolutePath);
    }
    AccessToken accessToken = ApplicationManager.getApplication().acquireWriteActionLock(null);
    try {
      ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
      String supportUrl = getUrl(testDataPath + "/../../support");
      String genUrl = getUrl(testDataPath + "/../../gen");
      if (add) {
        model.addContentEntry(supportUrl).addSourceFolder(supportUrl, false);
        model.addContentEntry(genUrl).addSourceFolder(genUrl, false);
      }
      else {
        for (ContentEntry entry : model.getContentEntries()) {
          if (supportUrl.equals(entry.getUrl()) || genUrl.equals(entry.getUrl())) {
            model.removeContentEntry(entry);
          }
        }
      }
      model.commit();
    }
    finally {
      accessToken.finish();
    }
    assertTrue("GrammarKit src problem", add == (null != facade.findPackage("org.intellij.grammar.psi")));
  }
View Full Code Here

    @Override
    public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
      ErlangModule module = PsiTreeUtil.getParentOfType(problemDescriptor.getPsiElement(), ErlangModule.class);
      if (module == null) return;
      AccessToken token = WriteAction.start();
      String name;
      try {
        ErlangElementFactory.createQAtomFromText(project, myShouldBeName);
        name = myShouldBeName;
      } catch (Exception e) {
        name = "'" + myShouldBeName + "'";
      }
      try {
        module.setName(name);
      } finally {
        token.finish();
      }
    }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.application.AccessToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.