标签:

#!/usr/bin/env python

import os

import sys

import os.path

def find_import(line):

line=line.strip()

IMPORT_CMD="import "

if not line.startswith(IMPORT_CMD):

return None

line=line[len(IMPORT_CMD):].strip()

line=line.strip(‘;‘)

parts=line.split("{")

if len(parts)==1:

return parts

head=parts[0]

parts=parts[1].strip("}")

parts=parts.split(",")

parts=["%s%s"%(head, part.strip()) for part in parts]

return parts

def import2path(roots, import_name):

spath = import_name.replace(‘.‘, ‘/‘)

for root in roots:

fpath=os.path.join(root, "%s.java"%spath)

if os.path.isfile(fpath):

return fpath

fpath=os.path.join(root, "%s.scala"%spath)

if os.path.isfile(fpath):

return fpath

return None

def file_info(fpath):

f=open(fpath, "r")

lines=f.readlines()

f.close()

lines=[line.strip() for line in lines if line.strip()!=""]

imports=[]

for line in lines:

import_array = find_import(line)

if import_array != None:

imports.extend(import_array)

return ( len(lines) - len(imports), imports)

def collect_file_info(collected, roots, entry_name):

if entry_name in collected:

return

fpath=import2path(roots, entry_name)

if fpath==None:

collected[entry_name]=None

return

if fpath in collected:

return

info=file_info(fpath)

collected[fpath]=info[0]

for import_name in info[1]:

collect_file_info(collected, roots, import_name)

def collect_ref_info(roots, entry_names):

collect_info={}

for entry_name in entry_names:

collect_file_info(collect_info, roots, entry_name)

return collect_info

def show_files_with_lines(files, title):

print("=============== %s ================="%title)

lines_total=0

files_total=0

for f in files:

lines_total=f[1]+lines_total

files_total=files_total+1

print("%s:%s"%(f[0], f[1]))

print("=============== total lines = %d,total files = %d ================="%(lines_total,files_total))

def show_files(files, title):

print("=============== %s ================="%title)

for f in files:

print(f)

if __name__== "__main__":

roots=open(sys.argv[1]).readlines()

roots=[root.strip() for root in roots if root.strip()!=""]

entry_names=open(sys.argv[2]).readlines()

entry_names=[entry_name.strip() for entry_name in entry_names if entry_name.strip()!=""]

ref_info = collect_ref_info(roots, entry_names)

in_files=[item for item in ref_info.items() if item[1]!=None]

out_files=[item[0] for item in ref_info.items() if item[1]==None]

spark_not_found=[f for f in out_files if f.startswith("org.apache.spark.")]

spark_not_found.sort()

hadoop_files=[f for f in out_files if f.startswith("org.apache.hadoop.")]

hadoop_files.sort()

other_files=list(set(out_files) - set(spark_not_found) - set(hadoop_files))

other_files.sort()

show_files_with_lines(in_files, "spark source")

show_files(spark_not_found, "spark import name not file name")

show_files(hadoop_files, "hadoop ref")

show_files(other_files, "others ref")

标签:

python类的调用关系_JAVA 查找类的所有引用关系(python实现)相关推荐

  1. java常用类需要记吗_java 常用类

    java 常用类库 Object 类:clone(), equals(), toString() Runtime 类:代表 java 程序的运行环境 定时器: Timer 和 TimerTask 类 ...

  2. spring@Autowired的对象为null,非容器中的类如何调用容器中的类

    1.问题描述 我们平时使用@Autowired注入对象时,一般被注入的类都带有@Coponent.@Controller.@Service .@repository等注解才可以.注入类和被注入类都被s ...

  3. java类的子类_java 查找类的所有子类

    package _02; import java.io.File; import java.net.URL; public class MainTest_FindAllSubClass { publi ...

  4. java 所有子类_java 查找类的所有子类

    package _02; import java.io.File; import java.net.URL; public class MainTest_FindAllSubClass { publi ...

  5. java类的运行顺序_Java语言类的基本运行顺序

    本文主要向大家介绍了Java语言类的基本运行顺序,通过具体的代码向大家展示,希望对大家学习Java语言有所帮助.我们以下面的类来说明一个基本的 Java 类的运行顺序:1. public class  ...

  6. php 类 静态调用 实例化 效率,php类的静态调用和实例化调用有哪些不同点?

    不同点有:1.静态方法在程序开始时生成内存,实例方法在程序运行中生成内存:2.静态方法可以直接调用,实例方法要先成生实例,通过实例调用方法:3.静态的内存是连续的,实例申请的是离散的空间,所以没有静态 ...

  7. java哪些类重写equals方法_Java自定义类中重写equals方法

    equals方法的要求: a.自反性:对于任何非空的x,x.equals(x)都应该返回true b.对称性:对于任何引用x和y,当且仅当x.equals(y)返回true时,y.equals(x)也 ...

  8. 编写一个带有main函数的类,调用上面的汽车类,实例化奔驰、大众、丰田等不同品牌和型号,模拟开车过程:启动、加速、转弯、刹车、息火,实时显示速度。...

    //程序入口     public static void main(String[] args) {         // TODO Auto-generated method stub       ...

  9. java实体类间的转换_java 实体类集合转换和实体类转换

    1.首先要先创建一个函数式接口接口(@FunctionalInterface),回调方法 @FunctionalInterface public interface BeanCopyUtilCallB ...

最新文章

  1. 分布式系统理论基础1: 一致性、2PC和3PC
  2. H5_canvas与svg
  3. kotlin学习之类的扩展(四)
  4. Linux tm time_t timeval timespec以及与时间相关函数用法
  5. git 管理 Linux 文件系统
  6. linux下服务器重定向,linux – DHCP服务器将任何URL重定向到登录页面
  7. 一只青蛙跳向三个台阶_Java版剑指offer编程题第9题--变态跳台阶
  8. emacs自动连接mysql数据库
  9. JVM(十),垃圾回收之新生代垃圾收集器
  10. 在Seismic.NET下用最少的语句写出一个剖面显示程序
  11. vue-cli3创建项目时报错
  12. HDU2147 kiki's game
  13. 【Android 逆向】加壳技术识别 ( VMP 加壳示例 | Dex2C 加壳示例 )
  14. 部分IT公司面试流程小结
  15. 美团构建实时数仓的痛点是什么?如何解决?
  16. ElasticSearch 从5.6.3升级到7.9.3遇到问题总结
  17. 工单流转 指派 php,第三节 工单的指派和处理
  18. 【Java】所有做过的面试题
  19. 计算机学院姚茜,2019年东南大学计算机科学与工程学院硕士研究生拟录取名单公示...
  20. Mysql安装文件夹下找不到my.ini文件怎么办?如何创建my.ini文件

热门文章

  1. Lucene实战(第2版)》
  2. 十三、流程控制之if语句
  3. 革命离成功还非常非常远,我还不怎么努力
  4. HTML5+PhoneGap相机拍照
  5. JAVA随机存储_java-如何将随机整数存储到类的实例中
  6. Linux find命令批量替换字符串find roles/hadoop_ha/vars/ -name “*.yml“ |xargs perl -pi -e ‘s|node135|node108|g‘
  7. Ansible自动化运维企业实际应用场景分析
  8. Scala Array中_ filter map的用法示例
  9. Python报错:IndentationError: unindent does not match any outer indentation level解决办法
  10. Hadoop MapReduce实例:按手机上网总流量降序排序代码实现及结果演示