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());
}
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);
}
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);
}
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);
}
}
}
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);
}
}
Aggregations