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

The following examples show how to use org.eclipse.jdt.core.Signature#getTypeErasure() . 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: CompletionProposalDescriptionProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
	char[] declaringTypeSignature= proposal.getDeclarationSignature();
	declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
	String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
	item.setInsertText(name);
	StringBuilder buf= new StringBuilder();
	buf.append(name);
	buf.append('(');
	appendUnboundedParameterList(buf, proposal);
	buf.append(')');
	buf.append("  "); //$NON-NLS-1$
	buf.append("Anonymous Inner Type"); //TODO: consider externalization
	item.setLabel(buf.toString());

	if (proposal.getRequiredProposals() != null) {
		char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
		if (signatureQualifier.length > 0) {
			item.setDetail(String.valueOf(signatureQualifier) + "." + name);
		}
	}
	setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
 
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: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope) throws JavaModelException {
	if (type.getDimensions() != Signature.getArrayCount(candidate))
		return false;

	// Normalizes types
	if (type.isArray())
		type= type.getElementType();
	candidate= Signature.getElementType(candidate);

	if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE) != type.isPrimitive()) {
		return false;
	}

	if (type.isPrimitive() || type.isTypeVariable()) {
		return type.getName().equals(Signature.toString(candidate));
	} else {
		// normalize (quick hack until binding.getJavaElement works)
		candidate= Signature.getTypeErasure(candidate);
		type= type.getErasure();

		if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) {
			return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type));
		} else {
			String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate));
			if (qualifiedCandidates == null || qualifiedCandidates.length == 0)
				return false;
			String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$
			String typeName= getTypeQualifiedName(type);
			for (int i= 0; i < qualifiedCandidates.length; i++) {
				String[] qualifiedCandidate= qualifiedCandidates[i];
				if (	qualifiedCandidate[0].equals(packageName) &&
						qualifiedCandidate[1].equals(typeName))
					return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: BinaryMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String [] getErasedParameterTypes() {
	if (this.erasedParamaterTypes == null) {
		int paramCount = this.parameterTypes.length;
		String [] erasedTypes = new String [paramCount];
		boolean erasureNeeded = false;
		for (int i = 0; i < paramCount; i++) {
			String parameterType = this.parameterTypes[i];
			if ((erasedTypes[i] = Signature.getTypeErasure(parameterType)) != parameterType)
				erasureNeeded = true;
		}
		this.erasedParamaterTypes = erasureNeeded ? erasedTypes : this.parameterTypes;
	}
	return this.erasedParamaterTypes;
}
 
Example 5
Source File: MethodProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the simple erased name for a given type signature, possibly replacing type variables.
 *
 * @param signature the type signature
 * @param typeVariables the Map&lt;SimpleName, VariableName>
 * @return the simple erased name for signature
 */
private String computeSimpleTypeName(String signature, Map<String, char[]> typeVariables) {
	// method equality uses erased types
	String erasure= Signature.getTypeErasure(signature);
	erasure= erasure.replaceAll("/", ".");  //$NON-NLS-1$//$NON-NLS-2$
	String simpleName= Signature.getSimpleName(Signature.toString(erasure));
	char[] typeVar= typeVariables.get(simpleName);
	if (typeVar != null)
		simpleName= String.valueOf(Signature.getSignatureSimpleName(typeVar));
	return simpleName;
}
 
Example 6
Source File: JavaElementReturnTypeHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void open() {
	try {
		String returnTypeSignature= fMethod.getReturnType();
		int kind= Signature.getTypeSignatureKind(returnTypeSignature);
		if (kind == Signature.ARRAY_TYPE_SIGNATURE) {
			returnTypeSignature= Signature.getElementType(returnTypeSignature);
		} else if (kind == Signature.CLASS_TYPE_SIGNATURE) {
			returnTypeSignature= Signature.getTypeErasure(returnTypeSignature);
		}
		String returnType= Signature.toString(returnTypeSignature);

		String[][] resolvedType= fMethod.getDeclaringType().resolveType(returnType);
		if (resolvedType == null || resolvedType.length == 0) {
			openMethodAndShowErrorInStatusLine();
			return;
		}

		String typeName= JavaModelUtil.concatenateName(resolvedType[0][0], resolvedType[0][1]);
		IType type= fMethod.getJavaProject().findType(typeName, (IProgressMonitor)null);
		if (type != null) {
			fOpenAction.run(new StructuredSelection(type));
			return;
		}
		openMethodAndShowErrorInStatusLine();
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
		return;
	}
}
 
Example 7
Source File: SignatureUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the qualified signature corresponding to
 * <code>signature</code>.
 *
 * @param signature the signature to qualify
 * @param context the type inside which an unqualified type will be
 *        resolved to find the qualifier, or <code>null</code> if no
 *        context is available
 * @return the qualified signature
 */
public static String qualifySignature(final String signature, final IType context) {
	if (context == null)
		return signature;

	String qualifier= Signature.getSignatureQualifier(signature);
	if (qualifier.length() > 0)
		return signature;

	String elementType= Signature.getElementType(signature);
	String erasure= Signature.getTypeErasure(elementType);
	String simpleName= Signature.getSignatureSimpleName(erasure);
	String genericSimpleName= Signature.getSignatureSimpleName(elementType);

	int dim= Signature.getArrayCount(signature);

	try {
		String[][] strings= context.resolveType(simpleName);
		if (strings != null && strings.length > 0)
			qualifier= strings[0][0];
	} catch (JavaModelException e) {
		// ignore - not found
	}

	if (qualifier.length() == 0)
		return signature;

	String qualifiedType= Signature.toQualifiedName(new String[] {qualifier, genericSimpleName});
	String qualifiedSignature= Signature.createTypeSignature(qualifiedType, true);
	String newSignature= Signature.createArraySignature(qualifiedSignature, dim);

	return newSignature;
}
 
Example 8
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void appendMethodReference(IMethod meth, StringBuffer buf) throws JavaModelException {
	buf.append(meth.getElementName());

	/*
	 * The Javadoc tool for Java SE 8 changed the anchor syntax and now tries to avoid "strange" characters in URLs.
	 * This breaks all clients that directly create such URLs.
	 * We can't know what format is required, so we just guess by the project's compiler compliance.
	 */
	boolean is18OrHigher= JavaModelUtil.is18OrHigher(meth.getJavaProject());
	buf.append(is18OrHigher ? '-' : '(');
	String[] params= meth.getParameterTypes();
	IType declaringType= meth.getDeclaringType();
	boolean isVararg= Flags.isVarargs(meth.getFlags());
	int lastParam= params.length - 1;
	for (int i= 0; i <= lastParam; i++) {
		if (i != 0) {
			buf.append(is18OrHigher ? "-" : ", "); //$NON-NLS-1$ //$NON-NLS-2$
		}
		String curr= Signature.getTypeErasure(params[i]);
		String fullName= JavaModelUtil.getResolvedTypeName(curr, declaringType);
		if (fullName == null) { // e.g. a type parameter "QE;"
			fullName= Signature.toString(Signature.getElementType(curr));
		}
		if (fullName != null) {
			buf.append(fullName);
			int dim= Signature.getArrayCount(curr);
			if (i == lastParam && isVararg) {
				dim--;
			}
			while (dim > 0) {
				buf.append(is18OrHigher ? ":A" : "[]"); //$NON-NLS-1$ //$NON-NLS-2$
				dim--;
			}
			if (i == lastParam && isVararg) {
				buf.append("..."); //$NON-NLS-1$
			}
		}
	}
	buf.append(is18OrHigher ? '-' : ')');
}
 
Example 9
Source File: RemoteServiceUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static String resolveToQualifiedErasure(IType context,
    String typeSignature) throws RemoteServiceException {
  try {
    String typeErasureSig = Signature.getTypeErasure(typeSignature);
    String type = Signature.getSignatureSimpleName(typeErasureSig);
    String qualifiedErasure = JavaModelSearch.resolveTypeName(context, type);
    if (qualifiedErasure == null) {
      throw new RemoteServiceException("Could not resolve type " + type);
    }
    return qualifiedErasure;
  } catch (JavaModelException e) {
    throw new RemoteServiceException(e);
  }
}
 
Example 10
Source File: JavaModelSearch.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes any type parameters and any array nesting in a type signature.
 */
private static String getBaseType(String typeSignature) {
  // Strip off any type parameters
  typeSignature = Signature.getTypeErasure(typeSignature);

  // Strip off any array nesting
  typeSignature = Signature.getElementType(typeSignature);

  return typeSignature;
}
 
Example 11
Source File: JavaDocLocations.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void appendMethodReference(IMethod meth, StringBuffer buf) throws JavaModelException {
	buf.append(meth.getElementName());

	/*
	 * The Javadoc tool for Java SE 8 changed the anchor syntax and now tries to avoid "strange" characters in URLs.
	 * This breaks all clients that directly create such URLs.
	 * We can't know what format is required, so we just guess by the project's compiler compliance.
	 */
	boolean is18OrHigher = JavaModelUtil.is18OrHigher(meth.getJavaProject());
	buf.append(is18OrHigher ? '-' : '(');
	String[] params = meth.getParameterTypes();
	IType declaringType = meth.getDeclaringType();
	boolean isVararg = Flags.isVarargs(meth.getFlags());
	int lastParam = params.length - 1;
	for (int i = 0; i <= lastParam; i++) {
		if (i != 0) {
			buf.append(is18OrHigher ? "-" : ", "); //$NON-NLS-1$ //$NON-NLS-2$
		}
		String curr = Signature.getTypeErasure(params[i]);
		String fullName = JavaModelUtil.getResolvedTypeName(curr, declaringType);
		if (fullName == null) { // e.g. a type parameter "QE;"
			fullName = Signature.toString(Signature.getElementType(curr));
		}
		if (fullName != null) {
			buf.append(fullName);
			int dim = Signature.getArrayCount(curr);
			if (i == lastParam && isVararg) {
				dim--;
			}
			while (dim > 0) {
				buf.append(is18OrHigher ? ":A" : "[]"); //$NON-NLS-1$ //$NON-NLS-2$
				dim--;
			}
			if (i == lastParam && isVararg) {
				buf.append("..."); //$NON-NLS-1$
			}
		}
	}
	buf.append(is18OrHigher ? '-' : ')');
}
 
Example 12
Source File: JavaStatementPostfixContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Type createType(String typeSig, AST ast) {
	int sigKind = Signature.getTypeSignatureKind(typeSig);
       switch (sigKind) {
           case Signature.BASE_TYPE_SIGNATURE:
               return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig)));
           case Signature.ARRAY_TYPE_SIGNATURE:
               Type elementType = createType(Signature.getElementType(typeSig), ast);
               return ast.newArrayType(elementType, Signature.getArrayCount(typeSig));
           case Signature.CLASS_TYPE_SIGNATURE:
               String erasureSig = Signature.getTypeErasure(typeSig);

               String erasureName = Signature.toString(erasureSig);
               if (erasureSig.charAt(0) == Signature.C_RESOLVED) {
                   erasureName = addImport(erasureName);
               }
               
               Type baseType= ast.newSimpleType(ast.newName(erasureName));
               String[] typeArguments = Signature.getTypeArguments(typeSig);
               if (typeArguments.length > 0) {
                   ParameterizedType type = ast.newParameterizedType(baseType);
                   List argNodes = type.typeArguments();
                   for (int i = 0; i < typeArguments.length; i++) {
                       String curr = typeArguments[i];
                       if (containsNestedCapture(curr)) {
                           argNodes.add(ast.newWildcardType());
                       } else {
                           argNodes.add(createType(curr, ast));
                       }
                   }
                   return type;
               }
               return baseType;
           case Signature.TYPE_VARIABLE_SIGNATURE:
               return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig)));
           case Signature.WILDCARD_TYPE_SIGNATURE:
               WildcardType wildcardType= ast.newWildcardType();
               char ch = typeSig.charAt(0);
               if (ch != Signature.C_STAR) {
                   Type bound= createType(typeSig.substring(1), ast);
                   wildcardType.setBound(bound, ch == Signature.C_EXTENDS);
               }
               return wildcardType;
           case Signature.CAPTURE_TYPE_SIGNATURE:
               return createType(typeSig.substring(1), ast);
       }
       
       return ast.newSimpleType(ast.newName("java.lang.Object"));
}
 
Example 13
Source File: ImportRewrite.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds a new import to the rewriter's record and returns a {@link Type} node that can be used
 * in the code as a reference to the type. The type binding can be an array binding, type variable or wildcard.
 * If the binding is a generic type, the type parameters are ignored. For parameterized types, also the type
 * arguments are processed and imports added if necessary. Anonymous types inside type arguments are normalized to their base type, wildcard
 * of wildcards are ignored.
 * 	<p>
	 * No imports are added for types that are already known. If a import for a type is recorded to be removed, this record is discarded instead.
 * </p>
 * <p>
 * The content of the compilation unit itself is actually not modified
 * in any way by this method; rather, the rewriter just records that a new import has been added.
 * </p>
 * @param typeSig the signature of the type to be added.
 * @param ast the AST to create the returned type for.
 * @param context an optional context that knows about types visible in the current scope or <code>null</code>
 * to use the default context only using the available imports.
 * @return a type node for the given type signature. Type names are simple names if an import could be used,
 * or else qualified names if an import conflict prevented an import.
 */
public Type addImportFromSignature(String typeSig, AST ast, ImportRewriteContext context) {
	if (typeSig == null || typeSig.length() == 0) {
		throw new IllegalArgumentException("Invalid type signature: empty or null"); //$NON-NLS-1$
	}
	int sigKind= Signature.getTypeSignatureKind(typeSig);
	switch (sigKind) {
		case Signature.BASE_TYPE_SIGNATURE:
			return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig)));
		case Signature.ARRAY_TYPE_SIGNATURE:
			Type elementType= addImportFromSignature(Signature.getElementType(typeSig), ast, context);
			return ast.newArrayType(elementType, Signature.getArrayCount(typeSig));
		case Signature.CLASS_TYPE_SIGNATURE:
			String erasureSig= Signature.getTypeErasure(typeSig);

			String erasureName= Signature.toString(erasureSig);
			if (erasureSig.charAt(0) == Signature.C_RESOLVED) {
				erasureName= internalAddImport(erasureName, context);
			}
			Type baseType= ast.newSimpleType(ast.newName(erasureName));
			String[] typeArguments= Signature.getTypeArguments(typeSig);
			if (typeArguments.length > 0) {
				ParameterizedType type= ast.newParameterizedType(baseType);
				List argNodes= type.typeArguments();
				for (int i= 0; i < typeArguments.length; i++) {
					String curr= typeArguments[i];
					if (containsNestedCapture(curr)) { // see bug 103044
						argNodes.add(ast.newWildcardType());
					} else {
						argNodes.add(addImportFromSignature(curr, ast, context));
					}
				}
				return type;
			}
			return baseType;
		case Signature.TYPE_VARIABLE_SIGNATURE:
			return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig)));
		case Signature.WILDCARD_TYPE_SIGNATURE:
			WildcardType wildcardType= ast.newWildcardType();
			char ch= typeSig.charAt(0);
			if (ch != Signature.C_STAR) {
				Type bound= addImportFromSignature(typeSig.substring(1), ast, context);
				wildcardType.setBound(bound, ch == Signature.C_EXTENDS);
			}
			return wildcardType;
		case Signature.CAPTURE_TYPE_SIGNATURE:
			return addImportFromSignature(typeSig.substring(1), ast, context);
		default:
			throw new IllegalArgumentException("Unknown type signature kind: " + typeSig); //$NON-NLS-1$
	}
}
 
Example 14
Source File: ImportCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Computes the replacement string.
 *
 * @return the replacement string
 */
private String computeReplacementString() {
	int proposalKind= fProposal.getKind();
	String qualifiedTypeName= null;
	char[] qualifiedType= null;
		if (proposalKind == CompletionProposal.TYPE_IMPORT) {
			qualifiedType= fProposal.getSignature();
	 		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
		} else if (proposalKind == CompletionProposal.METHOD_IMPORT || proposalKind == CompletionProposal.FIELD_IMPORT) {
           qualifiedType= Signature.getTypeErasure(fProposal.getDeclarationSignature());
           qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else {
		/*
		 * In 3.3 we only support the above import proposals, see
		 * CompletionProposal#getRequiredProposals()
		 */
		 Assert.isTrue(false);
	}

		/* Add imports if the preference is on. */
		fImportRewrite= createImportRewrite();
		if (fImportRewrite != null) {
 		if (proposalKind == CompletionProposal.TYPE_IMPORT) {
 			String simpleType= fImportRewrite.addImport(qualifiedTypeName, fImportContext);
	 		if (fParentProposalKind == CompletionProposal.METHOD_REF)
	 			return simpleType + "."; //$NON-NLS-1$
			} else {
			String res= fImportRewrite.addStaticImport(qualifiedTypeName, String.valueOf(fProposal.getName()), proposalKind == CompletionProposal.FIELD_IMPORT, fImportContext);
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				String typeName= fImportRewrite.addImport(res.substring(0, dot), fImportContext);
				return typeName + '.';
			}
		}
 		return ""; //$NON-NLS-1$
 	}

	// Case where we don't have an import rewrite (see allowAddingImports)

	if (fCompilationUnit != null && JavaModelUtil.isImplicitImport(Signature.getQualifier(qualifiedTypeName), fCompilationUnit)) {
		/* No imports for implicit imports. */

		if (fProposal.getKind() == CompletionProposal.TYPE_IMPORT && fParentProposalKind == CompletionProposal.FIELD_REF)
			return ""; //$NON-NLS-1$
		qualifiedTypeName= String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
	}

	return qualifiedTypeName + "."; //$NON-NLS-1$
}
 
Example 15
Source File: CompletionProposalReplacementProvider.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private StringBuilder appendImportProposal(StringBuilder buffer, CompletionProposal proposal, int coreKind) {
	int proposalKind= proposal.getKind();
	String qualifiedTypeName= null;
	char[] qualifiedType= null;
	if (proposalKind == CompletionProposal.TYPE_IMPORT) {
		qualifiedType= proposal.getSignature();
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else if (proposalKind == CompletionProposal.METHOD_IMPORT || proposalKind == CompletionProposal.FIELD_IMPORT) {
		qualifiedType= Signature.getTypeErasure(proposal.getDeclarationSignature());
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else {
		/*
		 * In 3.3 we only support the above import proposals, see
		 * CompletionProposal#getRequiredProposals()
		 */
		Assert.isTrue(false);
	}

	/* Add imports if the preference is on. */
	if (importRewrite != null) {
		if (proposalKind == CompletionProposal.TYPE_IMPORT) {
			String simpleType= importRewrite.addImport(qualifiedTypeName, null);
			if (coreKind == CompletionProposal.METHOD_REF) {
				buffer.append(simpleType);
				buffer.append(COMMA);
				return buffer;
			}
		} else {
			String res= importRewrite.addStaticImport(qualifiedTypeName, String.valueOf(proposal.getName()), proposalKind == CompletionProposal.FIELD_IMPORT, null);
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				buffer.append(importRewrite.addImport(res.substring(0, dot), null));
				buffer.append('.');
				return buffer;
			}
		}
		return buffer;
	}

	// Case where we don't have an import rewrite (see allowAddingImports)

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

		if (proposal.getKind() == CompletionProposal.TYPE_IMPORT && coreKind == CompletionProposal.FIELD_REF) {
			return buffer;
		}
		qualifiedTypeName= String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
	}
	buffer.append(qualifiedTypeName);
	buffer.append('.');
	return buffer;
}
 
Example 16
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public String getTypeErasure(String signature) {
	String fixedSignature = signature.replaceAll(">\\.", ">\\$");
	return Signature.getTypeErasure(fixedSignature);
}
 
Example 17
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));
}
 
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: SignatureUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the fully qualified type name of the given signature, with any
 * type parameters and arrays erased.
 *
 * @param signature the signature
 * @return the fully qualified type name of the signature
 * @throws IllegalArgumentException if the signature is syntactically incorrect
 */
public static String stripSignatureToFQN(String signature) throws IllegalArgumentException {
	signature= Signature.getTypeErasure(signature);
	signature= Signature.getElementType(signature);
	return Signature.toString(signature);
}