Java Code Examples for org.eclipse.jdt.core.Signature#createArraySignature()
The following examples show how to use
org.eclipse.jdt.core.Signature#createArraySignature() .
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: CreateMethodOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the type signatures of the parameter types of the * current <code>MethodDeclaration</code> */ protected String[] convertASTMethodTypesToSignatures() { if (this.parameterTypes == null) { if (this.createdNode != null) { MethodDeclaration methodDeclaration = (MethodDeclaration) this.createdNode; List parameters = methodDeclaration.parameters(); int size = parameters.size(); this.parameterTypes = new String[size]; Iterator iterator = parameters.iterator(); // convert the AST types to signatures for (int i = 0; i < size; i++) { SingleVariableDeclaration parameter = (SingleVariableDeclaration) iterator.next(); String typeSig = Util.getSignature(parameter.getType()); int extraDimensions = parameter.getExtraDimensions(); if (methodDeclaration.isVarargs() && i == size-1) extraDimensions++; this.parameterTypes[i] = Signature.createArraySignature(typeSig, extraDimensions); } } } return this.parameterTypes; }
Example 3
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; }