org.eclipse.jdt.core.CompletionProposal Java Examples

The following examples show how to use org.eclipse.jdt.core.CompletionProposal. 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: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 String createParameterList(CompletionProposal proposal) {
	String paramList;
	int kind= proposal.getKind();
	switch (kind) {
		case CompletionProposal.METHOD_REF:
		case CompletionProposal.CONSTRUCTOR_INVOCATION:
			paramList= appendUnboundedParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		case CompletionProposal.TYPE_REF:
		case CompletionProposal.JAVADOC_TYPE_REF:
			paramList= appendTypeParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
		case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
			paramList= appendUnboundedParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		default:
			Assert.isLegal(false);
			return null; // dummy
	}
}
 
Example #2
Source File: AnonymousTypeCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected String getPrefix(IDocument document, int offset) {
	CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal;
	if (coreProposal.getKind() != CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION)
		return super.getPrefix(document, offset);

	int replacementOffset= coreProposal.getRequiredProposals()[0].getReplaceStart();

	try {
		int length= offset - replacementOffset;
		if (length > 0)
			return document.get(replacementOffset, length);
	} catch (BadLocationException x) {
	}
	return ""; //$NON-NLS-1$

}
 
Example #3
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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
	}
}
 
Example #4
Source File: JavaMethodCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: CompilationUnitCompletion.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: JsniCompletionProposal.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private String createReplaceString() {
  switch (wrappedProposal.getKind()) {
    case CompletionProposal.PACKAGE_REF:
      return computePackageCompletion();
    case CompletionProposal.TYPE_REF:
      return computeTypeCompletion();
    case CompletionProposal.FIELD_REF:
      return computeFieldCompletion();
    case CompletionProposal.METHOD_REF:
      if (wrappedProposal.isConstructor()) {
        return computeCtorCompletion();
      } else {
        return computeMethodCompletion();
      }
    default:
      return "";
  }
}
 
Example #7
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: JavaZipModule.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets tuples with the java element and the corresponding completion proposal for that element.
 *
 * @param contents the contents that should be set for doing the code-completion
 * @param completionOffset the offset where the code completion should be requested
 * @param filterCompletionName if specified, only return matches from elements that have the name passed (otherwise it should be null)
 * @return a list of tuples corresponding to the element and the proposal for the gotten elements
 * @throws JavaModelException
 */
@Override
protected List<Tuple<IJavaElement, CompletionProposal>> getJavaCompletionProposals(String contents,
        int completionOffset, final String filterCompletionName) throws JavaModelException {

    final List<Tuple<IJavaElement, CompletionProposal>> ret = new ArrayList<Tuple<IJavaElement, CompletionProposal>>();

    IClasspathEntry entries[] = getClasspathEntries();
    //Using old version for compatibility with eclipse 3.2
    ICompilationUnit unit = new WorkingCopyOwner() {
    }.newWorkingCopy(name, entries, null, new NullProgressMonitor());
    unit.getBuffer().setContents(contents);
    CompletionProposalCollector collector = createCollector(filterCompletionName, ret, unit);

    unit.codeComplete(completionOffset, collector); //fill the completions while searching it
    return ret;
}
 
Example #9
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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) + "." + name);
		}
	}
	setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
 
Example #10
Source File: CompletionProposalRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void accept(CompletionProposal proposal) {
	if (isFiltered(proposal)) {
		return;
	}
	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);
		}
	}
}
 
Example #11
Source File: ProposalContextInformation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new context information.
 *
 * @param proposal the JDT Core completion proposal
 */
public ProposalContextInformation(CompletionProposal proposal) {
	// don't cache the core proposal because the ContentAssistant might
	// hang on to the context info.
	CompletionProposalLabelProvider labelProvider= new CompletionProposalLabelProvider();
	fInformationDisplayString= labelProvider.createParameterList(proposal);
	ImageDescriptor descriptor= labelProvider.createImageDescriptor(proposal);
	if (descriptor != null)
		fImage= JavaPlugin.getImageDescriptorRegistry().get(descriptor);
	else
		fImage= null;
	if (proposal.getCompletion().length == 0)
		fPosition= proposal.getCompletionLocation() + 1;
	else
		fPosition= -1;
	fContextDisplayString= labelProvider.createLabel(proposal);
}
 
Example #12
Source File: JavaElExpressionProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void computeProposals(List<ICompletionProposal> proposals)
    throws UiBinderException {
  IEvaluationContext evalContext = createEvaluationContext();

  try {
    // Get proposals for instance methods and static methods by treating the
    // Java type as an instance.
    // Since the type does not necessarily have to have a zero-arg
    // constructor, we use a local variable in the completion request below
    JavaElExpressionCompletionRequestor requestor = new JavaElExpressionCompletionRequestor(
        CompletionProposal.METHOD_REF);
    String snippet = javaType.getFullyQualifiedName('.') + " tmpVar; tmpVar."
        + getEnteredText();
    evalContext.codeComplete(snippet, snippet.length(), requestor);
    proposals.addAll(requestor.getProposals());

  } catch (JavaModelException e) {
    throw new UiBinderException(e);
  }
}
 
Example #13
Source File: ProposalGeneratingCompletionRequestor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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);
  }
}
 
Example #14
Source File: CompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IJavaCompletionProposal createJavadocSimpleProposal(CompletionProposal javadocProposal) {
		// TODO do better with javadoc proposals
//		String completion= String.valueOf(proposal.getCompletion());
//		int start= proposal.getReplaceStart();
//		int length= getLength(proposal);
//		String label= fLabelProvider.createSimpleLabel(proposal);
//		Image image= getImage(fLabelProvider.createImageDescriptor(proposal));
//		int relevance= computeRelevance(proposal);
//
//		JavaCompletionProposal javaProposal= new JavaCompletionProposal(completion, start, length, image, label, relevance);
//		if (fJavaProject != null)
//			javaProposal.setProposalInfo(new FieldProposalInfo(fJavaProject, proposal));
//
//		javaProposal.setTriggerCharacters(VAR_TRIGGER);
//
//		return javaProposal;
		LazyJavaCompletionProposal proposal = new LazyJavaCompletionProposal(javadocProposal, getInvocationContext());
//		adaptLength(proposal, javadocProposal);
		return proposal;
	}
 
Example #15
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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);
	}

}
 
Example #16
Source File: JavaTypeCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #17
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: JavaModuleInProject.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see AbstractJavaClassModule#getJavaCompletionProposals(String, int, String)
 *
 * @note: the completionOffset is ignored (we find the type and go for the completions on that type).
 */
@Override
protected List<Tuple<IJavaElement, CompletionProposal>> getJavaCompletionProposals(String contents,
        int completionOffset, String filterCompletionName) throws Exception {
    try {
        IType type = this.javaProject.findType(name);

        final List<Tuple<IJavaElement, CompletionProposal>> ret = new ArrayList<Tuple<IJavaElement, CompletionProposal>>();

        //we only get actual completions on a class (otherwise, what we have is a package -- which is treated
        //as if it was an empty __init__.py file -- without any tokens).
        if (type != null) {
            getCompletionsForType(contents, filterCompletionName, type, ret);
        }

        if (this.moduleType == UNKNOWN) {
            //if we found the type, it's a class (otherwise it's a package).
            if (type == null) {
                this.moduleType = IS_PACKAGE;
            } else {
                this.moduleType = IS_CLASS;
                this.file = new File(SharedCorePlugin.getIResourceOSString(type.getResource()));
            }
        }

        return ret;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
Example #19
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IJavaElement[][] getAssignableElements(CompletionProposal proposal) {
	char[] signature = SignatureUtil.fix83600(proposal.getSignature());
	char[][] types = Signature.getParameterTypes(signature);

	IJavaElement[][] assignableElements = new IJavaElement[types.length][];
	for (int i = 0; i < types.length; i++) {
		assignableElements[i] = context.getVisibleElements(new String(types[i]));
	}
	return assignableElements;
}
 
Example #20
Source File: JavaModuleInProject.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see AbstractJavaClassModule#getJavaCompletionProposals(String, String)
 */
@Override
protected List<Tuple<IJavaElement, CompletionProposal>> getJavaCompletionProposals(String completeClassDesc,
        String filterCompletionName) throws Exception {
    String contents;
    if (filterCompletionName != null) {
        //pre-filter it a bit if we already know the completion name
        contents = "new %s().%s";
        contents = StringUtils.format(contents, completeClassDesc, completeClassDesc, filterCompletionName);

    } else {
        contents = "new %s().";
        contents = StringUtils.format(contents, completeClassDesc, completeClassDesc);
    }

    List<Tuple<IJavaElement, CompletionProposal>> javaCompletionProposals = getJavaCompletionProposals(contents,
            contents.length(), filterCompletionName);
    if (javaCompletionProposals.size() == 0) {
        //Handle static access (notice that we don't create an instance.)
        if (filterCompletionName != null) {
            //pre-filter it a bit if we already know the completion name
            contents = "%s.%s";
            contents = StringUtils.format(contents, completeClassDesc, completeClassDesc, filterCompletionName);

        } else {
            contents = "%s.";
            contents = StringUtils.format(contents, completeClassDesc, completeClassDesc);
        }
        javaCompletionProposals = getJavaCompletionProposals(contents, contents.length() - 2, filterCompletionName);

    }
    return javaCompletionProposals;
}
 
Example #21
Source File: LazyJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public LazyJavaCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) {
	super(context);
	Assert.isNotNull(proposal);
	Assert.isNotNull(context);
	Assert.isNotNull(context.getCoreContext());
	fProposal= proposal;
}
 
Example #22
Source File: MemberProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new proposal info.
 *
 * @param project the java project to reference when resolving types
 * @param proposal the proposal to generate information for
 */
public MemberProposalInfo(IJavaProject project, CompletionProposal proposal) {
	Assert.isNotNull(project);
	Assert.isNotNull(proposal);
	fJavaProject= project;
	fProposal= proposal;
}
 
Example #23
Source File: CompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaCompletionProposal createLocalVariableProposal(CompletionProposal proposal) {
	String completion= String.valueOf(proposal.getCompletion());
	int start= proposal.getReplaceStart();
	int length= getLength(proposal);
	Image image= getImage(fLabelProvider.createLocalImageDescriptor(proposal));
	StyledString label= fLabelProvider.createSimpleLabelWithType(proposal);
	int relevance= computeRelevance(proposal);
	final JavaCompletionProposal javaProposal= new JavaCompletionProposal(completion, start, length, image, label, relevance);
	javaProposal.setTriggerCharacters(VAR_TRIGGER);
	return javaProposal;
}
 
Example #24
Source File: CompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaCompletionProposal createKeywordProposal(CompletionProposal proposal) {
	String completion= String.valueOf(proposal.getCompletion());
	int start= proposal.getReplaceStart();
	int length= getLength(proposal);
	StyledString label= fLabelProvider.createSimpleLabel(proposal);
	int relevance= computeRelevance(proposal);
	return new JavaCompletionProposal(completion, start, length, null, label, relevance);
}
 
Example #25
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 "java.lang.Object"; //$NON-NLS-1$
	return SignatureUtil.stripSignatureToFQN(String.valueOf(declaringTypeSignature));
}
 
Example #26
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;
}
 
Example #27
Source File: JavaMethodCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int getPrefixCompletionStart(IDocument document, int completionOffset) {
	if (fProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
		return fProposal.getTokenStart();
	} else if (fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION)
		return fProposal.getRequiredProposals()[0].getReplaceStart();
	return super.getPrefixCompletionStart(document, completionOffset);
}
 
Example #28
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static void createAndAddJavaCompletionProposal(CompletionProposalCollector completionProposalCollector, CompletionProposal newProposal,
		List<IJavaCompletionProposal> proposals) {
	
	try {
		proposals.add((IJavaCompletionProposal) Reflection.createJavaCompletionProposalMethod.invoke(completionProposalCollector, newProposal));
	} catch (Exception ignore) {
		// ignore
	}
}
 
Example #29
Source File: JsniCompletionProposalCollector.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static CompletionProposalCollector createMemberProposalCollector(
    ICompilationUnit cu, int refOffset, int refLength,
    String refQualifiedTypeName) {
  JsniCompletionProposalCollector collector = new JsniCompletionProposalCollector(
      cu, refOffset, refLength);
  collector.setIgnored(CompletionProposal.PACKAGE_REF, true);
  collector.setIgnored(CompletionProposal.TYPE_REF, true);
  collector.setQualifiedTypeName(refQualifiedTypeName);

  return collector;
}
 
Example #30
Source File: JavaZipModule.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the java element corresponding to the passed module.
 */
@Override
protected IJavaElement findJavaElement(String javaClassModuleName) throws Exception {
    String contents = "import %s.;";
    contents = StringUtils.format(contents, FullRepIterable.getWithoutLastPart(javaClassModuleName));
    final String lookingForClass = FullRepIterable.getLastPart(javaClassModuleName);
    List<Tuple<IJavaElement, CompletionProposal>> javaCompletionProposals = getJavaCompletionProposals(contents,
            contents.length() - 1, lookingForClass);
    if (javaCompletionProposals.size() > 0) {
        return javaCompletionProposals.get(0).o1;
    }
    return null;
}