Search in sources :

Example 91 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class ExternalCommandsSubPage method createExternalCommandsSection.

// creates the maincontroller section if needed
private void createExternalCommandsSection() {
    if (executeCommandSectionHandler == null || executeCommandSectionHandler.getLastSectionRoot() != null) {
        return;
    }
    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);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 92 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class DefineItemTransfer method nativeToJava.

@Override
protected Definition[] nativeToJava(final TransferData transferData) {
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
    try {
        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[] {};
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ByteArrayInputStream(java.io.ByteArrayInputStream) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) DefineSectionHandler(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 93 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class DefineSectionDropTargetListener method drop.

@Override
public void drop(final DropTargetEvent event) {
    if (DefineItemTransfer.getInstance().isSupportedType(event.currentDataType)) {
        if (event.item != null && viewer.getInput() != null) {
            DefineSectionHandler defineSectionHandler = (DefineSectionHandler) viewer.getInput();
            Definition element = (Definition) event.item.getData();
            Definition[] items = (Definition[]) event.data;
            int baseindex = defineSectionHandler.getDefinitions().indexOf(element);
            final ParseTree parent = defineSectionHandler.getLastSectionRoot();
            ConfigTreeNodeUtilities.removeChild(parent, element.getRoot());
            ConfigTreeNodeUtilities.addChild(parent, element.getRoot(), baseindex);
            if (items.length > 0) {
                for (int i = 0; i < items.length - 1; i++) {
                    defineSectionHandler.getDefinitions().add(++baseindex, items[i]);
                }
                defineSectionHandler.getDefinitions().add(++baseindex, items[items.length - 1]);
            }
            viewer.refresh(true);
            editor.setDirty();
        }
    }
}
Also used : Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) DefineSectionHandler(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 94 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class DefineSubPage method createNewDefineSection.

private void createNewDefineSection() {
    if (defineSectionHandler == null) {
        return;
    }
    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);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 95 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class DefineSubPage method createNewDefineItem.

private Definition createNewDefineItem() {
    if (defineSectionHandler == null) {
        return null;
    }
    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;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)311 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)104 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)60 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)49 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)46 CharStream (org.antlr.v4.runtime.CharStream)43 Test (org.junit.Test)43 CommonToken (org.antlr.v4.runtime.CommonToken)35 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)35 JavadocContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocContext)31 TextContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.TextContext)29 File (java.io.File)26 ArrayList (java.util.ArrayList)22 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)22 CancellationException (java.util.concurrent.CancellationException)20 ConsoleErrorListener (org.antlr.v4.runtime.ConsoleErrorListener)20 Grammar (org.antlr.v4.tool.Grammar)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 IOException (java.io.IOException)19 LexerGrammar (org.antlr.v4.tool.LexerGrammar)16