Java Code Examples for org.eclipse.jdt.ui.text.java.CompletionProposalCollector#getJavaCompletionProposals()

The following examples show how to use org.eclipse.jdt.ui.text.java.CompletionProposalCollector#getJavaCompletionProposals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsniCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Collects the proposals generated at the end of the specified snippet of
 * Java code, scoped to the specific type.
 */
private IJavaCompletionProposal[] codeComplete(String qualifiedTypeName,
    String snippet, CompletionProposalCollector requestor)
    throws JavaModelException {
  IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

  IType type = cu.getJavaProject().findType(qualifiedTypeName);
  if (type != null) {
    // This can always be false, since the set of available completions
    // (static vs. instance) depends on the JSNI ref itself, not the modifiers
    // on the method in which it is defined.
    boolean isStatic = false;

    // Have the JDT generate completions in the context of the type, but at
    // an unspecified location (source offset -1), since the real position
    // is inside a Java comment block, which is not allowed by codeComplete.
    type.codeComplete(snippet.toCharArray(), -1, snippet.length(),
        new char[0][0], new char[0][0], new int[0], isStatic, requestor);
    proposals = requestor.getJavaCompletionProposals();
  }

  return proposals;
}
 
Example 2
Source File: JsniCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private IJavaCompletionProposal[] computePackageAndTypeProposals(String js,
    int lineStartOffset, int cursorOffset) throws JavaModelException {
  Matcher matcher = PACKAGE_OR_TYPE_REF_START.matcher(js);
  if (!matcher.find()) {
    // Bail if we're not inside a JSNI Java package/type reference
    return null;
  }

  // Extract from the match the (maybe partial) package/type reference
  int refOffset = matcher.start(1) + lineStartOffset;
  int refLength = cursorOffset - refOffset;
  String partialRef = matcher.group(1);

  CompletionProposalCollector requestor = JsniCompletionProposalCollector.createPackageAndTypeProposalCollector(
      cu, refOffset, refLength);
  IEvaluationContext evalContext = createEvaluationContext();
  evalContext.codeComplete(partialRef, partialRef.length(), requestor);
  return requestor.getJavaCompletionProposals();
}
 
Example 3
Source File: JavaContentAssistUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Generates an {@link IJavaCompletionProposal} from Java's
 * {@link CompletionProposal}.
 * 
 * @param completionProposal the {@link CompletionProposal}
 * @param completionContext the context of the {@link CompletionProposal}
 * @param javaProject the java project for the given completion proposal
 * @return a {@link IJavaCompletionProposal}, or null
 */
public static IJavaCompletionProposal getJavaCompletionProposal(
    CompletionProposal completionProposal,
    CompletionContext completionContext, IJavaProject javaProject) {
  CompletionProposalCollector collector = new CompletionProposalCollector(
      javaProject);
  collector.acceptContext(completionContext);
  collector.accept(completionProposal);
  IJavaCompletionProposal[] javaCompletionProposals = collector.getJavaCompletionProposals();
  return javaCompletionProposals.length > 0 ? javaCompletionProposals[0]
      : null;
}