Java Code Examples for org.eclipse.jdt.core.Signature#getParameterCount()

The following examples show how to use org.eclipse.jdt.core.Signature#getParameterCount() . 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: JavaMethodCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected String computeSortString() {
	/*
	 * Lexicographical sort order:
	 * 1) by relevance (done by the proposal sorter)
	 * 2) by method name
	 * 3) by parameter count
	 * 4) by parameter type names
	 */
	char[] name= fProposal.getName();
	char[] parameterList= Signature.toCharArray(fProposal.getSignature(), null, null, false, false);
	int parameterCount= Signature.getParameterCount(fProposal.getSignature()) % 10; // we don't care about insane methods with >9 parameters
	StringBuffer buf= new StringBuffer(name.length + 2 + parameterList.length);

	buf.append(name);
	buf.append('\0'); // separator
	buf.append(parameterCount);
	buf.append(parameterList);
	return buf.toString();
}
 
Example 2
Source File: JavaElExpressionProposalComputer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ICompletionProposal createProposal(CompletionProposal javaProposal) {
  char[] signature = javaProposal.getSignature();
  String replacementText = null;
  int relevanceAdjustment = 0;

  if (javaProposal.getKind() != CompletionProposal.METHOD_REF) {
    return null;
  }

  if (Signature.getParameterCount(signature) != 0) {
    // Only zero-arg methods are allowed
    return null;
  }

  String returnType = String.valueOf(Signature.getReturnType(signature));
  if (Signature.SIG_VOID.equals(returnType)) {
    // Methods with void return type are not allowed
    return null;
  }

  relevanceAdjustment += getRelevanceAdjustmentForMyTypeAndDeclarationType(
      returnType, javaProposal.getDeclarationSignature());
  replacementText = String.valueOf(javaProposal.getName());

  IJavaCompletionProposal jdtCompletionProposal = JavaContentAssistUtilities.getJavaCompletionProposal(
      javaProposal, getContext(), getJavaProject());
  ReplacementCompletionProposal proposal = ReplacementCompletionProposal.fromExistingCompletionProposal(
      replacementText, getReplaceOffset(), getReplaceLength(),
      jdtCompletionProposal);

  if (relevanceAdjustment != 0) {
    proposal.setRelevance(proposal.getRelevance() + relevanceAdjustment);
  }

  return proposal;
}
 
Example 3
Source File: FillArgumentNamesCompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) {
	String completion= String.valueOf(methodProposal.getCompletion());
	// super class' behavior if this is not a normal completion or has no
	// parameters
	if ((completion.length() == 0) || ((completion.length() == 1) && completion.charAt(0) == ')') || Signature.getParameterCount(methodProposal.getSignature()) == 0 || getContext().isInJavadoc())
		return super.createJavaCompletionProposal(methodProposal);

	LazyJavaCompletionProposal proposal= null;
	proposal= ParameterGuessingProposal.createProposal(methodProposal, getInvocationContext(), fIsGuessArguments);
	if (proposal == null) {
		proposal= new FilledArgumentNamesMethodProposal(methodProposal, getInvocationContext());
	}
	return proposal;
}
 
Example 4
Source File: Disassembler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private char[][] getParameterNames(char[] methodDescriptor, ICodeAttribute codeAttribute, IMethodParametersAttribute parametersAttribute, int accessFlags) {
	int paramCount = Signature.getParameterCount(methodDescriptor);
	char[][] parameterNames = new char[paramCount][];
	// check if the code attribute has debug info for this method
	if (parametersAttribute != null) {
		int parameterCount = parametersAttribute.getMethodParameterLength();
		for (int i = 0; i < paramCount; i++) {
			if (i < parameterCount && parametersAttribute.getParameterName(i) != null) {
				parameterNames[i] = parametersAttribute.getParameterName(i);
			} else {
				parameterNames[i] = Messages.disassembler_anonymousparametername.toCharArray();
			}
		}
	} else if (codeAttribute != null) {
			ILocalVariableAttribute localVariableAttribute = codeAttribute.getLocalVariableAttribute();
			if (localVariableAttribute != null) {
				ILocalVariableTableEntry[] entries = localVariableAttribute.getLocalVariableTable();
				final int startingIndex = (accessFlags & IModifierConstants.ACC_STATIC) != 0 ? 0 : 1;
				for (int i = 0; i < paramCount; i++) {
					ILocalVariableTableEntry searchedEntry = getEntryFor(getLocalIndex(startingIndex, i, methodDescriptor), entries);
					if (searchedEntry != null) {
						parameterNames[i] = searchedEntry.getName();
					} else {
						parameterNames[i] = CharOperation.concat(Messages.disassembler_parametername.toCharArray(), Integer.toString(i).toCharArray());
					}
				}
			} else {
				for (int i = 0; i < paramCount; i++) {
					parameterNames[i] = CharOperation.concat(Messages.disassembler_parametername.toCharArray(), Integer.toString(i).toCharArray());
				}
			}
	} else {
		for (int i = 0; i < paramCount; i++) {
			parameterNames[i] = CharOperation.concat(Messages.disassembler_parametername.toCharArray(), Integer.toString(i).toCharArray());
		}
	}
	return parameterNames;
}
 
Example 5
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private boolean hasParameters(CompletionProposal proposal) throws IllegalArgumentException {
	return hasArgumentList(proposal) &&
			Signature.getParameterCount(proposal.getSignature()) > 0;
}
 
Example 6
Source File: JavaMethodCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean computeHasParameters() throws IllegalArgumentException {
	return Signature.getParameterCount(fProposal.getSignature()) > 0;
}
 
Example 7
Source File: BinaryMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public String[] getRawParameterNames() throws JavaModelException {
	IBinaryMethod info = (IBinaryMethod) getElementInfo();
	int paramCount = Signature.getParameterCount(new String(info.getMethodDescriptor()));
	return getRawParameterNames(paramCount);
}
 
Example 8
Source File: AnonymousTypeCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if the method being inserted has at least one parameter. Note
 * that this does not say anything about whether the argument list should be inserted.
 *
 * @return <code>true</code> if the method has any parameters, <code>false</code> if it has no parameters
 * @since 3.4
 */
private boolean hasParameters() {
	CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal;
	return Signature.getParameterCount(proposal.getSignature()) > 0;
}