Search in sources :

Example 11 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class AbstractTab method updateErrors.

/**
 * Don't recommend to start projects which have errors.
 * TODO: manipulating the error message here does not cooperate well with isValid().
 */
protected boolean updateErrors() {
    boolean res = true;
    String projectName = getSelectedProjectName();
    String prod = getSelectedProductName();
    if (this.lastProjectName != null && this.lastProd != null && this.lastProjectName.equals(projectName) && this.lastProd.equals(prod)) {
        // every time something changes in the run configuration dialog
        return lastResult;
    }
    if (projectName != null) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        try {
            AbsNature nat = UtilityFunctions.getAbsNature(project);
            assert nat != null;
            synchronized (nat.modelLock) {
                Model model = nat.getCompleteModel();
                /* E.g. errors in the project */
                if (model == null)
                    return false;
                /* Check product if any */
                // work on a copy:
                model = model.treeCopyNoTransform();
                model.flushTreeCache();
                if (prod != null) {
                    model.flattenForProduct(prod);
                    /* Type check again */
                    // #335, see IncrementalModelBuilder#flushAll()
                    model.flushCache();
                }
                SemanticConditionList errs = model.getErrors();
                // TODO: check for warnings also
                if (errs != null && errs.containsErrors()) {
                    createMarkers(nat, errs);
                    throw new AbsJobException(new TypeCheckerException(errs));
                }
                errs = model.typeCheck();
                // TODO: check for warnings also
                if (errs != null && errs.containsErrors()) {
                    createMarkers(nat, errs);
                    throw new AbsJobException(new TypeCheckerException(errs));
                }
            }
            setErrorMessage(null);
        } catch (AbsJobException e) {
            setErrorMessage(e.getMessage());
            res = false;
        } catch (WrongProgramArgumentException e) {
            setErrorMessage(e.getMessage());
            res = false;
        } catch (DeltaModellingException e) {
            setErrorMessage(e.getMessage());
            res = false;
        }
        getLaunchConfigurationDialog().updateMessage();
    }
    // cache the result
    lastProd = prod;
    lastProjectName = projectName;
    lastResult = res;
    return res;
}
Also used : TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 12 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class JavaRunConfiguration method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    JavaLaunchConfig launchConfig = new JavaLaunchConfig(config);
    IAction action = createNewAction(launchConfig);
    IProject project = ActionUtils.getProject(config);
    IFile file = null;
    ActionUtils.saveDirtyEditors(project);
    JavaJob job = new JavaJob(JavaJob.RUN_JOB, action, project, file);
    String product = launchConfig.getProductName();
    if (product != null) {
        try {
            Model model = JavaJob.getModelFromProject(project);
            job.setProduct(model.findProduct(product));
        } catch (WrongProgramArgumentException e) {
            throw new CoreException(new Status(IStatus.ERROR, Constants.PLUGIN_ID, "Launch failed", e));
        } catch (AbsJobException e) {
            throw new CoreException(new Status(IStatus.ERROR, Constants.PLUGIN_ID, "Launch failed", e));
        }
    }
    if (launchConfig.getTestExecution()) {
        List<String> obs = launchConfig.getDebuggerObserverList();
        obs.add(ABSTestObserver.class.getName());
    }
    modifyDebuggerArguments(launchConfig, job);
    if (launchConfig.getTestExecution()) {
        // execution of unit tests
        Job testJob = new ABSUnitTestJavaExecutionJob(project, product, job);
        testJob.schedule();
    } else {
        // normal execution
        job.schedule();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IAction(org.eclipse.jface.action.IAction) JavaJob(org.absmodels.abs.plugin.actions.JavaJob) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) ABSUnitTestJavaExecutionJob(org.absmodels.abs.plugin.actions.ABSUnitTestJavaExecutionJob) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Model(abs.frontend.ast.Model) JavaLaunchConfig(org.absmodels.abs.plugin.actions.runconfig.java.JavaLaunchConfig) Job(org.eclipse.core.runtime.jobs.Job) JavaJob(org.absmodels.abs.plugin.actions.JavaJob) ABSUnitTestJavaExecutionJob(org.absmodels.abs.plugin.actions.ABSUnitTestJavaExecutionJob) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException) ABSTestObserver(abs.backend.java.absunit.ABSTestObserver)

Aggregations

AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)12 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)6 Model (abs.frontend.ast.Model)5 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)5 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 ModuleDecl (abs.frontend.ast.ModuleDecl)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 ArrayList (java.util.ArrayList)2 NoABSNatureException (org.absmodels.abs.plugin.exceptions.NoABSNatureException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ABSTestObserver (abs.backend.java.absunit.ABSTestObserver)1 JavaCode (abs.backend.java.codegeneration.JavaCode)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 File (java.io.File)1 IOException (java.io.IOException)1