Java Code Examples for org.eclipse.jdt.core.Signature#toString()
The following examples show how to use
org.eclipse.jdt.core.Signature#toString() .
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: JavaElementLinks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected String getSimpleTypeName(IJavaElement enclosingElement, String typeSig) { String typeName= super.getSimpleTypeName(enclosingElement, typeSig); String title= ""; //$NON-NLS-1$ String qualifiedName= Signature.toString(Signature.getTypeErasure(typeSig)); int qualifierLength= qualifiedName.length() - typeName.length() - 1; if (qualifierLength > 0) { if (qualifiedName.endsWith(typeName)) { title= qualifiedName.substring(0, qualifierLength); title= Messages.format(JavaUIMessages.JavaElementLinks_title, title); } else { title= qualifiedName; // Not expected. Just show the whole qualifiedName. } } try { String uri= createURI(JAVADOC_SCHEME, enclosingElement, qualifiedName, null, null); return createHeaderLink(uri, typeName, title); } catch (URISyntaxException e) { JavaPlugin.log(e); return typeName; } }
Example 2
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 3
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 4
Source File: CompilationUnitContextType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected String resolve(TemplateContext context) { IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD); if (element == null) return null; try { return Signature.toString(((IMethod) element).getReturnType()); } catch (JavaModelException e) { return null; } }
Example 5
Source File: JavaDocLocations.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
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 6
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 7
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkMethodReturnTypes(final IProgressMonitor monitor, final RefactoringStatus status, final Set<IMember> notDeletedMembersInSubtypes) throws JavaModelException { final Map<IMember, Set<IMember>> mapping= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), true); final IMember[] members= getCreatedDestinationMembers(); for (int i= 0; i < members.length; i++) { if (members[i].getElementType() != IJavaElement.METHOD) continue; final IMethod method= (IMethod) members[i]; if (mapping.containsKey(method)) { final Set<IMember> set= mapping.get(method); if (set != null) { final String returnType= Signature.toString(Signature.getReturnType(method.getSignature()).toString()); for (final Iterator<IMember> iter= set.iterator(); iter.hasNext();) { final IMethod matchingMethod= (IMethod) iter.next(); if (method.equals(matchingMethod)) continue; if (!notDeletedMembersInSubtypes.contains(matchingMethod)) continue; if (returnType.equals(Signature.toString(Signature.getReturnType(matchingMethod.getSignature()).toString()))) continue; final String[] keys= { JavaElementLabels.getTextLabel(matchingMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(matchingMethod.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String message= Messages.format(RefactoringCoreMessages.PullUpRefactoring_different_method_return_type, keys); final RefactoringStatusContext context= JavaStatusContext.create(matchingMethod.getCompilationUnit(), matchingMethod.getNameRange()); status.addError(message, context); } } } } }
Example 8
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { RefactoringStatus result= new RefactoringStatus(); pm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_msg_check_initial_condition, 5); try { result.merge(fDescriptor.validateDescriptor()); if (!result.isOK()) return result; IType type= fDescriptor.getType(); result.merge(Checks.checkAvailability(type)); if (!result.isOK()) return result; pm.worked(1); Field[] fields= ExtractClassDescriptor.getFields(fDescriptor.getType()); pm.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); fVariables= new LinkedHashMap<String, FieldInfo>(); if (fields.length == 0) { result.addFatalError(RefactoringCoreMessages.ExtractClassRefactoring_error_no_usable_fields, JavaStatusContext.create(type)); return result; } for (int i= 0; i < fields.length; i++) { Field field= fields[i]; String fieldName= field.getFieldName(); IField declField= type.getField(fieldName); ParameterInfo info= new ParameterInfo(Signature.toString(declField.getTypeSignature()), fieldName, i); fVariables.put(fieldName, new FieldInfo(info, declField)); if (pm.isCanceled()) throw new OperationCanceledException(); } pm.worked(3); } finally { pm.done(); } return result; }
Example 9
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new change signature refactoring. * @param method the method, or <code>null</code> if invoked by scripting framework * @throws JavaModelException if something's wrong with the given method */ public ChangeSignatureProcessor(IMethod method) throws JavaModelException { fMethod= method; fOldVarargIndex= -1; fDelegateUpdating= false; fDelegateDeprecation= true; if (fMethod != null) { fParameterInfos= createParameterInfoList(method); // fExceptionInfos is created in checkInitialConditions fReturnTypeInfo= new ReturnTypeInfo(Signature.toString(Signature.getReturnType(fMethod.getSignature()))); fMethodName= fMethod.getElementName(); fVisibility= JdtFlags.getVisibilityCode(fMethod); } }
Example 10
Source File: JavaElementDeclaredTypeHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String getHyperlinkText() { if (fQualify) { if (fTypeSig == null) { String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_FULLY_QUALIFIED); return Messages.format(JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText_qualified, new Object[] { elementLabel }); } else { String type= Signature.toString(fTypeSig); return Messages.format(JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText_qualified_signature, new Object[] { type }); } } else { return JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText; } }
Example 11
Source File: GetterSetterCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static StyledString getDisplayName(IField field, boolean isGetter) throws JavaModelException { StyledString buf= new StyledString(); String fieldTypeName= Signature.toString(field.getTypeSignature()); String fieldNameLabel= BasicElementLabels.getJavaElementName(field.getElementName()); if (isGetter) { buf.append(BasicElementLabels.getJavaElementName(GetterSetterUtil.getGetterName(field, null) + "() : " + fieldTypeName)); //$NON-NLS-1$ buf.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ buf.append(Messages.format(JavaTextMessages.GetterSetterCompletionProposal_getter_label, fieldNameLabel), StyledString.QUALIFIER_STYLER); } else { buf.append(BasicElementLabels.getJavaElementName(GetterSetterUtil.getSetterName(field, null) + '(' + fieldTypeName + ") : void" )); //$NON-NLS-1$ buf.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ buf.append(Messages.format(JavaTextMessages.GetterSetterCompletionProposal_setter_label, fieldNameLabel), StyledString.QUALIFIER_STYLER); } return buf; }
Example 12
Source File: AddJavaDocStubOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private String createFieldComment(IField field, String lineDelimiter) throws JavaModelException, CoreException { String typeName= Signature.toString(field.getTypeSignature()); String fieldName= field.getElementName(); return CodeGeneration.getFieldComment(field.getCompilationUnit(), typeName, fieldName, lineDelimiter); }
Example 13
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void createFragmentForTypeVariable(String signature, StringBuilder uriBuilder) { String readable = Signature.toString(signature); uriBuilder.append('/'); uriBuilder.append(readable); }
Example 14
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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 15
Source File: JsniCompletionProposal.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private String computeTypeCompletion() { // Completion is the fully-qualified name of the type return Signature.toString(new String(wrappedProposal.getSignature())); }
Example 16
Source File: GetterSetterUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a stub for a getter of the given field using getter/setter templates. The resulting code * has to be formatted and indented. * @param field The field to create a getter for * @param setterName The chosen name for the setter * @param addComments If <code>true</code>, comments will be added. * @param flags The flags signaling visibility, if static, synchronized or final * @return Returns the generated stub. * @throws CoreException when stub creation failed */ public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException { String fieldName= field.getElementName(); IType parentType= field.getDeclaringType(); String returnSig= field.getTypeSignature(); String typeName= Signature.toString(returnSig); IJavaProject project= field.getJavaProject(); String accessorName= StubUtility.getBaseName(field); String argname= StubUtility.suggestArgumentName(project, accessorName, EMPTY); boolean isStatic= Flags.isStatic(flags); boolean isSync= Flags.isSynchronized(flags); boolean isFinal= Flags.isFinal(flags); String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$ StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim); if (comment != null) { buf.append(comment); buf.append(lineDelim); } } buf.append(JdtFlags.getVisibilityString(flags)); buf.append(' '); if (isStatic) buf.append("static "); //$NON-NLS-1$ if (isSync) buf.append("synchronized "); //$NON-NLS-1$ if (isFinal) buf.append("final "); //$NON-NLS-1$ buf.append("void "); //$NON-NLS-1$ buf.append(setterName); buf.append('('); buf.append(typeName); buf.append(' '); buf.append(argname); buf.append(") {"); //$NON-NLS-1$ buf.append(lineDelim); boolean useThis= StubUtility.useThisForFieldAccess(project); if (argname.equals(fieldName) || (useThis && !isStatic)) { if (isStatic) fieldName= parentType.getElementName() + '.' + fieldName; else fieldName= "this." + fieldName; //$NON-NLS-1$ } String body= CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim); if (body != null) { buf.append(body); } buf.append("}"); //$NON-NLS-1$ buf.append(lineDelim); return buf.toString(); }
Example 17
Source File: GetterSetterUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a stub for a getter of the given field using getter/setter templates. The resulting code * has to be formatted and indented. * @param field The field to create a getter for * @param getterName The chosen name for the getter * @param addComments If <code>true</code>, comments will be added. * @param flags The flags signaling visibility, if static, synchronized or final * @return Returns the generated stub. * @throws CoreException when stub creation failed */ public static String getGetterStub(IField field, String getterName, boolean addComments, int flags) throws CoreException { String fieldName= field.getElementName(); IType parentType= field.getDeclaringType(); boolean isStatic= Flags.isStatic(flags); boolean isSync= Flags.isSynchronized(flags); boolean isFinal= Flags.isFinal(flags); String typeName= Signature.toString(field.getTypeSignature()); String accessorName= StubUtility.getBaseName(field); String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$ StringBuffer buf= new StringBuffer(); if (addComments) { String comment= CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim); if (comment != null) { buf.append(comment); buf.append(lineDelim); } } buf.append(JdtFlags.getVisibilityString(flags)); buf.append(' '); if (isStatic) buf.append("static "); //$NON-NLS-1$ if (isSync) buf.append("synchronized "); //$NON-NLS-1$ if (isFinal) buf.append("final "); //$NON-NLS-1$ buf.append(typeName); buf.append(' '); buf.append(getterName); buf.append("() {"); //$NON-NLS-1$ buf.append(lineDelim); boolean useThis= StubUtility.useThisForFieldAccess(field.getJavaProject()); if (useThis && !isStatic) { fieldName= "this." + fieldName; //$NON-NLS-1$ } String body= CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim); if (body != null) { buf.append(body); } buf.append("}"); //$NON-NLS-1$ buf.append(lineDelim); return buf.toString(); }
Example 18
Source File: ParameterGuesser.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public Variable createVariable(IJavaElement element, IType enclosingType, String expectedType, int positionScore) throws JavaModelException { int variableType; int elementType= element.getElementType(); String elementName= element.getElementName(); String typeSignature; switch (elementType) { case IJavaElement.FIELD: { IField field= (IField) element; if (field.getDeclaringType().equals(enclosingType)) { variableType= Variable.FIELD; } else { variableType= Variable.INHERITED_FIELD; } if (field.isResolved()) { typeSignature= new BindingKey(field.getKey()).toSignature(); } else { typeSignature= field.getTypeSignature(); } break; } case IJavaElement.LOCAL_VARIABLE: { ILocalVariable locVar= (ILocalVariable) element; variableType= Variable.LOCAL; typeSignature= locVar.getTypeSignature(); break; } case IJavaElement.METHOD: { IMethod method= (IMethod) element; if (isMethodToSuggest(method)) { if (method.getDeclaringType().equals(enclosingType)) { variableType= Variable.METHOD; } else { variableType= Variable.INHERITED_METHOD; } if (method.isResolved()) { typeSignature= Signature.getReturnType(new BindingKey(method.getKey()).toSignature()); } else { typeSignature= method.getReturnType(); } elementName= elementName + "()"; //$NON-NLS-1$ } else { return null; } break; } default: return null; } String type= Signature.toString(typeSignature); boolean isAutoboxMatch= isPrimitiveType(expectedType) != isPrimitiveType(type); return new Variable(type, elementName, variableType, isAutoboxMatch, positionScore); }
Example 19
Source File: ImportRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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 20
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); }