private List<Method> GetMethods(java.lang.reflect.Method[] methods) { List<Method> list = new ArrayList<>(); for (java.lang.reflect.Method mthd : methods) { String visibility = this.GetVisibility(mthd.getModifiers()); boolean isStatic = this.GetIsStatic(mthd.getModifiers()); boolean isfinal = this.GetIsFinal(mthd.getModifiers()); String outputType = mthd.getGenericReturnType().toString(); List<InputParameter> inputParameters = this.GetInputParameters(mthd.getParameters()); List<String> annotations = this.GetAnnotations(mthd.getAnnotations()); String name = mthd.getName(); if (name.contains("_")) continue; boolean isThrowExceptions = false; if (mthd.getExceptionTypes().length > 0) { isThrowExceptions = true; } Method method = ModelFactory.GetMethodWithValue( outputType, name, visibility, isfinal, isStatic, isThrowExceptions, inputParameters, annotations, new ArrayList<>()); list.add(method); } return list; }
private List<InputParameter> GetInputParameters(Parameter[] pars) { List<InputParameter> list = new ArrayList<>(); for (Parameter par : pars) { String name = par.getName(); String type = par.getType().toString(); int lastIndexOfSpace = type.lastIndexOf(" "); if (lastIndexOfSpace != -1) { type = type.substring(lastIndexOfSpace); } if (par.getParameterizedType() instanceof ParameterizedType) { type = ((ParameterizedType) par.getParameterizedType()).getTypeName(); } InputParameter ip = ModelFactory.GetInputParameterWithValue(type, name); list.add(ip); } return list; }
private List<Field> GetFields(java.lang.reflect.Field[] fields) { List<Field> list = new ArrayList<>(); for (java.lang.reflect.Field field : fields) { String visibility = this.GetVisibility(field.getModifiers()); boolean isStatic = this.GetIsStatic(field.getModifiers()); boolean isFinal = this.GetIsFinal(field.getModifiers()); String type = field.getGenericType().toString(); String name = field.getName(); if (name.contains("_")) continue; List<String> annotationList = this.GetAnnotations(field.getAnnotations()); String defaultValue = ""; Field item = ModelFactory.GetFieldWithValue( type, name, visibility, defaultValue, annotationList, isStatic, isFinal); list.add(item); } return list; }
public void CreateModel(Path folder, Path filePath) throws Exception { Path rtPath = Paths.get(RTPath); Path jfxrtPath = Paths.get(FXPath); File[] files = new File[] {rtPath.toFile(), jfxrtPath.toFile()}; List<ACClass> clsList = new ArrayList<>(); for (File file : files) { System.out.println("reading " + file); try (JarInputStream jarInputStream = new JarInputStream(new BufferedInputStream(new FileInputStream(file)))) { JarEntry jarEntry = null; while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { if (jarEntry.isDirectory()) { continue; } String jarEntryName = jarEntry.getName(); if (jarEntryName.contains(SubClass) || jarEntryName.contains(Internal) || jarEntryName.contains("_")) { continue; } if (jarEntryName.startsWith(JAVAFX) || jarEntryName.startsWith(JAVA) || jarEntryName.startsWith(JAVAX)) { String clsName = jarEntryName.substring(0, jarEntryName.lastIndexOf(".")); clsName = clsName.replace("/", "."); Class<?> cls = Class.forName(clsName); List<String> clsAnnotations = this.GetAnnotations(cls.getAnnotations()); String visibility = this.GetVisibility(cls.getModifiers()); boolean isFinal = this.GetIsFinal(cls.getModifiers()); boolean isAbstract = this.GetIsAbstract(cls.getModifiers()); boolean isInterface = cls.isInterface(); boolean isEnum = cls.isEnum(); String name = cls.getName(); List<Field> fields = this.GetFields(cls.getFields()); List<Method> methods = this.GetMethods(cls.getMethods()); List<String> extds = this.GetExtends(cls); List<String> imps = this.GetImplements(cls); ACClass accls = ModelFactory.GetClassWithValue( name, visibility, isFinal, isAbstract, extds, imps, fields, methods, clsAnnotations, isEnum, isInterface, 0, 0); clsList.add(accls); } } } catch (Exception e) { e.printStackTrace(System.out); } } Model_Java model = new Model_Java(System.getProperty("java.version"), clsList); this.SaveToFile(folder, filePath, model); }