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

The following examples show how to use org.eclipse.jdt.core.Signature#toCharArray() . 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: TypeParameterPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param findDeclarations
 * @param findReferences
 * @param typeParameter
 * @param matchRule
 */
public TypeParameterPattern(boolean findDeclarations, boolean findReferences, ITypeParameter typeParameter, int matchRule) {
	super(TYPE_PARAM_PATTERN, matchRule);

	this.findDeclarations = findDeclarations; // set to find declarations & all occurences
	this.findReferences = findReferences; // set to find references & all occurences
	this.typeParameter = typeParameter;
	this.name = typeParameter.getElementName().toCharArray(); // store type parameter name
	IMember member = typeParameter.getDeclaringMember();
	this.declaringMemberName = member.getElementName().toCharArray(); // store type parameter declaring member name

	// For method type parameter, store also declaring class name and parameters type names
	if (member instanceof IMethod) {
		IMethod method = (IMethod) member;
		this.methodDeclaringClassName = method.getParent().getElementName().toCharArray();
		String[] parameters = method.getParameterTypes();
		int length = parameters.length;
		this.methodArgumentTypes = new char[length][];
		for (int i=0; i<length; i++) {
			this.methodArgumentTypes[i] = Signature.toCharArray(parameters[i].toCharArray());
		}
	}
}
 
Example 2
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 3
Source File: Disassembler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private char[] getSignatureForField(char[] fieldDescriptor) {
	char[] newFieldDescriptor = CharOperation.replaceOnCopy(fieldDescriptor, '/', '.');
	newFieldDescriptor = CharOperation.replaceOnCopy(newFieldDescriptor, '$', '%');
	char[] fieldDescriptorSignature = Signature.toCharArray(newFieldDescriptor);
	CharOperation.replace(fieldDescriptorSignature, '%', '$');
	return fieldDescriptorSignature;
}
 
Example 4
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 5
Source File: SimilarElementsRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void addType(char[] typeNameSig, int flags, int relevance) {
	int kind= getKind(flags, typeNameSig);
	if (!isKind(kind)) {
		return;
	}
	String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig)));
	if (TypeFilter.isFiltered(fullName)) {
		return;
	}
	if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) {
		addResult(new SimilarElement(kind, fullName, relevance));
	}
}
 
Example 6
Source File: SourceIndexerRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see ISourceElementRequestor#acceptConstructorReference(char[], int, int)
 */
public void acceptConstructorReference(char[] typeName, int argCount, int sourcePosition) {
	if (CharOperation.indexOf(Signature.C_GENERIC_START, typeName) > 0) {
		typeName = Signature.toCharArray(Signature.getTypeErasure(Signature.createTypeSignature(typeName, false)).toCharArray());
	}
	this.indexer.addConstructorReference(typeName, argCount);
	int lastDot = CharOperation.lastIndexOf('.', typeName);
	if (lastDot != -1) {
		char[][] qualification = CharOperation.splitOn('.', CharOperation.subarray(typeName, 0, lastDot));
		for (int i = 0, length = qualification.length; i < length; i++) {
			this.indexer.addNameReference(qualification[i]);
		}
	}
}
 
Example 7
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 8
Source File: InternalCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean canUseDiamond(CompletionContext coreContext) {
	if (this.getKind() != CONSTRUCTOR_INVOCATION) return false;
	if (coreContext instanceof InternalCompletionContext) {
		InternalCompletionContext internalCompletionContext = (InternalCompletionContext) coreContext;
		if (internalCompletionContext.extendedContext == null) return false;
		char[] name1 = this.declarationPackageName;
		char[] name2 = this.declarationTypeName;
		char[] declarationType = CharOperation.concat(name1, name2, '.');  // fully qualified name
		// even if the type arguments used in the method have been substituted,
		// extract the original type arguments only, since thats what we want to compare with the class
		// type variables (Substitution might have happened when the constructor is coming from another
		// CU and not the current one).
		char[] sign = (this.originalSignature != null)? this.originalSignature : getSignature();
		if (!(sign == null || sign.length < 2)) {
			sign = Signature.removeCapture(sign);
		}
		char[][] types= Signature.getParameterTypes(sign);
		String[] paramTypeNames= new String[types.length];
		for (int i= 0; i < types.length; i++) {
			paramTypeNames[i]= new String(Signature.toCharArray(types[i]));
		}
		return internalCompletionContext.extendedContext.canUseDiamond(paramTypeNames,declarationType);
	}
	else {
		return false;
	}
}
 
Example 9
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 10
Source File: SimilarElementsRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addType(char[] typeNameSig, int flags, int relevance) {
	int kind= getKind(flags, typeNameSig);
	if (!isKind(kind)) {
		return;
	}
	String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig)));
	if (TypeFilter.isFiltered(fullName)) {
		return;
	}
	if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) {
		addResult(new SimilarElement(kind, fullName, relevance));
	}
}
 
Example 11
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 12
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
StyledString createJavadocTypeProposalLabel(CompletionProposal typeProposal) {
	char[] fullName= Signature.toCharArray(typeProposal.getSignature());
	return createJavadocTypeProposalLabel(fullName);
}
 
Example 13
Source File: Disassembler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private String disassemble(IVerificationTypeInfo[] infos, int mode) {
	StringBuffer buffer = new StringBuffer();
	buffer.append('{');
	for (int i = 0, max = infos.length; i < max; i++) {
		if(i != 0) {
			buffer
					.append(Messages.disassembler_comma)
					.append(Messages.disassembler_space);
		}
		switch(infos[i].getTag()) {
			case IVerificationTypeInfo.ITEM_DOUBLE :
				buffer.append("double"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_FLOAT :
				buffer.append("float"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_INTEGER :
				buffer.append("int"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_LONG :
				buffer.append("long"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_NULL :
				buffer.append("null"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_OBJECT :
				char[] classTypeName = infos[i].getClassTypeName();
				CharOperation.replace(classTypeName, '/', '.');
				if (classTypeName.length > 0 && classTypeName[0] == '[') { // length check for resilience
					classTypeName = Signature.toCharArray(classTypeName);
				}
				buffer.append(returnClassName(classTypeName, '.', mode));
				break;
			case IVerificationTypeInfo.ITEM_TOP :
				buffer.append("_"); //$NON-NLS-1$
				break;
			case IVerificationTypeInfo.ITEM_UNINITIALIZED :
				buffer.append("uninitialized("); //$NON-NLS-1$
				buffer.append(infos[i].getOffset());
				buffer.append(')');
				break;
			case IVerificationTypeInfo.ITEM_UNINITIALIZED_THIS :
				buffer.append("uninitialized_this"); //$NON-NLS-1$
		}
	}
	buffer.append('}');
	return String.valueOf(buffer);
}
 
Example 14
Source File: CompletionProposalCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the type signature of the declaring type of a
 * <code>CompletionProposal</code>, or <code>null</code> for proposals
 * that do not have a declaring type. The return value is <em>not</em>
 * <code>null</code> for proposals of the following kinds:
 * <ul>
 * <li>METHOD_DECLARATION</li>
 * <li>METHOD_NAME_REFERENCE</li>
 * <li>METHOD_REF</li>
 * <li>ANNOTATION_ATTRIBUTE_REF</li>
 * <li>POTENTIAL_METHOD_DECLARATION</li>
 * <li>ANONYMOUS_CLASS_DECLARATION</li>
 * <li>FIELD_REF</li>
 * <li>PACKAGE_REF (returns the package, but no type)</li>
 * <li>TYPE_REF</li>
 * </ul>
 *
 * @param proposal the completion proposal to get the declaring type for
 * @return the type signature of the declaring type, or <code>null</code> if there is none
 * @see Signature#toCharArray(char[])
 */
protected final char[] getDeclaringType(CompletionProposal proposal) {
	switch (proposal.getKind()) {
		case CompletionProposal.METHOD_DECLARATION:
		case CompletionProposal.METHOD_NAME_REFERENCE:
		case CompletionProposal.JAVADOC_METHOD_REF:
		case CompletionProposal.METHOD_REF:
		case CompletionProposal.CONSTRUCTOR_INVOCATION:
		case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
		case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
		case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
		case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
		case CompletionProposal.FIELD_REF:
		case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		case CompletionProposal.JAVADOC_FIELD_REF:
		case CompletionProposal.JAVADOC_VALUE_REF:
			char[] declaration= proposal.getDeclarationSignature();
			// special methods may not have a declaring type: methods defined on arrays etc.
			// Currently known: class literals don't have a declaring type - use Object
			if (declaration == null)
				return "java.lang.Object".toCharArray(); //$NON-NLS-1$
			return Signature.toCharArray(declaration);
		case CompletionProposal.PACKAGE_REF:
			return proposal.getDeclarationSignature();
		case CompletionProposal.JAVADOC_TYPE_REF:
		case CompletionProposal.TYPE_REF:
			return Signature.toCharArray(proposal.getSignature());
		case CompletionProposal.LOCAL_VARIABLE_REF:
		case CompletionProposal.VARIABLE_DECLARATION:
		case CompletionProposal.KEYWORD:
		case CompletionProposal.LABEL_REF:
		case CompletionProposal.JAVADOC_BLOCK_TAG:
		case CompletionProposal.JAVADOC_INLINE_TAG:
		case CompletionProposal.JAVADOC_PARAM_REF:
			return null;
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example 15
Source File: JavaTypeCompletionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void accept(CompletionProposal proposal) {
	switch (proposal.getKind()) {
		case CompletionProposal.PACKAGE_REF :
			char[] packageName= proposal.getDeclarationSignature();
			if (TypeFilter.isFiltered(packageName))
				return;
			addAdjustedCompletion(
					new String(packageName),
					new String(proposal.getCompletion()),
					proposal.getReplaceStart(),
					proposal.getReplaceEnd(),
					proposal.getRelevance(),
					JavaPluginImages.DESC_OBJS_PACKAGE);
			return;

		case CompletionProposal.TYPE_REF :
			char[] signature= proposal.getSignature();
			char[] fullName= Signature.toCharArray(signature);
			if (TypeFilter.isFiltered(fullName))
				return;
			StringBuffer buf= new StringBuffer();
			buf.append(Signature.getSimpleName(fullName));
			if (buf.length() == 0)
				return; // this is the dummy class, whose $ have been converted to dots
			char[] typeQualifier= Signature.getQualifier(fullName);
			if (typeQualifier.length > 0) {
				buf.append(JavaElementLabels.CONCAT_STRING);
				buf.append(typeQualifier);
			}
			String name= buf.toString();

			// Only fully qualify if it's a top level type:
			boolean fullyQualify= fFullyQualify && CharOperation.equals(proposal.getDeclarationSignature(), typeQualifier);

			ImageDescriptor typeImageDescriptor;
			switch (Signature.getTypeSignatureKind(signature)) {
				case Signature.TYPE_VARIABLE_SIGNATURE :
					typeImageDescriptor= JavaPluginImages.DESC_OBJS_TYPEVARIABLE;
					break;
				case Signature.CLASS_TYPE_SIGNATURE :
					typeImageDescriptor= JavaElementImageProvider.getTypeImageDescriptor(false, false, proposal.getFlags(), false);
					break;
				default :
					typeImageDescriptor= null;
			}

			addAdjustedTypeCompletion(
					name,
					new String(proposal.getCompletion()),
					proposal.getReplaceStart(),
					proposal.getReplaceEnd(),
					proposal.getRelevance(),
					typeImageDescriptor,
					fullyQualify ? new String(fullName) : null);
			return;

		case CompletionProposal.KEYWORD:
			if (! fEnableBaseTypes)
				return;
			String keyword= new String(proposal.getName());
			if ( (fEnableVoid && VOID.equals(keyword)) || (fEnableBaseTypes && BASE_TYPES.contains(keyword)) )
				addAdjustedCompletion(
						keyword,
						new String(proposal.getCompletion()),
						proposal.getReplaceStart(),
						proposal.getReplaceEnd(),
						proposal.getRelevance(),
						null);
			return;

		default :
			return;
	}

}
 
Example 16
Source File: CompletionProposalRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * copied from
 * org.eclipse.jdt.ui.text.java.CompletionProposalCollector.getDeclaringType(CompletionProposal)
 */
protected final char[] getDeclaringType(CompletionProposal proposal) {
	switch (proposal.getKind()) {
		case CompletionProposal.METHOD_DECLARATION:
		case CompletionProposal.METHOD_NAME_REFERENCE:
		case CompletionProposal.JAVADOC_METHOD_REF:
		case CompletionProposal.METHOD_REF:
		case CompletionProposal.CONSTRUCTOR_INVOCATION:
		case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
		case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
		case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
		case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
		case CompletionProposal.FIELD_REF:
		case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		case CompletionProposal.JAVADOC_FIELD_REF:
		case CompletionProposal.JAVADOC_VALUE_REF:
			char[] declaration = proposal.getDeclarationSignature();
			// special methods may not have a declaring type: methods defined on arrays etc.
			// Currently known: class literals don't have a declaring type - use Object
			if (declaration == null) {
				return "java.lang.Object".toCharArray(); //$NON-NLS-1$
			}
			return Signature.toCharArray(declaration);
		case CompletionProposal.PACKAGE_REF:
		case CompletionProposal.MODULE_REF:
		case CompletionProposal.MODULE_DECLARATION:
			return proposal.getDeclarationSignature();
		case CompletionProposal.JAVADOC_TYPE_REF:
		case CompletionProposal.TYPE_REF:
			return Signature.toCharArray(proposal.getSignature());
		case CompletionProposal.LOCAL_VARIABLE_REF:
		case CompletionProposal.VARIABLE_DECLARATION:
		case CompletionProposal.KEYWORD:
		case CompletionProposal.LABEL_REF:
		case CompletionProposal.JAVADOC_BLOCK_TAG:
		case CompletionProposal.JAVADOC_INLINE_TAG:
		case CompletionProposal.JAVADOC_PARAM_REF:
			return null;
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example 17
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private void createJavadocTypeProposalLabel(CompletionProposal typeProposal, CompletionItem item) {
	char[] fullName= Signature.toCharArray(typeProposal.getSignature());
	createJavadocTypeProposalLabel(fullName, item);
}
 
Example 18
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a display label for a given type proposal. The display label
 * consists of:
 * <ul>
 *   <li>the simple type name (erased when the context is in javadoc)</li>
 *   <li>the package name</li>
 * </ul>
 * <p>
 * Examples:
 * A proposal for the generic type <code>java.util.List&lt;E&gt;</code>, the display label
 * is: <code>List<E> - java.util</code>.
 * </p>
 *
 * @param typeProposal the method proposal to display
 * @return the display label for the given type proposal
 */
StyledString createTypeProposalLabel(CompletionProposal typeProposal) {
	char[] signature;
	if (fContext != null && fContext.isInJavadoc())
		signature= Signature.getTypeErasure(typeProposal.getSignature());
	else
		signature= typeProposal.getSignature();
	char[] fullName= Signature.toCharArray(signature);
	return createTypeProposalLabel(fullName);
}
 
Example 19
Source File: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Updates a display label for a given type proposal. The display label
 * consists of:
 * <ul>
 *   <li>the simple type name (erased when the context is in javadoc)</li>
 *   <li>the package name</li>
 * </ul>
 * <p>
 * Examples:
 * A proposal for the generic type <code>java.util.List&lt;E&gt;</code>, the display label
 * is: <code>List<E> - java.util</code>.
 * </p>
 *
 * @param typeProposal the method proposal to display
 * @param item the completion to update
 */
private void createTypeProposalLabel(CompletionProposal typeProposal, CompletionItem item) {
	char[] signature;
	if (fContext != null && fContext.isInJavadoc()) {
		signature= Signature.getTypeErasure(typeProposal.getSignature());
	} else {
		signature= typeProposal.getSignature();
	}
	char[] fullName= Signature.toCharArray(signature);
	createTypeProposalLabel(fullName, item);
	setDeclarationSignature(item, String.valueOf(signature));
}