Java Code Examples for org.eclipse.jdt.core.CompletionProposal#isConstructor()
The following examples show how to use
org.eclipse.jdt.core.CompletionProposal#isConstructor() .
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: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * 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 }
Example 2
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Resolves the method described by the receiver and returns it if found. * Returns <code>null</code> if no corresponding member can be found. * * @param proposal * - completion proposal * @param javaProject * - Java project * * @return the resolved method or <code>null</code> if none is found * @throws JavaModelException * if accessing the java model fails */ public static IMethod resolveMethod(CompletionProposal proposal, IJavaProject javaProject) throws JavaModelException { char[] declarationSignature = proposal.getDeclarationSignature(); String typeName = SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature)); IType type = javaProject.findType(typeName); if (type != null) { String name = String.valueOf(proposal.getName()); if (proposal.getKind() == CompletionProposal.ANNOTATION_ATTRIBUTE_REF) { IMethod method = type.getMethod(name, CharOperation.NO_STRINGS); if (method.exists()) { return method; } else { return null; } } char[] signature = proposal.getSignature(); if (proposal instanceof InternalCompletionProposal) { Binding binding = ((InternalCompletionProposal) proposal).getBinding(); if (binding instanceof MethodBinding) { MethodBinding methodBinding = (MethodBinding) binding; MethodBinding original = methodBinding.original(); if (original != binding) { signature = Engine.getSignature(original); } } } String[] parameters = Signature.getParameterTypes(String.valueOf(SignatureUtil.fix83600(signature))); for (int i = 0; i < parameters.length; i++) { parameters[i] = SignatureUtil.getLowerBound(parameters[i]); } boolean isConstructor = proposal.isConstructor(); return JavaModelUtil.findMethod(name, parameters, isConstructor, type); } return null; }
Example 3
Source File: CompletionProposalLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a display label for the given method proposal. 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 * @return the display label for the given method proposal */ StyledString createMethodProposalLabel(CompletionProposal methodProposal) { StyledString nameBuffer= new StyledString(); // method name nameBuffer.append(methodProposal.getName()); // parameters nameBuffer.append('('); appendUnboundedParameterList(nameBuffer, methodProposal); nameBuffer.append(')'); // return type if (!methodProposal.isConstructor()) { // TODO remove SignatureUtil.fix83600 call when bugs are fixed char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature())))); nameBuffer.append(RETURN_TYPE_SEPARATOR); nameBuffer.append(returnType); } // declaring type nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER); String declaringType= extractDeclaringTypeFQN(methodProposal); if (methodProposal.getRequiredProposals() != null) { String qualifier= Signature.getQualifier(declaringType); if (qualifier.length() > 0) { nameBuffer.append(qualifier, StyledString.QUALIFIER_STYLER); nameBuffer.append('.', StyledString.QUALIFIER_STYLER); } } declaringType= Signature.getSimpleName(declaringType); nameBuffer.append(declaringType, StyledString.QUALIFIER_STYLER); return Strings.markJavaElementLabelLTR(nameBuffer); }
Example 4
Source File: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private final boolean canAutomaticallyAppendSemicolon(CompletionProposal proposal) { return !proposal.isConstructor() && CharOperation.equals(new char[] { Signature.C_VOID }, Signature.getReturnType(proposal.getSignature())); }