当前位置: 首页 > news >正文

django网站开发论文seo推广小分享

django网站开发论文,seo推广小分享,元宇宙软件开发,最专业的做音乐网站之前分享过一篇使用 AI 可视化 Java 项目的文章,同步在 AI 破局星球、知乎、掘金等地方都分享了。 原文在这里AI 编程:可视化 Java 项目 有很多人感兴趣,我打算写一个系列文章拆解这个项目,大家多多点赞支持~ 今天分享的是第一…

之前分享过一篇使用 AI 可视化 Java 项目的文章,同步在 AI 破局星球、知乎、掘金等地方都分享了。

原文在这里AI 编程:可视化 Java 项目

有很多人感兴趣,我打算写一个系列文章拆解这个项目,大家多多点赞支持~

今天分享的是第一篇:如何使用 Spoon + JavaParser 工具解析一个本地的 Java 项目。

解析这一步骤是整个项目的基础,是为了获得整个 Java 项目的元数据。

这个元数据包含什么呢?1)整个项目的所有的类信息;2)整个项目的所有方法信息

方法信息

序号字段名称字段描述
1method_id方法唯一id标识
2project_name
3method_name方法名
4class_id方法所属类名
5param_type参数类型
6response_type返回类型
7begin_line方法内容开始行
8end_line方法内容结束行
9branch分支
10method_desc方法描述
11chat_descGPT 描述
12invoke_count被调用数量
13mermaid_flow_graph流程图数据
14flow_graph_ignored是否忽略流程图
15annotation_info注解信息
16annotation_type注解类型
17access_modifier修饰符

类信息

序号字段名称字段描述
1class_id类唯一标识
2class_name类名
3project_name项目唯一标识
4package_name包名
5branch分支
6class_type类的类型
7chat_descGPT 类描述
8class_desc类注释
9annotation_info类注解
10method_annotation_info方法注解信息
11annotation_type注解类型

怎么拿到整个项目的类信息和方法信息呢?

首先我们需要一个类解析器、一个方法解析器。使用 Java 的反射,我们就能拿到具体类和方法的详细信息。

类解析器代码:

public void execute(List<CtType<?>> elements) {classStructs = Lists.newArrayList();for (CtType<?> type : elements) {try {// 匿名内部类和泛型会跳过解析if (type.isAnonymous()) {continue;}if (Objects.isNull(type.getPackage())) {continue;}// 获取类的简单类名String simpleClassName = type.getSimpleName();// GPT 接口获取解释String chatDesc = "";// 获取类所属包String packageName = type.getPackage().getQualifiedName();// 获取类注释信息String classComment = type.getDocComment();// 判断接口还是类ClassType classType = getClassType(type);// 获取类注解信息List<AnnotationInfo> annotationInfos = Lists.newArrayList();List<CtAnnotation<?>> annotations = type.getAnnotations();for (CtAnnotation<?> annotation : annotations) {AnnotationInfo annotationInfo = new AnnotationInfo();String annotationName = annotation.getAnnotationType().getSimpleName();annotationInfo.setAnnotationName(annotationName);Map<String, CtExpression> annotationValues = annotation.getValues();for (Map.Entry<String, CtExpression> entry : annotationValues.entrySet()) {String attributeName = entry.getKey();Object attributeValue = entry.getValue();annotationInfo.addAttributeName(attributeName, attributeValue.toString());}annotationInfos.add(annotationInfo);}// 构造类元信息ClassStruct classStruct = buildClassStruct(simpleClassName, packageName, classType,classComment, annotationInfos, chatDesc);classStructs.add(classStruct);} catch (Exception e) {log.error("class parse error, className ==>{}, errMsg ==>", type.getSimpleName(), e);}}// 类元信息入库}

方法解析器

public void execute(List<CtType<?>> elements) {methodStructs = Lists.newArrayList();for (CtType<?> element : elements) {if (element.isAnonymous()) {continue;}if (Objects.isNull(element.getPackage())) {continue;}// 获取包名String packageName = element.getPackage().getQualifiedName();// 获取类名String className = element.getSimpleName();// 获取方法列表Set<CtMethod<?>> methods = element.getMethods();for (CtMethod<?> method : methods) {try {// 获取简单方法名String methodName = method.getSimpleName();// 获取全限定参数String signatureParameters = method.getSignature();int firstIndex = method.getSignature().indexOf("(");int lastIndex = method.getSignature().indexOf(")");String parameters = signatureParameters.substring(firstIndex + 1, lastIndex);List<String> methodParameters = Splitter.on(",").omitEmptyStrings().splitToList(parameters);// 获取响应体类型String responseType = method.getType().getQualifiedName();// 获取方法开始的行int startLine = method.getPosition().getLine();// 获取方法结束的行int endLine = method.getPosition().getEndLine();// 获取方法注释String methodComment = method.getDocComment();// 获取方法包含的注解信息List<AnnotationInfo> annotationInfos = Lists.newArrayList();List<CtAnnotation<?>> annotations = method.getAnnotations();for (CtAnnotation<?> annotation : annotations) {AnnotationInfo annotationInfo = new AnnotationInfo();String annotationName = annotation.getAnnotationType().getSimpleName();annotationInfo.setAnnotationName(annotationName);Map<String, CtExpression> annotationValues = annotation.getValues();for (Map.Entry<String, CtExpression> entry : annotationValues.entrySet()) {String attributeName = entry.getKey();Object attributeValue = entry.getValue();annotationInfo.addAttributeName(attributeName, attributeValue.toString());}annotationInfos.add(annotationInfo);}// 获取方法的访问修饰符String accessModifier = "";if (Objects.isNull(method.getVisibility())) {accessModifier = "default";} else {accessModifier = method.getVisibility().toString();}String methodId = generateIdentityUtil.generateMethodId(MethodSignature.builder().packagePath(packageName).className(className).methodName(methodName).parameterTypeString(methodParameters).build(), endLine - startLine + 1);MethodStruct old = null;// 基于规则判断一波是否需要询问chatint lineCount = endLine - startLine;MethodStruct methodStruct = MethodStruct.builder().appCode(GlobalVariableUtil.getAppCodeName()).methodId(methodId).methodName(methodName).classId(generateIdentityUtil.generateClassId(className, packageName, GlobalVariableUtil.getAppCodeName())).paramTypes(methodParameters).responseType(responseType).beginLine(startLine).endLine(endLine).branch(GlobalVariableUtil.getBranch()).methodDesc(methodComment).annotationInfos(annotationInfos).accessModifier(accessModifier).invokeCount(old == null ? 0 : old.getInvokeCount()).mermaidFlowGraph(old == null ? "" : old.getMermaidFlowGraph()).build();if (old == null) {methodStructs.add(methodStruct);}} catch (Exception e) {log.error("method parse error, className ==>{}, methodName ==>{}, errMsg ==>",className, method.getSimpleName(), e);}}}
//       方法元信息入库}

通过这种方式,我们就能拿到整个 Java 项目的方法信息。

需要注意的是,我们这个时候还没有使用 AI 技术,所以这个元信息中部分字段是空的。

我们看到类解析器和方法解析器方法的入参都是 List<CtType<?>> elements

那么,这个信息从哪里来的呢?

我这里使用的是 Spoon 工具。

Spoon 是什么?

Spoon 框架常被用于解析和处理 Java 源代码。Spoon 是一个强大的源码分析与转换工具,它通过构建抽象语法树(Abstract Syntax Tree, AST)来表示 Java 源代码,并提供了一套丰富的 API 供开发者操作 AST。

Spoon 能够完整且准确地捕获源代码的所有细节,所以它非常适合于进行复杂的静态代码分析、重构、自动插入代码逻辑等工作。

Spoon 不会用?没关系,AI 可以帮你写代码。

我们可以看到,GPT 直接帮我们生成完整代码,我们只需要在对应的地方,替换成我们的类解析器和方法解析器即可。

提示词如下:

你是一个Java技术专家。
我需要解析本地的一个 Java 项目,获得这个项目中的类信息和方法信息。我会给你提供这个 Java 项目的绝对路径。
请你使用 Spoon 生成解析代码

写到这里,我要告诉你的是,其实类解析器和方法解析的代码,也可以交给 AI 来完成哟~ 你可以试试看,如果有问题,随时找阿七给你解答。

到这里,我们今天的内容就结束啦。

下一篇,我们分享使用 AI 生成方法的流程图,请期待~

http://www.tj-hxxt.cn/news/89116.html

相关文章:

  • 国外有哪些设计网站推荐seo网站页面优化包含
  • 品牌型网站建设理论上海seo顾问
  • 网站的策划做推广上海自媒体推广
  • 教育公司网站建设方案优化大师app下载安装
  • wordpress 建站 图床百度推广竞价是什么意思
  • 对企业网站的印象下载百度语音导航地图安装
  • 网站建设开发员百度明星人气榜
  • app界面设计优秀案例武汉seo公司哪家专业
  • 综合门户类网站有哪些seo收录查询工具
  • 惠州专业网站设计公司今天重大国际新闻
  • 企业门户网站免费模板官网seo优化
  • 长春做网站建设的公司百度论坛首页官网
  • 大型建设网站网络宣传推广方案范文
  • 友情链接页 wordpress搜索引擎优化网页
  • 做网站的最终目的百度网盘免费下载
  • 单页购物网站源码舆情优化公司
  • 服务器 打开网站iis7google官网入口下载
  • 自己怎么健网站视频教程开网店如何运营和推广
  • 设计模版网站万网官网登录
  • 网站建设属于移动互联网广州发布紧急通知
  • 为什么网站要域名百度电脑版下载安装
  • 娄底哪里做网站网络营销模式有哪些
  • 鞍山网站制作公司厦门小鱼网
  • wordpress如何设置标题字的大小seo外链推广员
  • aspnet动态网站开发题目推广平台排名
  • 做b2b比较好的网站有哪些seo怎么刷排名
  • 免费建企业网站网站建设推广专家服务
  • 设计比较有特色的网站最新足球消息
  • 简单的电影网站模板在线seo优化
  • 成品网站价格表百度软件商店