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

astra.compiler.ASTRAClass Maven / Gradle / Ivy

The newest version!
package astra.compiler;

import java.util.ArrayList;
import java.util.List;

import astra.ast.core.ASTRAClassElement;
import astra.ast.core.IJavaHelper;
import astra.ast.core.ParseException;

public class ASTRAClass {
	ASTRAClassElement element;
	List errorList = new ArrayList();
	
	String name;
	
	/**
	 * Creates instances of ASTRAClass. Any error that arises loading the AST is
	 * forwarded on to the method that requested the class be instantiated.
	 * 
	 * @param className the name of the class
	 */
	public ASTRAClass(String className) {
		this.name = className;
	}

	public boolean load(IJavaHelper helper) {
		errorList.clear();
		
		try {
			element = helper.loadAST(name);
			if (element == null) {
				System.out.println("[ASTRAClass] Fatal Error: Could not load AST for class: " + name);
				System.exit(1);
			}
			errorList.addAll(element.getErrorList());
		} catch (ParseException e) {
			errorList.add(e);
		}
		return errorList.isEmpty();
	}
	
	public String name() {
		return name;
	}
	
	public ASTRAClassElement element() {
		return element;
	}
	
	public List errorList() {
		return errorList;
	}

	public boolean isLoaded() {
		return errorList.isEmpty();
	}
	
	public boolean sourceChanged(IJavaHelper helper) {
		return (helper.lastModified(name,".astra") > helper.lastModified(name, ".class"));
	}
	
	public String toString() {
		return "ASTRAClass."+name + " [" + errorList.isEmpty() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy