Search in sources :

Example 1 with StyledString

use of org.eclipse.jface.viewers.StyledString in project che by eclipse.

the class CompletionProposalLabelProvider method createTypeProposalLabel.

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);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 2 with StyledString

use of org.eclipse.jface.viewers.StyledString in project che by eclipse.

the class CompletionProposalLabelProvider method createJavadocMethodProposalLabel.

/**
	 * 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);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 3 with StyledString

use of org.eclipse.jface.viewers.StyledString in project che by eclipse.

the class CompletionProposalLabelProvider method createMethodProposalLabel.

/**
	 * 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(org.eclipse.jdt.core.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);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with StyledString

use of org.eclipse.jface.viewers.StyledString in project che by eclipse.

the class CompletionProposalCollector method createMethodDeclarationProposal.

private IJavaCompletionProposal createMethodDeclarationProposal(CompletionProposal proposal) {
    if (fCompilationUnit == null || fJavaProject == null)
        return null;
    String name = String.valueOf(proposal.getName());
    String[] paramTypes = Signature.getParameterTypes(String.valueOf(proposal.getSignature()));
    for (int index = 0; index < paramTypes.length; index++) paramTypes[index] = Signature.toString(paramTypes[index]);
    int start = proposal.getReplaceStart();
    int length = getLength(proposal);
    StyledString label = fLabelProvider.createOverrideMethodProposalLabel(proposal);
    JavaCompletionProposal javaProposal = new OverrideCompletionProposal(fJavaProject, fCompilationUnit, name, paramTypes, start, length, label, String.valueOf(proposal.getCompletion()));
    javaProposal.setImage(getImage(fLabelProvider.createMethodImageDescriptor(proposal)));
    javaProposal.setProposalInfo(new MethodProposalInfo(fJavaProject, proposal));
    javaProposal.setRelevance(computeRelevance(proposal));
    fSuggestedMethodNames.add(new String(name));
    return javaProposal;
}
Also used : OverrideCompletionProposal(org.eclipse.jdt.internal.ui.text.java.OverrideCompletionProposal) MethodProposalInfo(org.eclipse.jdt.internal.ui.text.java.MethodProposalInfo) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal) LazyJavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal)

Example 5 with StyledString

use of org.eclipse.jface.viewers.StyledString in project che by eclipse.

the class CompletionProposalCollector method createFieldProposal.

private IJavaCompletionProposal createFieldProposal(CompletionProposal proposal) {
    String completion = String.valueOf(proposal.getCompletion());
    int start = proposal.getReplaceStart();
    int length = getLength(proposal);
    StyledString label = fLabelProvider.createStyledLabel(proposal);
    Image image = getImage(fLabelProvider.createFieldImageDescriptor(proposal));
    int relevance = computeRelevance(proposal);
    JavaCompletionProposal javaProposal = new JavaCompletionProposal(completion, start, length, image, label, relevance, getContext().isInJavadoc(), getInvocationContext());
    if (fJavaProject != null)
        javaProposal.setProposalInfo(new FieldProposalInfo(fJavaProject, proposal));
    javaProposal.setTriggerCharacters(VAR_TRIGGER);
    return javaProposal;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal) LazyJavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal) FieldProposalInfo(org.eclipse.jdt.internal.ui.text.java.FieldProposalInfo)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)202 Image (org.eclipse.swt.graphics.Image)22 ViewerCell (org.eclipse.jface.viewers.ViewerCell)10 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)9 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)9 Composite (org.eclipse.swt.widgets.Composite)9 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)8 LazyJavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal)8 GridData (org.eclipse.swt.layout.GridData)8 Entry (java.util.Map.Entry)7 Styler (org.eclipse.jface.viewers.StyledString.Styler)7 TableViewer (org.eclipse.jface.viewers.TableViewer)7 Label (org.eclipse.swt.widgets.Label)7 Table (org.eclipse.swt.widgets.Table)7 Test (org.junit.Test)7 EObject (org.eclipse.emf.ecore.EObject)6 StyleRange (org.eclipse.swt.custom.StyleRange)5 ParserRule (org.eclipse.xtext.ParserRule)5 IOException (java.io.IOException)4