Пример #1
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   monitor.beginTask("Warming up completion processor", 100000);
   Set<Module> modules =
       typeChecker
           .getPhasedUnits()
           .getModuleManager()
           .getContext()
           .getModules()
           .getListOfModules();
   monitor.worked(10000);
   for (Module m : modules) {
     List<Package> packages = m.getAllPackages();
     for (Package p : packages) {
       p.getMembers();
     }
     monitor.worked(90000 / max(modules.size(), 1));
     if (monitor.isCanceled()) {
       return Status.CANCEL_STATUS;
     }
   }
   monitor.done();
   return Status.OK_STATUS;
 }
    @Override
    public void apply(IDocument document) {
      super.apply(document);
      if (withBody && EditorsUI.getPreferenceStore().getBoolean(LINKED_MODE)) {
        final LinkedModeModel linkedModeModel = new LinkedModeModel();
        final Point selection = getSelection(document);
        List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
        for (final Declaration d : p.getMembers()) {
          if (Util.isResolvable(d) && d.isShared()) {
            proposals.add(
                new ICompletionProposal() {
                  @Override
                  public Point getSelection(IDocument document) {
                    return null;
                  }

                  @Override
                  public Image getImage() {
                    return getImageForDeclaration(d);
                  }

                  @Override
                  public String getDisplayString() {
                    return d.getName();
                  }

                  @Override
                  public IContextInformation getContextInformation() {
                    return null;
                  }

                  @Override
                  public String getAdditionalProposalInfo() {
                    return null;
                  }

                  @Override
                  public void apply(IDocument document) {
                    try {
                      document.replace(selection.x, selection.y, d.getName());
                    } catch (BadLocationException e) {
                      e.printStackTrace();
                    }
                    linkedModeModel.exit(ILinkedModeListener.UPDATE_CARET);
                  }
                });
          }
        }
        ProposalPosition linkedPosition =
            new ProposalPosition(
                document, selection.x, selection.y, 0, proposals.toArray(NO_COMPLETIONS));
        try {
          LinkedMode.addLinkedPosition(linkedModeModel, linkedPosition);
          LinkedMode.installLinkedMode(
              (CeylonEditor) EditorUtil.getCurrentEditor(),
              document,
              linkedModeModel,
              this,
              new LinkedMode.NullExitPolicy(),
              -1,
              0);
        } catch (BadLocationException ble) {
          ble.printStackTrace();
        }
      }
    }