Java Code Examples for org.eclipse.jdt.core.ITypeParameter#getBounds()
The following examples show how to use
org.eclipse.jdt.core.ITypeParameter#getBounds() .
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: StubCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected void appendTypeParameters(final ITypeParameter[] parameters) throws JavaModelException { final int length= parameters.length; if (length > 0) fBuffer.append("<"); //$NON-NLS-1$ for (int index= 0; index < length; index++) { if (index > 0) fBuffer.append(","); //$NON-NLS-1$ final ITypeParameter parameter= parameters[index]; fBuffer.append(parameter.getElementName()); final String[] bounds= parameter.getBounds(); final int size= bounds.length; if (size > 0) fBuffer.append(" extends "); //$NON-NLS-1$ for (int offset= 0; offset < size; offset++) { if (offset > 0) fBuffer.append(" & "); //$NON-NLS-1$ fBuffer.append(bounds[offset]); } } if (length > 0) fBuffer.append(">"); //$NON-NLS-1$ }
Example 2
Source File: NamedMember.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void appendTypeParameters(StringBuffer buffer) throws JavaModelException { ITypeParameter[] typeParameters = getTypeParameters(); int length = typeParameters.length; if (length == 0) return; buffer.append('<'); for (int i = 0; i < length; i++) { ITypeParameter typeParameter = typeParameters[i]; buffer.append(typeParameter.getElementName()); String[] bounds = typeParameter.getBounds(); int boundsLength = bounds.length; if (boundsLength > 0) { buffer.append(" extends "); //$NON-NLS-1$ for (int j = 0; j < boundsLength; j++) { buffer.append(bounds[j]); if (j < boundsLength-1) buffer.append(" & "); //$NON-NLS-1$ } } if (i < length-1) buffer.append(", "); //$NON-NLS-1$ } buffer.append('>'); }
Example 3
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 4
Source File: MethodOverrideTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getTypeParameterErasure(ITypeParameter typeParameter, IType context) throws JavaModelException { String[] bounds= typeParameter.getBounds(); if (bounds.length > 0) { return getSubstitutedTypeName(Signature.createTypeSignature(bounds[0], false), context); } return "Object"; //$NON-NLS-1$ }
Example 5
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 6
Source File: NamedMember.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected String getKey(IMethod method, boolean forceOpen) throws JavaModelException { StringBuffer key = new StringBuffer(); // declaring class String declaringKey = getKey((IType) method.getParent(), forceOpen); key.append(declaringKey); // selector key.append('.'); String selector = method.getElementName(); key.append(selector); // type parameters if (forceOpen) { ITypeParameter[] typeParameters = method.getTypeParameters(); int length = typeParameters.length; if (length > 0) { key.append('<'); for (int i = 0; i < length; i++) { ITypeParameter typeParameter = typeParameters[i]; String[] bounds = typeParameter.getBounds(); int boundsLength = bounds.length; char[][] boundSignatures = new char[boundsLength][]; for (int j = 0; j < boundsLength; j++) { boundSignatures[j] = Signature.createCharArrayTypeSignature(bounds[j].toCharArray(), method.isBinary()); CharOperation.replace(boundSignatures[j], '.', '/'); } char[] sig = Signature.createTypeParameterSignature(typeParameter.getElementName().toCharArray(), boundSignatures); key.append(sig); } key.append('>'); } } // parameters key.append('('); String[] parameters = method.getParameterTypes(); for (int i = 0, length = parameters.length; i < length; i++) key.append(parameters[i].replace('.', '/')); key.append(')'); // return type if (forceOpen) key.append(method.getReturnType().replace('.', '/')); else key.append('V'); return key.toString(); }
Example 7
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); }