use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class NavigatorContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof InternalASTNode) {
return outlineProvider.getChildren(parentElement);
} else if (parentElement instanceof IProject) {
if (((IProject) parentElement).isOpen()) {
AbsNature nature = UtilityFunctions.getAbsNature((IProject) parentElement);
assert nature != null;
return ModulePath.getRootHierarchy(nature).toArray();
}
} else if (parentElement instanceof ModulePath) {
ModulePath mPath = (ModulePath) parentElement;
ArrayList<Object> children = new ArrayList<Object>();
children.addAll(mPath.getChildModulePathsAndModuleDecls());
InternalASTNode<ModuleDecl> intNode = mPath.getModuleDecl();
// if the module path has a matching module declaration unfold its content..
if (intNode != null) {
ModuleDecl md = intNode.getASTNode();
ArrayList<ASTNode<?>> chld = getChildrenOf(md);
ASTNode<?>[] chldArr = chld.toArray(new ASTNode<?>[chld.size()]);
List<InternalASTNode<ASTNode<?>>> wrapASTNodes = InternalASTNode.wrapASTNodes(chldArr, mPath.getNature());
children.addAll(wrapASTNodes);
return (children.toArray());
}
return children.toArray();
}
return super.getChildren(parentElement);
}
use of abs.frontend.ast.ModuleDecl 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 abs.frontend.ast.ModuleDecl 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 abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class ABSUnitRunner method analyzeModelUnit.
private void analyzeModelUnit(Model model) {
System.out.println("Analyzing model:");
for (CompilationUnit cu : model.getCompilationUnits()) {
System.out.println(cu.getFileName());
for (ModuleDecl m : cu.getModuleDecls()) {
for (Decl cd : m.getDecls()) {
if (cd instanceof ClassDecl) {
for (MethodSig ms : ((ClassDecl) cd).getAllMethodSigs()) {
for (Annotation a : ms.getAnnotations()) {
if (a.getType().getSimpleName().equals("Test")) {
System.out.println("Found test method:" + ms.getName());
testMethods.add(ms);
} else if (a.getType().getSimpleName().equals("Suite")) {
System.out.println("Found test suite:" + ms.getName());
}
}
}
}
}
}
}
}
use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class LinkHelper method findSelection.
/**
* {@inheritDoc}
*/
@Override
public IStructuredSelection findSelection(IEditorInput anInput) {
if (anInput instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput) anInput;
IProject project = getProject(fileInput);
AbsNature nature = getAbsNature(project);
// If we did not get back an ABS nature, do nothing.
if (nature == null) {
return null;
}
ITextEditor editor = UtilityFunctions.openABSEditorForFile(fileInput.getPath(), project);
IFile file = fileInput.getFile();
ModuleDecl md = getModuleDeclAtCurrentCursor(file, nature, editor);
return buildTreeSelection(nature, project, new InternalASTNode<ModuleDecl>(md, nature));
}
return null;
}
Aggregations