use of costabs.exceptions.CostabsException in project abstools by abstools.
the class SourceUtils method obtainCurrProject.
public static IProject obtainCurrProject() throws CostabsException {
IEditorPart ieditorpart;
ClassLoader loader;
// we obtain the current window that is being edited
try {
ieditorpart = SourceUtils.obtainActiveEditor();
} catch (NullPointerException e) {
throw (new CostabsException("There is not any selected class."));
}
IResource jresource = extractResource(ieditorpart);
if (jresource == null)
throw (new CostabsException("Could not extract file from the current editor"));
return jresource.getProject();
}
use of costabs.exceptions.CostabsException in project abstools by abstools.
the class SourceUtils method ObtainCurrentlyEditingClass.
public static Class ObtainCurrentlyEditingClass() throws CostabsException {
IEditorPart ieditorpart;
ClassLoader loader;
// we obtain the current window that is being edited
try {
ieditorpart = SourceUtils.obtainActiveEditor();
// If the file is not safe we fail and say it
if (ieditorpart.isDirty()) {
throw (new CostabsException("Java file must be saved to analyze it."));
}
} catch (NullPointerException e) {
throw (new CostabsException("There is not any selected class."));
}
// obtain the file being modified
IResource jresource = extractResource(ieditorpart);
if (jresource == null)
throw (new CostabsException("Could not extract file from the current editor"));
// get the project that owns the file
IJavaProject jproject = obtainJavaProjectFromResource(jresource);
if (jproject == null)
throw (new CostabsException("Cannot load the File: project must be a Java Project"));
IJavaElement javaFile = JavaCore.create(jresource, jproject);
if (javaFile == null)
throw (new CostabsException("Cannot load the File: file must be a Java File"));
try {
loader = ClasspathUtils.getProjectClassLoader(jproject);
} catch (Exception e) {
throw (new CostabsException("Non valid project, failed to buid class loader"));
}
fileEvaluations(javaFile);
return getClassFromResource((ICompilationUnit) javaFile, loader);
}
use of costabs.exceptions.CostabsException in project abstools by abstools.
the class SourceUtils method getClassFromResource.
private static Class getClassFromResource(ICompilationUnit javaFile, ClassLoader loader) throws CostabsException {
try {
String className = javaFile.getElementName();
className = className.substring(0, className.length() - 5);
if (!"".equals(javaFile.getParent().getElementName()))
className = javaFile.getParent().getElementName() + "." + className;
Class clazz = loader.loadClass(className);
return clazz;
} catch (ClassNotFoundException t) {
// t.printStackTrace();
throw new CostabsException("The class loading failed... Classpath may be wrong");
}
}
Aggregations