From f3f1a9d229e25eb4f0237f396944ce91f4a62360 Mon Sep 17 00:00:00 2001 From: jkohnlein Date: Thu, 3 Jul 2008 15:31:08 +0000 Subject: [PATCH] removed unused stuff minor refactoring --- .../impl/EnclosingCompositeNodeFinder.java | 78 ------------------- .../parser/impl/NodeWithCachedOffset.java | 41 ---------- .../xtext/parsetree/NodeContentAdapter.java | 26 +++---- 3 files changed, 13 insertions(+), 132 deletions(-) delete mode 100644 plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/EnclosingCompositeNodeFinder.java delete mode 100644 plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/NodeWithCachedOffset.java diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/EnclosingCompositeNodeFinder.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/EnclosingCompositeNodeFinder.java deleted file mode 100644 index 79edb9090..000000000 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/EnclosingCompositeNodeFinder.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - *******************************************************************************/ -package org.eclipse.xtext.parser.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.xtext.parsetree.AbstractNode; -import org.eclipse.xtext.parsetree.CompositeNode; -import org.eclipse.xtext.parsetree.LeafNode; - -/** - * @author Jan Köhnlein - Initial contribution and API - * - */ -public class EnclosingCompositeNodeFinder { - - private int currentOffset = 0; - private int startTokenParentIndex = -1; - private List nodesEnclosingRegion; - private int offset; - private int length; - - public EnclosingCompositeNodeFinder(CompositeNode parentNode, int offset, int length) { - nodesEnclosingRegion = new ArrayList(); - this.offset = offset; - this.length = length; - findRegion(parentNode); - } - - /** - * @return the nodesEnclosingRegion - */ - public List getNodesEnclosingRegion() { - return nodesEnclosingRegion; - } - - private boolean findRegion(CompositeNode parentNode) { - boolean isLookingForStartToken = startTokenParentIndex == -1; - nodesEnclosingRegion.add(parentNode); - int currentParentIndex = nodesEnclosingRegion.size() - 1; - EList children = parentNode.getChildren(); - for (AbstractNode child : children) { - if (child instanceof LeafNode) { - currentOffset += child.getLength(); - if (isLookingForStartToken && currentOffset > offset) { - isLookingForStartToken = false; - startTokenParentIndex = currentParentIndex; - } - if (!isLookingForStartToken && currentOffset >= offset + length) { - removeUncommonParents(currentParentIndex); - return true; - } - } - else { - if (findRegion((CompositeNode) child)) { - return true; - } - } - } - nodesEnclosingRegion.remove(currentParentIndex); - return false; - } - - private void removeUncommonParents(int currentParentIndex) { - int commonParentIndex = Math.min(startTokenParentIndex, currentParentIndex); - while (nodesEnclosingRegion.size() > commonParentIndex + 1) { - nodesEnclosingRegion.remove(nodesEnclosingRegion.size() - 1); - } - } -} diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/NodeWithCachedOffset.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/NodeWithCachedOffset.java deleted file mode 100644 index be3d0d1d5..000000000 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parser/impl/NodeWithCachedOffset.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - *******************************************************************************/ -package org.eclipse.xtext.parser.impl; - -import org.eclipse.xtext.parsetree.AbstractNode; - -/** - * @author Jan Köhnlein - Initial contribution and API - * - */ -public class NodeWithCachedOffset { - - private AbstractNode theNode; - - private int offset; - - public NodeWithCachedOffset(int offset, AbstractNode theNode) { - this.offset = offset; - this.theNode = theNode; - } - - /** - * @return the offset - */ - public int getCachedOffset() { - return offset; - } - - /** - * @return the node - */ - public AbstractNode getNode() { - return theNode; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parsetree/NodeContentAdapter.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parsetree/NodeContentAdapter.java index ed16f65c0..2d543c836 100644 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parsetree/NodeContentAdapter.java +++ b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/parsetree/NodeContentAdapter.java @@ -33,26 +33,26 @@ public class NodeContentAdapter extends EContentAdapter { switch (eventType) { case Notification.ADD: if (position == 0) { - updateOffsetAndLine(child, new NodeInfo(parent.getOffset(), parent.getLine())); + updateNodeInfo(child, new NodeInfo(parent.getOffset(), parent.getLine())); } else { AbstractNode predecessor = parent.getChildren().get(position - 1); - updateOffsetAndLine(child, new NodeInfo((predecessor.getOffset() + predecessor.getLength()), predecessor.endLine())); + updateNodeInfo(child, new NodeInfo((predecessor.getOffset() + predecessor.getLength()), predecessor.endLine())); } break; case Notification.REMOVE: if (position == 0) { - updateOffsetAndLine(parent, new NodeInfo(parent.getOffset(), parent.getLine())); + updateNodeInfo(parent, new NodeInfo(parent.getOffset(), parent.getLine())); } else { AbstractNode successor = parent.getChildren().get(position); - updateOffsetAndLine(successor, new NodeInfo(child.getOffset(), child.getLine())); + updateNodeInfo(successor, new NodeInfo(child.getOffset(), child.getLine())); } break; case Notification.ADD_MANY: case Notification.MOVE: case Notification.REMOVE_MANY: - updateOffsetAndLine(parent, new NodeInfo(parent.getOffset(), parent.getLine())); + updateNodeInfo(parent, new NodeInfo(parent.getOffset(), parent.getLine())); break; default: break; @@ -70,15 +70,15 @@ public class NodeContentAdapter extends EContentAdapter { EList siblings = parent.getChildren(); int index = siblings.indexOf(target); if (index == 0) { - updateOffsetAndLine(targetNode, new NodeInfo(parent.getOffset(), parent.getLine())); + updateNodeInfo(targetNode, new NodeInfo(parent.getOffset(), parent.getLine())); } else { AbstractNode predecessor = siblings.get(index - 1); - updateOffsetAndLine(targetNode, new NodeInfo((predecessor.getOffset() + predecessor.getLength()), predecessor.endLine())); + updateNodeInfo(targetNode, new NodeInfo((predecessor.getOffset() + predecessor.getLength()), predecessor.endLine())); } } else { - updateOffsetAndLine(targetNode, new NodeInfo(0, 1)); + updateNodeInfo(targetNode, new NodeInfo(0, 1)); } } } @@ -93,7 +93,7 @@ public class NodeContentAdapter extends EContentAdapter { } } - protected NodeInfo updateOffsetAndLineInContents(AbstractNode node, NodeInfo info) { + protected NodeInfo updateNodeInfoInContents(AbstractNode node, NodeInfo info) { node.setOffset(info.offset); node.setLine(info.line); if (node instanceof LeafNode) { @@ -103,7 +103,7 @@ public class NodeContentAdapter extends EContentAdapter { } else if (node instanceof CompositeNode) { int length = 0; for (AbstractNode child : ((CompositeNode) node).getChildren()) { - info = updateOffsetAndLineInContents(child, info); + info = updateNodeInfoInContents(child, info); length += child.getLength(); } node.setLength(length); @@ -111,14 +111,14 @@ public class NodeContentAdapter extends EContentAdapter { return info; } - protected AbstractNode updateOffsetAndLine(AbstractNode node, NodeInfo info) { - updateOffsetAndLineInContents(node, info); + protected AbstractNode updateNodeInfo(AbstractNode node, NodeInfo info) { + updateNodeInfoInContents(node, info); CompositeNode parent = node.getParent(); if (parent != null) { EList siblings = parent.getChildren(); int index = siblings.indexOf(node); for (int i = index + 1; i < siblings.size(); ++i) { - info = updateOffsetAndLineInContents(siblings.get(i), info); + info = updateNodeInfoInContents(siblings.get(i), info); } } return node;