Tabnine Logo
CompletionProposal
Code IndexAdd Tabnine to your IDE (free)

How to use
CompletionProposal
in
org.eclipse.jdt.core

Best Java code snippets using org.eclipse.jdt.core.CompletionProposal (Showing top 20 results out of 315)

origin: eclipse/eclipse.jdt.ls

@Override
public void accept(CompletionProposal proposal) {
  if (proposal.getKind() == CompletionProposal.TYPE_REF) {
    addType(proposal.getSignature(), proposal.getFlags(), proposal.getRelevance());
  }
}
origin: eclipse/eclipse.jdt.ls

  @Override
  public void accept(CompletionProposal proposal) {
    if (elementName.equals(new String(proposal.getName()))) {
      CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
      for (int i= 0; i < requiredProposals.length; i++) {
        CompletionProposal curr= requiredProposals[i];
        if (curr.getKind() == CompletionProposal.METHOD_IMPORT || curr.getKind() == CompletionProposal.FIELD_IMPORT) {
          result.add(JavaModelUtil.concatenateName(Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
        }
      }
    }
  }
};
origin: org.eclipse.recommenders.completion.rcp/subwords

public static String getTokensBetweenLastWhitespaceAndFirstOpeningBracket(final CompletionProposal proposal) {
  boolean isPotentialMethodDecl = proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION;
  char[] token = proposal.getCompletion();
  if (Arrays.equals(token, new char[] { '(', ')' })) {
    token = proposal.getName();
  } else if (isPotentialMethodDecl && proposal.getCompletion().length == 0) {
    char[] signature = proposal.getDeclarationSignature();
    char[] typeName = Signature.getSignatureSimpleName(signature);
    return String.valueOf(typeName);
  }
  return getTokensBetweenLastWhitespaceAndFirstOpeningBracket(String.valueOf(token));
}
origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

@Override
protected boolean isOffsetValid(int offset) {
  if (fProposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION)
    return super.isOffsetValid(offset);
  return fProposal.getRequiredProposals()[0].getReplaceStart() <= offset;
}
origin: org.eclipse/org.eclipse.jdt.ui

protected int computeRelevance() {
  final int baseRelevance= fProposal.getRelevance() * 16;
  switch (fProposal.getKind()) {
    case CompletionProposal.PACKAGE_REF:
      return baseRelevance + 0;
    case CompletionProposal.LABEL_REF:
      return baseRelevance + 1;
    case CompletionProposal.KEYWORD:
      return baseRelevance + 2;
    case CompletionProposal.TYPE_REF:
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
      return baseRelevance + 3;
    case CompletionProposal.METHOD_REF:
    case CompletionProposal.METHOD_NAME_REFERENCE:
    case CompletionProposal.METHOD_DECLARATION:
    case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
      return baseRelevance + 4;
    case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
      return baseRelevance + 4 /* + 99 */;
    case CompletionProposal.FIELD_REF:
      return baseRelevance + 5;
    case CompletionProposal.LOCAL_VARIABLE_REF:
    case CompletionProposal.VARIABLE_DECLARATION:
      return baseRelevance + 6;
    default:
      return baseRelevance;
  }
}

origin: org.eclipse.jdt/org.eclipse.jdt.core

private void printDebug(CompletionProposal proposal, int tab, StringBuffer buffer){
  printDebugTab(tab, buffer);
  buffer.append("COMPLETION - "); //$NON-NLS-1$
  switch(proposal.getKind()) {
    case CompletionProposal.ANONYMOUS_CLASS_DECLARATION :
      buffer.append("ANONYMOUS_CLASS_DECLARATION"); //$NON-NLS-1$
  buffer.append("\tCompletion[").append(proposal.getCompletion() == null ? "null".toCharArray() : proposal.getCompletion()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  printDebugTab(tab, buffer);
  buffer.append("\tDeclarationSignature[").append(proposal.getDeclarationSignature() == null ? "null".toCharArray() : proposal.getDeclarationSignature()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  printDebugTab(tab, buffer);
  buffer.append("\tDeclarationKey[").append(proposal.getDeclarationKey() == null ? "null".toCharArray() : proposal.getDeclarationKey()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  printDebugTab(tab, buffer);
  buffer.append("\tSignature[").append(proposal.getSignature() == null ? "null".toCharArray() : proposal.getSignature()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  printDebugTab(tab, buffer);
  buffer.append("\tKey[").append(proposal.getKey() == null ? "null".toCharArray() : proposal.getKey()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  printDebugTab(tab, buffer);
  buffer.append("\tName[").append(proposal.getName() == null ? "null".toCharArray() : proposal.getName()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  int flags = proposal.getFlags();
  buffer.append(Flags.toString(flags));
  if((flags & Flags.AccInterface) != 0) buffer.append("interface ");//$NON-NLS-1$
  CompletionProposal[] proposals = proposal.getRequiredProposals();
  if(proposals != null) {
    printDebugTab(tab, buffer);
  buffer.append("\tCompletionLocation[").append(proposal.getCompletionLocation()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
  int start = proposal.getReplaceStart();
  int end = proposal.getReplaceEnd();
origin: org.eclipse.jdt/org.eclipse.jdt.ui

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);
}
origin: org.eclipse.recommenders.completion/rcp

public ProcessableAnonymousTypeCompletionProposal(CompletionProposal coreProposal, JavaCompletionProposal uiProposal,
    JavaContentAssistInvocationContext context) throws JavaModelException {
  super(context.getProject(), context.getCompilationUnit(), context, coreProposal.getReplaceStart(), uiProposal
      .getReplacementLength(), String.valueOf(coreProposal.getCompletion()), uiProposal
      .getStyledDisplayString(), String.valueOf(coreProposal.getDeclarationSignature()), (IType) context
      .getProject().findElement(String.valueOf(coreProposal.getDeclarationKey()), null), uiProposal
      .getRelevance());
  this.coreProposal = coreProposal;
}
origin: org.eclipse.jdt/org.eclipse.jdt.ui

/**
 * 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);
}
origin: org.eclipse/org.eclipse.jdt.debug.ui

protected boolean isFiltered(CompletionProposal proposal) {
  if (proposal.getKind() == CompletionProposal.LOCAL_VARIABLE_REF) {
    if (Arrays.equals(proposal.getName(), fgHiddenLocal)) {
      return true;
    }
  }
  return super.isFiltered(proposal);
}
origin: eclipse/eclipse.jdt.ls

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);
  }
}
origin: eclipse/eclipse.jdt.ls

@Override
public void accept(CompletionProposal proposal) {
  if (!isIgnored(proposal.getKind())) {
    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);
  }
}
origin: eclipse/eclipse.jdt.ls

private void createPackageProposalLabel(CompletionProposal proposal, CompletionItem item) {
  Assert.isTrue(proposal.getKind() == CompletionProposal.PACKAGE_REF || proposal.getKind() == CompletionProposal.MODULE_REF || proposal.getKind() == CompletionProposal.MODULE_DECLARATION);
  item.setLabel(String.valueOf(proposal.getDeclarationSignature()));
}
origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private IJavaCompletionProposal createMethodDeclarationProposal(CompletionProposal proposal) {
  if (fCompilationUnit == null || fJavaProject == null)
    return null;
  String name= String.valueOf(proposal.getName());
  String[] paramTypes= Signature.getParameterTypes(String.valueOf(proposal.getSignature()));
  for (int index= 0; index < paramTypes.length; index++)
    paramTypes[index]= Signature.toString(paramTypes[index]);
  int start= proposal.getReplaceStart();
  int length= getLength(proposal);
  StyledString label= fLabelProvider.createOverrideMethodProposalLabel(proposal);
  JavaCompletionProposal javaProposal= new OverrideCompletionProposal(fJavaProject, fCompilationUnit, name, paramTypes, start, length, label, String.valueOf(proposal.getCompletion()));
  javaProposal.setImage(getImage(fLabelProvider.createMethodImageDescriptor(proposal)));
  javaProposal.setProposalInfo(new MethodProposalInfo(fJavaProject, proposal));
  javaProposal.setRelevance(computeRelevance(proposal));
  fSuggestedMethodNames.add(new String(name));
  return javaProposal;
}
origin: eclipse/eclipse.jdt.ls

IBuffer buffer = this.compilationUnit.getBuffer();
document = JsonRpcHelpers.toDocument(buffer);
char[] declarationKey = proposal.getDeclarationKey();
if (declarationKey == null) {
  return;
int offset = proposal.getReplaceStart();
AnonymousTypeCompletionProposal overrider = new AnonymousTypeCompletionProposal(compilationUnit, offset, type, String.valueOf(proposal.getDeclarationSignature()), client.isCompletionSnippetsSupported());
String replacement = overrider.updateReplacementString(document, offset, importRewrite);
if (document.getLength() > offset && range != null) {
  if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
  } else if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION) {
origin: eclipse/eclipse.jdt.ls

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());
}
origin: org.eclipse.recommenders.completion/rcp

public ProcessableOverrideCompletionProposal(CompletionProposal coreProposal, JavaCompletionProposal uiProposal,
    JavaContentAssistInvocationContext context) {
  super(context.getProject(), context.getCompilationUnit(), String.valueOf(coreProposal.getName()),
      computeParamTypes(coreProposal), coreProposal.getReplaceStart(), uiProposal.getReplacementLength(),
      uiProposal.getStyledDisplayString(), String.valueOf(coreProposal.getCompletion()));
  this.coreProposal = coreProposal;
  final Image image = uiProposal.getImage();
  setImage(image);
  setRelevance(uiProposal.getRelevance());
}
origin: org.eclipse/org.eclipse.jdt.ui

private IJavaCompletionProposal createAnonymousTypeProposal(CompletionProposal proposal) {
  if (fCompilationUnit == null || fJavaProject == null)
    return null;
  String completion= String.valueOf(proposal.getCompletion());
  int start= proposal.getReplaceStart();
  int length= getLength(proposal);
  int relevance= computeRelevance(proposal);
  String label= fLabelProvider.createAnonymousTypeLabel(proposal);
  JavaCompletionProposal javaProposal= new AnonymousTypeCompletionProposal(fJavaProject, fCompilationUnit, start, length, completion, label, String.valueOf(proposal.getDeclarationSignature()), relevance);
  javaProposal.setProposalInfo(new AnonymousTypeProposalInfo(fJavaProject, proposal));
  return javaProposal;
}
origin: org.eclipse/org.eclipse.jdt.ui

private IJavaCompletionProposal createKeywordProposal(CompletionProposal proposal) {
  String completion= String.valueOf(proposal.getCompletion());
  int start= proposal.getReplaceStart();
  int length= getLength(proposal);
  String label= fLabelProvider.createSimpleLabel(proposal);
  int relevance= computeRelevance(proposal);
  return new JavaCompletionProposal(completion, start, length, null, label, relevance);
}
origin: eclipse/eclipse.jdt.ls

private Range toReplacementRange(CompletionProposal proposal){
  try {
    return JDTUtils.toRange(compilationUnit, proposal.getReplaceStart(), proposal.getReplaceEnd()-proposal.getReplaceStart());
  } catch (JavaModelException e) {
    JavaLanguageServerPlugin.logException(e.getMessage(), e);
  }
  return null;
}
org.eclipse.jdt.coreCompletionProposal

Javadoc

Completion proposal.

In typical usage, the user working in a Java code editor issues a code assist command. This command results in a call to ICodeAssist.codeComplete(position, completionRequestor) passing the current position in the source code. The code assist engine analyzes the code in the buffer, determines what kind of Java language construct is at that position, and proposes ways to complete that construct. These proposals are instances of the class CompletionProposal. These proposals, perhaps after sorting and filtering, are presented to the user to make a choice.

The proposal is as follows: insert the #getCompletion() into the source file buffer, replacing the characters between #getReplaceStart()and #getReplaceEnd(). The string can be arbitrary; for example, it might include not only the name of a method but a set of parentheses. Moreover, the source range may include source positions before or after the source position where ICodeAssist.codeComplete was invoked. The rest of the information associated with the proposal is to provide context that may help a user to choose from among competing proposals.

The completion engine creates instances of this class.

Most used methods

  • getKind
    Returns the kind of completion being proposed. The set of different kinds of completion proposals is
  • getName
    Returns the simple name of the method, field, member, or variable relevant in the context, ornull if
  • getSignature
    Returns the signature of the method or type relevant in the context, or null if none. This field is
  • findParameterNames
    Finds the method parameter names. This information is relevant to method reference (and method decla
  • getCompletion
    Returns the proposed sequence of characters to insert into the source file buffer, replacing the cha
  • getDeclarationSignature
    Returns the type signature or package name of the relevant declaration in the context, or null if no
  • getReplaceStart
    Returns the character index of the start of the subrange in the source file buffer to be replaced by
  • create
    Creates a basic completion proposal. All instance field have plausible default values unless otherwi
  • getDeclarationKey
    Returns the key of the relevant declaration in the context, or null if none. This field is availabl
  • getRelevance
    Returns the relative relevance rating of this proposal.
  • getReplaceEnd
    Returns the character index of the end of the subrange in the source file buffer to be replaced by t
  • getCompletionLocation
    Returns the character index in the source file buffer where source completion was requested (theoffs
  • getReplaceEnd,
  • getCompletionLocation,
  • getFlags,
  • getRequiredProposals,
  • setCompletion,
  • setDeclarationSignature,
  • setRelevance,
  • setReplaceRange,
  • setSignature,
  • setFlags

Popular in Java

  • Making http post requests using okhttp
  • getSupportFragmentManager (FragmentActivity)
  • requestLocationUpdates (LocationManager)
  • onRequestPermissionsResult (Fragment)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Runner (org.openjdk.jmh.runner)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now