Package com.thoughtworks.qdox.model

Examples of com.thoughtworks.qdox.model.ModelBuilder


            }
        }

        // Create a new builder and mimic the behaviour of the parser.
        // We're getting all the information we need via reflection instead.
        ModelBuilder binaryBuilder =
                new ModelBuilder(classLibrary, docletTagFactory);

        // Set the package name and class name
        if (packageName == null) {
            binaryBuilder.addPackage(getPackageName(name));
        } else {
            binaryBuilder.addPackage(packageName);
        }

        ClassDef classDef = new ClassDef();
        classDef.name = getClassName(name);

        // Set the extended class and interfaces.
        Class[] interfaces = clazz.getInterfaces();
        if (clazz.isInterface()) {
            // It's an interface
            classDef.type = ClassDef.INTERFACE;
            for (int i = 0; i < interfaces.length; i++) {
                Class anInterface = interfaces[i];
                classDef.extendz.add(anInterface.getName());
            }
        } else {
            // It's a class
            for (int i = 0; i < interfaces.length; i++) {
                Class anInterface = interfaces[i];
                classDef.implementz.add(anInterface.getName());
            }
            Class superclass = clazz.getSuperclass();
            if (superclass != null) {
                classDef.extendz.add(superclass.getName());
            }
        }

        addModifiers(classDef.modifiers, clazz.getModifiers());

        binaryBuilder.beginClass(classDef);

        // add the constructors
        //
        // This also adds the default constructor if any which is different
        // to the source code as that does not create a default constructor
        // if no constructor exists.
        Constructor[] constructors = clazz.getDeclaredConstructors();
        for (int i = 0; i < constructors.length; i++) {
            addMethodOrConstructor(constructors[i], binaryBuilder);
        }

        // add the methods
        Method[] methods = clazz.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            addMethodOrConstructor(methods[i], binaryBuilder);
        }

        Field[] fields = clazz.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            addField(fields[i], binaryBuilder);
        }

        binaryBuilder.endClass();
        JavaSource binarySource = binaryBuilder.getSource();
        // There is always only one class in a "binary" source.
        JavaClass result = binarySource.getClasses()[0];
        return result;
    }
View Full Code Here


    public JavaSource addSource(Reader reader) {
        return addSource(reader, "UNKNOWN SOURCE");
    }

    public JavaSource addSource(Reader reader, String sourceInfo) {
        ModelBuilder builder = new ModelBuilder(classLibrary, docletTagFactory);
        Lexer lexer = new JFlexLexer(reader);
        Parser parser = new Parser(lexer, builder);
        parser.setDebugLexer(debugLexer);
        parser.setDebugParser(debugParser);
        try {
            parser.parse();
        } catch (ParseException e) {
            e.setSourceInfo(sourceInfo);
            throw e;
        }
        JavaSource source = builder.getSource();
        sources.add(source);
        addClasses(source);
        return source;
    }
View Full Code Here

        }
        return result;
    }

    private JavaClass createUnknownClass(String name) {
        ModelBuilder unknownBuilder = new ModelBuilder(classLibrary, docletTagFactory);
        ClassDef classDef = new ClassDef();
        classDef.name = name;
        unknownBuilder.beginClass(classDef);
        unknownBuilder.endClass();
        JavaSource unknownSource = unknownBuilder.getSource();
        JavaClass result = unknownSource.getClasses()[0];
        return result;
    }
View Full Code Here

        if (clazz == null) {
            return null;
        } else {
            // Create a new builder and mimic the behaviour of the parser.
            // We're getting all the information we need via reflection instead.
            ModelBuilder binaryBuilder = new ModelBuilder(classLibrary, docletTagFactory);

            // Set the package name and class name
            String packageName = getPackageName(name);
            binaryBuilder.addPackage(packageName);

            ClassDef classDef = new ClassDef();
            classDef.name = getClassName(name);

            // Set the extended class and interfaces.
            Class[] interfaces = clazz.getInterfaces();
            if (clazz.isInterface()) {
                // It's an interface
                classDef.type = ClassDef.INTERFACE;
                for (int i = 0; i < interfaces.length; i++) {
                    Class anInterface = interfaces[i];
                    classDef.extendz.add(anInterface.getName());
                }
            } else {
                // It's a class
                for (int i = 0; i < interfaces.length; i++) {
                    Class anInterface = interfaces[i];
                    classDef.implementz.add(anInterface.getName());
                }
                Class superclass = clazz.getSuperclass();
                if (superclass != null) {
                    classDef.extendz.add(superclass.getName());
                }
            }

            addModifiers(classDef.modifiers, clazz.getModifiers());

            binaryBuilder.beginClass(classDef);

            // add the constructors
            Constructor[] constructors = clazz.getConstructors();
            for (int i = 0; i < constructors.length; i++) {
                addMethodOrConstructor(constructors[i], binaryBuilder);
            }

            // add the methods
            Method[] methods = clazz.getMethods();
            for (int i = 0; i < methods.length; i++) {
                // Ignore methods defined in superclasses
                if (methods[i].getDeclaringClass() == clazz) {
                    addMethodOrConstructor(methods[i], binaryBuilder);
                }
            }

            Field[] fields = clazz.getFields();
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].getDeclaringClass() == clazz) {
                    addField(fields[i], binaryBuilder);
                }
            }

            binaryBuilder.endClass();
            JavaSource binarySource = binaryBuilder.getSource();
            // There is always only one class in a "binary" source.
            JavaClass result = binarySource.getClasses()[0];
            return result;
        }
    }
View Full Code Here

        }
        return null;
    }

    protected JavaClass createUnknownClass(String name) {
        ModelBuilder unknownBuilder = new ModelBuilder(context, docletTagFactory, new HashMap());
        ClassDef classDef = new ClassDef();
        classDef.name = name;
        unknownBuilder.beginClass(classDef);
        unknownBuilder.endClass();
        JavaSource unknownSource = unknownBuilder.getSource();
        JavaClass result = unknownSource.getClasses()[0];
        return result;
    }
View Full Code Here

            return null;
        } else {
            try {
        // Create a new builder and mimic the behaviour of the parser.
        // We're getting all the information we need via reflection instead.
        ModelBuilder binaryBuilder = new ModelBuilder(context, docletTagFactory, new HashMap());

        // Set the package name and class name
        String packageName = getPackageName(name);
        binaryBuilder.addPackage(new PackageDef(packageName));

        ClassDef classDef = new ClassDef();
        classDef.name = getClassName(name);

        // Set the extended class and interfaces.
        Class[] interfaces = clazz.getInterfaces();
        if (clazz.isInterface()) {
            // It's an interface
            classDef.type = ClassDef.INTERFACE;
            for (int i = 0; i < interfaces.length; i++) {
                Class anInterface = interfaces[i];
                classDef.extendz.add(new TypeDef(anInterface.getName()));
            }
        } else {
            // It's a class
            for (int i = 0; i < interfaces.length; i++) {
                Class anInterface = interfaces[i];
                classDef.implementz.add(new TypeDef(anInterface.getName()));
            }
            Class superclass = clazz.getSuperclass();
            if (superclass != null) {
                classDef.extendz.add(new TypeDef(superclass.getName()));
            }
        }

        addModifiers(classDef.modifiers, clazz.getModifiers());

        binaryBuilder.beginClass(classDef);

        // add the constructors
        //
        // This also adds the default constructor if any which is different
        // to the source code as that does not create a default constructor
        // if no constructor exists.
        Constructor[] constructors = clazz.getDeclaredConstructors();
        for (int i = 0; i < constructors.length; i++) {
            addMethodOrConstructor(constructors[i], binaryBuilder);
        }

        // add the methods
        Method[] methods = clazz.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            addMethodOrConstructor(methods[i], binaryBuilder);
        }

        Field[] fields = clazz.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            addField(fields[i], binaryBuilder);
        }

        binaryBuilder.endClass();
        JavaSource binarySource = binaryBuilder.getSource();
        // There is always only one class in a "binary" source.
        JavaClass result = binarySource.getClasses()[0];
        return result;
      } catch (NoClassDefFoundError e) {
        return null;
View Full Code Here

    public JavaSource addSource(Reader reader) {
        return addSource(reader, "UNKNOWN SOURCE");
    }

    public JavaSource addSource(Reader reader, String sourceInfo) {
        ModelBuilder builder = new ModelBuilder(context, docletTagFactory, null);
        Lexer lexer = new JFlexLexer(reader);
        Parser parser = new Parser(lexer, builder);
        parser.setDebugLexer(debugLexer);
        parser.setDebugParser(debugParser);
        try {
            parser.parse();
        } catch (ParseException e) {
            e.setSourceInfo(sourceInfo);
            errorHandler.handle(e);
        }
        JavaSource source = builder.getSource();
        sources.add(source);
        addClasses(source);

        JavaPackage pkg = context.getPackageByName( source.getPackageName() );
        if (!packages.contains(pkg)) {
View Full Code Here

TOP

Related Classes of com.thoughtworks.qdox.model.ModelBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.