Search in sources :

Example 6 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException in project abstools by abstools.

the class IncrementalModelBuilder method typeCheckModel.

public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
    if (model == null)
        throw new NoModelException();
    if (model.hasParserErrors())
        // don't typecheck if the model has parsererrors
        return new SemanticConditionList();
    // throw new TypecheckInternalException(new Exception("Model has parser errors!"));
    // model.flushCache();
    flushAll(model);
    model.getTypeExt().clearTypeSystemExtensions();
    if (locationTypeChecking) {
        LocationType defaultLocType = LocationType.createFromName(defaultloctype);
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
        this.ltie = ltie;
        ltie.setDefaultType(defaultLocType);
        ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
        model.registerTypeSystemExtension(ltie);
    }
    try {
        SemanticConditionList semerrors = model.getErrors();
        /* Don't typecheck with semerrors, it might trip up. */
        if (!semerrors.containsErrors())
            semerrors = model.typeCheck();
        /* Check products for errors.
			 * Only the first error is reported (if any), on the product AST-node.
			 * TODO: May be time-consuming for large projects, hence the checkProducts-switch.
			 *       Also could use a timer to switch off if it becomes excessive.
			 * TODO: Use Eclipse's nested markers to show ALL contained errors?
			 * TODO: The outline could indicate the broken product as well.
			 */
        if (!semerrors.containsErrors() && checkProducts) {
            // arbitrary value
            monitor = new SubProgressMonitor(monitor, 10);
            monitor.beginTask("Checking products", model.getProductDecls().size());
            for (ProductDecl p : model.getProductDecls()) {
                monitor.subTask("Checking " + p.getName());
                Model m2 = model.treeCopyNoTransform();
                m2.flushTreeCache();
                try {
                    m2.flattenForProduct(p);
                    SemanticConditionList p_errs = m2.typeCheck();
                    if (p_errs.containsErrors()) {
                        // Only show first error, on product
                        semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
                    }
                } catch (WrongProgramArgumentException e) {
                    semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                } catch (DeltaModellingException e) {
                    /* We we have a better location for error reporting? */
                    final ASTNode<?> loc;
                    if (e instanceof DeltaModellingWithNodeException)
                        loc = ((DeltaModellingWithNodeException) e).getNode();
                    else
                        loc = p;
                    if (e.getDelta() == null)
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                    else
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
                }
            }
            monitor.done();
        }
        return semerrors;
    } catch (TypeCheckerException e) {
        return new SemanticConditionList(e);
    } catch (RuntimeException e) {
        throw new TypecheckInternalException(e);
    }
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) DeltaModellingWithNodeException(abs.frontend.delta.DeltaModellingWithNodeException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticError(abs.frontend.analyser.SemanticError) Model(abs.frontend.ast.Model) ASTNode(abs.frontend.ast.ASTNode) LocationType(abs.frontend.typechecker.locationtypes.LocationType) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 7 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException 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 8 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException 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

WrongProgramArgumentException (abs.common.WrongProgramArgumentException)8 Model (abs.frontend.ast.Model)4 DeltaModellingException (abs.frontend.delta.DeltaModellingException)4 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)3 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2 IProject (org.eclipse.core.resources.IProject)2 ABSTestObserver (abs.backend.java.absunit.ABSTestObserver)1 JavaCode (abs.backend.java.codegeneration.JavaCode)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1 ProductDecl (abs.frontend.ast.ProductDecl)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 ChocoSolver (abs.frontend.mtvl.ChocoSolver)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 Constraint (choco.kernel.model.constraints.Constraint)1 File (java.io.File)1