mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
removed unused stuff
minor refactoring
This commit is contained in:
parent
8fa77ac6c2
commit
f3f1a9d229
3 changed files with 13 additions and 132 deletions
|
@ -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<CompositeNode> nodesEnclosingRegion;
|
||||
private int offset;
|
||||
private int length;
|
||||
|
||||
public EnclosingCompositeNodeFinder(CompositeNode parentNode, int offset, int length) {
|
||||
nodesEnclosingRegion = new ArrayList<CompositeNode>();
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
findRegion(parentNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nodesEnclosingRegion
|
||||
*/
|
||||
public List<CompositeNode> getNodesEnclosingRegion() {
|
||||
return nodesEnclosingRegion;
|
||||
}
|
||||
|
||||
private boolean findRegion(CompositeNode parentNode) {
|
||||
boolean isLookingForStartToken = startTokenParentIndex == -1;
|
||||
nodesEnclosingRegion.add(parentNode);
|
||||
int currentParentIndex = nodesEnclosingRegion.size() - 1;
|
||||
EList<AbstractNode> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<AbstractNode> 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<AbstractNode> 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;
|
||||
|
|
Loading…
Reference in a new issue