List of usage examples for org.eclipse.jdt.core Signature getElementType
public static String getElementType(String typeSignature) throws IllegalArgumentException
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private StringBuffer internalGetSubstitutedTypeName(String typeSig, IMember context, boolean erasure, StringBuffer buf) throws JavaModelException { int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: return buf.append(Signature.toString(typeSig)); case Signature.ARRAY_TYPE_SIGNATURE: internalGetSubstitutedTypeName(Signature.getElementType(typeSig), context, erasure, buf); for (int i = Signature.getArrayCount(typeSig); i > 0; i--) { buf.append('[').append(']'); }/*from ww w. jav a 2s . c om*/ return buf; case Signature.CLASS_TYPE_SIGNATURE: { String erasureSig = Signature.getTypeErasure(typeSig); String erasureName = Signature.getSimpleName(Signature.toString(erasureSig)); char ch = erasureSig.charAt(0); if (ch == Signature.C_RESOLVED) { buf.append(erasureName); } else if (ch == Signature.C_UNRESOLVED) { // could be a type variable if (erasure) { buf.append(getVariableErasure(context, erasureName)); } else { buf.append(getVariableSubstitution(context, erasureName)); } } else { Assert.isTrue(false, "Unknown class type signature"); //$NON-NLS-1$ } if (!erasure) { String[] typeArguments = Signature.getTypeArguments(typeSig); if (typeArguments.length > 0) { buf.append('<'); for (int i = 0; i < typeArguments.length; i++) { if (i > 0) { buf.append(','); } internalGetSubstitutedTypeName(typeArguments[i], context, erasure, buf); } buf.append('>'); } } return buf; } case Signature.TYPE_VARIABLE_SIGNATURE: String varName = Signature.toString(typeSig); if (erasure) { return buf.append(getVariableErasure(context, varName)); } else { return buf.append(getVariableSubstitution(context, varName)); } case Signature.WILDCARD_TYPE_SIGNATURE: { buf.append('?'); char ch = typeSig.charAt(0); if (ch == Signature.C_STAR) { return buf; } else if (ch == Signature.C_EXTENDS) { buf.append(" extends "); //$NON-NLS-1$ } else { buf.append(" super "); //$NON-NLS-1$ } return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); } case Signature.CAPTURE_TYPE_SIGNATURE: return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); default: Assert.isTrue(false, "Unhandled type signature kind"); //$NON-NLS-1$ return buf; } }
From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java
License:Open Source License
/** * Returns the fully qualified type name of the given signature, with any * type parameters and arrays erased./*from w ww . j a va2 s . co m*/ * * @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); }
From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java
License:Open Source License
/** * Returns the qualified signature corresponding to * <code>signature</code>.//from ww w . ja va 2 s . co m * * @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; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the label for a method. Considers the M_* flags. * * @param method the element to render// w ww . j av a2 s.c o m * @param flags the rendering flags. Flags with names starting with 'M_' are considered. */ public void appendMethodLabel(IMethod method, long flags) { try { BindingKey resolvedKey = getFlag(flags, JavaElementLabels.USE_RESOLVED) && method.isResolved() ? new BindingKey(method.getKey()) : null; String resolvedSig = (resolvedKey != null) ? resolvedKey.toSignature() : null; // type parameters if (getFlag(flags, JavaElementLabels.M_PRE_TYPE_PARAMETERS)) { if (resolvedKey != null) { if (resolvedKey.isParameterizedMethod()) { String[] typeArgRefs = resolvedKey.getTypeArguments(); if (typeArgRefs.length > 0) { appendTypeArgumentSignaturesLabel(method, typeArgRefs, flags); fBuffer.append(' '); } } else { String[] typeParameterSigs = Signature.getTypeParameters(resolvedSig); if (typeParameterSigs.length > 0) { appendTypeParameterSignaturesLabel(typeParameterSigs, flags); fBuffer.append(' '); } } } else if (method.exists()) { ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters.length > 0) { appendTypeParametersLabels(typeParameters, flags); fBuffer.append(' '); } } } // return type if (getFlag(flags, JavaElementLabels.M_PRE_RETURNTYPE) && method.exists() && !method.isConstructor()) { String returnTypeSig = resolvedSig != null ? Signature.getReturnType(resolvedSig) : method.getReturnType(); appendTypeSignatureLabel(method, returnTypeSig, flags); fBuffer.append(' '); } // qualification if (getFlag(flags, JavaElementLabels.M_FULLY_QUALIFIED)) { appendTypeLabel(method.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } fBuffer.append(getElementName(method)); // constructor type arguments if (getFlag(flags, JavaElementLabels.T_TYPE_PARAMETERS) && method.exists() && method.isConstructor()) { if (resolvedSig != null && resolvedKey.isParameterizedType()) { BindingKey declaringType = resolvedKey.getDeclaringType(); if (declaringType != null) { String[] declaringTypeArguments = declaringType.getTypeArguments(); appendTypeArgumentSignaturesLabel(method, declaringTypeArguments, flags); } } } // parameters fBuffer.append('('); String[] declaredParameterTypes = method.getParameterTypes(); if (getFlag(flags, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES)) { String[] types = null; int nParams = 0; boolean renderVarargs = false; boolean isPolymorphic = false; if (getFlag(flags, JavaElementLabels.M_PARAMETER_TYPES)) { if (resolvedSig != null) { types = Signature.getParameterTypes(resolvedSig); } else { types = declaredParameterTypes; } nParams = types.length; renderVarargs = method.exists() && Flags.isVarargs(method.getFlags()); if (renderVarargs && resolvedSig != null && declaredParameterTypes.length == 1 && JavaModelUtil.isPolymorphicSignature(method)) { renderVarargs = false; isPolymorphic = true; } } String[] names = null; if (getFlag(flags, JavaElementLabels.M_PARAMETER_NAMES) && method.exists()) { names = method.getParameterNames(); if (isPolymorphic) { // handled specially below } else if (types == null) { nParams = names.length; } else { // types != null if (nParams != names.length) { if (resolvedSig != null && types.length > names.length) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=99137 nParams = names.length; String[] typesWithoutSyntheticParams = new String[nParams]; System.arraycopy(types, types.length - nParams, typesWithoutSyntheticParams, 0, nParams); types = typesWithoutSyntheticParams; } else { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=101029 // JavaPlugin.logErrorMessage("JavaElementLabels: Number of param types(" + nParams + ") != number of names(" + names.length + "): " + method.getElementName()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ names = null; // no names rendered } } } } ILocalVariable[] annotatedParameters = null; if (nParams > 0 && getFlag(flags, JavaElementLabels.M_PARAMETER_ANNOTATIONS)) { annotatedParameters = method.getParameters(); } for (int i = 0; i < nParams; i++) { if (i > 0) { fBuffer.append(JavaElementLabels.COMMA_STRING); } if (annotatedParameters != null && i < annotatedParameters.length) { appendAnnotationLabels(annotatedParameters[i].getAnnotations(), flags); } if (types != null) { String paramSig = types[i]; if (renderVarargs && (i == nParams - 1)) { int newDim = Signature.getArrayCount(paramSig) - 1; appendTypeSignatureLabel(method, Signature.getElementType(paramSig), flags); for (int k = 0; k < newDim; k++) { fBuffer.append('[').append(']'); } fBuffer.append(JavaElementLabels.ELLIPSIS_STRING); } else { appendTypeSignatureLabel(method, paramSig, flags); } } if (names != null) { if (types != null) { fBuffer.append(' '); } if (isPolymorphic) { fBuffer.append(names[0] + i); } else { fBuffer.append(names[i]); } } } } else { if (declaredParameterTypes.length > 0) { fBuffer.append(JavaElementLabels.ELLIPSIS_STRING); } } fBuffer.append(')'); if (getFlag(flags, JavaElementLabels.M_EXCEPTIONS)) { String[] types; if (resolvedKey != null) { types = resolvedKey.getThrownExceptions(); } else { types = method.exists() ? method.getExceptionTypes() : new String[0]; } if (types.length > 0) { fBuffer.append(" throws "); //$NON-NLS-1$ for (int i = 0; i < types.length; i++) { if (i > 0) { fBuffer.append(JavaElementLabels.COMMA_STRING); } appendTypeSignatureLabel(method, types[i], flags); } } } if (getFlag(flags, JavaElementLabels.M_APP_TYPE_PARAMETERS)) { int offset = fBuffer.length(); if (resolvedKey != null) { if (resolvedKey.isParameterizedMethod()) { String[] typeArgRefs = resolvedKey.getTypeArguments(); if (typeArgRefs.length > 0) { fBuffer.append(' '); appendTypeArgumentSignaturesLabel(method, typeArgRefs, flags); } } else { String[] typeParameterSigs = Signature.getTypeParameters(resolvedSig); if (typeParameterSigs.length > 0) { fBuffer.append(' '); appendTypeParameterSignaturesLabel(typeParameterSigs, flags); } } } else if (method.exists()) { ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters.length > 0) { fBuffer.append(' '); appendTypeParametersLabels(typeParameters, flags); } } // if (getFlag(flags, JavaElementLabels.COLORIZE) && offset != fBuffer.length()) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); // } } if (getFlag(flags, JavaElementLabels.M_APP_RETURNTYPE) && method.exists() && !method.isConstructor()) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.DECL_STRING); String returnTypeSig = resolvedSig != null ? Signature.getReturnType(resolvedSig) : method.getReturnType(); appendTypeSignatureLabel(method, returnTypeSig, flags); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); // } } // category if (getFlag(flags, JavaElementLabels.M_CATEGORY) && method.exists()) appendCategoryLabel(method, flags); // post qualification if (getFlag(flags, JavaElementLabels.M_POST_QUALIFIED)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendTypeLabel(method.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } } catch (JavaModelException e) { //TODO e.printStackTrace(); } }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags) { int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: fBuffer.append(Signature.toString(typeSig)); break;//from w w w . j a v a 2 s .com case Signature.ARRAY_TYPE_SIGNATURE: appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags); for (int dim = Signature.getArrayCount(typeSig); dim > 0; dim--) { fBuffer.append('[').append(']'); } break; case Signature.CLASS_TYPE_SIGNATURE: String baseType = getSimpleTypeName(enclosingElement, typeSig); fBuffer.append(baseType); String[] typeArguments = Signature.getTypeArguments(typeSig); appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags); break; case Signature.TYPE_VARIABLE_SIGNATURE: fBuffer.append(getSimpleTypeName(enclosingElement, typeSig)); break; case Signature.WILDCARD_TYPE_SIGNATURE: char ch = typeSig.charAt(0); if (ch == Signature.C_STAR) { //workaround for bug 85713 fBuffer.append('?'); } else { if (ch == Signature.C_EXTENDS) { fBuffer.append("? extends "); //$NON-NLS-1$ appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags); } else if (ch == Signature.C_SUPER) { fBuffer.append("? super "); //$NON-NLS-1$ appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags); } } break; case Signature.CAPTURE_TYPE_SIGNATURE: appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags); break; case Signature.INTERSECTION_TYPE_SIGNATURE: String[] typeBounds = Signature.getIntersectionTypeBounds(typeSig); appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags); break; default: // unknown } }
From source file:ca.mcgill.cs.swevo.jayfx.FastConverter.java
License:Open Source License
/** * Returns an IElement describing the argument Java element. Not designed to * be able to find initializer blocks or arrays. * //from ww w.j a v a 2 s. c om * @param pElement * Never null. * @return Never null */ public IElement getElement(final IJavaElement pElement) throws ConversionException { // assert( pElement != null ); IElement lReturn = null; if (pElement instanceof IType) lReturn = this.getClassElement((IType) pElement); else if (pElement instanceof IField) { final IElement lClass = this.getClassElement(((IField) pElement).getDeclaringType()); lReturn = FlyweightElementFactory.getElement(Category.FIELD, lClass.getId() + "." + ((IField) pElement).getElementName()); } else if (pElement instanceof IMethod) { final IElement lClass = this.getClassElement(((IMethod) pElement).getDeclaringType()); String lName = ((IMethod) pElement).getElementName(); try { if (((IMethod) pElement).isConstructor()) lName = "<init>"; } catch (final JavaModelException pException) { throw new ConversionException(pException); } String lSignature = "("; final String[] lParams = ((IMethod) pElement).getParameterTypes(); for (int i = 0; i < lParams.length - 1; i++) { String param = null; if (Signature.getTypeSignatureKind(lParams[i]) == Signature.TYPE_VARIABLE_SIGNATURE) // its // a // type // variable, // erase // it. param = "Ljava.lang.Object;"; else param = lParams[i]; lSignature += this.resolveType(param, ((IMethod) pElement).getDeclaringType()) + ","; } if (lParams.length > 0) { String param = lParams[lParams.length - 1]; if (Signature .getTypeSignatureKind(Signature.getElementType(param)) == Signature.TYPE_VARIABLE_SIGNATURE) // its // a // type // variable, // erase // it. param = "Ljava.lang.Object;"; else param = lParams[lParams.length - 1]; if (param.charAt(0) == 'Q' && param.charAt(1) == 'T') param = "Ljava.lang.Object;"; lSignature += this.resolveType(param, ((IMethod) pElement).getDeclaringType()); } lSignature += ")"; lReturn = FlyweightElementFactory.getElement(Category.METHOD, lClass.getId() + "." + lName + lSignature); } else if (pElement instanceof IAJCodeElement) { final String lName = ((IAJCodeElement) pElement).getElementName(); System.out.println(lName); } if (lReturn == null) { System.err.println("Error with element: " + pElement); throw new IllegalStateException("In trouble."); } return lReturn; }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavaDocLocations.java
License:Open Source License
private static void appendMethodReference(IMethod meth, StringBuffer buf) throws JavaModelException { buf.append(meth.getElementName());// ww w.j a v a 2s . c o m /* * 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 ? '-' : ')'); }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the label for a method. Considers the M_* flags. * * @param method the element to render// w ww .j a v a 2 s . c o m * @param flags the rendering flags. Flags with names starting with 'M_' are considered. */ public void appendMethodLabel(IMethod method, long flags) { try { BindingKey resolvedKey = getFlag(flags, JavaElementLabels.USE_RESOLVED) && method.isResolved() ? new BindingKey(method.getKey()) : null; String resolvedSig = (resolvedKey != null) ? resolvedKey.toSignature() : null; // type parameters if (getFlag(flags, JavaElementLabels.M_PRE_TYPE_PARAMETERS)) { if (resolvedKey != null) { if (resolvedKey.isParameterizedMethod()) { String[] typeArgRefs = resolvedKey.getTypeArguments(); if (typeArgRefs.length > 0) { appendTypeArgumentSignaturesLabel(method, typeArgRefs, flags); fBuffer.append(' '); } } else { String[] typeParameterSigs = Signature.getTypeParameters(resolvedSig); if (typeParameterSigs.length > 0) { appendTypeParameterSignaturesLabel(typeParameterSigs, flags); fBuffer.append(' '); } } } else if (method.exists()) { ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters.length > 0) { appendTypeParametersLabels(typeParameters, flags); fBuffer.append(' '); } } } // return type if (getFlag(flags, JavaElementLabels.M_PRE_RETURNTYPE) && method.exists() && !method.isConstructor()) { String returnTypeSig = resolvedSig != null ? Signature.getReturnType(resolvedSig) : method.getReturnType(); appendTypeSignatureLabel(method, returnTypeSig, flags); fBuffer.append(' '); } // qualification if (getFlag(flags, JavaElementLabels.M_FULLY_QUALIFIED)) { appendTypeLabel(method.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } fBuffer.append(getElementName(method)); // constructor type arguments if (getFlag(flags, JavaElementLabels.T_TYPE_PARAMETERS) && method.exists() && method.isConstructor()) { if (resolvedSig != null && resolvedKey.isParameterizedType()) { BindingKey declaringType = resolvedKey.getDeclaringType(); if (declaringType != null) { String[] declaringTypeArguments = declaringType.getTypeArguments(); appendTypeArgumentSignaturesLabel(method, declaringTypeArguments, flags); } } } // parameters fBuffer.append('('); String[] declaredParameterTypes = method.getParameterTypes(); if (getFlag(flags, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES)) { String[] types = null; int nParams = 0; boolean renderVarargs = false; boolean isPolymorphic = false; if (getFlag(flags, JavaElementLabels.M_PARAMETER_TYPES)) { if (resolvedSig != null) { types = Signature.getParameterTypes(resolvedSig); } else { types = declaredParameterTypes; } nParams = types.length; renderVarargs = method.exists() && Flags.isVarargs(method.getFlags()); if (renderVarargs && resolvedSig != null && declaredParameterTypes.length == 1 && JavaModelUtil.isPolymorphicSignature(method)) { renderVarargs = false; isPolymorphic = true; } } String[] names = null; if (getFlag(flags, JavaElementLabels.M_PARAMETER_NAMES) && method.exists()) { names = method.getParameterNames(); if (isPolymorphic) { // handled specially below } else if (types == null) { nParams = names.length; } else { // types != null if (nParams != names.length) { if (resolvedSig != null && types.length > names.length) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=99137 nParams = names.length; String[] typesWithoutSyntheticParams = new String[nParams]; System.arraycopy(types, types.length - nParams, typesWithoutSyntheticParams, 0, nParams); types = typesWithoutSyntheticParams; } else { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=101029 // JavaPlugin.logErrorMessage("JavaElementLabels: Number of param types(" + nParams + ") != number of names(" + names.length + "): " + method.getElementName()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ names = null; // no names rendered } } } } ILocalVariable[] annotatedParameters = null; if (nParams > 0 && getFlag(flags, JavaElementLabels.M_PARAMETER_ANNOTATIONS)) { annotatedParameters = method.getParameters(); } for (int i = 0; i < nParams; i++) { if (i > 0) { fBuffer.append(JavaElementLabels.COMMA_STRING); } if (annotatedParameters != null && i < annotatedParameters.length) { appendAnnotationLabels(annotatedParameters[i].getAnnotations(), flags); } if (types != null) { String paramSig = types[i]; if (renderVarargs && (i == nParams - 1)) { int newDim = Signature.getArrayCount(paramSig) - 1; appendTypeSignatureLabel(method, Signature.getElementType(paramSig), flags); for (int k = 0; k < newDim; k++) { fBuffer.append('[').append(']'); } fBuffer.append(JavaElementLabels.ELLIPSIS_STRING); } else { appendTypeSignatureLabel(method, paramSig, flags); } } if (names != null) { if (types != null) { fBuffer.append(' '); } if (isPolymorphic) { fBuffer.append(names[0] + i); } else { fBuffer.append(names[i]); } } } } else { if (declaredParameterTypes.length > 0) { fBuffer.append(JavaElementLabels.ELLIPSIS_STRING); } } fBuffer.append(')'); if (getFlag(flags, JavaElementLabels.M_EXCEPTIONS)) { String[] types; if (resolvedKey != null) { types = resolvedKey.getThrownExceptions(); } else { types = method.exists() ? method.getExceptionTypes() : new String[0]; } if (types.length > 0) { fBuffer.append(" throws "); //$NON-NLS-1$ for (int i = 0; i < types.length; i++) { if (i > 0) { fBuffer.append(JavaElementLabels.COMMA_STRING); } appendTypeSignatureLabel(method, types[i], flags); } } } if (getFlag(flags, JavaElementLabels.M_APP_TYPE_PARAMETERS)) { int offset = fBuffer.length(); if (resolvedKey != null) { if (resolvedKey.isParameterizedMethod()) { String[] typeArgRefs = resolvedKey.getTypeArguments(); if (typeArgRefs.length > 0) { fBuffer.append(' '); appendTypeArgumentSignaturesLabel(method, typeArgRefs, flags); } } else { String[] typeParameterSigs = Signature.getTypeParameters(resolvedSig); if (typeParameterSigs.length > 0) { fBuffer.append(' '); appendTypeParameterSignaturesLabel(typeParameterSigs, flags); } } } else if (method.exists()) { ITypeParameter[] typeParameters = method.getTypeParameters(); if (typeParameters.length > 0) { fBuffer.append(' '); appendTypeParametersLabels(typeParameters, flags); } } if (getFlag(flags, JavaElementLabels.COLORIZE) && offset != fBuffer.length()) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); } } if (getFlag(flags, JavaElementLabels.M_APP_RETURNTYPE) && method.exists() && !method.isConstructor()) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.DECL_STRING); String returnTypeSig = resolvedSig != null ? Signature.getReturnType(resolvedSig) : method.getReturnType(); appendTypeSignatureLabel(method, returnTypeSig, flags); if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); } } // category if (getFlag(flags, JavaElementLabels.M_CATEGORY) && method.exists()) appendCategoryLabel(method, flags); // post qualification if (getFlag(flags, JavaElementLabels.M_POST_QUALIFIED)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendTypeLabel(method.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } } catch (JavaModelException e) { LOG.error(e.getMessage(), e); // NotExistsException will not reach this point } }
From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java
License:Open Source License
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags, StringBuilder builder) {/*from w ww . ja v a2 s . co m*/ int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: builder.append(Signature.toString(typeSig)); break; case Signature.ARRAY_TYPE_SIGNATURE: appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags, builder); for (int dim = Signature.getArrayCount(typeSig); dim > 0; dim--) { builder.append('[').append(']'); } break; case Signature.CLASS_TYPE_SIGNATURE: String baseType = getSimpleTypeName(enclosingElement, typeSig); builder.append(baseType); String[] typeArguments = Signature.getTypeArguments(typeSig); appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags, builder); break; case Signature.TYPE_VARIABLE_SIGNATURE: builder.append(getSimpleTypeName(enclosingElement, typeSig)); break; case Signature.WILDCARD_TYPE_SIGNATURE: char ch = typeSig.charAt(0); if (ch == Signature.C_STAR) { //workaround for bug 85713 builder.append('?'); } else { if (ch == Signature.C_EXTENDS) { builder.append("? extends "); //$NON-NLS-1$ appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder); } else if (ch == Signature.C_SUPER) { builder.append("? super "); //$NON-NLS-1$ appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder); } } break; case Signature.CAPTURE_TYPE_SIGNATURE: appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder); break; case Signature.INTERSECTION_TYPE_SIGNATURE: String[] typeBounds = Signature.getIntersectionTypeBounds(typeSig); appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags, builder); break; default: // unknown } }
From source file:com.google.gdt.eclipse.appengine.rpc.util.JavaUtils.java
License:Open Source License
private static List<String> getElementSignatures(String typeName) { List<String> list = new ArrayList<String>(); if (Signature.getTypeSignatureKind(typeName) == Signature.ARRAY_TYPE_SIGNATURE) { list.add(Signature.getElementType(typeName)); } else {/*from w w w. ja v a 2 s . c om*/ String[] names = Signature.getTypeArguments(typeName); list.add(Signature.getTypeErasure(typeName)); if (names.length > 0) { list.add(names[0]); } } return list; }