Search in sources :

Example 1 with TypeCheckerException

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

the class ABSUnitTestExecutionJob method run.

protected IStatus run(IProgressMonitor monitor) {
    AbsNature nature = getAbsNature(project);
    if (nature == null) {
        return new Status(IStatus.INFO, PLUGIN_ID, "Could not compile current selection. Project is not an ABS project.");
    }
    monitor.beginTask("ABSUnit Test Execution", 112);
    // Parsing and Type Checking ABS model
    monitor.subTask("Generating Test Runner");
    try {
        if (!abort)
            generateTestRunner(monitor, nature);
    } catch (CoreException e1) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while generating test runner", e1);
    } catch (IOException e2) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while generating test runner", e2);
    } catch (ParseException e4) {
        return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_ERROR, "Could not generating test runnern. Code has parse errors.", e4);
    } catch (TypeCheckerException e5) {
        return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_ERROR, "Could not generating test runner. Code has type errors.", e5);
    }
    monitor.worked(12);
    try {
        // make sure the generated testrunner file is parsed:
        project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (CoreException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compiling tests", e);
    }
    monitor.subTask("Executing ABSUnit tests");
    IStatus status = null;
    try {
        status = executeTest(monitor);
    } catch (CoreException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while executing tests", e);
    }
    if (abort) {
        monitor.setCanceled(true);
        return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_USER_ABORT, null, null);
    }
    return new Status(IStatus.OK, PLUGIN_ID, ABSUNIT_TEST_OK, status.getMessage(), null);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)

Example 2 with TypeCheckerException

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

the class ABSUnitTestExecutionJobListener method done.

@Override
public void done(IJobChangeEvent event) {
    // When the Job is done get the IStatus and print messages on console
    final IStatus status = event.getResult();
    switch(status.getCode()) {
        case ABSUNIT_TEST_OK:
            initializeConsole();
            console.println(status.getMessage(), MessageType.MESSAGE_INFO);
            break;
        case ABSUNIT_TEST_ERROR:
            // encountered an exception during execution
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (status.getException() instanceof ParseException || status.getException() instanceof TypeCheckerException) {
                        showErrorMessage(status.getMessage(), status);
                    } else {
                        showErrorMessage(status.getMessage());
                    }
                }
            });
            break;
        case ABSUNIT_TEST_USER_ABORT:
            initializeConsole();
            console.println("Aborted Maude Job.", MessageType.MESSAGE_ERROR);
            break;
        default:
            // This should never happen... just in case...
            showErrorMessage("reached an unspecified status");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException)

Example 3 with TypeCheckerException

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

the class MaudeJobChangeListener method done.

@Override
public void done(IJobChangeEvent event) {
    // When the Job is done get the IStatus and print messages on console
    final IStatus status = event.getResult();
    switch(status.getCode()) {
        // Indicates a successful Job without Maude execution
        case MAUDE_OK:
            break;
        case MAUDE_INFO:
            // Execution of Maude was successful
            initializeConsole();
            console.println(status.getMessage(), MessageType.MESSAGE_INFO);
            break;
        case // This message type is not used
        MAUDE_WARNING:
            initializeConsole();
            console.println(status.getMessage(), MessageType.MESSAGE_WARNING);
            break;
        case MAUDE_ERROR_MAUDE:
            // Maude encountered an error during execution
            initializeConsole();
            console.println(status.getMessage(), MessageType.MESSAGE_ERROR);
            break;
        case MAUDE_ERROR_MAUDE_PATH:
            // missconfigured Maude path
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    showErrorMessage("Encountered IOException while executing Maude (probably misconfigured location of maude executable): " + status.getMessage());
                    PreferencesUtil.createPreferenceDialogOn(Display.getDefault().getActiveShell(), "org.abs-models.abs.plugin.preferences.ABSMaudePreferences", null, null).open();
                }
            });
            break;
        case MAUDE_ERROR:
            // encountered an exception during execution
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (status.getException() instanceof ParseException || status.getException() instanceof TypeCheckerException) {
                        showErrorMessage(status.getMessage(), status);
                    } else {
                        showErrorMessage(status.getMessage());
                    }
                }
            });
            break;
        case MAUDE_USER_ABORT:
            initializeConsole();
            console.println("Aborted Maude Job.", MessageType.MESSAGE_ERROR);
            break;
        default:
            // This should never happen... just in case...
            showErrorMessage("reached an unspecified status");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException)

Example 4 with TypeCheckerException

use of org.absmodels.abs.plugin.exceptions.TypeCheckerException 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 5 with TypeCheckerException

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

the class ABSUnitTestExecutionJob method generateTestRunner.

/**
 * Generate an ABS file from an ABS project that can be used to execute unit tests
 * @throws ParseException Is thrown, if the project which is compiled has parse errors
 * @throws TypeCheckerException Is thrown, if the project which is compiled has type errors
 * @throws DeltaModellingException
 * @throws WrongProgramArgumentException
 */
private void generateTestRunner(IProgressMonitor monitor, AbsNature nature) throws CoreException, IOException, ParseException, TypeCheckerException {
    PrintStream ps = null;
    FileInputStream fis = null;
    try {
        // find a way to change
        String path = Constants.DEFAULT_MAVEN_TARGET_ABS_PATH;
        IFolder folder = project.getFolder(path);
        MaudeJob.prepareFolder(monitor, folder);
        String fileName = "runner.abs";
        final IFile wspaceFile = folder.getFile(fileName);
        /* generateMaude only knows how to fill PrintStreams */
        final File tmpFile = File.createTempFile(fileName, null);
        ps = new PrintStream(tmpFile);
        // Get model, check for errors and throw respective exception
        Model model = nature.getCompleteModel();
        if (model.hasParserErrors()) {
            throw new ParseException(model.getParserErrors());
        }
        if (model.hasTypeErrors()) {
            throw new TypeCheckerException(model.typeCheck());
        }
        String mb = abs.backend.tests.ABSTestRunnerGenerator.RUNNER_MAIN;
        ABSTestRunnerGenerator gen = new ASTBasedABSTestRunnerGenerator(model);
        gen.generateTestRunner(ps);
        ps.close();
        fis = new FileInputStream(tmpFile);
        if (wspaceFile.exists())
            wspaceFile.setContents(fis, true, false, monitor);
        else
            wspaceFile.create(fis, true, monitor);
        fis.close();
        tmpFile.delete();
        destFile = new File(project.getLocation().append(path).toFile(), fileName);
    } finally {
        if (ps != null) {
            ps.flush();
            ps.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
}
Also used : ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) PrintStream(java.io.PrintStream) IFile(org.eclipse.core.resources.IFile) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) ABSTestRunnerGenerator(abs.backend.tests.ABSTestRunnerGenerator) Model(abs.frontend.ast.Model) ParseException(org.absmodels.abs.plugin.exceptions.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)5 ParseException (org.absmodels.abs.plugin.exceptions.ParseException)4 IStatus (org.eclipse.core.runtime.IStatus)3 Model (abs.frontend.ast.Model)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 ABSTestRunnerGenerator (abs.backend.tests.ABSTestRunnerGenerator)1 ASTBasedABSTestRunnerGenerator (abs.backend.tests.ASTBasedABSTestRunnerGenerator)1 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1