Java Code Examples for org.eclipse.jdt.internal.corext.util.Strings#markJavaElementLabelLTR()

The following examples show how to use org.eclipse.jdt.internal.corext.util.Strings#markJavaElementLabelLTR() . 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: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates and returns a parameter list of the given method or type proposal suitable for
 * display. The list does not include parentheses. The lower bound of parameter types is
 * returned.
 * <p>
 * Examples:
 * 
 * <pre>
 *   &quot;void method(int i, String s)&quot; -&gt; &quot;int i, String s&quot;
 *   &quot;? extends Number method(java.lang.String s, ? super Number n)&quot; -&gt; &quot;String s, Number n&quot;
 * </pre>
 * 
 * </p>
 * 
 * @param proposal the proposal to create the parameter list for
 * @return the list of comma-separated parameters suitable for display
 */
public String createParameterList(CompletionProposal proposal) {
	String paramList;
	int kind= proposal.getKind();
	switch (kind) {
		case CompletionProposal.METHOD_REF:
		case CompletionProposal.CONSTRUCTOR_INVOCATION:
			paramList= appendUnboundedParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		case CompletionProposal.TYPE_REF:
		case CompletionProposal.JAVADOC_TYPE_REF:
			paramList= appendTypeParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
		case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
			paramList= appendUnboundedParameterList(new StyledString(), proposal).getString();
			return Strings.markJavaElementLabelLTR(paramList);
		default:
			Assert.isLegal(false);
			return null; // dummy
	}
}
 
Example 2
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
StyledString createAnonymousTypeLabel(CompletionProposal proposal) {
	char[] declaringTypeSignature= proposal.getDeclarationSignature();
	declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);

	StyledString buffer= new StyledString();
	buffer.append(Signature.getSignatureSimpleName(declaringTypeSignature));
	buffer.append('(');
	appendUnboundedParameterList(buffer, proposal);
	buffer.append(')');
	buffer.append("  "); //$NON-NLS-1$
	buffer.append(JavaTextMessages.ResultCollector_anonymous_type);

	if (proposal.getRequiredProposals() != null) {
		char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
		if (signatureQualifier.length > 0) {
			buffer.append(JavaElementLabels.CONCAT_STRING, StyledString.QUALIFIER_STYLER);
			buffer.append(signatureQualifier, StyledString.QUALIFIER_STYLER);
		}
	}

	return Strings.markJavaElementLabelLTR(buffer);
}
 
Example 3
Source File: LazyGenericTypeProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String computeContextString(LazyGenericTypeProposal proposal) {
	try {
		TypeArgumentProposal[] proposals= proposal.computeTypeArgumentProposals();
		if (proposals.length == 0)
			return null;

		StringBuffer buf= new StringBuffer();
		for (int i= 0; i < proposals.length; i++) {
			buf.append(proposals[i].getDisplayName());
			if (i < proposals.length - 1)
				buf.append(", "); //$NON-NLS-1$
		}
		return Strings.markJavaElementLabelLTR(buf.toString());

	} catch (JavaModelException e) {
		return null;
	}
}
 
Example 4
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 5
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createTypeProposalLabel(char[] fullName) {
	// only display innermost type name as type name, using any
	// enclosing types as qualification
	int qIndex= findSimpleNameStart(fullName);

	StyledString buf= new StyledString();
	buf.append(new String(fullName, qIndex, fullName.length - qIndex));
	if (qIndex > 0) {
		buf.append(JavaElementLabels.CONCAT_STRING, StyledString.QUALIFIER_STYLER);
		buf.append(new String(fullName, 0, qIndex - 1), StyledString.QUALIFIER_STYLER);
	}
	return Strings.markJavaElementLabelLTR(buf);
}
 
Example 6
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createJavadocTypeProposalLabel(char[] fullName) {
	// only display innermost type name as type name, using any
	// enclosing types as qualification
	int qIndex= findSimpleNameStart(fullName);

	StyledString buf= new StyledString("{@link "); //$NON-NLS-1$
	buf.append(new String(fullName, qIndex, fullName.length - qIndex));
	buf.append('}');
	if (qIndex > 0) {
		buf.append(JavaElementLabels.CONCAT_STRING, StyledString.QUALIFIER_STYLER);
		buf.append(new String(fullName, 0, qIndex - 1), StyledString.QUALIFIER_STYLER);
	}
	return Strings.markJavaElementLabelLTR(buf);
}
 
Example 7
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createSimpleLabelWithType(CompletionProposal proposal) {
	StyledString buf= new StyledString();
	buf.append(proposal.getCompletion());
	char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
	if (typeName.length > 0) {
		buf.append(VAR_TYPE_SEPARATOR);
		buf.append(typeName);
	}
	return Strings.markJavaElementLabelLTR(buf);
}
 
Example 8
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
StyledString createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
	char[] name= proposal.getCompletion();
	if (!isThisPrefix(name))
		name= proposal.getName();

	StyledString buf= new StyledString();
	buf.append(name);
	char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
	if (typeName.length > 0) {
		buf.append(VAR_TYPE_SEPARATOR);
		buf.append(typeName);
	}
	char[] declaration= proposal.getDeclarationSignature();
	if (declaration != null) {
		declaration= Signature.getSignatureSimpleName(declaration);
		if (declaration.length > 0) {
			buf.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
			if (proposal.getRequiredProposals() != null) {
				String declaringType= extractDeclaringTypeFQN(proposal);
				String qualifier= Signature.getQualifier(declaringType);
				if (qualifier.length() > 0) {
					buf.append(qualifier, StyledString.QUALIFIER_STYLER);
					buf.append('.', StyledString.QUALIFIER_STYLER);
				}
			}
			buf.append(declaration, StyledString.QUALIFIER_STYLER);
		}
	}

	return Strings.markJavaElementLabelLTR(buf);
}
 
Example 9
Source File: JavaElementLinks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}.
 * Referenced element names in the label are rendered as header links.
 * If <code>linkAllNames</code> is <code>false</code>, don't link the name of the given element
 *
 * @param element the element to render
 * @param flags the rendering flags
 * @param linkAllNames if <code>true</code>, link all names; if <code>false</code>, link all names except original element's name
 * @return the label of the Java element
 * @since 3.6
 */
public static String getElementLabel(IJavaElement element, long flags, boolean linkAllNames) {
	StringBuffer buf= new StringBuffer();

	if (!Strings.USE_TEXT_PROCESSOR) {
		new JavaElementLinkedLabelComposer(linkAllNames ? null : element, buf).appendElementLabel(element, flags);
		return Strings.markJavaElementLabelLTR(buf.toString());
	} else {
		String label= JavaElementLabels.getElementLabel(element, flags);
		return label.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
	}
}
 
Example 10
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
StyledString createPackageProposalLabel(CompletionProposal proposal) {
	Assert.isTrue(proposal.getKind() == CompletionProposal.PACKAGE_REF);
	return Strings.markJavaElementLabelLTR(new StyledString(String.valueOf(proposal.getDeclarationSignature())));
}
 
Example 11
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
StyledString createSimpleLabel(CompletionProposal proposal) {
	return Strings.markJavaElementLabelLTR(new StyledString(String.valueOf(proposal.getCompletion())));
}
 
Example 12
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 the given method proposal. The display label consists of:
 * <ul>
 * <li>the method name</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) - List</code>.<br>
 * For the <code>add(E)</code> method of a variable of type <code>List</code>, the
 * following display name is returned:
 * <code>add(Object) - List</code>.<br>
 * </p>
 *
 * @param methodProposal the method proposal to display
 * @return the display label for the given method proposal
 * @since 3.2
 */
StyledString createJavadocMethodProposalLabel(CompletionProposal methodProposal) {
	StyledString nameBuffer= new StyledString();

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

	// declaring type
	nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
	String declaringType= extractDeclaringTypeFQN(methodProposal);
	declaringType= Signature.getSimpleName(declaringType);
	nameBuffer.append(declaringType, StyledString.QUALIFIER_STYLER);

	return Strings.markJavaElementLabelLTR(nameBuffer);
}
 
Example 13
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the label for a Java element with the flags as defined by this class.
 *
 * @param element the element to render
 * @param flags the rendering flags
 * @return the label of the Java element
 */
public static String getElementLabel(IJavaElement element, long flags) {
	StringBuffer result= new StringBuffer();
	getElementLabel(element, flags, result);
	return Strings.markJavaElementLabelLTR(result.toString());
}
 
Example 14
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the styled label for a Java element with the flags as defined by this class.
 *
 * @param element the element to render
 * @param flags the rendering flags
 * @return the label of the Java element
 *
 * @since 3.4
 */
public static StyledString getStyledElementLabel(IJavaElement element, long flags) {
	StyledString result= new StyledString();
	getElementLabel(element, flags, result);
	return Strings.markJavaElementLabelLTR(result);
}
 
Example 15
Source File: BasicElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns a label for Java element name. Example is 'new Test<? extends List>() { ...}'.
 * This method should only be used for simple element names. Use
 * {@link JavaElementLabels} to create a label from a Java element or {@link BindingLabelProvider}
 * for labels of bindings.
 *
 * @param name the Java element name.
 * @return the label for the Java element
 */
public static String getJavaElementName(String name) {
	return Strings.markJavaElementLabelLTR(name);
}