if (method.getSignature().asString().equals(methodSignature)) { refactoring.addMethod(method); refactoring.addMethodSignature(getFullMethodSignature(method));
/** * This method returns the global signature of a method as a string. * * @param methodDeclaration * @param position * @return * @throws BotRefactoringException */ private String getFullMethodSignature(MethodDeclaration methodDeclaration, Integer position, String parameterName) throws BotRefactoringException { // If method is at the refactored position if (methodDeclaration.getName().getBegin().isPresent()) { if (position == methodDeclaration.getName().getBegin().get().line) { // Check if method has parameter if (!methodDeclaration.getParameterByName(parameterName).isPresent()) { throw new BotRefactoringException("Method '" + methodDeclaration.getSignature() + "' does not have parameter '" + parameterName + "'!"); } try { ResolvedMethodDeclaration resolvedMethod = methodDeclaration.resolve(); return resolvedMethod.getQualifiedSignature(); } catch (Exception e) { throw new BotRefactoringException("Method '" + methodDeclaration.getSignature().asString() + "' can't be resolved. It might have parameters from external projects/libraries or method might be inside a class that extends a generic class! Error: " + e); } } } return null; }
/** * This method returns the global signature of a method as a string. * * @param methodDeclaration * @param position * @return * @throws BotRefactoringException */ private String getFullMethodSignature(MethodDeclaration methodDeclaration, Integer position) throws BotRefactoringException { // If method is at the refactored position if (methodDeclaration.getName().getBegin().isPresent()) { if (position == methodDeclaration.getName().getBegin().get().line) { try { ResolvedMethodDeclaration resolvedMethod = methodDeclaration.resolve(); return resolvedMethod.getQualifiedSignature(); } catch (Exception e) { throw new BotRefactoringException("Method '" + methodDeclaration.getSignature().asString() + "' can't be resolved. It might have parameters from external projects/libraries or method might be inside a class that extends a generic class! Error: " + e); } } } return null; }
/** * @param methodDeclaration * @return the local signature of a method as a string */ public static String getMethodSignatureAsString(MethodDeclaration methodDeclaration) { return methodDeclaration.getSignature().asString(); }