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