Search in sources :

Example 1 with ModuleDecl

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

the class ModulePathTest method validateLeafModuleDecl.

private final void validateLeafModuleDecl(Object object, String name, ModuleDecl originalDecl) {
    InternalASTNode<?> intNode;
    assertTrue(object instanceof InternalASTNode<?>);
    intNode = (InternalASTNode<?>) object;
    ModuleDecl modDecl = (ModuleDecl) intNode.getASTNode();
    assertEquals(modDecl, originalDecl);
    assertEquals(modDecl.getName(), name);
}
Also used : ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 2 with ModuleDecl

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

the class ModulePathTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Set up ABS nature
    natureMock = mock(AbsNature.class, Mockito.RETURNS_DEEP_STUBS);
    MainBlock main = mock(MainBlock.class, Mockito.RETURNS_DEEP_STUBS);
    natureMock.modelLock = new Object();
    // Set up mocks with @Mock annotation
    MockitoAnnotations.initMocks(this);
    declArray = new ModuleDecl[] { modDeclA, modDeclAAA, modDeclAAB, modDeclAAC, modDeclAAD, modDeclAAE };
    // Set up module paths
    modPathEmpty = new ModulePath(natureMock, "");
    modPathA = new ModulePath(natureMock, "A");
    modPathAA = new ModulePath(natureMock, "A.A");
    modPathAAA = new ModulePath(natureMock, "A.A.A");
    modPathAAB = new ModulePath(natureMock, "A.A.B");
    modPathAAC = new ModulePath(natureMock, "A.A.C");
    modPathAAD = new ModulePath(natureMock, "A.A.D");
    modPathAAE = new ModulePath(natureMock, "A.A.E");
    // Return "fake" module names.
    when(modDeclA.getName()).thenReturn("A");
    when(modDeclAAA.getName()).thenReturn("A.A.A");
    when(modDeclAAB.getName()).thenReturn("A.A.B");
    when(modDeclAAC.getName()).thenReturn("A.A.C");
    when(modDeclAAD.getName()).thenReturn("A.A.D");
    when(modDeclAAE.getName()).thenReturn("A.A.E");
    // Setting up child nodes of ModuleDecls
    // moduleDeclA and moduleDeclAAA are empty
    // moduleDeclAAB has a main block
    when(declArray[2].hasBlock()).thenReturn(true);
    when(declArray[2].getBlock()).thenReturn(main);
    // moduleDeclAAC has a decl (class declaration)
    when(declArray[3].getNumDecl()).thenReturn(1);
    abs.frontend.ast.List<Decl> declList = new abs.frontend.ast.List<Decl>();
    declList.add((Decl) mock(ClassDecl.class));
    when(declArray[3].getDeclList()).thenReturn(declList);
    // moduleDeclAAD has an Export
    when(declArray[4].getNumExport()).thenReturn(1);
    // moduleDeclAAD has an Import
    when(declArray[5].getNumImport()).thenReturn(2);
    decls = Arrays.asList(declArray);
    when(model.getModuleDecls()).thenReturn(decls);
    when(natureMock.getCompleteModel()).thenReturn(model);
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) ModuleDecl(abs.frontend.ast.ModuleDecl) Decl(abs.frontend.ast.Decl) ClassDecl(abs.frontend.ast.ClassDecl) ArrayList(java.util.ArrayList) List(java.util.List) MainBlock(abs.frontend.ast.MainBlock) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Before(org.junit.Before)

Example 3 with ModuleDecl

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

the class NewModuleWizard method setInitialInput.

private void setInitialInput() {
    if (firstSelection instanceof IFile) {
        IFile file = (IFile) firstSelection;
        if (file.getName().endsWith("." + Constants.ABS_FILE_EXTENSION)) {
            page.setInitialFileResource(file);
        }
    } else if (firstSelection instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) firstSelection;
        if (node.hasASTNodeOfType(ModuleDecl.class)) {
            ModuleDecl m = (ModuleDecl) node.getASTNode();
            page.setInitialValue(m.getName() + ".");
            IFile file = UtilityFunctions.getFileOfModuleDecl(m);
            page.setInitialFileResource(file);
        }
    } else if (firstSelection instanceof ModulePath) {
        ModulePath mp = (ModulePath) firstSelection;
        page.setInitialValue(mp.getModulePath() + ".");
        InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
        if (moduleDecl.hasASTNodeOfType(ModuleDecl.class)) {
            IFile fileOfModuleDecl = UtilityFunctions.getFileOfModuleDecl(mp.getModuleDecl().getASTNode());
            page.setInitialFileResource(fileOfModuleDecl);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl)

Example 4 with ModuleDecl

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

the class WizardUtil method getInsertionPosition.

/**
 * Determines the insertion position for a new interface/class declaration.
 * If the given ModuleDecl has a MainBlock the insertion point is right
 * before the main block. Otherwise, the insertion point is at the end of
 * the ModuleDecl.
 *
 * @param d
 *            The target document
 * @param astNode
 *            The target ModuleDecl
 * @return the insertion position of the new class or interface.
 * @throws BadLocationException
 *             if the location of the module declaration or the respective
 *             main block could not be found
 */
public static int getInsertionPosition(IDocument d, InternalASTNode<ModuleDecl> astNode) throws BadLocationException {
    Assert.isNotNull(d);
    Assert.isNotNull(astNode);
    final ModuleDecl m = astNode.getASTNode();
    Assert.isNotNull(m, "ModuleDecl argument is null!");
    final EditorPosition position;
    /* Classes and interfaces go before product lines / products in the grammar.
		 * We don't want to generate invalid input for the user.
		 */
    if (m.hasBlock()) {
        MainBlock block = m.getBlock();
        position = UtilityFunctions.getPosition(block);
        return d.getLineOffset(position.getLinestart()) + position.getColstart();
    } else {
        position = UtilityFunctions.getPosition(m);
        return d.getLineOffset(position.getLineend()) + position.getColend();
    }
}
Also used : EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) ModuleDecl(abs.frontend.ast.ModuleDecl) MainBlock(abs.frontend.ast.MainBlock)

Example 5 with ModuleDecl

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

the class ABSWizardStyledLabelProvider method getStyledString.

@Override
protected StyledString getStyledString(Object obj) {
    StyledString styledString;
    if (obj instanceof ModuleDecl) {
        String name = ((ModuleDecl) obj).getName();
        styledString = new StyledString(name, STYLER_BLACK);
    } else {
        styledString = super.getStyledString(obj);
    }
    return styledString;
}
Also used : ModuleDecl(abs.frontend.ast.ModuleDecl) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

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