use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.
the class ABSNavigatorStyledLabelProvider method getStyledString.
/**
* Gets a styledString for the object. If the object is
* <ul>
* <li>an InternalASTnode<ModuleDecl>, the part of the name after the last '.' will be returned.</li>
* </ul>
* In all other cases {@link org.absmodels.abs.plugin.editor.outline.ABSContentOutlineUtils#getLabel(ModulePath)} will be used.
* @param obj the Object whose String representation should be returned
* @return A String representation of obj
*/
protected StyledString getStyledString(Object obj) {
StyledString styledString;
if (obj instanceof InternalASTNode) {
InternalASTNode<?> node = (InternalASTNode<?>) obj;
if (node.getASTNode() instanceof ModuleDecl) {
String name = ((ModuleDecl) node.getASTNode()).getName();
String lastName;
if (name.indexOf('.') > 0) {
lastName = name.substring(name.lastIndexOf('.') + 1, name.length());
} else {
lastName = name;
}
styledString = new StyledString(lastName, STYLER_BLACK);
} else {
styledString = getLabel(node);
}
} else if (obj instanceof ModulePath) {
styledString = getLabel((ModulePath) obj);
} else {
styledString = getLabel(obj);
}
return styledString;
}
use of org.absmodels.abs.plugin.util.InternalASTNode 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 org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.
the class NavigatorUtils method openEditor.
/**
* Opens the file in an editor that corresponds to the given
* TreeSelection. Only the first element of the selection will be
* taken into account.
*
* @param ts TreeSelection that is used as a base to find an appropriate editor
* @throws PartInitException - if the editor could not be opened for highlighting
*/
public static void openEditor(TreeSelection ts) throws PartInitException {
if (!ts.equals(TreeSelection.EMPTY)) {
TreePath path = ts.getPaths()[0];
IProject project = getProject(path);
if (project != null) {
if (path.getLastSegment() instanceof InternalASTNode<?>) {
InternalASTNode<?> node = (InternalASTNode<?>) path.getLastSegment();
openAndHighlightEditor(node);
} else if (path.getLastSegment() instanceof ModulePath) {
ModulePath mp = (ModulePath) path.getLastSegment();
if (mp.hasModuleWithDecls()) {
InternalASTNode<ModuleDecl> moduleDecl = mp.getModuleDecl();
openAndHighlightEditor(moduleDecl);
}
} else if (path.getLastSegment() instanceof PackageAbsFile) {
openABSEditorForFile((PackageAbsFile) path.getLastSegment());
}
}
}
}
use of org.absmodels.abs.plugin.util.InternalASTNode 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.util.InternalASTNode in project abstools by abstools.
the class ModulePath method getModulesForPrefix.
/**
* Collects ModuleDecls with a given prefix. Only ModuleDecls with a name
* prefix.Name are returned, ModuleDecls with a name prefix.subPrefix.Name
* are ignored.
*
* prefix is the current module path of this instance.
*
* @return Only ModuleDecls with a name prefix.Name are returned,
* ModuleDecls with a name prefix.subPrefix.Name are ignored
*/
public Set<InternalASTNode<ModuleDecl>> getModulesForPrefix() {
LinkedHashSet<InternalASTNode<ModuleDecl>> names = new LinkedHashSet<InternalASTNode<ModuleDecl>>();
Model model = absNature.getCompleteModel();
if ("".equals(modulePath)) {
for (ModuleDecl m : model.getModuleDecls()) {
String name = m.getName();
if (!name.equals(STDLIB_NAME)) {
if (name.indexOf('.') < 0 && !hasSubModule(name) && !name.equals(modulePath) && !names.contains(m)) {
// FIXME: Review, can a ModuleDecl really be inside Set<nternalASTNode<..>>? GC_UNRELATED_TYPES
names.add(new InternalASTNode<ModuleDecl>(m, absNature));
}
}
}
return names;
} else {
for (ModuleDecl m : model.getModuleDecls()) {
String name = m.getName();
if (!name.equals(STDLIB_NAME)) {
String regex = NavigatorUtils.buildRegex(modulePath);
if ((name.matches(regex) && !existsSubLayer(name)) && !hasSubModule(name)) {
names.add(new InternalASTNode<ModuleDecl>(m, absNature));
}
}
}
return names;
}
}
Aggregations