Search in sources :

Example 1 with JoinPointClass

use of org.lara.language.specification.dsl.JoinPointClass in project lara-framework by specs-feup.

the class LanguageSpecificationSideBar method initJoinPoints.

private void initJoinPoints() {
    joinPoints.addItem(langSpec.getGlobal());
    for (JoinPointClass joinPoint : langSpec.getJoinPoints().values()) {
        joinPoints.addItem(joinPoint);
    }
    joinPoints.addActionListener(new GenericActionListener(e -> updateJPInfo((JoinPointClass) joinPoints.getSelectedItem())));
}
Also used : Color(java.awt.Color) Attribute(org.lara.language.specification.dsl.Attribute) SpecsEnums(pt.up.fe.specs.util.SpecsEnums) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) Function(java.util.function.Function) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) Action(org.lara.language.specification.dsl.Action) Parameter(org.lara.language.specification.dsl.Parameter) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) Select(org.lara.language.specification.dsl.Select) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericType(org.lara.language.specification.dsl.types.GenericType) FlowLayout(java.awt.FlowLayout) Declaration(org.lara.language.specification.dsl.Declaration) JButton(javax.swing.JButton) Font(java.awt.Font) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) LangSpecSorting(org.lara.interpreter.joptions.panels.editor.components.langspecsidebar.LangSpecSorting) Preferences(java.util.prefs.Preferences) JScrollPane(javax.swing.JScrollPane) ListCellRenderer(javax.swing.ListCellRenderer) Dimension(java.awt.Dimension) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) SpecsStrings(pt.up.fe.specs.util.SpecsStrings) JLabel(javax.swing.JLabel) EmptyBorder(javax.swing.border.EmptyBorder) GridBagLayout(java.awt.GridBagLayout) Collections(java.util.Collections) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) ListModel(javax.swing.ListModel) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener)

Example 2 with JoinPointClass

use of org.lara.language.specification.dsl.JoinPointClass in project lara-framework by specs-feup.

the class WeaverSpecification method getJoinPoint.

private JoinPointClass getJoinPoint(String joinPointName) {
    boolean isGlobal = joinPointName.equals(JoinPointClass.getGlobalName());
    JoinPointClass joinPoint = isGlobal ? ls.getGlobal() : ls.getJoinPoint(joinPointName);
    return joinPoint;
}
Also used : JoinPointClass(org.lara.language.specification.dsl.JoinPointClass)

Example 3 with JoinPointClass

use of org.lara.language.specification.dsl.JoinPointClass in project lara-framework by specs-feup.

the class LangSpecsXmlParser method parse.

public static LanguageSpecificationV2 parse(InputStream joinPointModel, InputStream attributeModel, InputStream actionModel, boolean validate) {
    // System.out.println("JP SCHEMA: " + SchemaResource.JOIN_POINT_SCHEMA.read());
    // System.out.println("JP SCHEMA: " + SchemaResource.JOIN_POINT_SCHEMA.getResource());
    var jpSchema = validate ? SchemaResource.JOIN_POINT_SCHEMA.toStream() : null;
    var attrSchema = validate ? SchemaResource.ATTRIBUTE_SCHEMA.toStream() : null;
    var actionSchema = validate ? SchemaResource.ACTION_SCHEMA.toStream() : null;
    var joinPointModelNode = XmlDocument.newInstance(joinPointModel, jpSchema);
    var attributeModelNode = XmlDocument.newInstance(attributeModel, attrSchema);
    var actionModelNode = XmlDocument.newInstance(actionModel, actionSchema);
    // Setup global JoinPointClass
    LanguageSpecificationV2 langSpecV2 = new LanguageSpecificationV2();
    JoinPointClass global = JoinPointClass.globalJoinPoint(langSpecV2);
    langSpecV2.setGlobal(global);
    // Initialize types (typedef, enums), to have access to available names
    for (var type : attributeModelNode.getElementsByName("object")) {
        var typeDef = new TypeDef(type.getAttribute("name"));
        langSpecV2.add(typeDef);
        setOptional(type.getAttribute("tooltip"), typeDef::setToolTip);
    }
    for (var type : attributeModelNode.getElementsByName("enum")) {
        var enumDef = new EnumDef(type.getAttribute("name"));
        langSpecV2.add(enumDef);
        setOptional(type.getAttribute("tooltip"), enumDef::setToolTip);
        List<EnumValue> valuesList = toEnumValues(type.getElementsByName("value"), langSpecV2);
        enumDef.setValues(valuesList);
    }
    List<JoinPointClass> jps = new ArrayList<>();
    for (var jpNode : joinPointModelNode.getElementsByName("joinpoint")) {
        var jp = new JoinPointClass(jpNode.getAttribute("class"), langSpecV2);
        setOptional(jpNode.getAttribute("tooltip"), jp::setToolTip);
        jps.add(jp);
    }
    Collections.sort(jps);
    jps.stream().forEach(langSpecV2::add);
    var joinpoints = joinPointModelNode.getElementsByName("joinpoints").get(0);
    langSpecV2.setRoot(joinpoints.getAttribute("root_class"));
    setOptional(joinpoints.getAttribute("root_alias"), langSpecV2::setRootAlias);
    // Map of actions according to class
    MultiMap<String, XmlElement> joinPointActions = new MultiMap<>();
    List<XmlElement> globalActions = new ArrayList<>();
    for (var actionNode : actionModelNode.getElementsByName("action")) {
        var classNames = actionNode.getAttribute("class");
        // Global actions do not have a class value, or its value is '*'
        if (classNames.isEmpty() || classNames.equals("*")) {
            globalActions.add(actionNode);
            continue;
        }
        // System.out.println("CLASS NAMES: " + classNames);
        for (String className : classNames.split(",")) {
            // System.out.println("NAME: " + className);
            joinPointActions.add(className.strip(), actionNode);
        }
    }
    populateGlobal(joinPointModelNode, attributeModelNode, actionModelNode, langSpecV2, global, globalActions);
    // Populate TypeDef
    for (var typeNode : attributeModelNode.getElementsByName("object")) {
        TypeDef typeDef = langSpecV2.getTypeDefs().get(typeNode.getAttribute("name"));
        List<Attribute> attributesList = convertAttributes(typeNode.getElementsByName("attribute"), langSpecV2);
        typeDef.setFields(attributesList);
    }
    for (var jpNode : joinPointModelNode.getElementsByName("joinpoint")) {
        String jpClass = jpNode.getAttribute("class");
        JoinPointClass jp = langSpecV2.getJoinPoint(jpClass);
        String extendsType = jpNode.getAttribute("extends");
        if (!extendsType.isEmpty()) {
            jp.setExtend(langSpecV2.getJoinPoint(extendsType));
        } else {
            jp.setExtend(global);
        }
        // Obtain attribute nodes from artifacts
        List<XmlElement> artifactNodes = attributeModelNode.getElementsByName("artifact").stream().filter(attribute -> attribute.getAttribute("class").equals(jpClass)).collect(Collectors.toList());
        var attributeNodes = artifactNodes.stream().flatMap(art -> art.getElementsByName("attribute").stream()).collect(Collectors.toList());
        // Add attributes
        jp.setAttributes(convertAttributes(attributeNodes, langSpecV2));
        // Add selects
        jp.setSelects(convertSelects(langSpecV2, jpNode.getElementsByName("select")));
        // Add actions
        jp.setActions(convertActions(langSpecV2, joinPointActions.get(jpClass)));
        // Set default attributes
        for (var artifact : attributeModelNode.getElementsByName("artifact")) {
            var defaultValue = artifact.getAttribute("default");
            if (defaultValue.isEmpty()) {
                continue;
            }
            // Get corresponding join point and set default
            // System.out.println("ARTIFACT CLASS: " + artifact.getAttribute("class"));
            // System.out.println("JP: " + langSpecV2.getJoinPoint(artifact.getAttribute("class")));
            var artifactJp = langSpecV2.getJoinPoint(artifact.getAttribute("class"));
            if (artifactJp == null) {
                SpecsLogs.info("Artifact without join point: " + artifact.getAttribute("class"));
                continue;
            }
            artifactJp.setDefaultAttribute(defaultValue);
        // System.out.println("SETTING DEFAULT '" + defaultValue + "' for JP " +
        // artifact.getAttribute("class"));
        }
    }
    // Add default global attributes (e.g., joinPointType, instanceOf)
    addDefaultGlobalAttributes(langSpecV2);
    return langSpecV2;
}
Also used : Arrays(java.util.Arrays) IType(org.lara.language.specification.dsl.types.IType) Attribute(org.lara.language.specification.dsl.Attribute) ResourceProvider(pt.up.fe.specs.util.providers.ResourceProvider) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) ArrayList(java.util.ArrayList) Action(org.lara.language.specification.dsl.Action) Parameter(org.lara.language.specification.dsl.Parameter) Select(org.lara.language.specification.dsl.Select) PrimitiveClasses(org.lara.language.specification.dsl.types.PrimitiveClasses) XmlDocument(pt.up.fe.specs.util.xml.XmlDocument) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) TypeDef(org.lara.language.specification.dsl.types.TypeDef) Declaration(org.lara.language.specification.dsl.Declaration) MultiMap(pt.up.fe.specs.util.collections.MultiMap) SpecsIo(pt.up.fe.specs.util.SpecsIo) EnumValue(org.lara.language.specification.dsl.types.EnumValue) XmlElement(pt.up.fe.specs.util.xml.XmlElement) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) SpecsLogs(pt.up.fe.specs.util.SpecsLogs) Collections(java.util.Collections) InputStream(java.io.InputStream) EnumDef(org.lara.language.specification.dsl.types.EnumDef) EnumDef(org.lara.language.specification.dsl.types.EnumDef) Attribute(org.lara.language.specification.dsl.Attribute) EnumValue(org.lara.language.specification.dsl.types.EnumValue) ArrayList(java.util.ArrayList) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) MultiMap(pt.up.fe.specs.util.collections.MultiMap) TypeDef(org.lara.language.specification.dsl.types.TypeDef) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) XmlElement(pt.up.fe.specs.util.xml.XmlElement)

Example 4 with JoinPointClass

use of org.lara.language.specification.dsl.JoinPointClass in project lara-framework by specs-feup.

the class Selector method selectWithMiddlePath.

private Stack<Select> selectWithMiddlePath(String targetJP, JoinPointClass source, SelectionPathV2 selPath) {
    Stack<Select> path = new Stack<>();
    final Set<JoinPointClass> ignoreSet = new HashSet<>();
    ignoreSet.add(source);
    // for (final Select select : source.getSelect()) {
    for (final Select select : source.getSelects()) {
        // final JoinPointType next = select.getClazz();
        final JoinPointClass next = select.getClazz();
        final Stack<Select> pathAux = selectionPathAux(next, targetJP, new ArrayList<JoinPointClass>(), ignoreSet, selPath);
        if (!pathAux.isEmpty()) {
            pathAux.push(select);
            if (!path.isEmpty()) {
                if (!alreadyFound) {
                    // System.out.println(
                    // "More than one path for inital join point '" + targetJP + "'. Two of then are: ");
                    // System.out.println("\t1. " + path + "->" + targetJP);
                    // System.out.println("\t2. " + pathAux + "->" + targetJP);
                    int pos = 1;
                    Select first = path.get(0);
                    Select second = pathAux.get(0);
                    while (first.equals(second)) {
                        // && pos < max) { <-- this should not happen in these conditions
                        first = path.get(pos);
                        second = pathAux.get(pos);
                        pos++;
                    }
                    // boolean firstWOalias = first.getAlias().equals(first.getClazz().getClazz());
                    // boolean secondWOAlias = second.getAlias().equals(second.getClazz().getClazz());
                    boolean firstWOalias = first.getSelectName().equals(first.getClazz().getName());
                    boolean secondWOAlias = second.getSelectName().equals(second.getClazz().getName());
                    if (first.getClazz().equals(second.getClazz())) {
                        selPath.setTieBreakReason("use the one with specific join point type (i.e. without label)");
                        if (!firstWOalias && secondWOAlias) {
                            selPath.setSecondaryPath(path);
                            path = pathAux;
                        } else {
                            selPath.setSecondaryPath(pathAux);
                        }
                    } else {
                        selPath.setTieBreakReason("use the first path found as primary (from a depth first search)");
                        selPath.setSecondaryPath(pathAux);
                    }
                    alreadyFound = true;
                }
                break;
            }
            path = pathAux;
        } else {
            ignoreSet.add(next);
        }
    }
    // If extends another join point
    if (path.isEmpty() && source.getExtend().isPresent()) {
        // source = (JoinPointType) source.getExtends();
        source = source.getExtend().get();
        return selectWithMiddlePath(targetJP, source, selPath);
    }
    return path;
}
Also used : Select(org.lara.language.specification.dsl.Select) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 5 with JoinPointClass

use of org.lara.language.specification.dsl.JoinPointClass in project lara-framework by specs-feup.

the class LanguageSpecificationSideBar method initRoot.

private void initRoot() {
    JLabel jLabel = new JLabel("Root: ");
    JoinPointClass root = langSpec.getRoot();
    String name = root.getName();
    if (!langSpec.getRootAlias().isEmpty()) {
        name = langSpec.getRootAlias() + "(" + name + ")";
    }
    JButton button = new JButton(" " + name + " ");
    button.setContentAreaFilled(false);
    button.setBorder(BorderFactory.createEtchedBorder());
    button.addActionListener(new GenericActionListener(e -> joinPoints.setSelectedItem(root)));
    rootPanel.add(jLabel);
    rootPanel.add(button);
// rootPanel.setPreferredSize(new Dimension(50, 50));
}
Also used : Color(java.awt.Color) Attribute(org.lara.language.specification.dsl.Attribute) SpecsEnums(pt.up.fe.specs.util.SpecsEnums) LanguageSpecificationV2(org.lara.language.specification.dsl.LanguageSpecificationV2) Function(java.util.function.Function) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) Action(org.lara.language.specification.dsl.Action) Parameter(org.lara.language.specification.dsl.Parameter) EditorPanel(org.lara.interpreter.joptions.panels.editor.EditorPanel) Select(org.lara.language.specification.dsl.Select) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) GenericType(org.lara.language.specification.dsl.types.GenericType) FlowLayout(java.awt.FlowLayout) Declaration(org.lara.language.specification.dsl.Declaration) JButton(javax.swing.JButton) Font(java.awt.Font) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) LangSpecSorting(org.lara.interpreter.joptions.panels.editor.components.langspecsidebar.LangSpecSorting) Preferences(java.util.prefs.Preferences) JScrollPane(javax.swing.JScrollPane) ListCellRenderer(javax.swing.ListCellRenderer) Dimension(java.awt.Dimension) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) SpecsStrings(pt.up.fe.specs.util.SpecsStrings) JLabel(javax.swing.JLabel) EmptyBorder(javax.swing.border.EmptyBorder) GridBagLayout(java.awt.GridBagLayout) Collections(java.util.Collections) JPanel(javax.swing.JPanel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) ListModel(javax.swing.ListModel) JoinPointClass(org.lara.language.specification.dsl.JoinPointClass) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener)

Aggregations

JoinPointClass (org.lara.language.specification.dsl.JoinPointClass)14 Select (org.lara.language.specification.dsl.Select)9 ArrayList (java.util.ArrayList)5 Action (org.lara.language.specification.dsl.Action)5 Attribute (org.lara.language.specification.dsl.Attribute)5 Collections (java.util.Collections)3 List (java.util.List)3 Stack (java.util.Stack)3 Collectors (java.util.stream.Collectors)3 Declaration (org.lara.language.specification.dsl.Declaration)3 LanguageSpecificationV2 (org.lara.language.specification.dsl.LanguageSpecificationV2)3 Parameter (org.lara.language.specification.dsl.Parameter)3 BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2 FlowLayout (java.awt.FlowLayout)2 Font (java.awt.Font)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2