Search in sources :

Example 11 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class JavaJob method findAndExecuteMain.

/**
 * Tries to find the main block in the chosen ABS file or in the
 * ABS project, if file is null.
 *
 * Finally: executes Modulename.Main
 *
 * @param absFrontendLocation - where to find the absfrontend
 * @throws AbsJobException - if no main block found
 * @throws IOException - If an I/O error occurs
 */
private void findAndExecuteMain(String absFrontendLocation) throws AbsJobException, IOException {
    String info = null;
    ModuleDecl module;
    if (absUnit) {
        module = getModuleByName(ABSTestRunnerGenerator.RUNNER_MAIN);
    } else if (runTarget != null) {
        module = getModuleByName(runTarget);
    } else {
        module = searchForMainBlockInCurrentFile();
        // Search for the main file if previous searching was not successful
        if (module == null) {
            List<ModuleDecl> modules = getAllModulesWithMainInCurrentProject();
            if (modules.size() == 0) {
                throw new AbsJobException("No Module with main block found.");
            } else {
                module = modules.get(0);
            }
            if (currentFile != null) {
                info = "No main file found for \"" + currentFile.getName() + "\".\nBut there is a main file in the project:";
            }
        }
    }
    String moduleName = JavaBackend.getFullJavaNameForMainBlock(module);
    try {
        debugAbsFiles(absFrontendLocation, javaPath, startSDE, moduleName, info);
    } catch (InvalidRandomSeedException e) {
        throw new AbsJobException(e);
    }
}
Also used : InvalidRandomSeedException(org.absmodels.abs.plugin.debug.model.Debugger.InvalidRandomSeedException) ModuleDecl(abs.frontend.ast.ModuleDecl) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 12 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ModuleDecorator method checkModulePath.

private void checkModulePath(IDecoration decoration, ModulePath m) {
    AbsNature nature = m.getNature();
    Model model = nature.getCompleteModel();
    if (model != null) {
        for (ModuleDecl mod : model.getModuleDecls()) {
            if (mod.getName().startsWith(m.getModulePath() + ".")) {
                if (hasModuleDeclErrors(mod, nature)) {
                    addErrorOverlay(decoration);
                    return;
                }
            }
        }
    }
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 13 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ModuleDecorator method decorate.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof InternalASTNode<?>) {
        InternalASTNode<?> node = (InternalASTNode<?>) element;
        if (node.hasASTNodeOfType(ModuleDecl.class)) {
            checkModuleDecl(decoration, (InternalASTNode<ModuleDecl>) node);
        }
    } else if (element instanceof ModulePath) {
        ModulePath m = (ModulePath) element;
        checkModulePath(decoration, m);
    } else if (element instanceof IProject) {
        IProject project = (IProject) element;
        checkProject(project, decoration);
    }
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) IProject(org.eclipse.core.resources.IProject)

Example 14 with ModuleDecl

use of abs.frontend.ast.ModuleDecl in project abstools by abstools.

the class ABSNavigatorStyledLabelProvider method getStyledString.

/**
 * Gets a styledString for the object. If the object is
 * <ul>
 *  <li>an InternalASTnode&lt;ModuleDecl&gt;, 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;
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 15 with ModuleDecl

use of abs.frontend.ast.ModuleDecl 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;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) ModuleDecl(abs.frontend.ast.ModuleDecl) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

ModuleDecl (abs.frontend.ast.ModuleDecl)29 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)10 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)8 Decl (abs.frontend.ast.Decl)7 Model (abs.frontend.ast.Model)7 ArrayList (java.util.ArrayList)7 ClassDecl (abs.frontend.ast.ClassDecl)6 CompilationUnit (abs.frontend.ast.CompilationUnit)6 ModulePath (org.absmodels.abs.plugin.navigator.ModulePath)5 IProject (org.eclipse.core.resources.IProject)5 InterfaceDecl (abs.frontend.ast.InterfaceDecl)4 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)4 Test (org.junit.Test)4 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 List (abs.frontend.ast.List)2 MainBlock (abs.frontend.ast.MainBlock)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EditorPosition (org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition)2 IFile (org.eclipse.core.resources.IFile)2