Search in sources :

Example 6 with ModuleDecl

use of abs.frontend.ast.ModuleDecl 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 7 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class WizardUtilsTests method testValidateClass.

@Test
public void testValidateClass() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    ClassDecl m1 = mock(ClassDecl.class);
    ClassDecl m2 = mock(ClassDecl.class);
    when(m1.getName()).thenReturn("Class1");
    when(m2.getName()).thenReturn("Class2");
    list.add(m1);
    list.add(m2);
    when(mockDecl.getDecls()).thenReturn(list);
    String valid1 = "A";
    String valid2 = "Abc3";
    String valid3 = "ABC3";
    String invalid1 = "";
    String invalid2 = "a";
    String invalid3 = "a.b";
    String invalid4 = ";";
    String invalid5 = "module";
    String invalid6 = "Class1";
    String invalid7 = "Class2";
    assertTrue(validateClass(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateClass(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateClass(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateClass(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateClass(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateClass(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateClass(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) List(abs.frontend.ast.List) Test(org.junit.Test)

Example 8 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("Apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 9 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ABSUnitTestCaseTranslator method validateOutput.

private void validateOutput() {
    CompilationUnit unit = new CompilationUnit();
    ModuleDecl cm = module.treeCopyNoTransform();
    unit.addModuleDecl(cm);
    for (DeltaWrapper d : deltas) {
        unit.addDeltaDecl(d.getDelta().treeCopyNoTransform());
    }
    unit.setProductLine(productline.treeCopyNoTransform());
    unit.addProductDecl(product.treeCopyNoTransform());
    Model copy = model.treeCopyNoTransform();
    copy.addCompilationUnit(unit);
    validateOutput(copy.treeCopyNoTransform(), null);
    validateOutput(copy.treeCopyNoTransform(), module.getName().concat(".").concat(PRODUCT_NAME));
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) DeltaWrapper(apet.absunit.DeltaForGetSetFieldsBuilder.DeltaWrapper) Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 10 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class JavaJob method findModulesWithMain.

/**
 * searches a compilation unit for modules with a main block
 * @param unit
 * @return a list of all modules which have a main block
 */
private List<ModuleDecl> findModulesWithMain(CompilationUnit unit) {
    List<ModuleDecl> result = new LinkedList<ModuleDecl>();
    if (unit != null) {
        int countModules = unit.getNumModuleDecl();
        int i = 0;
        while (i < countModules) {
            ModuleDecl module = unit.getModuleDecl(i);
            if (module.hasBlock()) {
                result.add(module);
            }
            // go to next module
            i++;
        }
    }
    return result;
}
Also used : ModuleDecl(abs.frontend.ast.ModuleDecl) LinkedList(java.util.LinkedList)

Aggregations

ModuleDecl (abs.frontend.ast.ModuleDecl)29 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)10 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)8 Decl (abs.frontend.ast.Decl)7 Model (abs.frontend.ast.Model)7 ArrayList (java.util.ArrayList)7 ClassDecl (abs.frontend.ast.ClassDecl)6 CompilationUnit (abs.frontend.ast.CompilationUnit)6 ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)5 IProject (org.eclipse.core.resources.IProject)5 InterfaceDecl (abs.frontend.ast.InterfaceDecl)4 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)4 Test (org.junit.Test)4 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EditorPosition (org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition)2 IFile (org.eclipse.core.resources.IFile)2