Пример #1
0
    @Override
    public JavaContentAssistInvocationContext apply(IInvocationContext context) {
      ICompilationUnit cu = context.getCompilationUnit();
      int offset = context.getSelectionOffset();
      try {
        cu.codeComplete(
            offset,
            new CompletionRequestor() {
              @Override
              public void acceptContext(CompletionContext context) {
                internalContext = context;
              }

              @Override
              public boolean isExtendedContextRequired() {
                return true;
              }

              @Override
              public void accept(CompletionProposal proposal) {}
            });
      } catch (JavaModelException e) {
        propagate(e);
      }

      JavaEditor editor = cast(EditorUtility.isOpenInEditor(cu));
      ISourceViewer viewer = editor.getViewer();
      return new JavaContentAssistInvocationContext(viewer, offset, editor) {

        @Override
        public CompletionContext getCoreContext() {
          return internalContext;
        }
      };
    }
 private IJavaCompletionProposal[] createJavaClassesProposals(String prefix)
     throws JavaModelException {
   if (prefix != null && !Utils.isEmpty(prefix.trim())) {
     CompletionProposalCollector collector = new CompletionProposalCollector(this.getProject());
     ICompilationUnit unit = getTemporaryCompilationUnit(this.getProject());
     String source = TEMPORAL_CLASS_START + prefix + "}}";
     setContentsToCU(unit, source);
     unit.codeComplete(source.length() - 2, collector, DefaultWorkingCopyOwner.PRIMARY);
     IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
     return proposals;
   } else {
     return new IJavaCompletionProposal[] {};
   }
 }
  private CompilationUnitCompletion getCompletion() {
    ICompilationUnit compilationUnit = getCompilationUnit();
    if (fCompletion == null) {
      fCompletion = new CompilationUnitCompletion(compilationUnit);

      if (compilationUnit != null) {
        try {
          compilationUnit.codeComplete(getStart(), fCompletion);
        } catch (JavaModelException e) {
          // ignore
        }
      }
    }

    return fCompletion;
  }