use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.
the class InternalASTNode method getParentHierarchyForModuleDecl.
/**
* Gives the module hierarchy for a given ModuleDecl
*
* @return An ArrayList of ModulePaths. This List will be empty if the
* ModuleDecl is null
*/
public ArrayList<ModulePath> getParentHierarchyForModuleDecl() {
ArrayList<ModulePath> hierarchy = new ArrayList<ModulePath>();
String moduleName = ((ModuleDecl) getASTNode()).getName();
String[] split = moduleName.split("\\.");
StringBuffer work = new StringBuffer();
for (int i = 0; i < split.length - 1; i++) {
work.append(split[i]);
ModulePath path = new ModulePath(getNature(), work.toString());
hierarchy.add(path);
work.append('.');
}
return hierarchy;
}
use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.
the class NewABSFileWizard method getProjectSelectionFromModulePath.
private IStructuredSelection getProjectSelectionFromModulePath(IStructuredSelection sel) {
ModulePath mp = getLastModulePathElement(sel);
if (mp != null) {
AbsNature nature = mp.getNature();
IProject project = nature.getProject();
Set<InternalASTNode<ModuleDecl>> modulesForPrefix = mp.getModulesForPrefix();
// Get first the of element in the HashSet
InternalASTNode<ModuleDecl> m = modulesForPrefix.isEmpty() ? null : modulesForPrefix.iterator().next();
List<IResource> folders = new ArrayList<IResource>();
folders.add(project);
if (m != null) {
CompilationUnit compilationUnit = m.getASTNode().getCompilationUnit();
IPath path = new Path(compilationUnit.getFileName());
path = path.makeRelativeTo(project.getLocation());
for (int i = 0; i < path.segmentCount() - 1; i++) {
folders.add(project.getFolder(path.segment(i)));
}
}
TreePath treePath = new TreePath(folders.toArray());
TreeSelection treeSelection = new TreeSelection(new TreePath[] { treePath });
return treeSelection;
}
return sel;
}
use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.
the class ModulePathTest method testClearRootHierarchyCache.
/**
* Test method for {@link org.absmodels.abs.plugin.navigator.ModulePath#clearRootHierarchyCache()}.
*/
@Test
public void testClearRootHierarchyCache() {
// Get the cached root hierarchy of our nature mock object
List<Object> rootHierarchy = ModulePath.getRootHierarchy(natureMock);
// The root hierarchy should only contain one element, namely the ModulePath A
assertTrue(rootHierarchy.size() == 1);
ModulePath originalObject = (ModulePath) rootHierarchy.get(0);
ModulePath.clearRootHierarchyCache();
// Get the new root hierarchy of our nature mock object
List<Object> newRootHierarchy = ModulePath.getRootHierarchy(natureMock);
// and check the size again
assertTrue(rootHierarchy.size() == 1);
ModulePath newObject = (ModulePath) newRootHierarchy.get(0);
// As the root hierarchy cache was cleared, the elements should not be the same...
assertTrue(newObject != originalObject);
// ...but contain the same information
assertEquals(newObject.getModulePath(), originalObject.getModulePath());
assertEquals(newObject.getModuleDecl(), originalObject.getModuleDecl());
}
use of org.absmodels.abs.plugin.navigator.ModulePath in project abstools by abstools.
the class NewABSFileWizard method insertModuleDeclaration.
/**
* If the original selection
* @param targeteditor
* @throws BadLocationException
*/
private void insertModuleDeclaration(ABSEditor targeteditor) throws BadLocationException {
IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
ModulePath mp = getLastModulePathElement(selection);
if (mp != null) {
doc.replace(0, 0, "module " + mp.getModulePath() + ".");
targeteditor.getSelectionProvider().setSelection(new TextSelection(8 + mp.getModulePath().length(), 0));
} else {
doc.replace(0, 0, "module ");
targeteditor.getSelectionProvider().setSelection(new TextSelection(7, 0));
}
}
Aggregations