Java Code Examples for org.eclipse.jdt.core.Signature#getElementType()
The following examples show how to use
org.eclipse.jdt.core.Signature#getElementType() .
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: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static List<ParameterInfo> createParameterInfoList(IMethod method) { try { String[] typeNames= method.getParameterTypes(); String[] oldNames= method.getParameterNames(); List<ParameterInfo> result= new ArrayList<ParameterInfo>(typeNames.length); for (int i= 0; i < oldNames.length; i++){ ParameterInfo parameterInfo; if (i == oldNames.length - 1 && Flags.isVarargs(method.getFlags())) { String varargSignature= typeNames[i]; int arrayCount= Signature.getArrayCount(varargSignature); String baseSignature= Signature.getElementType(varargSignature); if (arrayCount > 1) baseSignature= Signature.createArraySignature(baseSignature, arrayCount - 1); parameterInfo= new ParameterInfo(Signature.toString(baseSignature) + ParameterInfo.ELLIPSIS, oldNames[i], i); } else { parameterInfo= new ParameterInfo(Signature.toString(typeNames[i]), oldNames[i], i); } result.add(parameterInfo); } return result; } catch(JavaModelException e) { JavaPlugin.log(e); return new ArrayList<ParameterInfo>(0); } }
Example 2
Source File: Binding2JavaModel.java From lapse-plus with GNU General Public License v3.0 | 5 votes |
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 (isPrimitiveType(candidate) || type.isPrimitive()) { return type.getName().equals(Signature.toString(candidate)); } else { if (isResolvedType(candidate)) { return Signature.toString(candidate).equals(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 3
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void createFragmentForArray(String signature, StringBuilder uriBuilder) { String elementType = Signature.getElementType(signature); createFragment(elementType, uriBuilder); int dim = Signature.getArrayCount(signature); for (int i = 0; i < dim; i++) { uriBuilder.append("[]"); } }
Example 4
Source File: JavaModelSearch.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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 5
Source File: Bindings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 6
Source File: SignatureUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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 7
Source File: JavaElementReturnTypeHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 8
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void createResourceURIForArray(String signature, StringBuilder uriBuilder) { String elementType = Signature.getElementType(signature); createResourceURI(elementType, uriBuilder); }
Example 9
Source File: SignatureUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * 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); }