Top Description Fields Constructors Methods
org.apache.tools.ant.filters

public final Class StripJavaComments

extends BaseFilterReader
implements ChainableReader
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.filters.ChainableReader
Imports
java.io.IOException, .Reader

This is a Java comment and string stripper reader that filters those lexical tokens out for purposes of simple Java parsing. (if you have more complex Java parsing needs, use a real lexer). Since this class heavily relies on the single char read function, you are recommended to make it work on top of a buffered reader.

Field Summary

Modifier and TypeField and Description
private boolean
inString

Whether or not the parser is currently in the middle of a string literal.

private boolean
quoted

Whether or not the last char has been a backslash.

private int
readAheadCh

The read-ahead character, used for effectively pushing a single character back.

Constructor Summary

AccessConstructor and Description
public
StripJavaComments()

Constructor for "dummy" instances.

public
StripJavaComments(final Reader
A Reader object providing the underlying stream. Must not be null.
in
)

Creates a new filtered reader.

Method Summary

Modifier and TypeMethod and Description
public Reader

Returns:

a new filter based on this configuration, but filtering the specified reader
chain
(final Reader
A Reader object providing the underlying stream. Must not be null.
rdr
)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Creates a new StripJavaComments using the passed in Reader for instantiation.
public int

Returns:

the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
read
()

Overrides java.io.FilterReader.read.

Returns the next character in the filtered stream, not including Java comments.
Inherited from org.apache.tools.ant.filters.BaseFilterReader:
getInitializedgetProjectreadreadFullyreadLinesetInitializedsetProjectskip

Field Detail

inStringback to summary
private boolean inString

Whether or not the parser is currently in the middle of a string literal.

quotedback to summary
private boolean quoted

Whether or not the last char has been a backslash.

readAheadChback to summary
private int readAheadCh

The read-ahead character, used for effectively pushing a single character back. A value of -1 indicates that no character is in the buffer.

Constructor Detail

StripJavaCommentsback to summary
public StripJavaComments()

Constructor for "dummy" instances.

See Also
BaseFilterReader#BaseFilterReader()
StripJavaCommentsback to summary
public StripJavaComments(final Reader in)

Creates a new filtered reader.

Parameters
in:Reader

A Reader object providing the underlying stream. Must not be null.

Method Detail

chainback to summary
public Reader chain(final Reader rdr)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Creates a new StripJavaComments using the passed in Reader for instantiation.

Parameters
rdr:Reader

A Reader object providing the underlying stream. Must not be null.

Returns:Reader

a new filter based on this configuration, but filtering the specified reader

readback to summary
public int read() throws IOException

Overrides java.io.FilterReader.read.

Returns the next character in the filtered stream, not including Java comments.

Returns:int

the next character in the resulting stream, or -1 if the end of the resulting stream has been reached

Exceptions
IOException:
if the underlying stream throws an IOException during reading