1 /******************************************************************************* 2 * Copyright (c) 2016, 2017 Red Hat Inc. and others 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Sopot Cela (Red Hat Inc.) 13 * Lucas Bullen (Red Hat Inc.) - [Bug 520004] autocomplete does not respect tag hierarchy 14 *******************************************************************************/ 15 package org.eclipse.pde.internal.genericeditor.target.extension.model; 16 17 import java.util.ArrayList; 18 import java.util.List; 19 import java.util.stream.Collectors; 20 21 /** 22 * Base class for model nodes in a target definition. 23 */ 24 public class Node { 25 26 private int offsetStart; 27 private int offsetEnd; 28 private String nodeTag; 29 private List<Node> childNodes; 30 private Node parentNode; 31 getOffsetStart()32 public int getOffsetStart() { 33 return offsetStart; 34 } 35 setOffsetStart(int offsetStart)36 public void setOffsetStart(int offsetStart) { 37 this.offsetStart = offsetStart; 38 } 39 getOffsetEnd()40 public int getOffsetEnd() { 41 return offsetEnd; 42 } 43 setOffsetEnd(int offsetEnd)44 public void setOffsetEnd(int offsetEnd) { 45 this.offsetEnd = offsetEnd; 46 } 47 getNodeTag()48 public String getNodeTag() { 49 return nodeTag; 50 } 51 setNodeTag(String nodeTag)52 public void setNodeTag(String nodeTag) { 53 this.nodeTag = nodeTag; 54 } 55 getChildNodes()56 public List<Node> getChildNodes() { 57 return childNodes; 58 } 59 getChildNodesByTag(String nodeTag)60 public List<Node> getChildNodesByTag(String nodeTag) { 61 return childNodes.stream().filter(n -> n.getNodeTag().equals(nodeTag)).collect(Collectors.toList()); 62 } 63 addChildNode(Node child)64 public void addChildNode(Node child) { 65 if (childNodes == null) { 66 childNodes = new ArrayList<>(); 67 } 68 childNodes.add(child); 69 child.setParentNode(this); 70 } 71 getParentNode()72 public Node getParentNode() { 73 return parentNode; 74 } 75 setParentNode(Node parentNode)76 private void setParentNode(Node parentNode) { 77 this.parentNode = parentNode; 78 } 79 } 80