use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.
the class ModuleGroupContentProvider method getChildrenOf.
/**
* Returns the children of a project.
*
* @param project
* @return The children of the Project or an empty object array if the
* project is closed or not an ABS project or an Exception occurs
*/
private Object[] getChildrenOf(IProject project) {
try {
if (project.isAccessible() && project.hasNature(Constants.NATURE_ID)) {
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature != null) {
synchronized (nature.modelLock) {
ArrayList<InternalASTNode<?>> decls = new ArrayList<InternalASTNode<?>>();
Model model = nature.getCompleteModel();
// something could be compiled in the project (i.e. the project is not empty...)
if (model != null) {
Collection<ModuleDecl> moduleDecls = model.getModuleDecls();
for (ModuleDecl m : moduleDecls) {
String name = m.getName();
/* Don't show internal resources which would be read-only anyway.
* This is either the standard lib, or e.g. ABS.FLI, ABS.DC */
if (name.startsWith("ABS.")) {
continue;
}
decls.add(new InternalASTNode<ModuleDecl>(m, nature));
}
}
return decls.toArray();
}
}
}
} catch (CoreException ce) {
ce.printStackTrace();
return EMPTY_OBJECT_ARRAY;
}
return EMPTY_OBJECT_ARRAY;
}
use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.
the class ABSContentOutlineProvider method getParent.
@Override
public Object getParent(Object element) {
if (element instanceof InternalASTNode<?>) {
InternalASTNode<?> node = (InternalASTNode<?>) element;
AbsNature nature = node.getNature();
ASTNode<?> parent = node.getASTNode().getParent();
assert nature != null;
/* Root nodes don't have parents, so there's nothing to wrap (ABSTools #301) */
if (parent == null) {
assert node.getASTNode() instanceof Model : element;
return null;
}
return new InternalASTNode<ASTNode<?>>(parent, nature);
}
return null;
}
use of org.absmodels.abs.plugin.util.InternalASTNode in project abstools by abstools.
the class ABSContentOutlineUtils method insertCostabsItems.
static void insertCostabsItems(ISelection sel) {
Object[] selectedItems = ((IStructuredSelection) sel).toArray();
CostabsLink.ENTRIES_STRINGS = new ArrayList<String>();
CostabsLink.ENTRIES_NODES = new ArrayList<ASTNode<?>>();
CostabsLink.LINE_ITEMS = new ArrayList<Integer>();
if (selectedItems.length > 0)
CostabsLink.ABS_NATURE = ((InternalASTNode<?>) selectedItems[0]).getNature();
for (int i = 0; i < selectedItems.length; i++) {
ASTNode<?> node = ((InternalASTNode<?>) selectedItems[i]).getASTNode();
CostabsLink.ENTRIES_NODES.add(node);
String callerName;
int line;
if (node instanceof FunctionDecl) {
FunctionDecl del = (FunctionDecl) node;
callerName = del.getName();
line = del.getStartLine();
CostabsLink.ENTRIES_STRINGS.add(callerName);
CostabsLink.LINE_ITEMS.add(line);
} else if (node instanceof MethodImpl) {
MethodImpl del = (MethodImpl) node;
ASTNode<?> par = del.getContextDecl();
if (par instanceof ClassDecl) {
ClassDecl cl = (ClassDecl) par;
callerName = cl.getName() + "." + del.getMethodSig().getName();
line = del.getStartLine();
CostabsLink.ENTRIES_STRINGS.add(callerName);
CostabsLink.LINE_ITEMS.add(line);
}
} else if (node instanceof MethodSig) {
MethodSig del = (MethodSig) node;
ASTNode<?> par = del.getContextDecl();
if (par instanceof ClassDecl) {
ClassDecl cl = (ClassDecl) par;
callerName = cl.getName() + "." + del.getName();
line = del.getStartLine();
CostabsLink.ENTRIES_STRINGS.add(callerName);
CostabsLink.LINE_ITEMS.add(line);
}
}
}
}
Aggregations