Package org.codehaus.backport175.compiler.bytecode

Examples of org.codehaus.backport175.compiler.bytecode.AnnotationEnhancer


    public void insertClassAnnotation(final RawAnnotation annotation) {
        if (m_reader == null) {
            throw new IllegalStateException("annotation enhancer is not initialized");
        }
        if (hasClassAnnotation(annotation)) {
            throw new CompilerException(
                    "duplicate class annotation " + annotation,
                    SourceLocation.render(annotation)
            );
        }
        m_classAnnotations.add(annotation);
View Full Code Here


        if (m_reader == null) {
            throw new IllegalStateException("annotation enhancer is not initialized");
        }
        FieldAnnotationInfo info = new FieldAnnotationInfo(field, annotation);
        if (hasFieldAnnotation(info)) {
            throw new CompilerException(
                    "duplicate field annotation " + annotation,
                    SourceLocation.render(annotation)
            );
        }
        m_fieldAnnotations.add(new FieldAnnotationInfo(field, annotation));
View Full Code Here

        if (m_reader == null) {
            throw new IllegalStateException("annotation enhancer is not initialized");
        }
        MethodAnnotationInfo info = new MethodAnnotationInfo(constructor, annotation);
        if (hasConstructorAnnotation(info)) {
            throw new CompilerException(
                    "duplicate constructor annotation " + annotation,
                    SourceLocation.render(annotation)
            );
        }
        m_constructorAnnotations.add(new MethodAnnotationInfo(constructor, annotation));
View Full Code Here

        File file = new File(filename);
        File parentFile = file.getParentFile();
        if (!parentFile.exists()) {
            // directory does not exist create all directories in the filename
            if (!parentFile.mkdirs()) {
                throw new CompilerException(
                        "could not create dir structure needed to write file " + filename + " to disk"
                );
            }
        }
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(filename);
            os.write(writer.toByteArray());
        } catch (IOException e) {
            throw new CompilerException("could not write compiled class file to disk [" + filename + "]", e);
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                throw new CompilerException("could not close file output stream for [" + filename + "]", e);
            }
        }
    }
View Full Code Here

        /**
         * Helper to stdout
         */
        public void dump() {
            for (Iterator iterator = compilerExceptions.iterator(); iterator.hasNext();) {
                CompilerException compilerException = (CompilerException) iterator.next();
                System.out.println("ERROR: "+ compilerException.toString());
            }
            for (Iterator iterator = acceptedLocations.iterator(); iterator.hasNext();) {
                SourceLocation sourceLocation = (SourceLocation) iterator.next();
                System.out.println("OK: " + sourceLocation.toString());
            }
View Full Code Here

            for (Iterator iterator = compilerExceptions.iterator(); iterator.hasNext();) {
                CompilerException compilerException = (CompilerException) iterator.next();
                System.out.println("ERROR: "+ compilerException.toString());
            }
            for (Iterator iterator = acceptedLocations.iterator(); iterator.hasNext();) {
                SourceLocation sourceLocation = (SourceLocation) iterator.next();
                System.out.println("OK: " + sourceLocation.toString());
            }
        }
View Full Code Here

        JavaClass[] classes = m_javaDocParser.getJavaClasses();
        for (int i = 0; i < classes.length; i++) {
            JavaClass clazz = classes[i];
            logInfo("parsing class [" + clazz.getFullyQualifiedName() + ']');
            try {
                AnnotationEnhancer enhancer = new AnnotationEnhancer(m_handler);
                if (enhancer.initialize(clazz.getFullyQualifiedName(), classPath)) {
                    handleClassAnnotations(enhancer, clazz);
                    //handleInnerClassAnnotations(enhancer, clazz, destDir);
                    JavaMethod[] methods = clazz.getMethods();
                    for (int j = 0; j < methods.length; j++) {
                        JavaMethod method = methods[j];
                        if (method.isConstructor()) {
                            handleConstructorAnnotations(enhancer, method);
                        } else {
                            handleMethodAnnotations(enhancer, method);
                        }
                    }
                    JavaField[] fields = clazz.getFields();
                    for (int j = 0; j < fields.length; j++) {
                        handleFieldAnnotations(enhancer, fields[j]);
                    }

                    // write enhanced class to disk
                    enhancer.write(destDir);
                }
            } catch (ParseException pe) {
                m_handler.error(pe);
                // non critical, go on
            } catch (CompilerException ce) {
View Full Code Here

        JavaClass[] classes = m_javaDocParser.getJavaClasses();
        for (int i = 0; i < classes.length; i++) {
            JavaClass clazz = classes[i];
            logInfo("parsing class [" + clazz.getFullyQualifiedName() + ']');
            try {
                AnnotationEnhancer enhancer = new AnnotationEnhancer(m_handler);
                if (enhancer.initialize(clazz.getFullyQualifiedName(), classPath)) {
                    handleClassAnnotations(enhancer, clazz);
                    //handleInnerClassAnnotations(enhancer, clazz, destDir);
                    JavaMethod[] methods = clazz.getMethods();
                    for (int j = 0; j < methods.length; j++) {
                        JavaMethod method = methods[j];
                        if (method.isConstructor()) {
                            handleConstructorAnnotations(enhancer, method);
                        } else {
                            handleMethodAnnotations(enhancer, method);
                        }
                    }
                    JavaField[] fields = clazz.getFields();
                    for (int j = 0; j < fields.length; j++) {
                        handleFieldAnnotations(enhancer, fields[j]);
                    }

                    // write enhanced class to disk
                    enhancer.write(destDir);
                }
            } catch (ParseException pe) {
                m_handler.error(pe);
                // non critical, go on
            } catch (CompilerException ce) {
View Full Code Here

            }
            destDirToUse = classpath[0];
        }

        // set up the parser sources
        final JavaDocParser javaDocParser = new JavaDocParser();
        try {
            // add classloader
            javaDocParser.addClassLoaderToSearchPath(compilationLoader);

            // add src dirs
            StringBuffer logDirs = new StringBuffer("parsing source dirs:");
            for (int i = 0; i < srcDirs.length; i++) {
                logDirs.append("\n\t" + srcDirs[i]);
            }
            messageHandler.info(logDirs.toString());
            javaDocParser.addSourceTrees(srcDirs);

            // add src files
            logDirs = new StringBuffer();
            for (int i = 0; i < srcFiles.length; i++) {
                logDirs.append("\n\t" + srcFiles[i]);
                javaDocParser.addSource(srcFiles[i]);
            }
            if (srcFiles.length > 0) {
                messageHandler.info(logDirs.toString());
            }
View Full Code Here

     * @param clazz
     */
    private void handleClassAnnotations(final AnnotationEnhancer enhancer, final JavaClass clazz) {
        DocletTag[] tags = clazz.getTags();
        for (int i = 0; i < tags.length; i++) {
            RawAnnotation rawAnnotation = getRawAnnotation(
                    tags[i], enhancer.getClassName(), enhancer.getClassFileName()
            );
            if (rawAnnotation == null) {
                continue;
            }
            enhancer.insertClassAnnotation(rawAnnotation);
            logInfo(
                    "\tprocessing class annotation [" + rawAnnotation.getName() + " @ "
                    + clazz.getFullyQualifiedName() + ']'
            );
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.backport175.compiler.bytecode.AnnotationEnhancer

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.