Search in sources :

Example 1 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.

the class ABSContentOutlineUtilsTest method testGetLabelModulePath.

@Test
public void testGetLabelModulePath() {
    ModulePath moduleMock0 = mock(ModulePath.class);
    when(moduleMock0.getModulePath()).thenReturn("A.A.B");
    ModulePath moduleMock1 = mock(ModulePath.class);
    when(moduleMock1.getModulePath()).thenReturn("A.A");
    ModulePath moduleMock2 = mock(ModulePath.class);
    when(moduleMock2.getModulePath()).thenReturn("A");
    ModulePath moduleMock3 = mock(ModulePath.class);
    when(moduleMock3.getModulePath()).thenReturn("");
    assertEquals("B", getLabel(moduleMock0).toString());
    assertEquals("A", getLabel(moduleMock1).toString());
    assertEquals("A", getLabel(moduleMock2).toString());
    assertEquals("", getLabel(moduleMock3).toString());
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) Test(org.junit.Test)

Example 2 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.

the class ModulePathTest method testGetChildModulePathsAndModuleDecls.

/**
 * Test method for {@link org.absmodels.abs.plugin.navigator.ModulePath#getChildModulePathsAndModuleDecls()}.
 */
@Test
public void testGetChildModulePathsAndModuleDecls() {
    ModulePath mPath;
    Object object;
    List<Object> paths = modPathEmpty.getChildModulePathsAndModuleDecls();
    assertTrue(paths.size() == 1);
    object = paths.get(0);
    assertTrue(object instanceof ModulePath);
    mPath = (ModulePath) object;
    assertEquals(mPath.getModulePath(), "A");
    assertNotNull(mPath.getModuleDecl());
    assertEquals(mPath.getModuleDecl().getASTNode(), modDeclA);
    assertSame(mPath.getModuleDecl().getNature(), modPathEmpty.getNature());
    paths = mPath.getChildModulePathsAndModuleDecls();
    assertTrue(paths.size() == 1);
    object = paths.get(0);
    assertTrue(object instanceof ModulePath);
    mPath = (ModulePath) paths.get(0);
    assertEquals(mPath.getModulePath(), "A.A");
    assertSame(mPath.getModuleDecl(), null);
    paths = mPath.getChildModulePathsAndModuleDecls();
    assertTrue(paths.size() == 5);
    validateLeafModuleDecl(paths.get(0), "A.A.A", modDeclAAA);
    validateLeafModuleDecl(paths.get(1), "A.A.B", modDeclAAB);
    validateLeafModuleDecl(paths.get(2), "A.A.C", modDeclAAC);
    validateLeafModuleDecl(paths.get(3), "A.A.D", modDeclAAD);
    validateLeafModuleDecl(paths.get(4), "A.A.E", modDeclAAE);
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) Test(org.junit.Test)

Example 3 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath 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 4 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath 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 5 with ModulePath

use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.

the class ModuleDecorator method decorate.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) element;
        if (node.hasASTNodeOfType(ModuleDecl.class)) {
            checkModuleDecl(decoration, (InternalASTNode<ModuleDecl>) node);
        }
    } else if (element instanceof ModulePath) {
        ModulePath m = (ModulePath) element;
        checkModulePath(decoration, m);
    } else if (element instanceof IProject) {
        IProject project = (IProject) element;
        checkProject(project, decoration);
    }
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) IProject(org.eclipse.core.resources.IProject)

Aggregations

ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)9 ModuleDecl (abs.frontend.ast.ModuleDecl)5 ArrayList (java.util.ArrayList)3 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)3 Test (org.junit.Test)3 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 IProject (org.eclipse.core.resources.IProject)2 ClassDecl (abs.frontend.ast.ClassDecl)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 Decl (abs.frontend.ast.Decl)1 MainBlock (abs.frontend.ast.MainBlock)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IDocument (org.eclipse.jface.text.IDocument)1 TextSelection (org.eclipse.jface.text.TextSelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1