com.thoughtworks.qdox.model.JavaClass Java Examples

The following examples show how to use com.thoughtworks.qdox.model.JavaClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
public static String getComponentDocumentation(JavaSource aAst, String aComponentTypeName) {
//    if (aComponentType.getName().contains("$")) {
//      // rec 2013-01-27: see comment on bindings resolving in ComponentDescriptionExtractor
//      getLog().warn(
//              "Inner classes not supported. Component description for [" + aComponentType.getName()
//                      + "] cannot be extracted. ");
//      return null;
//    }

    for (JavaClass clazz : aAst.getClasses()) {
      if (clazz.asType().getFullyQualifiedName().equals(aComponentTypeName)) {
        return postProcessJavaDoc(clazz.getComment());
      }
    }

    return null;
  }
 
Example #2
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 6 votes vote down vote up
public DefaultDescriptorsExtractor extract(MavenProject project, Log log) {
    final Collection<JavaClass> classes = javaClasses(project);

    final URLClassLoader classLoader = classLoader(project, log);
    logProjectDependencies(project, log);
    logDirectories(project, log);
    
    try {
        final Class<?> mailetClass = classLoader.loadClass(MAILET_CLASS_NAME);
        final Class<?> matcherClass = classLoader.loadClass(MATCHER_CLASS_NAME);

        for (JavaClass nextClass : classes) {
            addDescriptor(log, classLoader, mailetClass, matcherClass, nextClass);
        }
    } catch (ClassNotFoundException e) {
        log.debug(e);
        log.info("No mailets in " + project.getName());
    }
    return this;
}
 
Example #3
Source File: TestParser.java    From yatspec with Apache License 2.0 6 votes vote down vote up
private static Sequence<TestMethod> collectTestMethods(Class aClass, Sequence<Method> methods) throws IOException {
    final Option<JavaClass> javaClass = getJavaClass(aClass);
    if (javaClass.isEmpty()) {
        return empty();
    }

    Map<String, List<JavaMethod>> sourceMethodsByName = getMethods(javaClass.get()).toMap(sourceMethodName());
    Map<String, List<Method>> reflectionMethodsByName = methods.toMap(reflectionMethodName());

    List<TestMethod> testMethods = new ArrayList<TestMethod>();
    TestMethodExtractor extractor = new TestMethodExtractor();
    for (String name : sourceMethodsByName.keySet()) {
        List<JavaMethod> javaMethods = sourceMethodsByName.get(name);
        List<Method> reflectionMethods = reflectionMethodsByName.get(name);
        testMethods.add(extractor.toTestMethod(aClass, javaMethods.get(0), reflectionMethods.get(0)));
        // TODO: If people overload test methods we will have to use the full name rather than the short name
    }

    Sequence<TestMethod> myTestMethods = sequence(testMethods);
    Sequence<TestMethod> parentTestMethods = collectTestMethods(aClass.getSuperclass(), methods);

    return myTestMethods.join(parentTestMethods);
}
 
Example #4
Source File: SeleniumTestsReporter.java    From seleniumtestsframework with Apache License 2.0 6 votes vote down vote up
protected String getJavadocComments(final ITestNGMethod method) {

        try {
            final Method m = method.getConstructorOrMethod().getMethod();
            final String javaClass = m.getDeclaringClass().getName();
            final String javaMethod = m.getName();
            final JavaClass jc = getJavaDocBuilder(m.getDeclaringClass()).getClassByName(javaClass);
            final Class<?>[] types = method.getConstructorOrMethod().getMethod().getParameterTypes();
            final Type[] qdoxTypes = new Type[types.length];
            for (int i = 0; i < types.length; i++) {
                final String type = getType(types[i]);
                final int dim = getDim(types[i]);
                qdoxTypes[i] = new Type(type, dim);
            }

            final JavaMethod jm = jc.getMethodBySignature(javaMethod, qdoxTypes);
            return jm.getComment();
        } catch (final Throwable e) {
            logger.error("Exception loading the javadoc comments for : " + method.getMethodName() + e);
            return null;
        }

    }
 
Example #5
Source File: CfgDefGenerator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processClass(JarOutputStream jar, JavaClass javaClass) throws IOException {
    Optional<JavaAnnotation> annotation = javaClass.getAnnotations().stream()
            .filter(ja -> ja.getType().getName().equals(COMPONENT))
            .findFirst();
    if (annotation.isPresent()) {
        AnnotationValue property = annotation.get().getProperty(PROPERTY);
        List<String> lines = new ArrayList<>();
        if (property instanceof AnnotationValueList) {
            AnnotationValueList list = (AnnotationValueList) property;
            list.getValueList().forEach(v -> processProperty(lines, javaClass, v));
        } else {
            processProperty(lines, javaClass, property);
        }

        if (!lines.isEmpty()) {
            writeCatalog(jar, javaClass, lines);
        }
    }
}
 
Example #6
Source File: CfgDefGenerator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processProperty(List<String> lines, JavaClass javaClass,
                             AnnotationValue value) {
    String s = elaborate(value);
    String pex[] = s.split("=", 2);

    if (pex.length == 2) {
        String rex[] = pex[0].split(":", 2);
        String name = rex[0];
        String type = rex.length == 2 ? rex[1].toUpperCase() : STRING;
        String def = pex[1];
        String desc = description(javaClass, name);

        if (desc != null) {
            String line = name + SEP + type + SEP + def + SEP + desc + "\n";
            lines.add(line);
        }
    }
}
 
Example #7
Source File: SwaggerGenerator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processAllMethods(JavaClass javaClass, String resourcePath,
                               ObjectNode paths, ArrayNode tagArray, ObjectNode definitions,
                               File srcDirectory) {
    // map of the path to its methods represented by an ObjectNode
    Map<String, ObjectNode> pathMap = new HashMap<>();

    javaClass.getMethods().forEach(javaMethod -> {
        javaMethod.getAnnotations().forEach(annotation -> {
            String name = annotation.getType().getName();
            if (name.equals(PATCH) || name.equals(POST) || name.equals(GET) || name.equals(DELETE) ||
                    name.equals(PUT)) {
                // substring(12) removes "javax.ws.rs."
                String method = annotation.getType().toString().substring(12).toLowerCase();
                processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray, definitions, srcDirectory);
            }
        });
    });

    // for each path add its methods to the path node
    for (Map.Entry<String, ObjectNode> entry : pathMap.entrySet()) {
        paths.set(entry.getKey(), entry.getValue());
    }


}
 
Example #8
Source File: MockClassInfo.java    From auto-generate-test-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * mock父类的方法,mock父类和当前测试类非本测试方法的方法
 * @param javaClass 测试类信息
 * @param javaGenInfoModel 存储类的信息
 * @param javaClassModelMap 类信息存储,key - 类的全限定名称,value - 类信息
 */
private static void mockThisOtherMethod(JavaClass javaClass, JavaGenInfoModel javaGenInfoModel, Map<String, JavaClassModel> javaClassModelMap) {
    JavaClass superJavaClass = javaClass.getSuperJavaClass();
    JavaClassModel superJavaClassModel = new JavaClassModel();
    superJavaClassModel.setName(javaGenInfoModel.getModelNameLowerCamel());
    superJavaClassModel.setType(InitConstant.getAbbreviation(superJavaClass.getFullyQualifiedName()));
    superJavaClassModel.setFullyType(superJavaClass.getFullyQualifiedName());
    List<JavaMethodModel> javaMethodModelList1 = new ArrayList<>();
    //遍历父类的方法
    for (JavaMethod method : superJavaClass.getMethods()) {
        JavaMethodModel javaMethodModel = getJavaMethodModel(method,javaGenInfoModel.getModelNameLowerCamel(),javaClass.getFullyQualifiedName(), superJavaClass);
        String key = "this." + javaMethodModel.getName();
        Map<String, String> mockFullyTypeNameMap = javaGenInfoModel.getMockFullyTypeNameMap();
        if (!mockFullyTypeNameMap.containsKey(key)) {
            mockFullyTypeNameMap.put(key, superJavaClassModel.getFullyType());
        }
        javaMethodModelList1.add(javaMethodModel);
    }
    superJavaClassModel.setJavaMethodModelList(javaMethodModelList1);
    if (!javaClassModelMap.containsKey(superJavaClassModel.getFullyType())) {
        javaClassModelMap.put(superJavaClassModel.getFullyType(), superJavaClassModel);
    }
}
 
Example #9
Source File: OnosSwaggerMojo.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processAllMethods(JavaClass javaClass, String resourcePath,
                               ObjectNode paths, ArrayNode tagArray, ObjectNode definitions) {
    // map of the path to its methods represented by an ObjectNode
    Map<String, ObjectNode> pathMap = new HashMap<>();

    javaClass.getMethods().forEach(javaMethod -> {
        javaMethod.getAnnotations().forEach(annotation -> {
            String name = annotation.getType().getName();
            if (name.equals(POST) || name.equals(GET) || name.equals(DELETE) || name.equals(PUT)) {
                // substring(12) removes "javax.ws.rs."
                String method = annotation.getType().toString().substring(12).toLowerCase();
                processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray, definitions);
            }
        });
    });

    // for each path add its methods to the path node
    for (Map.Entry<String, ObjectNode> entry : pathMap.entrySet()) {
        paths.set(entry.getKey(), entry.getValue());
    }


}
 
Example #10
Source File: OnosCfgMojo.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processClass(JavaClass javaClass) throws IOException {
    Optional<JavaAnnotation> annotation = javaClass.getAnnotations().stream()
            .filter(ja -> ja.getType().getName().endsWith(COMPONENT))
            .findFirst();
    if (annotation.isPresent()) {
        AnnotationValue property = annotation.get().getProperty(PROPERTY);
        List<String> lines = new ArrayList<>();
        if (property instanceof AnnotationValueList) {
            AnnotationValueList list = (AnnotationValueList) property;
            list.getValueList().forEach(v -> processProperty(lines, javaClass, v));
        } else {
            processProperty(lines, javaClass, property);
        }

        if (!lines.isEmpty()) {
            writeCatalog(javaClass, lines);
        }
    }
}
 
Example #11
Source File: OnosCfgMojo.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processProperty(List<String> lines, JavaClass javaClass,
                             AnnotationValue value) {
    String s = elaborate(value);
    String[] pex = s.split("=", 2);

    if (pex.length == 2) {
        String[] rex = pex[0].split(":", 2);
        String name = rex[0];
        String type = rex.length == 2 ? rex[1].toUpperCase() : STRING;
        String def = pex[1];
        String desc = description(javaClass, name);

        if (desc != null) {
            String cleanedDesc = desc.trim().replace("\n", " ").replace("  ", " ");
            String line = name + SEP + type + SEP + def + SEP + cleanedDesc;
            getLog().info("Processing property " + line + " ...");
            lines.add(line + "\n");
        }
    }
}
 
Example #12
Source File: OnosSwaggerMojo.java    From onos with Apache License 2.0 5 votes vote down vote up
void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags, ObjectNode definitions) {
    // If the class does not have a Path tag then ignore it
    JavaAnnotation annotation = getPathAnnotation(javaClass);
    if (annotation == null) {
        return;
    }

    String path = getPath(annotation);
    if (path == null) {
        return;
    }

    String resourcePath = "/" + path;
    String tagPath = path.isEmpty() ? "/" : path;

    // Create tag node for this class.
    ObjectNode tagObject = mapper.createObjectNode();
    tagObject.put("name", tagPath);
    if (javaClass.getComment() != null) {
        tagObject.put("description", shortText(javaClass.getComment()));
    }
    tags.add(tagObject);

    // Create an array node add to all methods from this class.
    ArrayNode tagArray = mapper.createArrayNode();
    tagArray.add(tagPath);

    processAllMethods(javaClass, resourcePath, paths, tagArray, definitions);
}
 
Example #13
Source File: SwaggerGenerator.java    From onos with Apache License 2.0 5 votes vote down vote up
void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags,
                  ObjectNode definitions, File srcDirectory) {
    // If the class does not have a Path tag then ignore it
    JavaAnnotation annotation = getPathAnnotation(javaClass);
    if (annotation == null) {
        return;
    }

    String path = getPath(annotation);
    if (path == null) {
        return;
    }

    String resourcePath = "/" + path;
    String tagPath = path.isEmpty() ? "/" : path;

    // Create tag node for this class.
    ObjectNode tagObject = mapper.createObjectNode();
    tagObject.put("name", tagPath);
    if (javaClass.getComment() != null) {
        tagObject.put("description", shortText(javaClass.getComment()));
    }
    tags.add(tagObject);

    // Create an array node add to all methods from this class.
    ArrayNode tagArray = mapper.createArrayNode();
    tagArray.add(tagPath);

    processAllMethods(javaClass, resourcePath, paths, tagArray, definitions, srcDirectory);
}
 
Example #14
Source File: CfgDefGenerator.java    From onos with Apache License 2.0 5 votes vote down vote up
private void writeCatalog(JarOutputStream jar, JavaClass javaClass, List<String> lines)
        throws IOException {
    String name = javaClass.getPackageName().replace('.', '/') + "/" + javaClass.getName() + EXT;
    jar.putNextEntry(new JarEntry(name));
    jar.write("# This file is auto-generated\n".getBytes(UTF_8));
    for (String line : lines) {
        jar.write(line.getBytes(UTF_8));
    }
    jar.closeEntry();
}
 
Example #15
Source File: CfgDefGenerator.java    From onos with Apache License 2.0 5 votes vote down vote up
private String description(JavaClass javaClass, String name) {
    if (name.startsWith("_")) {
        // Static property - just leave it as is, not for inclusion in the cfg defs
        return null;
    }
    JavaField field = javaClass.getFieldByName(name);
    if (field != null) {
        String comment = field.getComment();
        return comment != null ? comment : NO_DESCRIPTION;
    }
    throw new IllegalStateException("cfgdef could not find a variable named " + name + " in " + javaClass.getName());
}
 
Example #16
Source File: CfgDefGenerator.java    From onos with Apache License 2.0 5 votes vote down vote up
public void generate() throws IOException {
    JarOutputStream jar = new JarOutputStream(new FileOutputStream(resourceJar));
    for (JavaClass javaClass : builder.getClasses()) {
        processClass(jar, javaClass);
    }
    jar.close();
}
 
Example #17
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private List<JavaClass> getAllInterfacesQdox(JavaClass javaClass) {
    List<JavaClass> res = new LinkedList<>();
    if (javaClass.getInterfaces() != null) {
        res.addAll(javaClass.getInterfaces());
    }
    if (javaClass.getSuperJavaClass() != null) {
        res.addAll(getAllInterfacesQdox(javaClass.getSuperJavaClass()));
    }
    return res;
}
 
Example #18
Source File: OnosCfgMojo.java    From onos with Apache License 2.0 5 votes vote down vote up
private String description(JavaClass javaClass, String name) {
    if (name.startsWith("_")) {
        // Static property - just leave it as is, not for inclusion in the cfg defs
        return null;
    }
    JavaField field = javaClass.getFieldByName(name);
    if (field != null) {
        String comment = field.getComment();
        return comment != null ? comment : NO_DESCRIPTION;
    }
    throw new IllegalStateException("cfgdef could not find a variable named " + name + " in " + javaClass.getName());
}
 
Example #19
Source File: OnosCfgMojo.java    From onos with Apache License 2.0 5 votes vote down vote up
private void writeCatalog(JavaClass javaClass, List<String> lines) {
    File dir = new File(dstDir, javaClass.getPackageName().replace('.', '/'));
    dir.mkdirs();

    File cfgDef = new File(dir, javaClass.getName().replace('.', '/') + ".cfgdef");
    try (FileWriter fw = new FileWriter(cfgDef);
         PrintWriter pw = new PrintWriter(fw)) {
        pw.println("# This file is auto-generated by onos-maven-plugin");
        lines.forEach(pw::println);
    } catch (IOException e) {
        System.err.println("Unable to write catalog for " + javaClass.getName());
        e.printStackTrace();
    }
}
 
Example #20
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Collection<JavaClass> javaClasses(MavenProject project) {
    JavaProjectBuilder builder = new JavaProjectBuilder();
    for (String s : (Iterable<String>) project.getCompileSourceRoots()) {
        builder.addSourceTree(new File(s));
    }
    return builder.getClasses();
}
 
Example #21
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void logInterfacesImplemented(Log log, JavaClass nextClass) {
    if (log.isDebugEnabled()) {
        final List<JavaClass> implementedInterfaces = getAllInterfacesQdox(nextClass);
        for (JavaClass implemented: implementedInterfaces) {
            log.debug("Interface implemented: " + implemented);
        }
    }
}
 
Example #22
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MailetMatcherDescriptor describeMailet(Log log,
        final JavaClass nextClass, String nameOfNextClass,
        final Class<?> klass) {

    final MailetMatcherDescriptor result = MailetMatcherDescriptor.builder()
            .name(nextClass.getName())
            .fullyQualifiedClassName(nameOfNextClass)
            .type(Type.MAILET)
            .info(fetchInfo(log, nameOfNextClass, klass, "getMailetInfo", Type.MAILET))
            .classDocs(nextClass.getComment())
            .experimental(isExperimental(nextClass));
    
    log.info("Found a Mailet: " + klass.getName());
    return result;
}
 
Example #23
Source File: DocBuilderTemplate.java    From smart-doc with Apache License 2.0 5 votes vote down vote up
/**
 * Build dictionary
 *
 * @param config             api config
 * @param javaProjectBuilder JavaProjectBuilder
 * @return list of ApiDocDict
 */
public List<ApiDocDict> buildDictionary(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
    List<ApiDataDictionary> apiDataDictionaryList = config.getDataDictionaries();
    if (CollectionUtil.isEmpty(apiDataDictionaryList)) {
        return new ArrayList<>(0);
    }
    List<ApiDocDict> apiDocDictList = new ArrayList<>();
    try {
        int order = 0;
        for (ApiDataDictionary apiDataDictionary : apiDataDictionaryList) {
            order++;
            Class<?> clazz = apiDataDictionary.getEnumClass();
            if (Objects.isNull(clazz)) {
                if (StringUtil.isEmpty(apiDataDictionary.getEnumClassName())) {
                    throw new RuntimeException("Enum class name can't be null.");
                }
                clazz = Class.forName(apiDataDictionary.getEnumClassName());
            }
            ApiDocDict apiDocDict = new ApiDocDict();
            apiDocDict.setOrder(order);
            apiDocDict.setTitle(apiDataDictionary.getTitle());
            JavaClass javaClass = javaProjectBuilder.getClassByName(clazz.getCanonicalName());
            if (apiDataDictionary.getTitle() == null) {
                apiDocDict.setTitle(javaClass.getComment());
            }
            List<DataDict> enumDictionaryList = EnumUtil.getEnumInformation(clazz, apiDataDictionary.getCodeField(),
                    apiDataDictionary.getDescField());
            if (!clazz.isEnum()) {
                throw new RuntimeException(clazz.getCanonicalName() + " is not an enum class.");
            }
            apiDocDict.setDataDictList(enumDictionaryList);
            apiDocDictList.add(apiDocDict);
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return apiDocDictList;
}
 
Example #24
Source File: BuildClass.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取导入的包名
 *
 * @param cls
 * @return
 */
private static List<JavaImplementsDTO> getJavaImplementsDTOList(JavaClass cls) {
    List<JavaType> javaTypeList = cls.getImplements();
    List<JavaImplementsDTO> javaImplementsDTOList = new ArrayList<>();
    for (JavaType javaType : javaTypeList) {
        JavaImplementsDTO javaImplementsDTO = new JavaImplementsDTO();
        javaImplementsDTO.setType(javaType.getFullyQualifiedName());
        javaImplementsDTOList.add(javaImplementsDTO);
    }
    return javaImplementsDTOList;
}
 
Example #25
Source File: MockClassInfo.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 存储父类的信息
 *  @param javaGenInfoModel 存储的类信息
 * @param javaField 类属性信息
 * @param javaMockClassInfoDTO 模板中的类信息
 * @param superClass 父类
 * @param javaClassModel 类信息
 */
private static void handleSuperClass(JavaGenInfoModel javaGenInfoModel, JavaField javaField, JavaMockClassInfoDTO javaMockClassInfoDTO, JavaClass superClass, JavaClassModel javaClassModel) {
    //父类的方法
    Map<String, JavaClassModel> javaClassModelMap= javaGenInfoModel.getJavaClassModelMap();
    List<JavaMethod> superJavaMethod = superClass.getMethods();
    JavaClassModel superJavaClassModel = new JavaClassModel();
    superJavaClassModel.setName(superClass.getName());
    superJavaClassModel.setType(InitConstant.getAbbreviation(superClass.getFullyQualifiedName()));
    superJavaClassModel.setFullyType(superClass.getFullyQualifiedName());
    List<JavaMethodModel> javaMethodModelList1 = new ArrayList<>();

    for (JavaMethod javaMethod : superJavaMethod) {
        JavaMethodModel javaMethodModel = getJavaMethodModel(javaMethod, javaField.getName(),javaField.getType().getFullyQualifiedName(), superClass);
        String key = javaClassModel.getName() + "." + javaMethodModel.getName();
        Map<String, String> mockFullyTypeNameMap = javaGenInfoModel.getMockFullyTypeNameMap();
        if (!mockFullyTypeNameMap.containsKey(key)) {
            mockFullyTypeNameMap.put(key, superJavaClassModel.getFullyType());
        }
        javaMethodModelList1.add(javaMethodModel);
    }
    superJavaClassModel.setJavaMethodModelList(javaMethodModelList1);
    if (!javaClassModelMap.containsKey(superJavaClassModel.getFullyType())) {
        javaClassModelMap.put(superJavaClassModel.getFullyType(), superJavaClassModel);
    }

    //TODO 暂时只处理一个接口 ,如果是接口,暂时设置最后一个接口的全限定名称 - 后面需要将接口和类进行区分
    javaMockClassInfoDTO.setParentClassFullyType(superClass.getFullyQualifiedName());

}
 
Example #26
Source File: MockClassInfo.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 设置mock方法的信息
 *
 * @param javaField 类属性
 * @param javaMethod 方法
 * @param superClass 父类
 */
private static JavaMockMethodInfoDTO setMockMethodInfo(JavaField javaField, JavaMethod javaMethod, JavaClass superClass) {

    JavaMethodModel javaMethodModel = getJavaMethodModel(javaMethod, javaField.getName(),javaField.getType().getFullyQualifiedName(), superClass);

    JavaMockMethodInfoDTO javaMockMethodInfoDTO = new JavaMockMethodInfoDTO();

    javaMockMethodInfoDTO.setParentClassFullyType(javaMethodModel.getParentClassFullyType());
    javaMockMethodInfoDTO.setFieldName(javaMethodModel.getFieldName());
    javaMockMethodInfoDTO.setClassType(javaMethodModel.getClassType());
    javaMockMethodInfoDTO.setName(javaMethodModel.getName());

    List<JavaParameteModel> javaParameteModelList = javaMethodModel.getJavaParameteModelList();
    List<JavaParameterDTO> javaParameterDTOList = new ArrayList<>();
    if (javaParameteModelList != null) {
        for (JavaParameteModel javaParameteModel : javaParameteModelList) {
            JavaParameterDTO javaParameterDTO = new JavaParameterDTO();
            javaParameterDTO.setName(javaParameteModel.getName());
            javaParameterDTO.setUpName(javaParameteModel.getUpName());
            javaParameterDTO.setType(javaParameteModel.getType());
            javaParameterDTO.setFullyType(javaParameteModel.getFullyType());
            javaParameterDTO.setCustomType(javaParameteModel.getCustomType());
            javaParameterDTO.setValue(javaParameteModel.getValue());
            javaParameterDTOList.add(javaParameterDTO);
        }
    }
    javaMockMethodInfoDTO.setJavaParameterDTOList(javaParameterDTOList);
    javaMockMethodInfoDTO.setReturnFullyType(javaMethodModel.getReturnFullyType());
    javaMockMethodInfoDTO.setReturnType(javaMethodModel.getReturnType());

    return javaMockMethodInfoDTO;
}
 
Example #27
Source File: DefaultDescriptorsExtractor.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MailetMatcherDescriptor describeMatcher(Log log,
        final JavaClass nextClass, String nameOfNextClass,
        final Class<?> klass) {

    MailetMatcherDescriptor result = MailetMatcherDescriptor.builder()
            .name(nextClass.getName())
            .fullyQualifiedClassName(nameOfNextClass)
            .type(Type.MATCHER)
            .info(fetchInfo(log, nameOfNextClass, klass, "getMatcherInfo", Type.MATCHER))
            .classDocs(nextClass.getComment())
            .experimental(isExperimental(nextClass));
    
    log.info("Found a Matcher: " + klass.getName());
    return result;
}
 
Example #28
Source File: BuildMockClassMethod.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 通过父类进行获取方法的属性
 *
 * @param javaGenInfoModel 存储的类信息
 * @param name 属性变量名称 + "." + 方法名称
 * @param methodName 方法名称
 * @param javaMethodModel 方法信息
 * @return 方法信息
 */
private static JavaMethodModel getJavaMethodModelByParent(JavaGenInfoModel javaGenInfoModel, String name, String methodName, JavaMethodModel javaMethodModel) {
    //通过父类再进行获取
    JavaClass javaClass = BaseConstant.javaProjectBuilder.getClassByName(name);
    if (javaClass == null) {
        log.warn("没有找到该类,类名:"
                + name + ",javaClass=null");
        return null;
    }
    JavaClass superJavaClass = javaClass.getSuperJavaClass();
    if (superJavaClass == null) {
        log.warn("没有找到该类的父类,类名:"
                + name + ",superJavaClass=null,javaClass=" + javaClass);
        return null;
    }

    JavaClassModel javaClassModel1 = javaGenInfoModel.getJavaClassModelMap().get(superJavaClass.getFullyQualifiedName());
    if (javaClassModel1 == null) {
        log.warn("没有找到该父类的JavaClassModel,superJavaClass:" + superJavaClass + ",javaClass:"
                + javaClass + ",javaGenInfoModel=" + javaGenInfoModel);
        return null;
    }
    for (JavaMethodModel methodModel : javaClassModel1.getJavaMethodModelList()) {
        //获取到对应的方法
        if (methodModel.getName().equals(methodName)) {
            return javaMethodModel;
        }
    }
    log.warn("在类中没有找到该方法,方法名:" + methodName + ",类名:"
            + name + ",javaGenInfoModel=" + javaGenInfoModel);

    return null;
}
 
Example #29
Source File: BuildClassMethod.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 方法抛出的异常
 *
 * @param javaMethod
 * @return
 */
private static List<JavaExceptionsDTO> getJavaExceptionsDTOList(JavaMethod javaMethod) {
    List<JavaClass> exceptions = javaMethod.getExceptions();
    List<JavaExceptionsDTO> javaExceptionsDTOS = new ArrayList<>();
    for (JavaClass exception : exceptions) {
        JavaExceptionsDTO javaExceptionsDTO = new JavaExceptionsDTO();
        javaExceptionsDTO.setType(exception.getFullyQualifiedName());
        javaExceptionsDTOS.add(javaExceptionsDTO);
    }
    return javaExceptionsDTOS;
}
 
Example #30
Source File: UnittestPlugin.java    From auto-generate-test-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    JavaProjectBuilder builder = new JavaProjectBuilder();
    builder.addSource(new File("/Users/chenhx/Desktop/github/auto-generate-test-maven-plugin/agt-core/src/main/java/com/uifuture/maven/plugins/core/model/JavaClassModel.java"));
    JavaClass javaClass1 = builder.getClassByName("JavaClassModel");
    JavaClass javaClass2 = builder.getClassByName("com.uifuture.maven.plugins.core.model.JavaClassModel");
    System.out.println(javaClass1 + "====" + javaClass2);
    JavaClass javaClass3 = builder.getClassByName("JavaProjectBuilder");
    JavaClass javaClass4 = builder.getClassByName("com.thoughtworks.qdox.JavaProjectBuilder");
    System.out.println(javaClass3 + "====" + javaClass4);
}