astra.compiler.ASTRAClass Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of astra-compiler Show documentation
Show all versions of astra-compiler Show documentation
Core compiler artifact for the ASTRA Language
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() + "]";
}
}