All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.code.java.IdentifierExtractor Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.code.java;

import java.util.Collection;

/**
 * Extracts the identifiers from a given line.
 * 
 * @author Oliver Richers
 */
public class IdentifierExtractor {

	private int index;
	private final String line;
	private final Collection identifiers;

	public IdentifierExtractor(String line, Collection identifiers) {

		this.index = 0;
		this.line = line;
		this.identifiers = identifiers;
	}

	public void extract() {

		while (index < line.length()) {
			if (findStartOfIdentifyer()) {
				readIdentifier();
			}
		}
	}

	private boolean findStartOfIdentifyer() {

		for (; index < line.length(); ++index) {
			if (isStartOfIdentifyer()) {
				return true;
			}
		}
		return false;
	}

	private boolean isStartOfIdentifyer() {

		char c = line.charAt(index);
		return Character.isJavaIdentifierStart(c);
	}

	private void readIdentifier() {

		String identifier = new IdentifierReader(line.substring(index)).read();
		index += identifier.length();
		identifiers.add(identifier);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy