hudson.plugins.pmd.util
Class AbstractAnnotationParser

java.lang.Object
  extended by hudson.plugins.pmd.util.AbstractAnnotationParser
All Implemented Interfaces:
AnnotationParser, java.io.Serializable
Direct Known Subclasses:
PmdParser

public abstract class AbstractAnnotationParser
extends java.lang.Object
implements AnnotationParser

A base class for parsers that work on files an produce annotations.

Author:
Ulli Hafner
See Also:
Serialized Form

Constructor Summary
protected AbstractAnnotationParser(java.lang.String defaultEncoding)
          Creates a new instance of AbstractAnnotationParser.
 
Method Summary
protected  int createContextHashCode(java.lang.String fileName, int line)
          Creates a hash code from the source code of the warning line and the surrounding context.
protected  java.lang.String getDefaultEncoding()
          Returns the default encoding to be used when reading and parsing files.
 java.util.Collection<FileAnnotation> parse(java.io.File file, java.lang.String moduleName)
          Returns the annotations found in the specified file.
abstract  java.util.Collection<FileAnnotation> parse(java.io.InputStream file, java.lang.String moduleName)
          Returns the annotations found in the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAnnotationParser

protected AbstractAnnotationParser(java.lang.String defaultEncoding)
Creates a new instance of AbstractAnnotationParser.

Parameters:
defaultEncoding - the default encoding to be used when reading and parsing files
Method Detail

getDefaultEncoding

protected final java.lang.String getDefaultEncoding()
Returns the default encoding to be used when reading and parsing files.

Returns:
the default encoding

parse

public java.util.Collection<FileAnnotation> parse(java.io.File file,
                                                  java.lang.String moduleName)
                                           throws java.lang.reflect.InvocationTargetException
Returns the annotations found in the specified file.

Specified by:
parse in interface AnnotationParser
Parameters:
file - the file to parse
moduleName - name of the maven module
Returns:
the parsed result (stored in the module instance)
Throws:
java.lang.reflect.InvocationTargetException - if the file could not be parsed (wrap your exception in this exception)

parse

public abstract java.util.Collection<FileAnnotation> parse(java.io.InputStream file,
                                                           java.lang.String moduleName)
                                                    throws java.lang.reflect.InvocationTargetException
Returns the annotations found in the specified file.

Parameters:
file - the file to parse
moduleName - name of the maven module
Returns:
the found annotations
Throws:
java.lang.reflect.InvocationTargetException - if the file could not be parsed (wrap your exception in this exception)

createContextHashCode

protected int createContextHashCode(java.lang.String fileName,
                                    int line)
                             throws java.io.IOException
Creates a hash code from the source code of the warning line and the surrounding context.

Parameters:
fileName - the absolute path of the file to read
line - the line of the warning
Returns:
a has code of the source code
Throws:
java.io.IOException - if the contents of the file could not be read


Copyright © 2009. All Rights Reserved.