org.eclipse.jdt.internal.corext.template.java.SignatureUtil Java Examples

The following examples show how to use org.eclipse.jdt.internal.corext.template.java.SignatureUtil. 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: TypeProposalUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
static String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException {
	String[] signatures= getSuperTypeSignatures(subType, superType);
	for (String signature : signatures) {
		String qualified= SignatureUtil.qualifySignature(signature, subType);
		String subFQN= SignatureUtil.stripSignatureToFQN(qualified);

		String superFQN= superType.getFullyQualifiedName();
		if (subFQN.equals(superFQN)) {
			return signature;
		}

		// TODO handle local types
	}

	return null;
	//		throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$
}
 
Example #2
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 StringBuilder appendUnboundedParameterList(StringBuilder 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;
	try {
		parameterNames = methodProposal.findParameterNames(null);
	} catch (Exception e) {
		JavaLanguageServerPlugin.logException(e.getMessage(), e);
		parameterNames = CompletionEngine.createDefaultParameterNames(Signature.getParameterCount(signature));
		methodProposal.setParameterNames(parameterNames);
	}
	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);
}
 
Example #3
Source File: MethodProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The type and method signatures received in
 * <code>CompletionProposals</code> of type <code>METHOD_REF</code>
 * contain concrete type bounds. When comparing parameters of the signature
 * with an <code>IMethod</code>, we have to make sure that we match the
 * case where the formal method declaration uses a type variable which in
 * the signature is already substituted with a concrete type (bound).
 * <p>
 * This method creates a map from type variable names to type signatures
 * based on the position they appear in the type declaration. The type
 * signatures are filtered through
 * {@link SignatureUtil#getLowerBound(char[])}.
 * </p>
 *
 * @param type the type to get the variables from
 * @return a map from type variables to concrete type signatures
 * @throws JavaModelException if accessing the java model fails
 */
private Map<String, char[]> computeTypeVariables(IType type) throws JavaModelException {
	Map<String, char[]> map= new HashMap<String, char[]>();
	char[] declarationSignature= fProposal.getDeclarationSignature();
	if (declarationSignature == null) // array methods don't contain a declaration signature
		return map;
	char[][] concreteParameters= Signature.getTypeArguments(declarationSignature);

	ITypeParameter[] typeParameters= type.getTypeParameters();
	for (int i= 0; i < typeParameters.length; i++) {
		String variable= typeParameters[i].getElementName();
		if (concreteParameters.length > i)
			// use lower bound since method equality is only parameter based
			map.put(variable, SignatureUtil.getLowerBound(concreteParameters[i]));
		else
			// fProposal.getDeclarationSignature() is a raw type - use Object
			map.put(variable, "Ljava.lang.Object;".toCharArray()); //$NON-NLS-1$
	}

	return map;
}
 
Example #4
Source File: MethodProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] declarationSignature= fProposal.getDeclarationSignature();
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
	IType type= fJavaProject.findType(typeName);
	if (type != null) {
		String name= String.valueOf(fProposal.getName());
		String[] parameters= Signature.getParameterTypes(String.valueOf(SignatureUtil.fix83600(fProposal.getSignature())));
		for (int i= 0; i < parameters.length; i++) {
			parameters[i]= SignatureUtil.getLowerBound(parameters[i]);
		}
		boolean isConstructor= fProposal.isConstructor();

		return findMethod(name, parameters, isConstructor, type);
	}

	return null;
}
 
Example #5
Source File: FieldProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] declarationSignature= fProposal.getDeclarationSignature();
	// for synthetic fields on arrays, declaration signatures may be null
	// TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
	if (declarationSignature == null)
		return null;
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
	IType type= fJavaProject.findType(typeName);
	if (type != null) {
		String name= String.valueOf(fProposal.getName());
		IField field= type.getField(name);
		if (field.exists())
			return field;
	}

	return null;
}
 
Example #6
Source File: LazyGenericTypeProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds and returns the super type signature in the
 * <code>extends</code> or <code>implements</code> clause of
 * <code>subType</code> that corresponds to <code>superType</code>.
 *
 * @param subType a direct and true sub type of <code>superType</code>
 * @param superType a direct super type (super class or interface) of
 *        <code>subType</code>
 * @return the super type signature of <code>subType</code> referring
 *         to <code>superType</code>
 * @throws JavaModelException if extracting the super type signatures
 *         fails, or if <code>subType</code> contains no super type
 *         signature to <code>superType</code>
 */
private String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException {
	String[] signatures= getSuperTypeSignatures(subType, superType);
	for (int i= 0; i < signatures.length; i++) {
		String signature= signatures[i];
		String qualified= SignatureUtil.qualifySignature(signature, subType);
		String subFQN= SignatureUtil.stripSignatureToFQN(qualified);

		String superFQN= superType.getFullyQualifiedName();
		if (subFQN.equals(superFQN)) {
			return signature;
		}

		// TODO handle local types
	}

	throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$
}
 
Example #7
Source File: AnnotationAtttributeProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] declarationSignature= fProposal.getDeclarationSignature();
	// for synthetic fields on arrays, declaration signatures may be null
	// TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
	if (declarationSignature == null)
		return null;
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
	IType type= fJavaProject.findType(typeName);
	if (type != null) {
		String name= String.valueOf(fProposal.getName());
		IMethod method= type.getMethod(name, CharOperation.NO_STRINGS);
		if (method.exists())
			return method;
	}
	return null;
}
 
Example #8
Source File: JavaContentAssistInvocationContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the expected type if any, <code>null</code> otherwise.
 * <p>
 * <strong>Note:</strong> This method may run
 * {@linkplain ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor) codeComplete}
 * on the compilation unit.
 * </p>
 *
 * @return the expected type if any, <code>null</code> otherwise
 */
public IType getExpectedType() {
	if (fType == null && getCompilationUnit() != null) {
		CompletionContext context= getCoreContext();
		if (context != null) {
			char[][] expectedTypes= context.getExpectedTypesSignatures();
			if (expectedTypes != null && expectedTypes.length > 0) {
				IJavaProject project= getCompilationUnit().getJavaProject();
				if (project != null) {
					try {
						fType= project.findType(SignatureUtil.stripSignatureToFQN(String.valueOf(expectedTypes[0])));
					} catch (JavaModelException x) {
						JavaPlugin.log(x);
					}
				}
			}
		}
	}
	return fType;
}
 
Example #9
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Resolves the field 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 field or <code>null</code> if none is found
 * @throws JavaModelException
 *             if accessing the java model fails
 */
public static IField resolveField(CompletionProposal proposal, IJavaProject javaProject) throws JavaModelException {
	char[] declarationSignature = proposal.getDeclarationSignature();
	// for synthetic fields on arrays, declaration signatures may be null
	// TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
	if (declarationSignature == null) {
		return null;
	}
	String typeName = SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
	IType type = javaProject.findType(typeName);
	if (type != null) {
		String name = String.valueOf(proposal.getName());
		IField field = type.getField(name);
		if (field.exists()) {
			return field;
		}
	}

	return null;
}
 
Example #10
Source File: JavaContentAssistInvocationContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the content assist type history for the expected type.
 *
 * @return the content assist type history for the expected type
 */
private RHSHistory getRHSHistory() {
	if (fRHSHistory == null) {
		CompletionContext context= getCoreContext();
		if (context != null) {
			char[][] expectedTypes= context.getExpectedTypesSignatures();
			if (expectedTypes != null && expectedTypes.length > 0) {
				String expected= SignatureUtil.stripSignatureToFQN(String.valueOf(expectedTypes[0]));
				fRHSHistory= JavaPlugin.getDefault().getContentAssistHistory().getHistory(expected);
			}
		}
		if (fRHSHistory == null)
			fRHSHistory= JavaPlugin.getDefault().getContentAssistHistory().getHistory(null);
	}
	return fRHSHistory;
}
 
Example #11
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: ParameterGuessingProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String[] getParameterTypes() {
	char[] signature= SignatureUtil.fix83600(fProposal.getSignature());
	char[][] types= Signature.getParameterTypes(signature);

	String[] ret= new String[types.length];
	for (int i= 0; i < types.length; i++) {
		ret[i]= new String(Signature.toCharArray(types[i]));
	}
	return ret;
}
 
Example #14
Source File: ParameterGuessingProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaElement[][] getAssignableElements() {
	char[] signature= SignatureUtil.fix83600(getProposal().getSignature());
	char[][] types= Signature.getParameterTypes(signature);

	IJavaElement[][] assignableElements= new IJavaElement[types.length][];
	for (int i= 0; i < types.length; i++) {
		assignableElements[i]= fCoreContext.getVisibleElements(new String(types[i]));
	}
	return assignableElements;
}
 
Example #15
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 #16
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createOverrideMethodProposalLabel(CompletionProposal methodProposal) {
	StyledString nameBuffer= new StyledString();

	// method name
	nameBuffer.append(methodProposal.getName());

	// parameters
	nameBuffer.append('(');
	appendUnboundedParameterList(nameBuffer, methodProposal);
	nameBuffer.append(')');

	nameBuffer.append(RETURN_TYPE_SEPARATOR);

	// return type
	// TODO remove SignatureUtil.fix83600 call when bugs are fixed
	char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
	nameBuffer.append(returnType);

	// declaring type
	nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);

	String declaringType= extractDeclaringTypeFQN(methodProposal);
	declaringType= Signature.getSimpleName(declaringType);
	nameBuffer.append(Messages.format(JavaTextMessages.ResultCollector_overridingmethod, BasicElementLabels.getJavaElementName(declaringType)), StyledString.QUALIFIER_STYLER);

	return nameBuffer;
}
 
Example #17
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #18
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Appends the type parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param typeProposal the type proposal
 * @return the modified <code>buffer</code>
 * @since 3.2
 */
private StyledString appendTypeParameterList(StyledString buffer, CompletionProposal typeProposal) {
	// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
	// gets fixed.
	char[] signature= SignatureUtil.fix83600(typeProposal.getSignature());
	char[][] typeParameters= Signature.getTypeArguments(signature);
	for (int i= 0; i < typeParameters.length; i++) {
		char[] param= typeParameters[i];
		typeParameters[i]= Signature.toCharArray(param);
	}
	return appendParameterSignature(buffer, typeParameters, null);
}
 
Example #19
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 #20
Source File: SignatureHelpRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public SignatureInformation toSignatureInformation(CompletionProposal methodProposal) {
	SignatureInformation $ = new SignatureInformation();
	StringBuilder desription = descriptionProvider.createMethodProposalDescription(methodProposal);
	$.setLabel(desription.toString());
	$.setDocumentation(this.computeJavaDoc(methodProposal));

	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] = Signature.getSimpleName(Signature.toCharArray(SignatureUtil.getLowerBound(parameterTypes[i])));
	}

	if (Flags.isVarargs(methodProposal.getFlags())) {
		int index = parameterTypes.length - 1;
		parameterTypes[index] = convertToVararg(parameterTypes[index]);
	}

	List<ParameterInformation> parameterInfos = new LinkedList<>();
	for (int i = 0; i < parameterTypes.length; i++) {
		StringBuilder builder = new StringBuilder();
		builder.append(parameterTypes[i]);
		builder.append(' ');
		builder.append(parameterNames[i]);

		parameterInfos.add(new ParameterInformation(builder.toString()));
	}

	$.setParameters(parameterInfos);

	return $;
}
 
Example #21
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 #22
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Originally copied from
 * org.eclipse.jdt.internal.ui.text.java.ParameterGuessingProposal.getParameterTypes()
 */
private String[] getParameterTypes(CompletionProposal proposal) {
	char[] signature = SignatureUtil.fix83600(proposal.getSignature());
	char[][] types = Signature.getParameterTypes(signature);

	String[] ret = new String[types.length];
	for (int i = 0; i < types.length; i++) {
		ret[i] = new String(Signature.toCharArray(types[i]));
	}
	return ret;
}
 
Example #23
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.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 OBJECT;
	}
	return SignatureUtil.stripSignatureToFQN(String.valueOf(declaringTypeSignature));
}
 
Example #24
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void createOverrideMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
	StringBuilder nameBuffer= new StringBuilder();

	// method name
	String name = new String(methodProposal.getName());
	item.setInsertText(name);
	nameBuffer.append(name);
	// parameters
	nameBuffer.append('(');
	appendUnboundedParameterList(nameBuffer, methodProposal);
	nameBuffer.append(')');

	nameBuffer.append(RETURN_TYPE_SEPARATOR);

	// return type
	// TODO remove SignatureUtil.fix83600 call when bugs are fixed
	char[] returnType= createTypeDisplayName(SignatureUtil.getUpperBound(Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
	nameBuffer.append(returnType);
	item.setLabel(nameBuffer.toString());
	item.setFilterText(name);

	// declaring type
	StringBuilder typeBuffer = new StringBuilder();
	String declaringType= extractDeclaringTypeFQN(methodProposal);
	declaringType= Signature.getSimpleName(declaringType);
	typeBuffer.append(String.format("Override method in '%s'", declaringType));
	item.setDetail(typeBuffer.toString());

	setSignature(item, String.valueOf(methodProposal.getSignature()));
	setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
	setName(item, String.valueOf(methodProposal.getName()));
}
 
Example #25
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Appends the type parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param typeProposal the type proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendTypeParameterList(StringBuilder buffer, CompletionProposal typeProposal) {
	// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
	// gets fixed.
	char[] signature= SignatureUtil.fix83600(typeProposal.getSignature());
	char[][] typeParameters= Signature.getTypeArguments(signature);
	for (int i= 0; i < typeParameters.length; i++) {
		char[] param= typeParameters[i];
		typeParameters[i]= Signature.toCharArray(param);
	}
	return appendParameterSignature(buffer, typeParameters, null);
}
 
Example #26
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private String computeJavaTypeReplacementString(CompletionProposal proposal) {
	String replacement = String.valueOf(proposal.getCompletion());

	/* No import rewriting ever from within the import section. */
	if (isImportCompletion(proposal)) {
		return replacement;
	}

	/*
	 * Always use the simple name for non-formal javadoc references to
	 * types.
	 */
	// TODO fix
	if (proposal.getKind() == CompletionProposal.TYPE_REF
			&& context.isInJavadocText()) {
		return SignatureUtil.getSimpleTypeName(proposal);
	}

	String qualifiedTypeName = SignatureUtil.getQualifiedTypeName(proposal);

	// Type in package info must be fully qualified.
	if (compilationUnit != null
			&& TypeProposalUtils.isPackageInfo(compilationUnit)) {
		return qualifiedTypeName;
	}

	if (qualifiedTypeName.indexOf('.') == -1 && replacement.length() > 0) {
		// default package - no imports needed
		return qualifiedTypeName;
	}

	/*
	 * If the user types in the qualification, don't force import rewriting
	 * on him - insert the qualified name.
	 */
	String prefix="";
	try{
		IDocument document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
		IRegion region= document.getLineInformationOfOffset(proposal.getReplaceEnd());
		prefix =  document.get(region.getOffset(), proposal.getReplaceEnd() -region.getOffset()).trim();
	}catch(BadLocationException | JavaModelException e){

	}
	int dotIndex = prefix.lastIndexOf('.');
	// match up to the last dot in order to make higher level matching still
	// work (camel case...)
	if (dotIndex != -1
			&& qualifiedTypeName.toLowerCase().startsWith(
					prefix.substring(0, dotIndex + 1).toLowerCase())) {
		return qualifiedTypeName;
	}

	/*
	 * The replacement does not contain a qualification (e.g. an inner type
	 * qualified by its parent) - use the replacement directly.
	 */
	if (replacement.indexOf('.') == -1) {
		if (isInJavadoc())
		{
			return SignatureUtil.getSimpleTypeName(proposal); // don't use
		}
		// the
		// braces
		// added for
		// javadoc
		// link
		// proposals
		return replacement;
	}

	/* Add imports if the preference is on. */
	if (importRewrite != null) {
		return importRewrite.addImport(qualifiedTypeName, null);
	}

	// fall back for the case we don't have an import rewrite (see
	// allowAddingImports)

	/* No imports for implicit imports. */
	if (compilationUnit != null
			&& TypeProposalUtils.isImplicitImport(
					Signature.getQualifier(qualifiedTypeName),
					compilationUnit)) {
		return Signature.getSimpleName(qualifiedTypeName);
	}


	/* Default: use the fully qualified type name. */
	return qualifiedTypeName;
}
 
Example #27
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private IJavaElement resolveJavaElement(IJavaProject project, CompletionProposal proposal) throws JavaModelException {
	char[] signature= proposal.getSignature();
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(signature));
	return project.findType(typeName);
}
 
Example #28
Source File: JavaExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private String toQualifiedName(final Object item) throws JavaModelException {
    return SignatureUtil.stripSignatureToFQN(((IMethod) item).getReturnType());
}
 
Example #29
Source File: TypeProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] signature= fProposal.getSignature();
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(signature));
	return fJavaProject.findType(typeName);
}
 
Example #30
Source File: AnonymousTypeProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] signature= fProposal.getDeclarationSignature();
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(signature));
	return fJavaProject.findType(typeName);
}