public static boolean isReplaceInvocationsAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (method.isConstructor()) return false; return true; }
public static IMethod[] getAllConstructors(IType type) throws JavaModelException { if (JavaModelUtil.isInterfaceOrAnnotation(type)) return new IMethod[0]; List result= new ArrayList(); IMethod[] methods= type.getMethods(); for (int i= 0; i < methods.length; i++) { IMethod iMethod= methods[i]; if (iMethod.isConstructor()) result.add(iMethod); } return (IMethod[]) result.toArray(new IMethod[result.size()]); }
public static boolean isVirtual(IMethod method) throws JavaModelException { if (method.isConstructor()) return false; if (JdtFlags.isPrivate(method)) return false; if (JdtFlags.isStatic(method)) return false; return true; }
private void addMethodRename(final String unQualifiedTypeName, RenamingNameSuggestor sugg, final IMethod currentMethod) throws JavaModelException { if (!currentMethod.isConstructor()) { final String newMethodName= sugg.suggestNewMethodName(currentMethod.getElementName(), unQualifiedTypeName, getNewElementName()); if (newMethodName != null) fPreloadedElementToName.put(currentMethod, newMethodName); } }
private static SuperConstructorInvocation getSuperConstructorCallNode(IMethod constructor, CompilationUnit cuNode) throws JavaModelException { Assert.isTrue(constructor.isConstructor()); MethodDeclaration constructorNode= ASTNodeSearchUtil.getMethodDeclarationNode(constructor, cuNode); Assert.isTrue(constructorNode.isConstructor()); Block body= constructorNode.getBody(); Assert.isNotNull(body); List statements= body.statements(); if (! statements.isEmpty() && statements.get(0) instanceof SuperConstructorInvocation) return (SuperConstructorInvocation)statements.get(0); return null; } }
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; }
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; }
/** * Finds a method in an array of methods. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param methods * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IMethod[] methods) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), methods); }
/** * Finds a method in an array of methods. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param methods * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IMethod[] methods) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), methods); }
private SearchResultGroup[] findOccurrences(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException{ if (fMethod.isConstructor()){ // workaround for bug 27236: return ConstructorReferenceFinder.getConstructorOccurrences(fMethod, pm, status); }else{ SearchPattern pattern= RefactoringSearchEngine.createOrPattern(fRippleMethods, IJavaSearchConstants.ALL_OCCURRENCES); return RefactoringSearchEngine.search(pattern, createRefactoringScope(), pm, status); } }
/** * Finds a method in a type. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param type * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IType type) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), type.getMethods()); }
private RefactoringStatus checkForMethodsWithConstructorNames() throws CoreException { IMethod[] methods = fType.getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].isConstructor()) { continue; } RefactoringStatus check = Checks.checkIfConstructorName(methods[i], methods[i].getElementName(), getNewElementName()); if (check != null) { return check; } } return null; }
/** * Finds a method in a type. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param type * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IType type) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), type.getMethods()); }
private String createMethodComment(IMethod meth, String lineDelimiter) throws CoreException { IType declaringType= meth.getDeclaringType(); IMethod overridden= null; if (!meth.isConstructor()) { ITypeHierarchy hierarchy= SuperTypeHierarchyCache.getTypeHierarchy(declaringType); MethodOverrideTester tester= new MethodOverrideTester(declaringType, hierarchy); overridden= tester.findOverriddenMethod(meth, true); } return CodeGeneration.getMethodComment(meth, overridden, lineDelimiter); }
public static String createMethodSignature(IMethod method){ try { return Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, ! method.isConstructor()); } catch(JavaModelException e) { return method.getElementName(); //fallback } }
/** * Checks whether or not a method can be overridden. * * @param method the method * @return <code>true</code> if the method cannot be overridden, <code>false</code> otherwise * @throws JavaModelException if this element does not exist or if an exception occurs while * accessing its corresponding resource * @since 3.7 */ private static boolean cannotBeOverriddenMethod(IMethod method) throws JavaModelException { return JdtFlags.isPrivate(method) || JdtFlags.isFinal(method) || JdtFlags.isStatic(method) || method.isConstructor() || JdtFlags.isFinal((IMember)method.getParent()); }
public static String createMethodSignature(IMethod method){ try { return BasicElementLabels.getJavaElementName(Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, ! method.isConstructor())); } catch(JavaModelException e) { return BasicElementLabels.getJavaElementName(method.getElementName()); //fallback } }
public static String createMethodSignature(IMethod method){ try { return BasicElementLabels.getJavaElementName(Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, ! method.isConstructor())); } catch(JavaModelException e) { return BasicElementLabels.getJavaElementName(method.getElementName()); //fallback } }
private RefactoringStatus checkIfMethodDeclaredIn(final IMethod iMethod, final IType type) throws JavaModelException { final IMethod methodInType= JavaModelUtil.findMethod(iMethod.getElementName(), iMethod.getParameterTypes(), iMethod.isConstructor(), type); if (methodInType == null || !methodInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(methodInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Method_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(methodInType); return RefactoringStatus.createWarningStatus(msg, context); }
private RefactoringStatus checkIfMethodDeclaredIn(final IMethod iMethod, final IType type) throws JavaModelException { final IMethod methodInType= JavaModelUtil.findMethod(iMethod.getElementName(), iMethod.getParameterTypes(), iMethod.isConstructor(), type); if (methodInType == null || !methodInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(methodInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Method_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(methodInType); return RefactoringStatus.createWarningStatus(msg, context); }