Java 类org.eclipse.jdt.core.CompletionProposal 实例源码

项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Creates and returns a parameter list of the given method or type proposal suitable for
 * display. The list does not include parentheses. The lower bound of parameter types is
 * returned.
 * <p>
 * Examples:
 *
 * <pre>
 *   &quot;void method(int i, String s)&quot; -&gt; &quot;int i, String s&quot;
 *   &quot;? extends Number method(java.lang.String s, ? super Number n)&quot; -&gt; &quot;String s, Number n&quot;
 * </pre>
 *
 * </p>
 *
 * @param proposal the proposal to create the parameter list for
 * @return the list of comma-separated parameters suitable for display
 */
public StringBuilder createParameterList(CompletionProposal proposal) {
    int kind= proposal.getKind();
    switch (kind) {
    case CompletionProposal.METHOD_REF:
    case CompletionProposal.CONSTRUCTOR_INVOCATION:
        return appendUnboundedParameterList(new StringBuilder(), proposal);
    case CompletionProposal.TYPE_REF:
    case CompletionProposal.JAVADOC_TYPE_REF:
        return appendTypeParameterList(new StringBuilder(), proposal);
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
    case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
        return appendUnboundedParameterList(new StringBuilder(), proposal);
    default:
        Assert.isLegal(false);
        return null; // dummy
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) {
    // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
    // gets fixed.
    char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
    char[][] parameterNames= methodProposal.findParameterNames(null);
    char[][] parameterTypes= Signature.getParameterTypes(signature);

    for (int i= 0; i < parameterTypes.length; i++) {
        parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
    }

    if (Flags.isVarargs(methodProposal.getFlags())) {
        int index= parameterTypes.length - 1;
        parameterTypes[index]= convertToVararg(parameterTypes[index]);
    }
    return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
    char[] declaringTypeSignature= proposal.getDeclarationSignature();
    declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
    String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
    item.setInsertText(name);
    StringBuilder buf= new StringBuilder();
    buf.append(name);
    buf.append('(');
    appendUnboundedParameterList(buf, proposal);
    buf.append(')');
    buf.append("  "); //$NON-NLS-1$
    buf.append("Anonymous Inner Type"); //TODO: consider externalization
    item.setLabel(buf.toString());

    if (proposal.getRequiredProposals() != null) {
        char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
        if (signatureQualifier.length > 0) {
            item.setDetail(String.valueOf(signatureQualifier));
        }
    }
    setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
项目:eclipse.jdt.ls    文件:CompletionProposalRequestor.java   
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
    try {
        IJavaElement enclosingElement = null;
        if (response.getContext().isExtended()) {
            enclosingElement = response.getContext().getEnclosingElement();
        } else if (unit != null) {
            // kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
            enclosingElement = unit.getElementAt(proposal.getCompletionLocation() + 1);
        }
        if (enclosingElement == null) {
            return;
        }
        IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
        if (type != null) {
            String prefix = String.valueOf(proposal.getName());
            int completionStart = proposal.getReplaceStart();
            int completionEnd = proposal.getReplaceEnd();
            int relevance = proposal.getRelevance() + 6;

            GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, proposals);
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Accept potential method declaration failed for completion ", e);
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalReplacementProvider.java   
/**
 * @param completionBuffer
 * @param proposal
 */
private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) {
    IDocument document;
    try {
        document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
        String signature = String.valueOf(proposal.getSignature());
        String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t))
                .toArray(String[]::new);
        String methodName = String.valueOf(proposal.getName());
        int offset = proposal.getReplaceStart();
        String completion = new String(proposal.getCompletion());
        OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types,
                completion);
        String replacement = overrider.updateReplacementString(document, offset, importRewrite,
                client.isCompletionSnippetsSupported());
        completionBuffer.append(replacement);
    } catch (BadLocationException | CoreException e) {
        JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalReplacementProvider.java   
private void appendMethodNameReplacement(StringBuilder buffer, CompletionProposal proposal) {
    if (proposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
        String coreCompletion = String.valueOf(proposal.getCompletion());
        if (client.isCompletionSnippetsSupported()) {
            coreCompletion = CompletionUtils.sanitizeCompletion(coreCompletion);
        }
        //          String lineDelimiter = TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument());
        //          String replacement= CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, coreCompletion, 0, lineDelimiter, fInvocationContext.getProject());
        //          buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1));
        buffer.append(coreCompletion);
    }

    if (proposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION) {
        String str = new String(proposal.getName());
        if (client.isCompletionSnippetsSupported()) {
            str = CompletionUtils.sanitizeCompletion(str);
        }
        buffer.append(str);
    }

}
项目:eclipse.jdt.ls    文件:CompletionProposalReplacementProvider.java   
private void appendGuessingCompletion(StringBuilder buffer, CompletionProposal proposal) {
    char[][] parameterNames= proposal.findParameterNames(null);

    int count= parameterNames.length;

    if(client.isCompletionSnippetsSupported()){
        for (int i= 0; i < count; i++) {
            if (i != 0) {
                buffer.append(COMMA);
                buffer.append(SPACE);
            }
            char[] argument = parameterNames[i];
            if (client.isCompletionSnippetsSupported()) {
                String replace = new String(argument);
                replace = CompletionUtils.sanitizeCompletion(replace);
                argument = replace.toCharArray();
            }
            buffer.append("${");
            buffer.append(Integer.toString(i+1));
            buffer.append(":");
            buffer.append(argument);
            buffer.append("}");
        }
    }
}
项目:che    文件:CompletionProposalLabelProvider.java   
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StyledString appendUnboundedParameterList(
    StyledString buffer, CompletionProposal methodProposal) {
  // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
  // gets fixed.
  char[] signature = SignatureUtil.fix83600(methodProposal.getSignature());
  char[][] parameterNames = methodProposal.findParameterNames(null);
  char[][] parameterTypes = Signature.getParameterTypes(signature);

  for (int i = 0; i < parameterTypes.length; i++)
    parameterTypes[i] = createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));

  if (Flags.isVarargs(methodProposal.getFlags())) {
    int index = parameterTypes.length - 1;
    parameterTypes[index] = convertToVararg(parameterTypes[index]);
  }
  return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
项目:che    文件:JavaContentAssistInvocationContext.java   
/**
 * Fallback to retrieve a core context and keyword proposals when no collector is available. Runs
 * code completion on the cu and collects keyword proposals. {@link #fKeywordProposals} is non-
 * <code>null</code> after this call.
 *
 * @since 3.3
 */
private void computeKeywordsAndContext() {
  ICompilationUnit cu = getCompilationUnit();
  if (cu == null) {
    if (fKeywordProposals == null) fKeywordProposals = new IJavaCompletionProposal[0];
    return;
  }

  CompletionProposalCollector collector = new CompletionProposalCollector(cu, true);
  collector.setIgnored(CompletionProposal.KEYWORD, false);

  try {
    cu.codeComplete(getInvocationOffset(), collector);
    if (fCoreContext == null) fCoreContext = collector.getContext();
    if (fKeywordProposals == null) fKeywordProposals = collector.getKeywordCompletionProposals();
    if (fLabelProvider == null) fLabelProvider = collector.getLabelProvider();
  } catch (JavaModelException x) {
    if (!x.isDoesNotExist()
        || cu.getJavaProject() == null
        || cu.getJavaProject().isOnClasspath(cu)) JavaPlugin.log(x);
    if (fKeywordProposals == null) fKeywordProposals = new IJavaCompletionProposal[0];
  }
}
项目:vsminecraft    文件:JavaParser.java   
private List<AutocompleteResponse.Completion> Autocomplete(ITypeRoot cu, int cursorPosition) throws JavaModelException 
{
    final List<AutocompleteResponse.Completion> proposals = new ArrayList<AutocompleteResponse.Completion>();
    cu.codeComplete(cursorPosition, new CompletionRequestor()
    {
        @Override
        public void accept(CompletionProposal proposal) {
            try
            {
                System.out.println(proposal.toString());
                proposals.add(translateToCompletion(proposal));
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    });     
    return proposals;
}
项目:che    文件:CompletionProposalCollector.java   
/**
 * Returns the replacement length of a given completion proposal. The replacement length is
 * usually the difference between the return values of <code>proposal.getReplaceEnd</code> and
 * <code>proposal.getReplaceStart</code>, but this behavior may be overridden by calling {@link
 * #setReplacementLength(int)}.
 *
 * @param proposal the completion proposal to get the replacement length for
 * @return the replacement length for <code>proposal</code>
 */
protected final int getLength(CompletionProposal proposal) {
  int start = proposal.getReplaceStart();
  int end = proposal.getReplaceEnd();
  int length;
  if (fUserReplacementLength == -1) {
    length = end - start;
  } else {
    length = fUserReplacementLength;
    // extend length to begin at start
    int behindCompletion = proposal.getCompletionLocation() + 1;
    if (start < behindCompletion) {
      length += behindCompletion - start;
    }
  }
  return length;
}
项目:che    文件:CompletionProposalCollector.java   
private IJavaCompletionProposal createAnnotationAttributeReferenceProposal(
    CompletionProposal proposal) {
  StyledString displayString = fLabelProvider.createLabelWithTypeAndDeclaration(proposal);
  ImageDescriptor descriptor = fLabelProvider.createMethodImageDescriptor(proposal);
  String completion = String.valueOf(proposal.getCompletion());
  JavaCompletionProposal javaProposal =
      new JavaCompletionProposal(
          completion,
          proposal.getReplaceStart(),
          getLength(proposal),
          getImage(descriptor),
          displayString,
          computeRelevance(proposal));
  if (fJavaProject != null)
    javaProposal.setProposalInfo(new AnnotationAtttributeProposalInfo(fJavaProject, proposal));
  return javaProposal;
}
项目:che    文件:CompilationUnitCompletion.java   
/**
 * Creates a compilation unit completion.
 *
 * @param unit the compilation unit, may be <code>null</code>.
 */
CompilationUnitCompletion(ICompilationUnit unit) {
  reset(unit);
  setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, true);
  setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, true);
  setIgnored(CompletionProposal.KEYWORD, true);
  setIgnored(CompletionProposal.LABEL_REF, true);
  setIgnored(CompletionProposal.METHOD_DECLARATION, true);
  setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, true);
  setIgnored(CompletionProposal.METHOD_REF, true);
  setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, true);
  setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, true);
  setIgnored(CompletionProposal.PACKAGE_REF, true);
  setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, true);
  setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
  setIgnored(CompletionProposal.TYPE_REF, true);
}
项目:che    文件:CompilationUnitCompletion.java   
@Override
public void accept(CompletionProposal proposal) {

  String name = String.valueOf(proposal.getCompletion());
  String signature = String.valueOf(proposal.getSignature());

  switch (proposal.getKind()) {
    case CompletionProposal.LOCAL_VARIABLE_REF:
      // collect local variables
      fLocalVariables.add(new Variable(name, signature));
      break;
    case CompletionProposal.FIELD_REF:
      // collect local variables
      fFields.add(new Variable(name, signature));
      break;

    default:
      break;
  }
}
项目:gwt-eclipse-plugin    文件:ProposalGeneratingCompletionRequestor.java   
private void ignoreAll() {
  int[] ignoredKinds = new int[] {
      CompletionProposal.ANONYMOUS_CLASS_DECLARATION,
      CompletionProposal.FIELD_REF, CompletionProposal.KEYWORD,
      CompletionProposal.LABEL_REF, CompletionProposal.LOCAL_VARIABLE_REF,
      CompletionProposal.METHOD_REF, CompletionProposal.METHOD_DECLARATION,
      CompletionProposal.PACKAGE_REF, CompletionProposal.TYPE_REF,
      CompletionProposal.VARIABLE_DECLARATION,
      CompletionProposal.POTENTIAL_METHOD_DECLARATION,
      CompletionProposal.METHOD_NAME_REFERENCE,
      CompletionProposal.ANNOTATION_ATTRIBUTE_REF,
      CompletionProposal.JAVADOC_FIELD_REF,
      CompletionProposal.JAVADOC_METHOD_REF,
      CompletionProposal.JAVADOC_TYPE_REF,
      CompletionProposal.JAVADOC_VALUE_REF,
      CompletionProposal.JAVADOC_PARAM_REF,
      CompletionProposal.JAVADOC_BLOCK_TAG,
      CompletionProposal.JAVADOC_INLINE_TAG, CompletionProposal.FIELD_IMPORT,
      CompletionProposal.METHOD_IMPORT, CompletionProposal.TYPE_IMPORT};

  for (int kind : ignoredKinds) {
    setIgnored(kind, true);
  }
}
项目:che    文件:JavaTypeCompletionProposalComputer.java   
private IJavaCompletionProposal createTypeProposal(
    int relevance, String fullyQualifiedType, JavaContentAssistInvocationContext context)
    throws JavaModelException {
  IType type = context.getCompilationUnit().getJavaProject().findType(fullyQualifiedType);
  if (type == null) return null;

  CompletionProposal proposal =
      CompletionProposal.create(CompletionProposal.TYPE_REF, context.getInvocationOffset());
  proposal.setCompletion(fullyQualifiedType.toCharArray());
  proposal.setDeclarationSignature(type.getPackageFragment().getElementName().toCharArray());
  proposal.setFlags(type.getFlags());
  proposal.setRelevance(relevance);
  proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset());
  proposal.setSignature(Signature.createTypeSignature(fullyQualifiedType, true).toCharArray());

  if (shouldProposeGenerics(context.getProject()))
    return new LazyGenericTypeProposal(proposal, context);
  else return new LazyJavaTypeCompletionProposal(proposal, context);
}
项目:che    文件:AbstractJavaCompletionProposal.java   
/**
 * Tells whether required proposals are supported by this proposal.
 *
 * @return <code>true</code> if required proposals are supported by this proposal
 * @see org.eclipse.jdt.core.CompletionProposal#getRequiredProposals()
 * @since 3.3
 */
protected boolean isSupportingRequiredProposals() {
  if (fInvocationContext == null) return false;

  ProposalInfo proposalInfo = getProposalInfo();
  if (!(proposalInfo instanceof MemberProposalInfo
      || proposalInfo instanceof AnonymousTypeProposalInfo)) return false;

  CompletionProposal proposal = ((MemberProposalInfo) proposalInfo).fProposal;
  return proposal != null
      && (proposal.getKind() == CompletionProposal.METHOD_REF
          || proposal.getKind() == CompletionProposal.FIELD_REF
          || proposal.getKind() == CompletionProposal.TYPE_REF
          || proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION
          || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION);
}
项目:gwt-eclipse-plugin    文件:ProposalGeneratingCompletionRequestor.java   
protected ICompletionProposal createProposal(CompletionProposal javaProposal) {
  String completion = String.valueOf(javaProposal.getCompletion());
  int kind = javaProposal.getKind();
  if (kind == CompletionProposal.TYPE_REF) {
    // Make sure it is fully qualified
    completion = JavaContentAssistUtilities.getFullyQualifiedTypeName(javaProposal);
  }

  if (forceFullyQualifiedFieldNames
      && (kind == CompletionProposal.FIELD_IMPORT || kind == CompletionProposal.FIELD_REF)) {
    char[] decSig = javaProposal.getDeclarationSignature();
    if (decSig != null && decSig.length > 2) {
      // declaration signatures for objects are like Ljava.lang.String;, so lop off first
      // and last chars
      completion = new String(decSig, 1, decSig.length - 2) + "."
          + new String(javaProposal.getCompletion());
      completion = completion.replace('$', '.');
    }
  }

  ICompletionProposal jdtCompletionProposal = JavaContentAssistUtilities.getJavaCompletionProposal(
      javaProposal, context, javaProject);
  return ReplacementCompletionProposal.fromExistingCompletionProposal(completion,
      replaceOffset, replaceLength, jdtCompletionProposal);
}
项目:che    文件:JavaAllCompletionProposalComputer.java   
@Override
protected CompletionProposalCollector createCollector(
    JavaContentAssistInvocationContext context) {
  CompletionProposalCollector collector = super.createCollector(context);
  collector.setIgnored(CompletionProposal.ANNOTATION_ATTRIBUTE_REF, false);
  collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, false);
  collector.setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, false);
  collector.setIgnored(CompletionProposal.FIELD_REF, false);
  collector.setIgnored(CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER, false);
  collector.setIgnored(CompletionProposal.KEYWORD, false);
  collector.setIgnored(CompletionProposal.LABEL_REF, false);
  collector.setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, false);
  collector.setIgnored(CompletionProposal.METHOD_DECLARATION, false);
  collector.setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, false);
  collector.setIgnored(CompletionProposal.METHOD_REF, false);
  collector.setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, false);
  collector.setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, false);
  collector.setIgnored(CompletionProposal.PACKAGE_REF, false);
  collector.setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, false);
  collector.setIgnored(CompletionProposal.VARIABLE_DECLARATION, false);
  collector.setIgnored(CompletionProposal.TYPE_REF, false);
  return collector;
}
项目:gwt-eclipse-plugin    文件:ProposalComputerFactory.java   
/**
 * Creates a proposal computer for autocompleting the UiBinder root element
 * URN import scheme. For example, <ui:UiBinder
 * xmlns:g="urn:import:com.google.gwt._" />
 */
public static IProposalComputer newUrnImportProposalComputer(
    ContentAssistRequest contentAssistRequest, IJavaProject javaProject) {
  IDOMAttr attribute = XmlContentAssistUtilities.getAttribute(contentAssistRequest);
  if (attribute == null) {
    return null;
  }

  String attrValue = XmlContentAssistUtilities.getAttributeValueUsingMatchString(contentAssistRequest);
  if (!UiBinderXmlModelUtilities.isUrnImportAttribute(attribute)) {
    return null;
  }

  int urnImportLength = UiBinderConstants.URN_IMPORT_NAMESPACE_BEGINNING.length();
  if (attrValue.length() < urnImportLength) {
    return null;
  }

  String replaceText = attrValue.substring(urnImportLength);
  int replaceOffset = XmlContentAssistUtilities.getAttributeValueOffset(contentAssistRequest)
      + urnImportLength;

  return new CodeCompleteProposalComputer(
      new int[]{CompletionProposal.PACKAGE_REF}, javaProject, replaceText,
      replaceOffset, replaceText.length(), null, false);
}
项目:che    文件:JavaMethodCompletionProposal.java   
@Override
protected IContextInformation computeContextInformation() {
  // no context information for METHOD_NAME_REF proposals (e.g. for static imports)
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654
  if ((fProposal.getKind() == CompletionProposal.METHOD_REF
          || fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION)
      && hasParameters()
      && (getReplacementString().endsWith(RPAREN)
          || getReplacementString().endsWith(SEMICOLON)
          || getReplacementString().length() == 0)) {
    ProposalContextInformation contextInformation = new ProposalContextInformation(fProposal);
    if (fContextInformationPosition != 0 && fProposal.getCompletion().length == 0)
      contextInformation.setContextInformationPosition(fContextInformationPosition);
    return contextInformation;
  }
  return super.computeContextInformation();
}
项目:gwt-eclipse-plugin    文件:JsniCompletionProposalCollector.java   
@Override
protected IJavaCompletionProposal createJavaCompletionProposal(
    CompletionProposal proposal) {
  IJavaCompletionProposal defaultProposal = super.createJavaCompletionProposal(proposal);

  // For members of inner classes, there's a bug in the JDT which results in
  // the declaration signature of the proposal missing the outer classes, so
  // we have to manually set the signature instead.
  if (proposal.getKind() == CompletionProposal.METHOD_REF
      || proposal.getKind() == CompletionProposal.FIELD_REF) {
    char[] typeSignature = Signature.createTypeSignature(qualifiedTypeName,
        true).toCharArray();
    proposal.setDeclarationSignature(typeSignature);
  }

  return JsniCompletionProposal.create(defaultProposal, proposal,
      getCompilationUnit().getJavaProject(), refOffset, refLength);
}
项目:che    文件:JavaMethodCompletionProposal.java   
@Override
protected boolean isValidPrefix(String prefix) {
  if (super.isValidPrefix(prefix)) return true;

  String word = TextProcessor.deprocess(getDisplayString());
  if (fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION) {
    int start =
        word.indexOf(JavaElementLabels.CONCAT_STRING) + JavaElementLabels.CONCAT_STRING.length();
    word = word.substring(start);
    return isPrefix(prefix, word) || isPrefix(prefix, new String(fProposal.getName()));
  }

  if (isInJavadoc()) {
    int idx = word.indexOf("{@link "); // $NON-NLS-1$
    if (idx == 0) {
      word = word.substring(7);
    } else {
      idx = word.indexOf("{@value "); // $NON-NLS-1$
      if (idx == 0) {
        word = word.substring(8);
      }
    }
  }
  return isPrefix(prefix, word);
}
项目:che    文件:JavadocCompletionProposalComputer.java   
@Override
protected CompletionProposalCollector createCollector(
    JavaContentAssistInvocationContext context) {
  CompletionProposalCollector collector = super.createCollector(context);
  collector.setIgnored(CompletionProposal.JAVADOC_TYPE_REF, false);
  collector.setIgnored(CompletionProposal.JAVADOC_FIELD_REF, false);
  collector.setIgnored(CompletionProposal.JAVADOC_METHOD_REF, false);
  collector.setIgnored(CompletionProposal.JAVADOC_PARAM_REF, false);
  collector.setIgnored(CompletionProposal.JAVADOC_VALUE_REF, false);
  collector.setIgnored(CompletionProposal.JAVADOC_BLOCK_TAG, false);
  collector.setIgnored(CompletionProposal.JAVADOC_INLINE_TAG, false);
  collector.setIgnored(CompletionProposal.TYPE_REF, false);
  collector.setIgnored(CompletionProposal.FIELD_REF, false);
  collector.setIgnored(CompletionProposal.METHOD_REF, false);
  return collector;
}
项目:che    文件:FillArgumentNamesCompletionProposalCollector.java   
IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) {
  final ICompilationUnit cu = getCompilationUnit();
  if (cu == null || getContext() != null && getContext().isInJavadoc())
    return super.createJavaCompletionProposal(typeProposal);

  IJavaProject project = cu.getJavaProject();
  if (!shouldProposeGenerics(project)) return super.createJavaCompletionProposal(typeProposal);

  char[] completion = typeProposal.getCompletion();
  // don't add parameters for import-completions nor for proposals with an empty completion (e.g.
  // inside the type argument list)
  if (completion.length > 0
      && (completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.'))
    return super.createJavaCompletionProposal(typeProposal);

  LazyJavaCompletionProposal newProposal =
      new LazyGenericTypeProposal(typeProposal, getInvocationContext());
  return newProposal;
}
项目:che    文件:AnonymousTypeCompletionProposal.java   
protected IContextInformation computeContextInformation() {
  try {
    fContextInformationPosition = getReplacementOffset() - 1;

    CompletionProposal proposal = ((MemberProposalInfo) getProposalInfo()).fProposal;
    // no context information for METHOD_NAME_REF proposals (e.g. for static imports)
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654
    if (hasParameters()
        && (getReplacementString().endsWith(")")
            || getReplacementString().length() == 0)) { // $NON-NLS-1$
      ProposalContextInformation contextInformation = new ProposalContextInformation(proposal);
      fContextInformationPosition = getReplacementOffset() + getCursorPosition();
      if (fContextInformationPosition != 0 && proposal.getCompletion().length == 0)
        contextInformation.setContextInformationPosition(fContextInformationPosition);
      return contextInformation;
    }
    return null;
  } finally {
    fIsContextInformationComputed = true;
  }
}
项目:lombok-ianchiu    文件:PatchExtensionMethodCompletionProposal.java   
private static void createAndAddJavaCompletionProposal(CompletionProposalCollector completionProposalCollector, CompletionProposal newProposal,
        List<IJavaCompletionProposal> proposals) {

    try {
        proposals.add((IJavaCompletionProposal) Reflection.createJavaCompletionProposalMethod.invoke(completionProposalCollector, newProposal));
    } catch (Exception ignore) {
        // ignore
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Creates and returns the method signature suitable for display.
 *
 * @param proposal
 *            the proposal to create the description for
 * @return the string of method signature suitable for display
 */
public StringBuilder createMethodProposalDescription(CompletionProposal proposal) {
    int kind = proposal.getKind();
    StringBuilder description = new StringBuilder();
    switch (kind) {
        case CompletionProposal.METHOD_REF:
        case CompletionProposal.METHOD_NAME_REFERENCE:
        case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
        case CompletionProposal.CONSTRUCTOR_INVOCATION:

            // method name
            description.append(proposal.getName());

            // parameters
            description.append('(');
            appendUnboundedParameterList(description, proposal);
            description.append(')');

            // return type
            if (!proposal.isConstructor()) {
                // TODO remove SignatureUtil.fix83600 call when bugs are fixed
                char[] returnType = createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(proposal.getSignature()))));
                description.append(RETURN_TYPE_SEPARATOR);
                description.append(returnType);
            }
    }
    return description; // dummy
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Appends the type parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param typeProposal the type proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendTypeParameterList(StringBuilder buffer, CompletionProposal typeProposal) {
    // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
    // gets fixed.
    char[] signature= SignatureUtil.fix83600(typeProposal.getSignature());
    char[][] typeParameters= Signature.getTypeArguments(signature);
    for (int i= 0; i < typeParameters.length; i++) {
        char[] param= typeParameters[i];
        typeParameters[i]= Signature.toCharArray(param);
    }
    return appendParameterSignature(buffer, typeParameters, null);
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Updates a display label for the given method proposal to item. The display label
 * consists of:
 * <ul>
 *   <li>the method name</li>
 *   <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
 *   <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
 *   <li>the raw simple name of the declaring type</li>
 * </ul>
 * <p>
 * Examples:
 * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
 * display name is returned: <code>get(int index)  Number - List</code>.<br>
 * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
 * display name is returned: <code>add(Number o)  void - List</code>.<br>
 * </p>
 *
 * @param methodProposal the method proposal to display
 * @param item to update
 */
private void createMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
    StringBuilder description = this.createMethodProposalDescription(methodProposal);
    item.setLabel(description.toString());
    item.setInsertText(String.valueOf(methodProposal.getName()));

    // declaring type
    StringBuilder typeInfo = new StringBuilder();
    String declaringType= extractDeclaringTypeFQN(methodProposal);

    if (methodProposal.getRequiredProposals() != null) {
        String qualifier= Signature.getQualifier(declaringType);
        if (qualifier.length() > 0) {
            typeInfo.append(qualifier);
            typeInfo.append('.');
        }
    }

    declaringType= Signature.getSimpleName(declaringType);
    typeInfo.append(declaringType);
    item.setDetail(typeInfo.toString());

    setSignature(item, String.valueOf(methodProposal.getSignature()));
    setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
    setName(item, String.valueOf(methodProposal.getName()));

}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private void createOverrideMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
    StringBuilder nameBuffer= new StringBuilder();

    // method name
    String name = new String(methodProposal.getName());
    item.setInsertText(name);
    nameBuffer.append(name);
    // parameters
    nameBuffer.append('(');
    appendUnboundedParameterList(nameBuffer, methodProposal);
    nameBuffer.append(')');

    nameBuffer.append(RETURN_TYPE_SEPARATOR);

    // return type
    // TODO remove SignatureUtil.fix83600 call when bugs are fixed
    char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
    nameBuffer.append(returnType);
    item.setLabel(nameBuffer.toString());
    item.setFilterText(name);

    // declaring type
    StringBuilder typeBuffer = new StringBuilder();
    String declaringType= extractDeclaringTypeFQN(methodProposal);
    declaringType= Signature.getSimpleName(declaringType);
    typeBuffer.append(String.format("Override method in '%s'", declaringType));
    item.setDetail(typeBuffer.toString());

    setSignature(item, String.valueOf(methodProposal.getSignature()));
    setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
    setName(item, String.valueOf(methodProposal.getName()));
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Extracts the fully qualified name of the declaring type of a method
 * reference.
 *
 * @param methodProposal a proposed method
 * @return the qualified name of the declaring type
 */
private String extractDeclaringTypeFQN(CompletionProposal methodProposal) {
    char[] declaringTypeSignature= methodProposal.getDeclarationSignature();
    // special methods may not have a declaring type: methods defined on arrays etc.
    // TODO remove when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
    if (declaringTypeSignature == null)
    {
        return OBJECT;
    }
    return SignatureUtil.stripSignatureToFQN(String.valueOf(declaringTypeSignature));
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private void createSimpleLabelWithType(CompletionProposal proposal, CompletionItem item) {
    StringBuilder nameBuffer= new StringBuilder();
    nameBuffer.append(proposal.getCompletion());
    item.setInsertText(nameBuffer.toString());
    char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
    if (typeName.length > 0) {
        nameBuffer.append(VAR_TYPE_SEPARATOR);
        nameBuffer.append(typeName);
    }
    item.setLabel(nameBuffer.toString());
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private void createLabelWithTypeAndDeclaration(CompletionProposal proposal, CompletionItem item) {
    char[] name= proposal.getCompletion();
    if (!isThisPrefix(name)) {
        name= proposal.getName();
    }
    StringBuilder buf= new StringBuilder();

    buf.append(name);
    item.setInsertText(buf.toString());
    char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
    if (typeName.length > 0) {
        buf.append(VAR_TYPE_SEPARATOR);
        buf.append(typeName);
    }
    item.setLabel(buf.toString());

    char[] declaration= proposal.getDeclarationSignature();
    if (declaration != null) {
        setDeclarationSignature(item, String.valueOf(declaration));
        StringBuilder declBuf = new StringBuilder();
        declaration= Signature.getSignatureSimpleName(declaration);
        if (declaration.length > 0) {
            if (proposal.getRequiredProposals() != null) {
                String declaringType= extractDeclaringTypeFQN(proposal);
                String qualifier= Signature.getQualifier(declaringType);
                if (qualifier.length() > 0) {
                    declBuf.append(qualifier);
                    declBuf.append('.');
                }
            }
            declBuf.append(declaration);
            item.setDetail(declBuf.toString());
        }
    }
    setName(item,String.valueOf(name));
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
private String getProposal(CompletionProposal proposal) {
    try {
        for (Field field : CompletionProposal.class.getDeclaredFields()) {
            if (int.class.equals(field.getType()) && Integer.valueOf(proposal.getKind()).equals(field.get(null))) {
                return field.getName();
            }
        }
    } catch (Exception e) {
    }
    return "unknown";
}
项目:eclipse.jdt.ls    文件:CompletionProposalRequestor.java   
@Override
public void accept(CompletionProposal proposal) {
    if (!isIgnored(proposal.getKind())) {
        if (proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION) {
            acceptPotentialMethodDeclaration(proposal);
        } else {
            if (proposal.getKind() == CompletionProposal.PACKAGE_REF && unit.getParent() != null && String.valueOf(proposal.getCompletion()).equals(unit.getParent().getElementName())) {
                // Hacky way to boost relevance of current package, for package completions, until
                // https://bugs.eclipse.org/518140 is fixed
                proposal.setRelevance(proposal.getRelevance() + 1);
            }
            proposals.add(proposal);
        }
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalRequestor.java   
public CompletionItem toCompletionItem(CompletionProposal proposal, int index) {
    final CompletionItem $ = new CompletionItem();
    $.setKind(mapKind(proposal.getKind()));
    Map<String, String> data = new HashMap<>();
    // append data field so that resolve request can use it.
    data.put(CompletionResolveHandler.DATA_FIELD_URI,unit.getResource().getLocationURI().toString());
    data.put(CompletionResolveHandler.DATA_FIELD_REQUEST_ID,String.valueOf(response.getId()));
    data.put(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID,String.valueOf(index));
    $.setData(data);
    this.descriptionProvider.updateDescription(proposal, $);
    $.setSortText(SortTextHelper.computeSortText(proposal));
    return $;
}
项目:eclipse.jdt.ls    文件:CompletionProposalRequestor.java   
@Override
public void setIgnored(int completionProposalKind, boolean ignore) {
    super.setIgnored(completionProposalKind, ignore);
    if (completionProposalKind == CompletionProposal.METHOD_DECLARATION && !ignore) {
        setRequireExtendedContext(true);
    }
}
项目:eclipse.jdt.ls    文件:SortTextHelper.java   
/**
 * Computes the relevance for a given <code>CompletionProposal</code>.
 *
 * @param proposal the proposal to compute the relevance for
 * @return the relevance for <code>proposal</code>
 */
public static String computeSortText(CompletionProposal proposal) {
    final int baseRelevance= proposal.getRelevance() * 16;
    switch (proposal.getKind()) {
    case CompletionProposal.LABEL_REF:
        return convertRelevance( baseRelevance + 1);
    case CompletionProposal.KEYWORD:
        return convertRelevance(baseRelevance + 2);
    case CompletionProposal.TYPE_REF:
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
    case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
        return convertRelevance(baseRelevance + 3);
    case CompletionProposal.METHOD_REF:
    case CompletionProposal.CONSTRUCTOR_INVOCATION:
    case CompletionProposal.METHOD_NAME_REFERENCE:
    case CompletionProposal.METHOD_DECLARATION:
    case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
    case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
        return convertRelevance(baseRelevance + 4);
    case CompletionProposal.FIELD_REF:
        return convertRelevance(baseRelevance + 5);
    case CompletionProposal.LOCAL_VARIABLE_REF:
    case CompletionProposal.VARIABLE_DECLARATION:
        return convertRelevance(baseRelevance + 6);
    case CompletionProposal.PACKAGE_REF://intentional fall-through
    default:
        return convertRelevance(baseRelevance);
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalReplacementProvider.java   
private Range toReplacementRange(CompletionProposal proposal){
    try {
        return JDTUtils.toRange(compilationUnit, proposal.getReplaceStart(), proposal.getReplaceEnd()-proposal.getReplaceStart());
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}