Java Code Examples for org.eclipse.jdt.core.IMethod#getParameterTypes()
The following examples show how to use
org.eclipse.jdt.core.IMethod#getParameterTypes() .
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: RefactoringHandleTransplanter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String[] resolveParameterTypes(IMethod method) { final String[] oldParameterTypes= method.getParameterTypes(); final String[] newparams= new String[oldParameterTypes.length]; final String[] possibleOldSigs= new String[4]; possibleOldSigs[0]= Signature.createTypeSignature(fOldType.getElementName(), false); possibleOldSigs[1]= Signature.createTypeSignature(fOldType.getElementName(), true); possibleOldSigs[2]= Signature.createTypeSignature(fOldType.getFullyQualifiedName(), false); possibleOldSigs[3]= Signature.createTypeSignature(fOldType.getFullyQualifiedName(), true); final String[] possibleNewSigs= new String[4]; possibleNewSigs[0]= Signature.createTypeSignature(fNewType.getElementName(), false); possibleNewSigs[1]= Signature.createTypeSignature(fNewType.getElementName(), true); possibleNewSigs[2]= Signature.createTypeSignature(fNewType.getFullyQualifiedName(), false); possibleNewSigs[3]= Signature.createTypeSignature(fNewType.getFullyQualifiedName(), true); // Textually replace all occurrences // This handles stuff like Map<SomeClass, some.package.SomeClass> for (int i= 0; i < oldParameterTypes.length; i++) { newparams[i]= oldParameterTypes[i]; for (int j= 0; j < possibleOldSigs.length; j++) { newparams[i]= replaceAll(newparams[i], possibleOldSigs[j], possibleNewSigs[j]); } } return newparams; }
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: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Checks whether a method with the proposed name already exists in the * target type. * * @param monitor * the progress monitor to display progress * @param status * the status of the condition checking * @throws JavaModelException * if the declared methods of the target type could not be * retrieved */ protected void checkConflictingMethod(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { Assert.isNotNull(monitor); Assert.isNotNull(status); final IMethod[] methods= fTargetType.getMethods(); int newParamCount= fMethod.getParameterTypes().length; if (!fTarget.isField()) newParamCount--; // moving to a parameter if (needsTargetNode()) newParamCount++; // will add a parameter for the old 'this' try { monitor.beginTask("", methods.length); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); IMethod method= null; for (int index= 0; index < methods.length; index++) { method= methods[index]; if (method.getElementName().equals(fMethodName) && method.getParameterTypes().length == newParamCount) status.merge(RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_method_already_exists, new String[] { BasicElementLabels.getJavaElementName(fMethodName), BasicElementLabels.getJavaElementName(fTargetType.getElementName()) }), JavaStatusContext.create(method))); monitor.worked(1); } if (fMethodName.equals(fTargetType.getElementName())) status.merge(RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_method_type_clash, BasicElementLabels.getJavaElementName(fMethodName)), JavaStatusContext.create(fTargetType))); } finally { monitor.done(); } }
Example 4
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) { try { ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); parser.setProject(overridden.getJavaProject()); IBinding[] bindings= parser.createBindings(new IJavaElement[] { overridden }, null); if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) { return getParameterTypeNamesForSeeTag((IMethodBinding)bindings[0]); } } catch (IllegalStateException e) { // method does not exist } // fall back code. Not good for generic methods! String[] paramTypes= overridden.getParameterTypes(); String[] paramTypeNames= new String[paramTypes.length]; for (int i= 0; i < paramTypes.length; i++) { paramTypeNames[i]= Signature.toString(Signature.getTypeErasure(paramTypes[i])); } return paramTypeNames; }
Example 5
Source File: RenameMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static IMethod[] classesDeclareMethodName(ITypeHierarchy hier, List<IType> classes, IMethod method, String newName) throws CoreException { Set<IMethod> result= new HashSet<IMethod>(); IType type= method.getDeclaringType(); List<IType> subtypes= Arrays.asList(hier.getAllSubtypes(type)); int parameterCount= method.getParameterTypes().length; boolean isMethodPrivate= JdtFlags.isPrivate(method); for (Iterator<IType> iter= classes.iterator(); iter.hasNext(); ){ IType clazz= iter.next(); IMethod[] methods= clazz.getMethods(); boolean isSubclass= subtypes.contains(clazz); for (int j= 0; j < methods.length; j++) { IMethod foundMethod= Checks.findMethod(newName, parameterCount, false, new IMethod[] {methods[j]}); if (foundMethod == null) continue; if (isSubclass || type.equals(clazz)) result.add(foundMethod); else if ((! isMethodPrivate) && (! JdtFlags.isPrivate(methods[j]))) result.add(foundMethod); } } return result.toArray(new IMethod[result.size()]); }
Example 6
Source File: JsniMethodBodyCompletionProposalComputer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Proposes a JSNI method of the form <code>return this.property[x]</code> if * the java method has a single integral type parameter. */ private void maybeProposeIndexedPropertyRead(IJavaProject project, IMethod method, int invocationOffset, int indentationUnits, List<ICompletionProposal> proposals, String propertyName, String[] parameterNames, boolean isStatic, int numCharsFilled, int numCharsToOverwrite) throws JavaModelException { if (parameterNames.length != 1) { return; } String indexParameterType = method.getParameterTypes()[0]; if (isIndexType(indexParameterType)) { String expression = "return " + createJsIndexedPropertyReadExpression(propertyName, parameterNames[0], isStatic) + ";"; String code = createJsniBlock(project, expression, indentationUnits); proposals.add(createProposal(method.getFlags(), code, invocationOffset, numCharsFilled, numCharsToOverwrite, expression)); } }
Example 7
Source File: PatternStrings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static String getUnqualifiedMethodSignature(IMethod method, boolean includeName) { StringBuffer buffer= new StringBuffer(); if (includeName) { buffer.append(method.getElementName()); } buffer.append('('); String[] types= method.getParameterTypes(); for (int i= 0; i < types.length; i++) { if (i > 0) buffer.append(", "); //$NON-NLS-1$ String typeSig= Signature.toString(types[i]); buffer.append(typeSig); } buffer.append(')'); return buffer.toString(); }
Example 8
Source File: SetterAttributeProposalComputer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Determines whether a setter's parameter signature can be parsed from an * attribute based on the GWT AttributeParsers implementation. */ private boolean isParsableSetter(IMethod method) { StringBuffer signature = new StringBuffer(); for (String paramType : method.getParameterTypes()) { if (signature.length() > 0) { signature.append(','); } String qualifier = Signature.getSignatureQualifier(paramType); if (qualifier.length() > 0) { signature.append(qualifier); signature.append('.'); } signature.append(Signature.getSignatureSimpleName(paramType)); } return PARSABLE_ARGS.contains(signature.toString()); }
Example 9
Source File: SourceMapper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a handle that has parameter types that are not * fully qualified so that the correct source is found. */ protected IJavaElement[] getUnqualifiedMethodHandle(IMethod method, boolean noDollar) { boolean hasDollar = false; String[] qualifiedParameterTypes = method.getParameterTypes(); String[] unqualifiedParameterTypes = new String[qualifiedParameterTypes.length]; for (int i = 0; i < qualifiedParameterTypes.length; i++) { StringBuffer unqualifiedTypeSig = new StringBuffer(); getUnqualifiedTypeSignature(qualifiedParameterTypes[i], 0/*start*/, qualifiedParameterTypes[i].length(), unqualifiedTypeSig, noDollar); unqualifiedParameterTypes[i] = unqualifiedTypeSig.toString(); hasDollar |= unqualifiedParameterTypes[i].lastIndexOf('$') != -1; } IJavaElement[] result = new IJavaElement[2]; result[0] = ((IType) method.getParent()).getMethod( method.getElementName(), unqualifiedParameterTypes); if(hasDollar) { result[1] = result[0]; } return result; }
Example 10
Source File: JavaElementFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private boolean doParametersMatch(JvmExecutable object, IMethod method, IType declaringType) throws JavaModelException { int numberOfParameters = method.getNumberOfParameters(); String[] parameterTypes = method.getParameterTypes(); boolean match = true; for (int i = 0; i < numberOfParameters && match; i++) { JvmFormalParameter formalParameter = object.getParameters().get(i); String parameterType = parameterTypes[i]; String readable = toQualifiedRawTypeName(parameterType, declaringType); String qualifiedParameterType = getQualifiedParameterType(formalParameter); if (!readable.equals(qualifiedParameterType)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=387576 if (qualifiedParameterType != null && qualifiedParameterType.endsWith("$") && qualifiedParameterType.startsWith(readable)) { for(int c = readable.length(); c < qualifiedParameterType.length() && match; c++) { if (qualifiedParameterType.charAt(c) != '$') { match = false; } } } else { match = false; } } } return match; }
Example 11
Source File: JavaElementDelegateMainLaunch.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override protected boolean containsElementsSearchedFor(IFile file) { IJavaElement element = JavaCore.create(file); if (element == null || !element.exists() || ! (element instanceof ICompilationUnit)) { return false; } try { ICompilationUnit cu = (ICompilationUnit) element; for (IType type : cu.getAllTypes()) { for (IMethod method : type.getMethods()) { int flags = method.getFlags(); if (Modifier.isPublic(flags) && Modifier.isStatic(flags) && "main".equals(method.getElementName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals("[QString;")) { //$NON-NLS-1$ return true; } } } } catch (JavaModelException e) { log.error(e.getMessage(), e); } return super.containsElementsSearchedFor(file); }
Example 12
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 13
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 14
Source File: MethodsViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IMethod findSimilarMethod(IMethod meth, Object[] elements) throws JavaModelException { String name= meth.getElementName(); String[] paramTypes= meth.getParameterTypes(); boolean isConstructor= meth.isConstructor(); for (int i= 0; i < elements.length; i++) { Object curr= elements[i]; if (curr instanceof IMethod && JavaModelUtil.isSameMethodSignature(name, paramTypes, isConstructor, (IMethod) curr)) { return (IMethod) curr; } } return null; }
Example 15
Source File: RemoteServiceUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Computes the synchronous method parameter types from the asynchronous * method model. * * @throws RemoteServiceException if there was an error resolving a type */ public static String[] computeSyncParameterTypes(IMethod asyncMethod) throws RemoteServiceException { List<String> parameters = new ArrayList<String>(); String[] asyncParamTypeSigs = asyncMethod.getParameterTypes(); for (int i = 0; i < asyncParamTypeSigs.length - 1; i++) { parameters.add(resolveToQualifiedErasure(asyncMethod.getDeclaringType(), asyncParamTypeSigs[i])); } return parameters.toArray(NO_STRINGS); }
Example 16
Source File: ASTNodeFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public AbstractMethodDeclaration findMethod(IMethod methodHandle) { TypeDeclaration typeDecl = findType((IType)methodHandle.getParent()); if (typeDecl == null) return null; AbstractMethodDeclaration[] methods = typeDecl.methods; if (methods != null) { char[] selector = methodHandle.getElementName().toCharArray(); String[] parameterTypeSignatures = methodHandle.getParameterTypes(); int parameterCount = parameterTypeSignatures.length; nextMethod: for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (CharOperation.equals(selector, method.selector)) { Argument[] args = method.arguments; int argsLength = args == null ? 0 : args.length; if (argsLength == parameterCount) { for (int j = 0; j < parameterCount; j++) { TypeReference type = args[j].type; String signature = Util.typeSignature(type); if (!signature.equals(parameterTypeSignatures[j])) { continue nextMethod; } } return method; } } } } return null; }
Example 17
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static IMethod findMethod(String name, int parameters, boolean isConstructor, IMethod[] methods) throws JavaModelException { for (int i= methods.length-1; i >= 0; i--) { IMethod curr= methods[i]; if (name.equals(curr.getElementName())) { if (isConstructor == curr.isConstructor()) { if (parameters == curr.getParameterTypes().length) { return curr; } } } } return null; }
Example 18
Source File: Bindings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean sameParameters(IMethodBinding method, IMethod candidate) throws JavaModelException { ITypeBinding[] methodParamters= method.getParameterTypes(); String[] candidateParameters= candidate.getParameterTypes(); if (methodParamters.length != candidateParameters.length) return false; IType scope= candidate.getDeclaringType(); for (int i= 0; i < methodParamters.length; i++) { ITypeBinding methodParameter= methodParamters[i]; String candidateParameter= candidateParameters[i]; if (!sameParameter(methodParameter, candidateParameter, scope)) return false; } return true; }
Example 19
Source File: RenameMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private IMethod getMethodInWorkingCopy(IMethod method, String elementName, IType typeWc) { String[] paramTypeSignatures= method.getParameterTypes(); return typeWc.getMethod(elementName, paramTypeSignatures); }
Example 20
Source File: RenameMethodProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private IMethod getMethodInWorkingCopy(IMethod method, String elementName, IType typeWc) { String[] paramTypeSignatures= method.getParameterTypes(); return typeWc.getMethod(elementName, paramTypeSignatures); }