Search in sources :

Example 11 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType 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 12 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class AbsNature method createLocationTypeInferenceMarker.

private void createLocationTypeInferenceMarker() throws CoreException {
    synchronized (modelLock) {
        LocationTypeInferrerExtension locationTypeInferrerExtension = modelbuilder.getLocationTypeInferrerExtension();
        if (locationTypeInferrerExtension != null) {
            Map<LocationTypeVariable, LocationType> inferResult = locationTypeInferrerExtension.getResults();
            if (inferResult != null) {
                if (getProjectPreferenceStore().getBoolean(LOCATION_TYPE_OVERLAY)) {
                    for (Entry<LocationTypeVariable, LocationType> e : inferResult.entrySet()) {
                        LocationType annoType = e.getKey().getAnnotatedType();
                        if (annoType == null || annoType.equals(LocationType.INFER)) {
                            int severity = IMarker.SEVERITY_ERROR;
                            if (e.getValue().isNear()) {
                                severity = IMarker.SEVERITY_INFO;
                            } else if (e.getValue().isSomewhere()) {
                                severity = IMarker.SEVERITY_WARNING;
                            }
                            createMarker(e.getKey().getNode(), "Inferred Location Type: " + e.getValue(), severity, LOCATION_TYPE_INFERENCE_MARKER_TYPE);
                        }
                    }
                }
            } else {
                IMarker marker = getProject().createMarker(TYPECHECK_MARKER_TYPE);
                marker.setAttribute(IMarker.MESSAGE, "Location Type Inference Failed");
                marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
            }
        }
    }
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) LocationType(abs.frontend.typechecker.locationtypes.LocationType) LocationTypeVariable(abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)

Example 13 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class AbsModelManagerImpl method extendedTypechecking.

private void extendedTypechecking() {
    if (absNature.getProject() != null) {
        IPersistentPreferenceStore projectPreferences = absNature.getProjectPreferenceStore();
        IncrementalModelBuilder.flushAll(model);
        model.getTypeExt().clearTypeSystemExtensions();
        boolean dolocationtypecheck = projectPreferences.getBoolean(LOCATION_TYPECHECK);
        if (dolocationtypecheck) {
            String defaultlocationtypeprecision = projectPreferences.getString(LOCATION_TYPE_PRECISION);
            LocationType defaultLocType = LocationType.createFromName(projectPreferences.getString(DEFAULT_LOCATION_TYPE));
            LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
            ltie.setDefaultType(defaultLocType);
            ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(defaultlocationtypeprecision));
            model.registerTypeSystemExtension(ltie);
        }
    }
    SemanticConditionList typeErrors = model.typeCheck();
    updateMarkers(typeErrors);
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationType(abs.frontend.typechecker.locationtypes.LocationType) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Aggregations

LocationType (abs.frontend.typechecker.locationtypes.LocationType)13 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)6 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)6 Model (abs.frontend.ast.Model)5 FrontendTest (abs.frontend.FrontendTest)3 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)3 IOException (java.io.IOException)3 IPersistentPreferenceStore (org.eclipse.jface.preference.IPersistentPreferenceStore)3 Test (org.junit.Test)3 ClassDecl (abs.frontend.ast.ClassDecl)2 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 HashMap (java.util.HashMap)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 HasCogs (abs.frontend.analyser.HasCogs)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1