/** * @param methodDeclaration * @param position * @return true if given method starts at given position, false otherwise */ public static boolean isMethodDeclarationAtLine(MethodDeclaration methodDeclaration, Integer position) { if (methodDeclaration.getName().getBegin().isPresent()) { if (position == methodDeclaration.getName().getBegin().get().line) { return true; } } return false; }
private static Location getFieldLocation( SearchContext context, File targetFile, FieldDeclaration declaration) throws IOException { final List<VariableDeclarator> variables = declaration.getVariables(); for (final VariableDeclarator variable : variables) { final SimpleName simpleName = variable.getName(); final String name = simpleName.getIdentifier(); final Optional<Position> begin = simpleName.getBegin(); if (name.equals(context.name) && begin.isPresent()) { final Position position = begin.get(); return new Location(targetFile.getCanonicalPath(), position.line, position.column); } } 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; }
final String typeName = simpleName.getIdentifier(); final String name = ClassNameUtils.getSimpleName(fqcn); final Optional<Position> begin = simpleName.getBegin(); if (typeName.equals(name) && begin.isPresent()) { final Position position = begin.get(); final SimpleName simpleName = declaration.getName(); final String name = simpleName.getIdentifier(); final Optional<Position> begin = simpleName.getBegin(); if (name.equals(ctx.name) && begin.isPresent()) { final Position position = begin.get(); final SimpleName simpleName = declaration.getName(); final String name = simpleName.getIdentifier(); final Optional<Position> begin = simpleName.getBegin(); if (name.equals(ctx.name) && begin.isPresent()) { final Position position = begin.get(); final Position pos = constructor.getName().getBegin().get(); return new Location(targetFile.getCanonicalPath(), pos.line, pos.column); final Position pos = method.getName().getBegin().get(); return new Location(targetFile.getCanonicalPath(), pos.line, pos.column);
/** * 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; }