private Class<?> getReturnType(final MethodDeclaration md) { Class<?> clazz = void.class; final String returnType = md.getType().asString(); if (!returnType.equals("void")) { final List<String> classNames = new ArrayList<>(); if (returnType.contains(".")) { classNames.add(returnType.trim()); } else { this.getNativeJavaPackages().forEach(p -> classNames.add(p + returnType.trim())); } final List<Class<?>> classes = this.loadClasses(classNames).stream().collect(Collectors.toList()); clazz = classes.isEmpty() ? void.class : classes.get(0); } return clazz; }
private Class<?> getType(final FieldDeclaration fd) { final String type = fd.getVariables().get(0).getType().asString(); final List<String> classNames = new ArrayList<>(); if (type.contains(".")) { classNames.add(type.trim()); } else { this.getNativeJavaPackages().forEach(p -> classNames.add(p + type.trim())); } final List<Class<?>> classes = this.loadClasses(classNames) .stream() .collect(Collectors.toList()); return classes.isEmpty() ? Object.class : classes.get(0); }
/** * <b>Note:</b> This will not return the actual identifier but only the simple names of the types (return type & parameter types). * Doing a full type resolving with all imports adds too much complexity at this point. * This is a best-effort approach. */ private MethodIdentifier calculateMethodIdentifier(MethodDeclaration method) { String[] parameters = method.getParameters().stream() .map(p -> p.getType().asString()) .map(p -> p.replace('.', '/')) .toArray(String[]::new); String returnType = method.getType().asString().replace('.', '/'); if (method.isStatic()) { return ofStatic(className, method.getNameAsString(), returnType, parameters); } return ofNonStatic(className, method.getNameAsString(), returnType, parameters); }
/** * <b>Note:</b> This will not return the actual identifier but only the simple names of the types (return type & parameter types). * Doing a full type resolving with all imports adds too much complexity at this point. * This is a best-effort approach. */ private MethodIdentifier calculateMethodIdentifier(MethodDeclaration method) { String[] parameters = method.getParameters().stream() .map(p -> p.getType().asString()) .map(p -> p.replace('.', '/')) .toArray(String[]::new); String returnType = method.getType().asString().replace('.', '/'); if (method.isStatic()) { return ofStatic(className, method.getNameAsString(), returnType, parameters); } return ofNonStatic(className, method.getNameAsString(), returnType, parameters); }
public void index(com.github.javaparser.ast.body.Parameter parameter, int methodId) { io.github.benas.jql.model.Parameter p = new io.github.benas.jql.model.Parameter(parameter.getNameAsString(), parameter.getType().asString(), methodId); parameterDao.save(p); } }
prop.setId(indexedName); val elementType = fieldDecl.getElementType().asString(); if (elementType.equals(String.class.getSimpleName()) || elementType.equals(Integer.class.getSimpleName())
@Override public void visit(MethodDeclaration method, ClassBuilder builder) { super.visit(method, builder); TypeFactory factory = new TypeFactory(packageName, imports); if (method.getParentNode().isPresent() && method.getParentNode().get() instanceof ClassOrInterfaceDeclaration && isClass((ClassOrInterfaceDeclaration) method.getParentNode().get()) && isGetter(method.getNameAsString(), method.getType().asString()) && !skipFieldOrGetter(method.getModifiers())) { builder.withGetter(new Method( method.getNameAsString(), factory.build(method.getType().asString(), method.getType() instanceof PrimitiveType) )); } }
public void index(FieldDeclaration fieldDeclaration, int typeId) { List<VariableDeclarator> variables = fieldDeclaration.getVariables(); for (VariableDeclarator variable : variables) { String name = variable.getNameAsString(); fieldDao.save(new Field(name, fieldDeclaration.getElementType().asString(), fieldDeclaration.isPublic(), fieldDeclaration.isStatic(), fieldDeclaration.isFinal(), fieldDeclaration.isTransient(), typeId)); } }
/** {@inheritDoc} */ @Override public void visit(FieldDeclaration field, ClassBuilder builder) { super.visit(field, builder); TypeFactory factory = new TypeFactory(packageName, imports); if (!skipFieldOrGetter(field.getModifiers())) { field.getVariables().forEach(variable -> builder.withField(new Field( isNullable(field), variable.getNameAsString(), factory.build(variable.getType().asString(), variable.getType() instanceof PrimitiveType) ))); } }