@Override public void visit(SimpleName n, Void arg) { out.println("SimpleName: " + (extended ? n : n.getIdentifier())); super.visit(n, arg); }
private static ClassOrInterfaceType simpleParametricType(String className, String... typeArgs) { NodeList<Type> typeArguments = new NodeList<Type>(); for (String typeArg : typeArgs) { typeArguments.add(classType(typeArg)); } return new ClassOrInterfaceType(null, new SimpleName(className), typeArguments); }
private static void writeHashCode(PrintStream s, Map<String, String> imports, String indent, List<VariableDeclarator> vars) { s.format("\n\n%s@%s", indent, resolve(imports, Override.class)); s.format("\n%spublic int hashCode() {", indent); s.format("\n%s%sreturn %s.hash(%s);", indent, indent, resolve(imports, Objects.class), // vars.stream() // .map(y -> y.getName().toString()) // .collect(Collectors.joining(", "))); s.format("\n%s}", indent); }
final List<BodyDeclaration<?>> members = n.getMembers(); final SimpleName simpleName = n.getName(); final String clazz = simpleName.getId(); final ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) body; String name = classOrInterfaceDeclaration.getName().getIdentifier(); String key = this.pkg + '.' + name; name = this.originClassName + '.' + name;
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; }
public static Optional<SimpleName> findSimpleName(Node node, String name) { return node.findFirst(SimpleName.class, n -> n.asString().equals(name)); }
/** * @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 void writeHashCode(PrintStream s, Map<String, String> imports, String indent, List<VariableDeclarator> vars) { s.format("\n\n%s@%s", indent, resolve(imports, Override.class)); s.format("\n%spublic int hashCode() {", indent); s.format("\n%s%sreturn %s.hash(%s);", indent, indent, resolve(imports, Objects.class), // vars.stream() // .map(y -> y.getName().toString()) // .collect(Collectors.joining(", "))); s.format("\n%s}", indent); }
if (ctx.kind.equals(SearchKind.CLASS)) { final SimpleName simpleName = type.getName(); 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 ConstructorDeclaration declaration = (ConstructorDeclaration) member; 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 MethodDeclaration declaration = (MethodDeclaration) member; 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);
@Override public Void visit(ClassOrInterfaceDeclaration n, Map<AccessibleObject, String[]> arg) { currentClassName.append("$").append(n.getName()); super.visit(n, arg); currentClassName.delete(currentClassName.length() - n.getName().asString().length() - 1, currentClassName.length()); 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; }
private void getParameterNames(MethodDeclaration methodDeclaration, boolean isInterface) { final EnumSet<Modifier> modifiers = methodDeclaration.getModifiers(); if (isInterface || modifiers.contains(Modifier.PUBLIC)) { String methodName = methodDeclaration.getName().getIdentifier(); List<Parameter> parameters = methodDeclaration.getParameters(); names.className = this.className; List<List<ParameterName>> parameterNames = names.names.computeIfAbsent(methodName, k -> new ArrayList<>(4)); final List<ParameterName> temp = new ArrayList<>(); for (final Parameter parameter : parameters) { ParameterName parameterName = new ParameterName(); String type = parameter.getType().toString(); String name = parameter.getName().getIdentifier(); if (name.contains("[]")) { type = type + "[]"; name = name.replace("[]", ""); } parameterName.type = type; parameterName.name = name; temp.add(parameterName); } parameterNames.add(temp); } } }
@Override public String getName() { return wrappedNode.getName().getId(); }
private static void writeWiths(PrintStream s, String indent, ClassOrInterfaceDeclaration c, List<VariableDeclarator> vars) { vars.stream() // .forEach(x -> { s.format("\n\n%spublic %s with%s(%s %s) {", indent, c.getName(), capFirst(x.getName().toString()), x.getType(), x.getName()); s.format("\n%s%sreturn new %s(%s);", indent, indent, c.getName(), // vars.stream() // .map(y -> y.getName().toString()) // .collect(Collectors.joining(", "))); s.format("\n%s}", indent); }); }
@Override public Void visit(ClassOrInterfaceDeclaration n, Map<AccessibleObject, String[]> arg) { currentClassName.append("$").append(n.getName()); super.visit(n, arg); currentClassName.delete(currentClassName.length() - n.getName().asString().length() - 1, currentClassName.length()); return null; }
private static ClassOrInterfaceType simpleParametricType(String className, String... typeArgs) { NodeList<Type> typeArguments = new NodeList<Type>(); for (String typeArg : typeArgs) { typeArguments.add(classType(typeArg)); } return new ClassOrInterfaceType(null, new SimpleName(className), typeArguments); }
/** * 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; }
@Override public void process(Node node) { String label = ""; if (node instanceof SimpleName) label = ((SimpleName) node).getIdentifier(); else if (node instanceof StringLiteralExpr) label = ((StringLiteralExpr) node).asString(); else if (node instanceof BooleanLiteralExpr) label = Boolean.toString(((BooleanLiteralExpr) node).getValue()); else if (node instanceof LiteralStringValueExpr) label = ((LiteralStringValueExpr) node).getValue(); pushNode(node, label); }