Ejemplo n.º 1
0
 private Declaration getDirectMemberFromSource(String name) {
   for (Declaration d : super.getMembers()) {
     if (com.redhat.ceylon.compiler.typechecker.model.Util.isResolvable(d) /* && d.isShared() */
         && com.redhat.ceylon.compiler.typechecker.model.Util.isNamed(name, d)) {
       return d;
     }
   }
   return null;
 }
    @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();
        }
      }
    }