use of org.eclipse.titan.common.parsers.AddedParseTree 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;
}
use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.
the class IncludeItemTransfer method nativeToJava.
@Override
protected ParseTree[] nativeToJava(final TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
int n = in.readInt();
ParseTree[] items = new ParseTree[2 * n];
String fileName;
String hiddenBefore;
for (int i = 0; i < n; i++) {
hiddenBefore = in.readUTF();
fileName = in.readUTF();
items[2 * i] = ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore);
items[2 * i + 1] = new AddedParseTree(fileName);
}
return items;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
return new ParseTree[] {};
}
}
use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.
the class CfgParseTreePrinter method print.
/**
* RECURSIVE
* Builds parse tree text including hidden tokens
* @param aParseTree parse tree
* @param aTokens token list from the lexer (all, hidden and not hidden also)
* @param aPrintHiddenBefore true to print hidden tokens before the parse tree
* (NOTE: hidden tokens in the parse tree will be printed)
* @param aResolveMode mode of resolving
* @param aFile the parse tree of this file to print
* needed only if aResolveMode != NO_RESOLVING, in case of [ORDERED_INCLUDE]
*/
private void print(final ParseTree aParseTree, final List<Token> aTokens, final boolean aPrintHiddenBefore, final ResolveMode aResolveMode, final Path aFile) {
if (aParseTree == null) {
ErrorReporter.logWarning("ConfigTreeNodeUtilities.print(): aParseTree == null");
return;
}
if (aParseTree instanceof ParserRuleContext) {
final ParserRuleContext rule = (ParserRuleContext) aParseTree;
if (mDisallowedNodes != null && mDisallowedNodes.contains(rule.start.getType())) {
return;
}
if (aPrintHiddenBefore && rule.getChildCount() > 0 && rule.getChild(0) instanceof AddedParseTree) {
// special case: if AddedParseTree is the 1st in the rule, it has no information
// about the hidden tokens, as it has no position in the token list, but the rule may have
printHiddenTokensBefore(rule, aTokens);
}
} else if (aParseTree instanceof TerminalNodeImpl) {
final TerminalNodeImpl tn = (TerminalNodeImpl) aParseTree;
final Token token = tn.getSymbol();
if (mDisallowedNodes == null || !mDisallowedNodes.contains(token.getType())) {
printToken(token, aTokens, aPrintHiddenBefore, aResolveMode, aFile);
}
} else if (aParseTree instanceof AddedParseTree) {
final AddedParseTree t = (AddedParseTree) aParseTree;
mSb.append(t.getText());
} else {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.print(): unexpected ParseTree type");
}
for (int i = 0; i < aParseTree.getChildCount(); i++) {
final ParseTree child = aParseTree.getChild(i);
if (child == aParseTree) {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.print(): child == aParseTree");
} else {
print(child, aTokens, aPrintHiddenBefore || i > 0, aResolveMode, aFile);
}
}
}
use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.
the class ConfigTreeNodeUtilities method setParent.
/**
* Sets the parent of a child node
* @param aChild child node to modify
* @param aParent parent rule, NOT null
*/
private static void setParent(final ParseTree aChild, final ParserRuleContext aParent) {
if (aChild == null) {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): aChild == null");
return;
}
if (aChild == aParent) {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): aChild == aParent");
return;
}
if (aChild instanceof ParserRuleContext) {
final ParserRuleContext rule = (ParserRuleContext) aChild;
rule.parent = aParent;
} else if (aChild instanceof TerminalNodeImpl) {
final TerminalNodeImpl tn = (TerminalNodeImpl) aChild;
tn.parent = aParent;
} else if (aChild instanceof AddedParseTree) {
final AddedParseTree t = (AddedParseTree) aChild;
t.setParent(aParent);
} else {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setParent(): unhandled ParseTree class type");
}
}
use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.
the class ConfigTreeNodeUtilities method setText.
/**
* Changes the text of a parse tree
* @param aParseTree parse tree to modify
* @param aText new text
*/
public static void setText(final ParseTree aParseTree, final String aText) {
if (aParseTree == null) {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): aParseTree == null");
return;
}
if (aParseTree instanceof ParserRuleContext) {
final ParserRuleContext rule = (ParserRuleContext) aParseTree;
// just delete it and replace the children with an AddedParseTree
if (rule.children != null) {
rule.children.clear();
} else {
rule.children = new ArrayList<ParseTree>();
}
final ParseTree newNode = new AddedParseTree(aText);
addChild(rule, newNode);
} else if (aParseTree instanceof AddedParseTree) {
final AddedParseTree node = (AddedParseTree) aParseTree;
node.setText(aText);
} else if (aParseTree instanceof TerminalNodeImpl) {
final TerminalNodeImpl node = (TerminalNodeImpl) aParseTree;
final Token t = node.symbol;
if (t instanceof WritableToken) {
final WritableToken ct = (WritableToken) t;
ct.setText(aText);
} else {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): unhandled token class type");
}
} else {
ErrorReporter.INTERNAL_ERROR("ConfigTreeNodeUtilities.setText(): unhandled ParseTree class type");
}
}
Aggregations