Search in sources :

Example 1 with InferMain

use of abs.frontend.typechecker.locationtypes.infer.InferMain 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 2 with InferMain

use of abs.frontend.typechecker.locationtypes.infer.InferMain in project abstools by abstools.

the class LocationTypeTests method writeBackSolutions.

private String writeBackSolutions(String code) throws Exception {
    File f = File.createTempFile("test", ".abs");
    f.deleteOnExit();
    FileWriter fw = new FileWriter(f);
    fw.write(code);
    fw.close();
    Model m = assertParseFileOk(f.getAbsolutePath(), Config.WITH_STD_LIB);
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    m.registerTypeSystemExtension(ltie);
    SemanticConditionList e = m.typeCheck();
    assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), false, e.containsErrors());
    new InferMain().writeInferenceResultsBack(ltie.getResults());
    String res = FileUtils.fileToStringBuilder(f).toString();
    f.delete();
    return res;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) InferMain(abs.frontend.typechecker.locationtypes.infer.InferMain) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model)

Example 3 with InferMain

use of abs.frontend.typechecker.locationtypes.infer.InferMain 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)

Aggregations

InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)3 LocationType (abs.frontend.typechecker.locationtypes.LocationType)2 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)2 IOException (java.io.IOException)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPersistentPreferenceStore (org.eclipse.jface.preference.IPersistentPreferenceStore)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 Model (abs.frontend.ast.Model)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1