Java Code Examples for org.eclipse.jdt.core.ITypeParameter#getElementName()
The following examples show how to use
org.eclipse.jdt.core.ITypeParameter#getElementName() .
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: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private String computeTypeProposal(ITypeParameter parameter) throws JavaModelException { String[] bounds= parameter.getBounds(); String elementName= parameter.getElementName(); if (bounds.length == 1 && !"java.lang.Object".equals(bounds[0])) { return Signature.getSimpleName(bounds[0]); } else { return elementName; } }
Example 2
Source File: TypeVariableUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a type variable mapping from a domain to a range. * * @param domain * the domain of the mapping * @param range * the range of the mapping * @param indexes * <code>true</code> if the indexes should be compared, <code>false</code> if the names should be compared * @return a possibly empty type variable mapping */ private static TypeVariableMaplet[] parametersToSignatures(final ITypeParameter[] domain, final String[] range, final boolean indexes) { Assert.isNotNull(domain); Assert.isNotNull(range); final Set<TypeVariableMaplet> set= new HashSet<TypeVariableMaplet>(); ITypeParameter source= null; String target= null; String element= null; String signature= null; for (int index= 0; index < domain.length; index++) { source= domain[index]; for (int offset= 0; offset < range.length; offset++) { target= range[offset]; element= source.getElementName(); signature= Signature.toString(target); if (indexes) { if (offset == index) set.add(new TypeVariableMaplet(element, index, signature, offset)); } else { if (element.equals(signature)) set.add(new TypeVariableMaplet(element, index, signature, offset)); } } } final TypeVariableMaplet[] result= new TypeVariableMaplet[set.size()]; set.toArray(result); return result; }
Example 3
Source File: LazyGenericTypeProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String computeTypeParameterDisplayName(ITypeParameter parameter, String[] bounds) { if (bounds.length == 0 || bounds.length == 1 && "java.lang.Object".equals(bounds[0])) //$NON-NLS-1$ return parameter.getElementName(); StringBuffer buf= new StringBuffer(parameter.getElementName()); buf.append(" extends "); //$NON-NLS-1$ for (int i= 0; i < bounds.length; i++) { buf.append(Signature.getSimpleName(bounds[i])); if (i < bounds.length - 1) buf.append(" & "); //$NON-NLS-1$ } return buf.toString(); }
Example 4
Source File: SelectionRequestor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean areTypeParametersCompatible(IMethod method, char[][] typeParameterNames, char[][][] typeParameterBoundNames) { try { ITypeParameter[] typeParameters = method.getTypeParameters(); int length1 = typeParameters == null ? 0 : typeParameters.length; int length2 = typeParameterNames == null ? 0 : typeParameterNames.length; if (length1 != length2) { return false; } else { for (int j = 0; j < length1; j++) { ITypeParameter typeParameter = typeParameters[j]; String typeParameterName = typeParameter.getElementName(); if (!typeParameterName.equals(new String(typeParameterNames[j]))) { return false; } String[] bounds = typeParameter.getBounds(); int boundCount = typeParameterBoundNames[j] == null ? 0 : typeParameterBoundNames[j].length; if (bounds.length != boundCount) { return false; } else { for (int k = 0; k < boundCount; k++) { String simpleName = Signature.getSimpleName(bounds[k]); int index = simpleName.indexOf('<'); if (index != -1) { simpleName = simpleName.substring(0, index); } if (!simpleName.equals(new String(typeParameterBoundNames[j][k]))) { return false; } } } } } } catch (JavaModelException e) { return false; } return true; }
Example 5
Source File: LazyGenericTypeProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Returns a type argument proposal for a given type parameter. The proposal is: * <ul> * <li>the type bound for type parameters with a single bound</li> * <li>the type parameter name for all other (unbounded or more than one bound) type parameters</li> * </ul> * Type argument proposals for type parameters are always ambiguous. * * @param parameter the type parameter of the inserted type * @return a type argument proposal for <code>parameter</code> * @throws JavaModelException if this element does not exist or if an exception occurs while * accessing its corresponding resource */ private TypeArgumentProposal computeTypeProposal(ITypeParameter parameter) throws JavaModelException { String[] bounds= parameter.getBounds(); String elementName= parameter.getElementName(); String displayName= computeTypeParameterDisplayName(parameter, bounds); if (bounds.length == 1 && !"java.lang.Object".equals(bounds[0])) //$NON-NLS-1$ return new TypeArgumentProposal(Signature.getSimpleName(bounds[0]), true, displayName); else return new TypeArgumentProposal(elementName, true, displayName); }