Java Code Examples for org.eclipse.jdt.internal.corext.template.java.SignatureUtil#stripSignatureToFQN()

The following examples show how to use org.eclipse.jdt.internal.corext.template.java.SignatureUtil#stripSignatureToFQN() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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);
}