Search in sources :

Example 1 with AbsNature

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

the class NewModuleWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    super.init(workbench, selection);
    setWindowTitle("New ABS class");
    firstSelection = selection.getFirstElement();
    AbsNature nature = ABSContentOutlineUtils.getNatureForObject(firstSelection);
    if (nature != null) {
        project = nature.getProject();
    }
}
Also used : AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 2 with AbsNature

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

the class UtilityFunctionsTest method testGetPathOfModuleDecl.

@Test
public void testGetPathOfModuleDecl() throws Exception {
    ModuleDecl md = mock(ModuleDecl.class);
    CompilationUnit cd = mock(CompilationUnit.class);
    AbsNature nature = mock(AbsNature.class);
    InternalASTNode<ModuleDecl> internalASTNode = new InternalASTNode<ModuleDecl>(md, nature);
    when(cd.getFileName()).thenReturn("C:/test.abs");
    when(md.getCompilationUnit()).thenReturn(cd);
    IPath pathOfModuleDecl = getPathOfModuleDecl(internalASTNode);
    assertEquals("C:/test.abs", pathOfModuleDecl.toString());
    assertSame(getPathOfModuleDecl(null), null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Test(org.junit.Test)

Example 3 with AbsNature

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

the class WizardUtilsTests method testGetProjectOfModuleDecl.

@Test
public void testGetProjectOfModuleDecl() {
    AbsNature natureMock = mock(AbsNature.class);
    IProject project = mock(IProject.class);
    when(project.getName()).thenReturn("");
    when(natureMock.getProject()).thenReturn(project);
    ModuleDecl moduleMock = mock(ModuleDecl.class);
    InternalASTNode<ModuleDecl> node = new InternalASTNode<ModuleDecl>(moduleMock, natureMock);
    assertSame(node.getProject(), project);
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 4 with AbsNature

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

the class JavaJob method generateJavaCode.

/**
 * Generates .java files (no .class files).
 * If 'product' is set, will flatten accordingly.
 * @param monitor - must not be null
 * @param path - where to add the modules / java-files
 * @param project - the ABS project
 * @throws IOException, if unable to create java files
 * @throws AbsJobException, if unable to generate java files
 * @throws JavaCodeGenerationException, if unable to generate java files
 * @throws CoreException
 * @throws NoModelException
 */
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
    assert monitor != null;
    monitor.subTask("Creating java source files");
    AbsNature nat = UtilityFunctions.getAbsNature(project);
    synchronized (nat.modelLock) {
        Model model = nat.getCompleteModel();
        if (model == null)
            throw new NoModelException();
        JavaCode javaCode = new JavaCode(path.toFile());
        if (product != null) {
            /* [stolz] Flattening for a product will mangle the model according to [ramus]...
                 */
            // work on a copy:
            model = model.treeCopyNoTransform();
            model.flushTreeCache();
            String productN = product.getName();
            try {
                model.flattenForProduct(productN);
                model.flushCache();
                if (model.hasErrors() || model.hasTypeErrors()) {
                    nat.createMarkers(model);
                    throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
                }
            } catch (WrongProgramArgumentException e) {
                throw new AbsJobException(e);
            } catch (DeltaModellingException e) {
                throw new AbsJobException(e);
            }
        }
        // TODO: the second parameter toggles listener code creation (3
        // Java method calls per ABS statement); make this configurable
        model.generateJavaCode(javaCode, true);
        int countUnits = model.getNumCompilationUnit();
        if (countUnits == 0)
            throw new AbsJobException("No compilation unit found");
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) JavaCode(abs.backend.java.codegeneration.JavaCode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 5 with AbsNature

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

the class JavaJob method getModelFromProject.

/**
 * @Deprecated According to Yannick, you need to hold {@link AbsNature#modelLock} to safely do anything with the model,
 * which means you need the nature first, and then this helper is just a fancy wrapper around {@link AbsNature#getCompleteModel()}...
 * @see AbsNature#getCompleteModel()
 */
public static Model getModelFromProject(IProject project) throws AbsJobException {
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("The file is not in an ABS project!");
    }
    Model model = nature.getCompleteModel();
    // if (model==null && curFile!=null ) model = abs.frontend.parser.Main.parse(new File(curFile.getLocation().toString()), withStdLib);
    if (model == null) {
        throw new AbsJobException("No ABS model found");
    }
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
        // just to be sure
        throw new AbsJobException("An ABS file in the project has type or parser errors");
    }
    return model;
}
Also used : Model(abs.frontend.ast.Model) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

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