Search in sources :

Example 6 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class MaudeJob method runJob.

public IStatus runJob(IProgressMonitor monitor) {
    abort = false;
    boolean failed = false;
    StringBuffer output = new StringBuffer();
    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.");
    }
    // Compile Maude Code
    monitor.subTask("Compiling ABS model to Maude");
    try {
        if (!abort)
            compileMaude(monitor, nature);
    } catch (CoreException e1) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e1);
    } catch (IOException e2) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e2);
    } catch (ParseException e4) {
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has parse errors.", e4);
    } catch (TypeCheckerException e5) {
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has type errors.", e5);
    } catch (WrongProgramArgumentException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
    } catch (DeltaModellingException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
    } catch (NoModelException e) {
        return new Status(IStatus.INFO, PLUGIN_ID, "No ABS model in project");
    }
    monitor.worked(5);
    // Execute generated Maude code
    monitor.subTask("Executing generated Maude code");
    if (exec) {
        try {
            if (!abort)
                failed = !executeMaude(output);
        } catch (IOException e1) {
            return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR_MAUDE_PATH, "Encountered IOException while executing Maude (probably misconfigured location of maude executable)", e1);
        } catch (InterruptedException e2) {
            return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while executing Maude", e2);
        } finally {
            if (!monitor.isCanceled()) {
                monitor.worked(5);
                monitor.done();
            }
        }
    }
    // If an error was encountered during Maude execution, the info code of the status is set to ERROR_MAUDE, otherwise MAUDE_INFO.
    if (!abort) {
        if (failed) {
            return new Status(IStatus.OK, PLUGIN_ID, MAUDE_ERROR_MAUDE, output.toString(), null);
        } else {
            if (exec) {
                return new Status(IStatus.OK, PLUGIN_ID, MAUDE_INFO, output.toString(), null);
            } else {
                return new Status(IStatus.OK, PLUGIN_ID, MAUDE_OK, output.toString(), null);
            }
        }
    } else {
        monitor.setCanceled(true);
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_USER_ABORT, null, null);
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 7 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class AbstractTab method fillProductDropDownMenue.

/**
 * Lists all products in the current project's module, incl. a "<base>" product if
 * no particular product is selected.
 * @param preSelected The product that should be preselected, or null for <base>.
 */
protected void fillProductDropDownMenue(String preSelected) {
    productDropDown.removeAll();
    productDropDown.add("<base>");
    IProject proj = getSelectedProject();
    if (proj == null) {
        return;
    }
    AbsNature n = UtilityFunctions.getAbsNature(proj);
    Model m = n.getCompleteModel();
    if (m == null)
        return;
    Collection<ProductDecl> prods = m.getProductDecls();
    if (prods == null)
        return;
    int i = 1;
    /* base comes first */
    int selected = 0;
    for (ProductDecl p : prods) {
        final String name = p.getName();
        productDropDown.add(name);
        if (name.equals(preSelected)) {
            selected = i;
        }
        i++;
    }
    productDropDown.select(selected);
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 8 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class FileAddLocationHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    Object firstElement = selection.getFirstElement();
    if (firstElement instanceof IFile) {
        IFile file = (IFile) firstElement;
        IProject project = file.getProject();
        AbsNature nature = UtilityFunctions.getAbsNature(project);
        if (nature == null)
            return null;
        IPersistentPreferenceStore projectStore = nature.getProjectPreferenceStore();
        boolean locationTypecheckingEnabled = projectStore.getBoolean(Constants.LOCATION_TYPECHECK);
        if (!locationTypecheckingEnabled) {
            MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Locationtypechecking", "Location type checking is disabled. Please enable for this function to work!");
            return null;
        }
        UtilityFunctions.saveEditor(file, false);
        Map<LocationTypeVariable, LocationType> locationTypeInferrerResult = nature.getLocationTypeInferrerResult();
        if (locationTypeInferrerResult != null) {
            Map<LocationTypeVariable, LocationType> filteredResults = new HashMap<LocationTypeVariable, LocationType>();
            ASTNode<?> node;
            CompilationUnit cu;
            for (Entry<LocationTypeVariable, LocationType> entry : locationTypeInferrerResult.entrySet()) {
                node = entry.getKey().getNode();
                if (node == null)
                    continue;
                cu = node.getCompilationUnit();
                if (cu == null)
                    continue;
                if (file.getLocation().toFile().getAbsolutePath().equals(cu.getFileName())) {
                    filteredResults.put(entry.getKey(), entry.getValue());
                }
            }
            InferMain inferMain = new InferMain();
            String commandId = event.getCommand().getId();
            if ("org.abs-models.abs.plugin.fileaddalllocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.values());
            } else if ("org.abs-models.abs.plugin.fileaddclasslocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.CLASSES);
            } else if ("org.abs-models.abs.plugin.fileaddfieldlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FIELDS);
            } else if ("org.abs-models.abs.plugin.fileaddfunctionlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FUNCTIONS);
            } else if ("org.abs-models.abs.plugin.fileaddinterfacelocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.INTERFACES);
            }
            try {
                inferMain.writeInferenceResultsBack(filteredResults);
                try {
                    file.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    Activator.logException(e);
                }
            } catch (IOException e) {
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Error while inserting locations", "An error occurred while inserting locations!\n" + e.getLocalizedMessage());
            }
        }
    }
    return null;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) IFile(org.eclipse.core.resources.IFile) InferMain(abs.frontend.typechecker.locationtypes.infer.InferMain) HashMap(java.util.HashMap) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) LocationTypeVariable(abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable) CoreException(org.eclipse.core.runtime.CoreException) LocationType(abs.frontend.typechecker.locationtypes.LocationType) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 9 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature 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 10 with AbsNature

use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.

the class ModuleDecorator method checkModulePath.

private void checkModulePath(IDecoration decoration, ModulePath m) {
    AbsNature nature = m.getNature();
    Model model = nature.getCompleteModel();
    if (model != null) {
        for (ModuleDecl mod : model.getModuleDecls()) {
            if (mod.getName().startsWith(m.getModulePath() + ".")) {
                if (hasModuleDeclErrors(mod, nature)) {
                    addErrorOverlay(decoration);
                    return;
                }
            }
        }
    }
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Aggregations

AbsNature (org.absmodels.abs.plugin.builder.AbsNature)27 IProject (org.eclipse.core.resources.IProject)10 Model (abs.frontend.ast.Model)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)8 ArrayList (java.util.ArrayList)6 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)6 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)6 CompilationUnit (abs.frontend.ast.CompilationUnit)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 DeltaModellingException (abs.frontend.delta.DeltaModellingException)3 IOException (java.io.IOException)3 LocationType (abs.frontend.typechecker.locationtypes.LocationType)2 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)2 File (java.io.File)2 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2