Example usage for org.antlr.v4.runtime ParserRuleContext ParserRuleContext

List of usage examples for org.antlr.v4.runtime ParserRuleContext ParserRuleContext

Introduction

In this page you can find the example usage for org.antlr.v4.runtime ParserRuleContext ParserRuleContext.

Prototype

public ParserRuleContext() 

Source Link

Usage

From source file:org.eclipse.titan.designer.editors.configeditor.pages.execute.ExternalCommandsSubPage.java

License:Open Source License

void createExternalcommandsSection(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
    Section section = toolkit.createSection(parent,
            ExpandableComposite.TWISTIE | Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    section.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
    section.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR));

    section.setText("External commands");
    section.setDescription(// w ww  .  j a v a2 s.co m
            "Specify the external commands to be called at execution time for this configuration.");
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {
        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    section.setLayoutData(gd);

    Composite client = toolkit.createComposite(section, SWT.WRAP);
    section.setClient(client);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    client.setLayout(layout);

    toolkit.paintBordersFor(client);

    valueChanged = true;

    toolkit.createLabel(client, "Begin control part:");
    beginControlPartText = toolkit.createText(client, "", SWT.SINGLE);
    beginControlPartText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    beginControlPartText.setEnabled(executeCommandSectionHandler != null);
    beginControlPartText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }

            editor.setDirty();

            String temp = beginControlPartText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getBeginControlPartRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(),
                            executeCommandSectionHandler.getBeginControlPartRoot());
                }
                executeCommandSectionHandler.setBeginControlPart(null);
                executeCommandSectionHandler.setBeginControlPartRoot(null);

                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getBeginControlPart() == null) {
                // create the node
                createExternalCommandsSection();

                ParseTree beginControlPartRoot = new ParserRuleContext();
                executeCommandSectionHandler.setBeginControlPartRoot(beginControlPartRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(),
                        beginControlPartRoot);
                ConfigTreeNodeUtilities.addChild(beginControlPartRoot,
                        new AddedParseTree("\nbeginControlPart := "));
                ParseTree beginControlPart = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setBeginControlPart(beginControlPart);
                ConfigTreeNodeUtilities.addChild(beginControlPartRoot, beginControlPart);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getBeginControlPart(),
                        temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getBeginControlPart() != null) {
        beginControlPartText
                .setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getBeginControlPart()));
    }
    Button browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(beginControlPartText,
            (IFile) editor.getEditorInput().getAdapter(IFile.class)));

    toolkit.createLabel(client, "Begin testcase:");
    beginTestCaseText = toolkit.createText(client, "", SWT.SINGLE);
    beginTestCaseText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    beginTestCaseText.setEnabled(executeCommandSectionHandler != null);
    beginTestCaseText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }

            editor.setDirty();

            String temp = beginTestCaseText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getBeginTestcaseRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(),
                            executeCommandSectionHandler.getBeginTestcaseRoot());
                }
                executeCommandSectionHandler.setBeginTestcase(null);
                executeCommandSectionHandler.setBeginTestcaseRoot(null);

                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getBeginTestcase() == null) {
                // create the node
                createExternalCommandsSection();

                ParseTree beginTestcaseRoot = new ParserRuleContext();
                executeCommandSectionHandler.setBeginTestcaseRoot(beginTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(),
                        beginTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(beginTestcaseRoot, new AddedParseTree("\nbeginTestcase := "));
                ParseTree beginTestcase = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setBeginTestcase(beginTestcase);
                ConfigTreeNodeUtilities.addChild(beginTestcaseRoot, beginTestcase);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getBeginTestcase(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getBeginTestcase() != null) {
        beginTestCaseText
                .setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getBeginTestcase()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(beginTestCaseText,
            (IFile) editor.getEditorInput().getAdapter(IFile.class)));

    toolkit.createLabel(client, "End control part:");
    endControlPartText = toolkit.createText(client, "", SWT.SINGLE);
    endControlPartText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    endControlPartText.setEnabled(executeCommandSectionHandler != null);
    endControlPartText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }

            editor.setDirty();

            String temp = endControlPartText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getEndControlPartRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(),
                            executeCommandSectionHandler.getEndControlPartRoot());
                }
                executeCommandSectionHandler.setEndControlPart(null);
                executeCommandSectionHandler.setEndControlPartRoot(null);

                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getEndControlPart() == null) {
                // create the node
                createExternalCommandsSection();

                ParseTree endControlPartRoot = new ParserRuleContext();
                executeCommandSectionHandler.setEndControlPartRoot(endControlPartRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(),
                        endControlPartRoot);
                ConfigTreeNodeUtilities.addChild(endControlPartRoot,
                        new AddedParseTree("\nendControlPart := "));
                ParseTree endControlPart = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setEndControlPart(endControlPart);
                ConfigTreeNodeUtilities.addChild(endControlPartRoot, endControlPart);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getEndControlPart(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getEndControlPart() != null) {
        endControlPartText
                .setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getEndControlPart()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(endControlPartText,
            (IFile) editor.getEditorInput().getAdapter(IFile.class)));

    toolkit.createLabel(client, "End testcase:");
    endTestCaseText = toolkit.createText(client, "", SWT.SINGLE);
    endTestCaseText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    endTestCaseText.setEnabled(executeCommandSectionHandler != null);
    endTestCaseText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }

            editor.setDirty();

            String temp = endTestCaseText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getEndTestcaseRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(),
                            executeCommandSectionHandler.getEndTestcaseRoot());
                }
                executeCommandSectionHandler.setEndTestcase(null);
                executeCommandSectionHandler.setEndTestcaseRoot(null);

                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getEndTestcase() == null) {
                // create the node
                createExternalCommandsSection();

                ParseTree endTestcaseRoot = new ParserRuleContext();
                executeCommandSectionHandler.setEndTestcaseRoot(endTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(),
                        endTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(endTestcaseRoot, new AddedParseTree("\nendTestcase := "));
                ParseTree endTestcase = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setEndTestcase(endTestcase);
                ConfigTreeNodeUtilities.addChild(endTestcaseRoot, endTestcase);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getEndTestcase(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getEndTestcase() != null) {
        endTestCaseText
                .setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getEndTestcase()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(endTestCaseText,
            (IFile) editor.getEditorInput().getAdapter(IFile.class)));

    valueChanged = false;
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.execute.ExternalCommandsSubPage.java

License:Open Source License

private void createExternalCommandsSection() {
    if (executeCommandSectionHandler == null || executeCommandSectionHandler.getLastSectionRoot() != null) {
        return;//w  w w  .  ja va 2 s  .  c o  m
    }

    ParserRuleContext sectionRoot = new ParserRuleContext();
    executeCommandSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[EXTERNAL_COMMANDS]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);

    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.DefineItemTransfer.java

License:Open Source License

@Override
protected Definition[] nativeToJava(final TransferData transferData) {
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));

    try {/*from   w  w w.j  a v a2 s.  c om*/
        int n = in.readInt();
        Definition[] items = new Definition[n];

        String name;
        String value;
        String hiddenBefore;
        for (int i = 0; i < n; i++) {
            items[i] = new DefineSectionHandler.Definition();

            final ParseTree root = new ParserRuleContext();
            items[i].setRoot(root);

            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            name = in.readUTF();
            final ParseTree nameNode = new AddedParseTree(name);
            items[i].setDefinitionName(nameNode);
            ConfigTreeNodeUtilities.addChild(root, nameNode);

            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(":="));

            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            value = in.readUTF();
            final ParseTree valueNode = new AddedParseTree(value);
            items[i].setDefinitionValue(valueNode);
            ConfigTreeNodeUtilities.addChild(root, valueNode);
        }
        return items;
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return new Definition[] {};
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.DefineSubPage.java

License:Open Source License

private void createNewDefineSection() {
    if (defineSectionHandler == null) {
        return;//from w ww. j  a  v a 2 s .c  o m
    }

    ParserRuleContext sectionRoot = new ParserRuleContext();
    defineSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[DEFINE]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);

    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.DefineSubPage.java

License:Open Source License

private Definition createNewDefineItem() {
    if (defineSectionHandler == null) {
        return null;
    }/* www .j av  a2 s .c om*/

    final Definition item = new DefineSectionHandler.Definition();
    final ParseTree root = new ParserRuleContext();
    item.setRoot(root);

    final ParseTree name = new AddedParseTree("definition_name");
    final ParseTree value = new AddedParseTree("definition_value");
    item.setDefinitionName(name);
    item.setDefinitionValue(value);

    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, name);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
    ConfigTreeNodeUtilities.addChild(root, value);

    return item;
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.include.IncludeSubPage.java

License:Open Source License

private void createNewIncludeSection() {
    if (includeSectionHandler == null) {
        return;//from ww  w  . j av  a 2s . com
    }

    ParserRuleContext sectionRoot = new ParserRuleContext();
    includeSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[INCLUDE]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);

    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.logging.GeneralOptionsSubPage.java

License:Open Source License

private void createLogFileNode(final LoggingSectionHandler.LoggerTreeElement lte, final LogParamEntry logentry,
        final String value) {
    logentry.setLogFileRoot(new ParserRuleContext());
    logentry.setLogFile(new AddedParseTree(value));
    createNode(lte, logentry, value, "LogFile", logentry.getLogFileRoot(), logentry.getLogFile());
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.logging.GeneralOptionsSubPage.java

License:Open Source License

private void createTimeStampFormatNode(final LoggingSectionHandler.LoggerTreeElement lte,
        final LogParamEntry logentry, final String value) {
    logentry.setTimestampFormatRoot(new ParserRuleContext());
    logentry.setTimestampFormat(new AddedParseTree(value));
    createNode(lte, logentry, value, "TimeStampFormat", logentry.getTimestampFormatRoot(),
            logentry.getTimestampFormat());
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.logging.GeneralOptionsSubPage.java

License:Open Source License

private void createSourceInfoFormatNode(final LoggingSectionHandler.LoggerTreeElement lte,
        final LogParamEntry logentry, final String value) {
    logentry.setSourceInfoFormatRoot(new ParserRuleContext());
    logentry.setSourceInfoFormat(new AddedParseTree(value));
    createNode(lte, logentry, value, "SourceInfoFormat", logentry.getSourceInfoFormatRoot(),
            logentry.getSourceInfoFormat());
}

From source file:org.eclipse.titan.designer.editors.configeditor.pages.logging.GeneralOptionsSubPage.java

License:Open Source License

private void createAppendFileNode(final LoggingSectionHandler.LoggerTreeElement lte,
        final LogParamEntry logentry, final String value) {
    logentry.setAppendFileRoot(new ParserRuleContext());
    logentry.setAppendFile(new AddedParseTree(value));
    createNode(lte, logentry, value, "AppendFile", logentry.getAppendFileRoot(), logentry.getAppendFile());
}