Exemple #1
0
 public JavaElementToken(
     String rep,
     String doc,
     String args,
     String parentPackage,
     int type,
     IJavaElement javaElement,
     CompletionProposal completionProposal) {
   super(rep, doc, args, parentPackage, type, null);
   this.javaElement = javaElement;
   this.completionProposalKind = completionProposal.getKind();
   this.completionProposalFlags = completionProposal.getFlags();
   if (HAS_ADDITIONAL_FLAGS) {
     this.completionProposalAdditionalFlags = completionProposal.getAdditionalFlags();
   }
   this.completionPropsoalSignature = completionProposal.getSignature();
 }
 @Override
 public void process(IProcessableProposal proposal) {
   CompletionProposal cProposal = proposal.getCoreProposal().or(NULL_PROPOSAL);
   switch (cProposal.getKind()) {
     case CompletionProposal.METHOD_DECLARATION:
       final String signature = String.valueOf(cProposal.getSignature()).replace('.', '/');
       final String name = String.valueOf(cProposal.getName());
       final String propSignature = (name + signature).replaceAll("<\\.>", "");
       for (final OverridesRecommendation r : recommendations) {
         final String recSignature = r.method.getSignature();
         if (recSignature.equals(propSignature)) {
           final int percentage = (int) rint(r.probability * 100);
           int increment = 100 + percentage << 3;
           String label = percentage + "%";
           ProposalProcessorManager mgr = proposal.getProposalProcessorManager();
           mgr.addProcessor(new SimpleProposalProcessor(increment, label));
         }
       }
   }
 }
Exemple #3
0
  @Override
  public Image getImage() {
    if (this.image != null) {
      return this.image;
    }
    CompletionProposalLabelProvider provider = new CompletionProposalLabelProvider();
    CompletionProposal generatedProposal = CompletionProposal.create(completionProposalKind, 0);
    generatedProposal.setFlags(completionProposalFlags);
    if (HAS_ADDITIONAL_FLAGS) {
      generatedProposal.setAdditionalFlags(completionProposalAdditionalFlags);
    }
    generatedProposal.setDeclarationSignature(completionPropsoalSignature);
    generatedProposal.setSignature(completionPropsoalSignature);

    // uses: kind, flags, signature to create an image.
    ImageDescriptor descriptor = provider.createImageDescriptor(generatedProposal);
    return descriptor.createImage();
  }
 /**
  * Computes all of the Javadoc completion proposals
  *
  * @param jcontext
  * @param corecontext
  * @return the complete list of Javadoc completion proposals or an empty list, never <code>null
  *     </code>
  * @since 1.0.500
  */
 List<ICompletionProposal> computeJavadocProposals(
     JavaContentAssistInvocationContext jcontext, CompletionContext corecontext) {
   ICompilationUnit cunit = jcontext.getCompilationUnit();
   if (cunit != null) {
     try {
       int offset = jcontext.getInvocationOffset();
       IJavaElement element = cunit.getElementAt(offset);
       if (!isVisible(element)) {
         return Collections.EMPTY_LIST;
       }
       ImageDescriptor imagedesc =
           jcontext
               .getLabelProvider()
               .createImageDescriptor(
                   org.eclipse.jdt.core.CompletionProposal.create(
                       org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset));
       fImageHandle = (imagedesc == null ? null : imagedesc.createImage());
       int type = getType(element);
       int member = IApiJavadocTag.MEMBER_NONE;
       switch (element.getElementType()) {
         case IJavaElement.METHOD:
           {
             IMethod method = (IMethod) element;
             member = IApiJavadocTag.MEMBER_METHOD;
             if (method.isConstructor()) {
               member = IApiJavadocTag.MEMBER_CONSTRUCTOR;
             }
             break;
           }
         case IJavaElement.FIELD:
           {
             member = IApiJavadocTag.MEMBER_FIELD;
             break;
           }
         default:
           break;
       }
       IApiJavadocTag[] tags = ApiPlugin.getJavadocTagManager().getTagsForType(type, member);
       int tagcount = tags.length;
       if (tagcount > 0) {
         ArrayList<ICompletionProposal> list = null;
         collectExistingTags(element, jcontext);
         String completiontext = null;
         int tokenstart = corecontext.getTokenStart();
         int length = offset - tokenstart;
         for (int i = 0; i < tagcount; i++) {
           if (!acceptTag(tags[i], element)) {
             continue;
           }
           completiontext = tags[i].getCompleteTag(type, member);
           if (appliesToContext(
               jcontext.getDocument(), completiontext, tokenstart, (length > 0 ? length : 1))) {
             if (list == null) {
               list = new ArrayList<ICompletionProposal>(tagcount - i);
             }
             list.add(
                 new APIToolsJavadocCompletionProposal(
                     corecontext, completiontext, tags[i].getTagName(), fImageHandle));
           }
         }
         if (list != null) {
           return list;
         }
       }
     } catch (JavaModelException e) {
       fErrorMessage = e.getMessage();
     }
   }
   return Collections.EMPTY_LIST;
 }
  public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    Position[] positions = null;
    FormatterPrefs formatterPrefs = getFormatterPrefs();
    StringBuffer buffer = new StringBuffer();

    buffer.append(fProposal.getName());

    if (formatterPrefs.beforeOpeningParen) buffer.append(SPACE);

    buffer.append(LPAREN);

    if (formatterPrefs.afterOpeningParen) buffer.append(SPACE);

    if (Signature.getParameterCount(fProposal.getSignature()) > 0) {
      char[][] parameters = fProposal.findParameterNames(null);
      if (parameters != null) {
        positions = new Position[parameters.length];

        int base = getReplacementOffset();
        for (int i = 0; i < parameters.length; i++) {
          if (i != 0) {
            if (formatterPrefs.beforeComma) buffer.append(SPACE);

            buffer.append(COMMA);

            if (formatterPrefs.afterComma) buffer.append(SPACE);
          }
          Position position = new Position(0, 0);
          position.setOffset(base + buffer.length());
          position.setLength(parameters[i].length);
          positions[i] = position;
          buffer.append(parameters[i]);
        }
      }
    }

    if (formatterPrefs.beforeClosingParen) buffer.append(SPACE);

    buffer.append(RPAREN);
    setReplacementString(buffer.toString());

    super.apply(viewer, trigger, stateMask, offset);

    try {
      if (positions != null) {
        LinkedModeModel model = new LinkedModeModel();

        for (int i = 0; i < positions.length; i++) {
          LinkedPositionGroup group = new LinkedPositionGroup();
          Position position = positions[i];
          group.addPosition(
              new LinkedPosition(
                  viewer.getDocument(), position.getOffset(), position.getLength(), i));
          model.addGroup(group);
        }
        model.forceInstall();

        LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
        ui.setExitPosition(
            viewer, getReplacementOffset() + getReplacementString().length(), 0, Integer.MAX_VALUE);
        ui.setExitPolicy(new ExitPolicy(')', viewer.getDocument()));
        ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
        ui.setDoContextInfo(true);
        ui.enter();
        fSelectedRegion = ui.getSelectedRegion();
      }
    } catch (BadLocationException e) {

    }
  }