Search in sources :

Example 6 with InterfaceDecl

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

the class TypeHierarchyContentProvider method getChildren.

@Override
public Object[] getChildren(Object node) {
    if (node instanceof InterfaceDecl) {
        InterfaceDecl interfaceDecl = (InterfaceDecl) node;
        Collection<HasTypeHierarchy> subTypes = interfaceDecl.getDirectSubTypes();
        return subTypes.toArray();
    } else if (node instanceof DataTypeDecl) {
        DataTypeDecl dataTypeDecl = (DataTypeDecl) node;
        Object[] result = new Object[dataTypeDecl.getNumDataConstructor()];
        int i = 0;
        for (DataConstructor d : dataTypeDecl.getDataConstructors()) {
            result[i] = d;
            i++;
        }
        return result;
    } else if (node instanceof TypeSynDecl) {
        TypeSynDecl typeSynDecl = (TypeSynDecl) node;
        return new Object[] { typeSynDecl.getType().getDecl() };
    }
    return nothing;
}
Also used : InterfaceDecl(abs.frontend.ast.InterfaceDecl) HasTypeHierarchy(abs.frontend.ast.HasTypeHierarchy) DataConstructor(abs.frontend.ast.DataConstructor) DataTypeDecl(abs.frontend.ast.DataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl)

Example 7 with InterfaceDecl

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

the class DeltaSamplesTest method test_ticket322_P.

@Test
public void test_ticket322_P() throws Exception {
    Model m = assertTypeCheckFileOk("tests/abssamples/deltas/bug322.abs", true);
    m.flattenForProduct("P");
    m.flushCache();
    assertFalse(m.hasErrors());
    assertFalse(m.hasTypeErrors());
    InterfaceDecl i = (InterfaceDecl) DeltaTest.findDecl(m, "M", "I");
    assertNotNull(i);
    InterfaceDecl j = (InterfaceDecl) DeltaTest.findDecl(m, "M", "J");
    assertNotNull(j);
}
Also used : Model(abs.frontend.ast.Model) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 8 with InterfaceDecl

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

the class WizardUtil method validateInterface.

/**
 * Same as {@link #validate(String)} but additionally checks, whether the specified
 * interface name already exists in the given module declaration
 *
 * @param text
 *            Name to be checked.
 * @param decl
 *            Target ModuleDecl.
 * @return In case of a duplicate name, this method returns
 *         ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
 *         its information string.
 */
public static ErrorType validateInterface(String text, ModuleDecl decl) {
    if (decl != null) {
        for (Decl d : decl.getDecls()) {
            if (d instanceof InterfaceDecl && d.getName().equals(text)) {
                ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
                type.setInformationString(text);
                return type;
            }
        }
    }
    return validate(text);
}
Also used : InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 9 with InterfaceDecl

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

the class WizardUtilsTests method testValidateInterface.

@Test
public void testValidateInterface() {
    ModuleDecl mockDecl = mock(ModuleDecl.class);
    List<Decl> list = new List<Decl>();
    InterfaceDecl m1 = mock(InterfaceDecl.class);
    InterfaceDecl m2 = mock(InterfaceDecl.class);
    when(m1.getName()).thenReturn("Interface1");
    when(m2.getName()).thenReturn("Interface2");
    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 = "Interface1";
    String invalid7 = "Interface2";
    assertTrue(validateInterface(valid1, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid2, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(valid3, mockDecl).equals(ErrorType.NO_ERROR));
    assertTrue(validateInterface(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
    assertTrue(validateInterface(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
    assertTrue(validateInterface(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
    assertTrue(validateInterface(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
    assertTrue(validateInterface(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
    assertTrue(validateInterface(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Also used : 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) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Test(org.junit.Test)

Example 10 with InterfaceDecl

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

the class DeltaSamplesTest method test_ticket322_Q.

@Test
public void test_ticket322_Q() throws Exception {
    Model m = assertTypeCheckFileOk("tests/abssamples/deltas/bug322.abs", true);
    m.flattenForProduct("Q");
    m.flushCache();
    assertFalse(m.hasErrors());
    assertFalse(m.hasTypeErrors());
    InterfaceDecl i = (InterfaceDecl) DeltaTest.findDecl(m, "M", "I");
    assertNull(i);
    InterfaceDecl j = (InterfaceDecl) DeltaTest.findDecl(m, "M", "J");
    assertNull(j);
}
Also used : Model(abs.frontend.ast.Model) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

InterfaceDecl (abs.frontend.ast.InterfaceDecl)15 ClassDecl (abs.frontend.ast.ClassDecl)7 Decl (abs.frontend.ast.Decl)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 FrontendTest (abs.frontend.FrontendTest)2 DataTypeUse (abs.frontend.ast.DataTypeUse)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 FieldDecl (abs.frontend.ast.FieldDecl)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 List (abs.frontend.ast.List)2 MethodImpl (abs.frontend.ast.MethodImpl)2 Model (abs.frontend.ast.Model)2 ModuleDecl (abs.frontend.ast.ModuleDecl)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 MethodNamePredicate (abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 AbsASTBuilderUtil.findMethodSig (abs.backend.tests.AbsASTBuilderUtil.findMethodSig)1 Access (abs.frontend.ast.Access)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1