Search in sources :

Example 21 with AbsNature

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

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

the class ProjectAddLocationHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    Object firstElement = selection.getFirstElement();
    if (firstElement instanceof IProject) {
        IProject project = (IProject) firstElement;
        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.saveEditors(project, false);
        Map<LocationTypeVariable, LocationType> locationTypeInferrerResult = nature.getLocationTypeInferrerResult();
        if (locationTypeInferrerResult != null) {
            InferMain inferMain = new InferMain();
            String commandId = event.getCommand().getId();
            if ("org.abs-models.abs.plugin.projectaddalllocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.values());
            } else if ("org.abs-models.abs.plugin.projectaddclasslocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.CLASSES);
            } else if ("org.abs-models.abs.plugin.projectaddfieldlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FIELDS);
            } else if ("org.abs-models.abs.plugin.projectaddfunctionlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FUNCTIONS);
            } else if ("org.abs-models.abs.plugin.projectaddinterfacelocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.INTERFACES);
            }
            try {
                inferMain.writeInferenceResultsBack(locationTypeInferrerResult);
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException 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 : InferMain(abs.frontend.typechecker.locationtypes.infer.InferMain) 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 23 with AbsNature

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

the class JavaTabMain method getRunTargets.

private List<RunTarget> getRunTargets(IProject proj) {
    AbsNature n = UtilityFunctions.getAbsNature(proj);
    if (n == null) {
        return Collections.emptyList();
    }
    Model m = n.getCompleteModel();
    if (m == null) {
        return Collections.emptyList();
    }
    List<RunTarget> result = new ArrayList<RunTarget>();
    for (CompilationUnit cu : m.getCompilationUnits()) {
        for (ModuleDecl module : cu.getModuleDecls()) {
            if (module.getBlockOpt().hasChildren()) {
                if (module.getName().equals(ABSTestRunnerGenerator.RUNNER_MAIN)) {
                    // do not show generated unit test file
                    continue;
                }
                result.add(new RunTargetModule(module));
            }
        // TODO add unit test classes
        // for (Decl d : module.getDecls()) {
        // if (d.isInterface()) {
        // InterfaceDecl i = (InterfaceDecl) d;
        // for (Annotation annotation : i.getAnnotations()) {
        // if (annotation.getValue() )
        // }
        // }
        // }
        }
    }
    result.add(new RunTargetUnitTests());
    return result;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) Model(abs.frontend.ast.Model) ArrayList(java.util.ArrayList) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 24 with AbsNature

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

the class ABSCodeScanner method evalAST.

/**
 * Takes the AST-node for the current identifier, resolves uses (like e.g. type use) and
 * matches against the semantic rules
 * @return null, if the document could not be parsed, else the token of the matching semantic rule
 * or {@link Token#UNDEFINED} if no rule matched.
 */
private IToken evalAST() {
    if (compilationUnit == null) {
        return null;
    }
    IToken token = Token.UNDEFINED;
    try {
        AbsNature nature = fEditor.getAbsNature();
        if (nature == null)
            return token;
        synchronized (nature.modelLock) {
            final ASTNode<?> currentNode = getASTNodeOfOffset(fDocument, compilationUnit, fTokenOffset);
            Model typecheckedModel = nature.getCompleteModel();
            if (typecheckedModel == null)
                return null;
            Class<?> semClass = null;
            ASTNode<?> declNode = null;
            if (currentNode instanceof TypeUse) {
                TypeUse tu = (TypeUse) currentNode;
                declNode = resolveTypeUse(tu, typecheckedModel);
            }
            if (currentNode instanceof VarOrFieldUse) {
                VarOrFieldUse vofu = (VarOrFieldUse) currentNode;
                declNode = vofu.getDecl();
                if (declNode != null && declNode.getContextMethod() == null) {
                    semClass = FieldDecl.class;
                }
            }
            if (currentNode instanceof FnApp || currentNode instanceof DataConstructorExp) {
                semClass = currentNode.getClass();
            }
            if (semClass == null) {
                if (declNode != null) {
                    semClass = declNode.getClass();
                }
            }
            if (semClass != null) {
                Iterator<SemanticRule> iter = semanticrules.iterator();
                // iterate over rules and try to match
                while (iter.hasNext()) {
                    SemanticRule rule = iter.next();
                    if (rule.getSemclass().isAssignableFrom(semClass)) {
                        token = rule.getToken();
                        break;
                    }
                }
            }
        }
    } catch (BadLocationException e) {
        if (doDebug)
            e.printStackTrace();
    }
    return token;
}
Also used : AbsNature(org.absmodels.abs.plugin.builder.AbsNature) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with AbsNature

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

the class ABSEditor method initCompilationUnit.

private void initCompilationUnit() {
    AbsNature absNature = UtilityFunctions.getAbsNature(getResource());
    if (absNature != null) {
        AbsModelManager modelManager = absNature.getModelManager();
        compilationUnit = modelManager.getCompilationUnit(getAbsoluteFilePath());
    } else {
        // we are looking at abslang.abs or a file inside a jar-package
        IURIEditorInput uriInput = (IURIEditorInput) getEditorInput().getAdapter(IURIEditorInput.class);
        if (uriInput != null) {
            // We're looking e.g. at abslang.abs which only exists in memory.
            // create an empty model which only contains abslang.abs:
            absNature = new AbsNature();
            absNature.emptyModel();
            File f = new File(uriInput.getURI());
            String path = f.getAbsolutePath();
            compilationUnit = absNature.getCompilationUnit(path);
        }
    }
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) AbsModelManager(org.absmodels.abs.plugin.editor.reconciling.AbsModelManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File) 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