use of abs.frontend.ast.CompilationUnit in project abstools by abstools.
the class LinkHelper method getModuleDeclAtCurrentCursor.
private ModuleDecl getModuleDeclAtCurrentCursor(IFile file, AbsNature nature, ITextEditor editor) {
ModuleDecl md = null;
synchronized (nature.modelLock) {
if (nature.getCompilationUnit(file).getNumModuleDecl() > 0) {
// get start line of editor selection
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
int startLine = selection.getStartLine();
CompilationUnit cu = nature.getCompilationUnit(file);
// find the module which the selection is located in...
for (ModuleDecl m : cu.getModuleDecls()) {
EditorPosition position = UtilityFunctions.getPosition(m);
int moduleStartLine = position.getLinestart();
int moduleEndLine = position.getLineend();
if (startLine >= moduleStartLine && startLine <= moduleEndLine) {
md = m;
break;
}
}
// if no module was found or no selection was made, take the first one in the compilation unit as fallback
if (md == null) {
md = cu.getModuleDecl(0);
}
}
}
return md;
}
use of abs.frontend.ast.CompilationUnit 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.CompilationUnit 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.CompilationUnit in project abstools by abstools.
the class TraitTest method addModifyModifierAtRuntimeBackComp.
@Test
public void addModifyModifierAtRuntimeBackComp() {
Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())), false);
ModifyMethodModifier opr = new ModifyMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.addDeltaAccess(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(1, cls.getMethods().getNumChild());
assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
use of abs.frontend.ast.CompilationUnit in project abstools by abstools.
the class JavaJob method searchForMainBlockInCurrentFile.
/**
* @return a module with a main block from the current file or null if no such module was found
* @throws AbsJobException
*/
private ModuleDecl searchForMainBlockInCurrentFile() throws AbsJobException {
if (currentFile == null) {
return null;
}
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature == null) {
throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
}
synchronized (nature.modelLock) {
CompilationUnit unit = nature.getCompilationUnit(currentFile);
List<ModuleDecl> modules = findModulesWithMain(unit);
// TODO: is the module still valid once you have returned the lock?
return modules.size() == 0 ? null : modules.get(0);
}
}
Aggregations