List of usage examples for org.eclipse.jdt.core Signature getParameterTypes
public static String[] getParameterTypes(String methodSignature) throws IllegalArgumentException
From source file:at.bestsolution.fxide.jdt.editor.internal.MethodUtil.java
License:Open Source License
public IMethod resolve() throws JavaModelException { String[] parameters = Signature .getParameterTypes(String.valueOf(SignatureUtil.fix83600(this.methodSignature))); for (int i = 0; i < parameters.length; i++) { parameters[i] = SignatureUtil.getLowerBound(parameters[i]); }/*from w w w .java2 s . c o m*/ return findMethod(String.valueOf(name), parameters, constructor, type); }
From source file:at.bestsolution.fxide.jdt.editor.internal.MethodUtil.java
License:Open Source License
/** * Tests if a method equals to the given signature. Parameter types are only * compared by the simple name, no resolving for the fully qualified type * name is done. Constructors are only compared by parameters, not the name. * * @param name Name of the method/*from ww w . j a v a2 s . c o m*/ * @param paramTypes The type signatures of the parameters e.g. * <code>{"QString;","I"}</code> * @param isConstructor Specifies if the method is a constructor * @param method the method to be compared with this info's method * @param typeVariables a map from type variables to types * @param type the given type that declares the method * @return Returns <code>true</code> if the method has the given name and * parameter types and constructor state. * @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource */ private boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod method, Map<String, char[]> typeVariables, IType type) throws JavaModelException { if (isConstructor || name.equals(method.getElementName())) { if (isConstructor == method.isConstructor()) { String[] otherParams = method.getParameterTypes(); // types may be type variables boolean isBinaryConstructorForNonStaticMemberClass = method.isBinary() && type.isMember() && !Flags.isStatic(type.getFlags()); int syntheticParameterCorrection = isBinaryConstructorForNonStaticMemberClass && paramTypes.length == otherParams.length - 1 ? 1 : 0; if (paramTypes.length == otherParams.length - syntheticParameterCorrection) { fFallbackMatch = method; String signature = method.getSignature(); String[] otherParamsFromSignature = Signature.getParameterTypes(signature); // types are resolved / upper-bounded // no need to check method type variables since these are // not yet bound when proposing a method for (int i = 0; i < paramTypes.length; i++) { String ourParamName = computeSimpleTypeName(paramTypes[i], typeVariables); String otherParamName1 = computeSimpleTypeName( otherParams[i + syntheticParameterCorrection], typeVariables); String otherParamName2 = computeSimpleTypeName( otherParamsFromSignature[i + syntheticParameterCorrection], typeVariables); if (!ourParamName.equals(otherParamName1) && !ourParamName.equals(otherParamName2)) { return false; } } return true; } } } return false; }
From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java
License:Open Source License
/** * Takes a method signature// ww w . jav a 2 s . co m * <code>[< typeVariableName : formalTypeDecl >] ( paramTypeSig1* ) retTypeSig</code> * and returns it with any parameter signatures filtered through * <code>getLowerBound</code> and the return type filtered through * <code>getUpperBound</code>. Any preceding formal type variable * declarations are removed. * <p> * TODO this is a temporary workaround for * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83600 * </p> * * @param signature the method signature to convert * @return the signature with no bounded types */ public static char[] unboundedSignature(char[] signature) { if (signature == null || signature.length < 2) return signature; final boolean BUG_83600 = true; // XXX the signatures from CompletionRequestor contain a superfluous '+' // before type parameters to parameter types if (BUG_83600) { signature = fix83600(signature); } StringBuffer res = new StringBuffer("("); //$NON-NLS-1$ char[][] parameters = Signature.getParameterTypes(signature); for (int i = 0; i < parameters.length; i++) { char[] param = parameters[i]; res.append(getLowerBound(param)); } res.append(')'); res.append(getUpperBound(Signature.getReturnType(signature))); return res.toString().toCharArray(); }
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 w w . j av a 2s . com*/ * @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:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { if (!(message instanceof ICall)) return false; if (containsMessage(node)) { ICall call = (ICall) message;//from w w w .j ava 2s. co m IMethodBinding binding = node.resolveMethodBinding(); if (binding != null) { binding = binding.getMethodDeclaration(); if (binding != null) { IJavaElement element = binding.getJavaElement(); if (element instanceof IMethod) { try { IMethod jm = (IMethod) element; //get the target method. ITraceClassMethod am = call.getTarget().getActivation().getMethod(); String types[] = Signature.getParameterTypes(am.getSignature()); IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types); if (jm.isSimilar(testMethod)) { this.node = node; try { if (document.getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } catch (NullPointerException e) { return false; } } } } return true; } return false; }
From source file:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java
License:Open Source License
public boolean visit(SuperMethodInvocation node) { if (!(message instanceof ICall)) return false; if (containsMessage(node)) { ICall call = (ICall) message;/*from w ww .j ava 2s . c o m*/ IMethodBinding binding = node.resolveMethodBinding(); if (binding != null) { binding = binding.getMethodDeclaration(); if (binding != null) { IJavaElement element = binding.getJavaElement(); if (element instanceof IMethod) { try { IMethod jm = (IMethod) element; //get the target method. ITraceClassMethod am = call.getTarget().getActivation().getMethod(); String types[] = Signature.getParameterTypes(am.getSignature()); IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types); if (jm.isSimilar(testMethod)) { this.node = node; try { if (document.getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } catch (NullPointerException e) { return false; } } } } return true; } return false; }
From source file:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java
License:Open Source License
public boolean visit(SuperConstructorInvocation node) { if (!(message instanceof ICall)) return false; if (containsMessage(node)) { ICall call = (ICall) message;/* w ww .j a v a 2s .co m*/ IMethodBinding binding = node.resolveConstructorBinding(); if (binding != null) { binding = binding.getMethodDeclaration(); if (binding != null) { IJavaElement element = binding.getJavaElement(); if (element instanceof IMethod) { try { IMethod jm = (IMethod) element; //get the target method. ITraceClassMethod am = call.getTarget().getActivation().getMethod(); if (JavaSearchUtils.getFullyQualifiedName(jm.getDeclaringType(), true) .equals(am.getTraceClass().getName())) { String types[] = Signature.getParameterTypes(am.getSignature()); IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types); if (jm.isSimilar(testMethod)) { this.node = node; try { if (document .getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } } catch (NullPointerException e) { return false; } } } } return true; } return false; }
From source file:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java
License:Open Source License
@Override public boolean visit(ConstructorInvocation node) { if (!(message instanceof ICall)) return false; if (containsMessage(node)) { ICall call = (ICall) message;//ww w .j a v a 2 s . c o m IMethodBinding binding = node.resolveConstructorBinding(); if (binding != null) { binding = binding.getMethodDeclaration(); if (binding != null) { IJavaElement element = binding.getJavaElement(); if (element instanceof IMethod) { try { IMethod jm = (IMethod) element; //get the target method. ITraceClassMethod am = call.getTarget().getActivation().getMethod(); if (JavaSearchUtils.getFullyQualifiedName(jm.getDeclaringType(), true) .equals(am.getTraceClass().getName())) { String types[] = Signature.getParameterTypes(am.getSignature()); IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types); if (jm.isSimilar(testMethod)) { this.node = node; try { if (document .getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } } catch (NullPointerException e) { return false; } } } } return true; } return false; }
From source file:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java
License:Open Source License
public boolean visit(ClassInstanceCreation node) { if (!(message instanceof ICall)) return false; if (containsMessage(node)) { ICall call = (ICall) message;/*from w w w.ja v a 2 s . c o m*/ IMethodBinding binding = node.resolveConstructorBinding(); if (binding != null) { binding = binding.getMethodDeclaration(); if (binding != null) { IJavaElement element = binding.getJavaElement(); if (element instanceof IMethod) { try { IMethod jm = (IMethod) element; //get the target method. ITraceClassMethod am = call.getTarget().getActivation().getMethod(); if (JavaSearchUtils.getFullyQualifiedName(jm.getDeclaringType(), true) .equals(am.getTraceClass().getName())) { String types[] = Signature.getParameterTypes(am.getSignature()); IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types); if (jm.isSimilar(testMethod)) { this.node = node; try { if (document .getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } } catch (NullPointerException e) { return true; } } else { //try to match just on the class name ITypeBinding typeBinding = binding.getDeclaringClass(); IJavaElement je = typeBinding.getJavaElement(); if (je instanceof IType) { IType type = (IType) je; try { ITraceClassMethod am = call.getTarget().getActivation().getMethod(); if (JavaSearchUtils.getFullyQualifiedName(type, true) .equals(am.getTraceClass().getName())) { this.node = node; try { if (document .getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1)) //look for a better match. return true; } catch (BadLocationException e) { } return false; } } catch (NullPointerException e) { return true; } } } } } return true; } return false; }
From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java
License:Open Source License
/** * @param scope//from w w w.j a v a2s . c o m * @param monitor * @param classSignature * @param methodName * @param signature * @return * @throws CoreException * @throws InterruptedException */ public static IJavaElement searchForMethod(IJavaSearchScope scope, IProgressMonitor monitor, String classSignature, String methodName, String signature) throws CoreException, InterruptedException { SubProgressMonitor typeMonitor = new SubProgressMonitor(monitor, 100); SubProgressMonitor hierarchyMonitor = new SubProgressMonitor(monitor, 100); IType foundType = (IType) searchForType(classSignature, scope, typeMonitor); if (foundType == null) return null; boolean isConstructor = false; if (methodName.startsWith("<init")) { isConstructor = true; boolean i = isConstructor; boolean isAnonymous = false; if (!foundType.exists()) { //check anonymity using the dollar sign String elementName = foundType.getElementName(); if (elementName.length() > 0 && Character.isDigit(elementName.charAt(0))) { isAnonymous = true; } } else { isAnonymous = foundType.isAnonymous(); } if (isAnonymous) { methodName = ""; } else { methodName = foundType.getElementName(); } } String[] methodParamTypes = Signature.getParameterTypes(signature); IMethod searchMethod = foundType.getMethod(methodName, methodParamTypes); IMethod[] methods = foundType.getMethods(); for (IMethod checkMethod : methods) { if (isSimilar(searchMethod, checkMethod)) { return checkMethod; } } return searchMethod; }