Skip to content

Commit

Permalink
Some small improvements and the second suggestion from #281
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Jul 6, 2016
1 parent 43ac5e6 commit e81f9d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Expand Up @@ -42,7 +42,7 @@
* This class was generated automatically by javacc, do not edit.
* </p>
* <p>
* Parse Java 1.5 source code and creates Abstract Syntax Tree classes.
* Parse Java source code and creates Abstract Syntax Tree classes.
* </p>
*
* @author Júlio Vilmar Gesser
Expand Down
Expand Up @@ -22,7 +22,6 @@
package com.github.javaparser.ast.comments;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;

/**
Expand All @@ -40,16 +39,19 @@ private enum State {

private static final int COLUMNS_PER_TAB = 4;

public CommentsCollection parse(final String source) throws IOException, UnsupportedEncodingException {
InputStream in = new ByteArrayInputStream(source.getBytes(Charset.defaultCharset()));
return parse(in, Charset.defaultCharset().name());
public CommentsCollection parse(final String source) throws IOException {
return parse(new StringReader(source));
}

public CommentsCollection parse(final InputStream in, final String charsetName) throws IOException {
return parse(new InputStreamReader(in, charsetName));
}

/**
* Track the internal state of the parser, remembering the last characters observed.
*/
class ParserState {
private Deque prevTwoChars = new LinkedList<Character>();
private static class ParserState {
private Deque<Character> prevTwoChars = new LinkedList<Character>();

/**
* Is the last character the one expected?
Expand Down Expand Up @@ -86,9 +88,9 @@ public void reset() {
}
}

public CommentsCollection parse(final InputStream in, final String charsetName) throws IOException, UnsupportedEncodingException {
public CommentsCollection parse(final Reader in) throws IOException {
boolean lastWasASlashR = false;
BufferedReader br = new BufferedReader(new InputStreamReader(in, charsetName));
BufferedReader br = new BufferedReader(in);
CommentsCollection comments = new CommentsCollection();
int r;

Expand Down

0 comments on commit e81f9d1

Please sign in to comment.