org.yaml.snakeyaml.events.AliasEvent Java Examples
The following examples show how to use
org.yaml.snakeyaml.events.AliasEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Emitter.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private void expectNode(boolean root, boolean mapping, boolean simpleKey) throws IOException { rootContext = root; mappingContext = mapping; simpleKeyContext = simpleKey; if (event instanceof AliasEvent) { expectAlias(); } else if (event instanceof ScalarEvent || event instanceof CollectionStartEvent) { processAnchor("&"); processTag(); if (event instanceof ScalarEvent) { expectScalar(); } else if (event instanceof SequenceStartEvent) { if (flowLevel != 0 || canonical || ((SequenceStartEvent) event).getFlowStyle() || checkEmptySequence()) { expectFlowSequence(); } else { expectBlockSequence(); } } else {// MappingStartEvent if (flowLevel != 0 || canonical || ((MappingStartEvent) event).getFlowStyle() || checkEmptyMapping()) { expectFlowMapping(); } else { expectBlockMapping(); } } } else { throw new EmitterException("expected NodeEvent, but got " + event); } }
Example #2
Source File: Emitter.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private boolean checkSimpleKey() { int length = 0; if (event instanceof NodeEvent && ((NodeEvent) event).getAnchor() != null) { if (preparedAnchor == null) { preparedAnchor = prepareAnchor(((NodeEvent) event).getAnchor()); } length += preparedAnchor.length(); } String tag = null; if (event instanceof ScalarEvent) { tag = ((ScalarEvent) event).getTag(); } else if (event instanceof CollectionStartEvent) { tag = ((CollectionStartEvent) event).getTag(); } if (tag != null) { if (preparedTag == null) { preparedTag = prepareTag(tag); } length += preparedTag.length(); } if (event instanceof ScalarEvent) { if (analysis == null) { analysis = analyzeScalar(((ScalarEvent) event).getValue()); } length += analysis.scalar.length(); } return (length < 128 && (event instanceof AliasEvent || (event instanceof ScalarEvent && !analysis.empty && !analysis.multiline) || checkEmptySequence() || checkEmptyMapping())); }
Example #3
Source File: Emitter.java From snake-yaml with Apache License 2.0 | 5 votes |
private void expectNode(boolean root, boolean mapping, boolean simpleKey) throws IOException { rootContext = root; mappingContext = mapping; simpleKeyContext = simpleKey; if (event instanceof AliasEvent) { expectAlias(); } else if (event instanceof ScalarEvent || event instanceof CollectionStartEvent) { processAnchor("&"); processTag(); if (event instanceof ScalarEvent) { expectScalar(); } else if (event instanceof SequenceStartEvent) { if (flowLevel != 0 || canonical || ((SequenceStartEvent) event).getFlowStyle() || checkEmptySequence()) { expectFlowSequence(); } else { expectBlockSequence(); } } else {// MappingStartEvent if (flowLevel != 0 || canonical || ((MappingStartEvent) event).getFlowStyle() || checkEmptyMapping()) { expectFlowMapping(); } else { expectBlockMapping(); } } } else { throw new EmitterException("expected NodeEvent, but got " + event); } }
Example #4
Source File: Emitter.java From snake-yaml with Apache License 2.0 | 5 votes |
private boolean checkSimpleKey() { int length = 0; if (event instanceof NodeEvent && ((NodeEvent) event).getAnchor() != null) { if (preparedAnchor == null) { preparedAnchor = prepareAnchor(((NodeEvent) event).getAnchor()); } length += preparedAnchor.length(); } String tag = null; if (event instanceof ScalarEvent) { tag = ((ScalarEvent) event).getTag(); } else if (event instanceof CollectionStartEvent) { tag = ((CollectionStartEvent) event).getTag(); } if (tag != null) { if (preparedTag == null) { preparedTag = prepareTag(tag); } length += preparedTag.length(); } if (event instanceof ScalarEvent) { if (analysis == null) { analysis = analyzeScalar(((ScalarEvent) event).getValue()); } length += analysis.scalar.length(); } return length < 128 && (event instanceof AliasEvent || (event instanceof ScalarEvent && !analysis.empty && !analysis.multiline) || checkEmptySequence() || checkEmptyMapping()); }
Example #5
Source File: PyStructureTest.java From snake-yaml with Apache License 2.0 | 5 votes |
private void compareEvents(List<Event> events1, List<Event> events2, boolean full) { assertEquals(events1.size(), events2.size()); Iterator<Event> iter1 = events1.iterator(); Iterator<Event> iter2 = events2.iterator(); while (iter1.hasNext()) { Event event1 = iter1.next(); Event event2 = iter2.next(); assertEquals(event1.getClass(), event2.getClass()); if (event1 instanceof AliasEvent && full) { assertEquals(((AliasEvent) event1).getAnchor(), ((AliasEvent) event2).getAnchor()); } if (event1 instanceof CollectionStartEvent) { String tag1 = ((CollectionStartEvent) event1).getTag(); String tag2 = ((CollectionStartEvent) event1).getTag(); if (tag1 != null && !"!".equals(tag1) && tag2 != null && !"!".equals(tag1)) { assertEquals(tag1, tag2); } } if (event1 instanceof ScalarEvent) { ScalarEvent scalar1 = (ScalarEvent) event1; ScalarEvent scalar2 = (ScalarEvent) event2; if (scalar1.getImplicit().bothFalse() && scalar2.getImplicit().bothFalse()) { assertEquals(scalar1.getTag(), scalar2.getTag()); } assertEquals(scalar1.getValue(), scalar2.getValue()); } } }
Example #6
Source File: Emitter.java From Diorite with MIT License | 5 votes |
boolean checkSimpleKey() { int length = 0; if ((this.event instanceof NodeEvent) && (((NodeEvent) this.event).getAnchor() != null)) { if (this.preparedAnchor == null) { this.preparedAnchor = prepareAnchor(((NodeEvent) this.event).getAnchor()); } length += this.preparedAnchor.length(); } String tag = null; if (this.event instanceof ScalarEvent) { tag = ((ScalarEvent) this.event).getTag(); } else if (this.event instanceof CollectionStartEvent) { tag = ((CollectionStartEvent) this.event).getTag(); } if (tag != null) { if (this.preparedTag == null) { this.preparedTag = this.prepareTag(tag); } length += this.preparedTag.length(); } if (this.event instanceof ScalarEvent) { if (this.analysis == null) { this.analysis = this.analyzeScalar(((ScalarEvent) this.event).getValue()); } length += this.analysis.scalar.length(); } return (length < SMALL_LENGTH) && ((this.event instanceof AliasEvent) || ((this.event instanceof ScalarEvent) && ! ((this.analysis == null) || this.analysis.empty) && ! this.analysis.multiline) || this.checkEmptySequence() || this.checkEmptyMapping()); }
Example #7
Source File: Serializer.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private void serializeNode(Node node, Node parent) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node .getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = (node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true))); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); int indexCounter = 0; List<Node> list = seqNode.getValue(); for (Node item : list) { serializeNode(item, node); indexCounter++; } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = (node.getTag().equals(implicitTag)); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); serializeNode(key, mnode); serializeNode(value, mnode); } this.emitter.emit(new MappingEndEvent(null, null)); } } }
Example #8
Source File: Serializer.java From snake-yaml with Apache License 2.0 | 4 votes |
private void serializeNode(Node node, Node parent) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node .getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); for (Node item : list) { serializeNode(item, node); } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); serializeNode(key, mnode); serializeNode(value, mnode); } this.emitter.emit(new MappingEndEvent(null, null)); } } }
Example #9
Source File: Emitter.java From Diorite with MIT License | 4 votes |
void expectNode(boolean root, boolean mapping, boolean simpleKey, @Nullable Integer lastIndent) throws IOException { this.rootContext = root; this.mappingContext = mapping; this.simpleKeyContext = simpleKey; if (this.event instanceof AliasEvent) { this.expectAlias(); } else if ((this.event instanceof ScalarEvent) || (this.event instanceof CollectionStartEvent)) { this.processAnchor("&"); this.processTag(); if (this.event instanceof ScalarEvent) { this.expectScalar(lastIndent); } else if (this.event instanceof SequenceStartEvent) { if ((this.flowLevel != 0) || this.canonical || ((SequenceStartEvent) this.event).getFlowStyle() || this.checkEmptySequence()) { this.expectFlowSequence(); } else { this.expectBlockSequence(); } } else {// MappingStartEvent if ((this.flowLevel != 0) || this.canonical || ((MappingStartEvent) this.event).getFlowStyle() || this.checkEmptyMapping()) { this.expectFlowMapping(); } else { this.expectBlockMapping(); } } } else { throw new EmitterException("expected NodeEvent, but got " + this.event); } }
Example #10
Source File: Serializer.java From Diorite with MIT License | 4 votes |
private void serializeNode(Node node, @Nullable Node parent, LinkedList<String> commentPath, boolean mappingScalar) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); String[] pathNodes = commentPath.toArray(new String[commentPath.size()]); String comment; if (this.checkCommentsSet(pathNodes)) { comment = this.comments.getComment(pathNodes); } else { comment = null; } ImplicitTuple tuple = new ImplicitTupleExtension(node.getTag().equals(detectedTag), node.getTag().equals(defaultTag), comment); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); for (Node item : list) { this.serializeNode(item, node, commentPath, false); } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); if (key instanceof ScalarNode) { commentPath.add(((ScalarNode) key).getValue()); } this.serializeNode(key, mnode, commentPath, true); this.serializeNode(value, mnode, commentPath, false); if (key instanceof ScalarNode) { commentPath.removeLast(); } } this.emitter.emit(new MappingEndEvent(null, null)); } } }