* Copyright (C) 2010 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://fifesoft.com/rsyntaxtextarea
* This library is distributed under a modified BSD license. See the included
* RSTALanguageSupport.License.txt file for details.
package org.fife.rsta.ac.java.buildpath;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
* Reads plain text files enumerating classes to take from the classpath and
* add to a {@link ClasspathLibraryInfo}. Files should have a format similar
* - com.mycompany.pkg1.Class1
* - com.mycompany.pkg2.Foo
* Such files are expected to be UTF-8. The exact file structure is as follows:
* <li>Lines that start with a "<code>-</code>" denote a fully-qualified
* class, interface, or enum name.
* <li>Lines following a line starting with "<code>-</code>" are simply a
* class, interface, or enum name, and are assumed to be in the same
* package as the previous class on the "<code>-</code>" line.
* <li>Blank lines and lines starting with "<code>#</code>" are ignored.
public class ClassEnumerationReader {
* Private constructor to prevent instantiation.
private ClassEnumerationReader() {
* Returns the list of classes specified in the given stream.
* @param in The input stream to read from. This will be closed when
* @return The list of class names read.
* @throws IOException If an IO error occurs.
public static List getClassNames(InputStream in) throws IOException {
List classNames = new ArrayList();
BufferedReader r = new BufferedReader(new InputStreamReader(in, "UTF-8"));
while ((line=r.readLine())!=null) {
// Skip blank lines and comments
if (line.length()==0 || line.charAt(0)=='#') {
// A new fully-qualified class name
if (line.charAt(0)=='-') {
line = line.substring(1).trim();
int lastDot = line.lastIndexOf('.');
lastPkg = line.substring(0, lastDot+1);
className = lastPkg + className;
classNames.add(className);