mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[trace] Some fixes for computation of inverse trace regions
This commit is contained in:
parent
642014d616
commit
3ae1cff276
5 changed files with 80 additions and 21 deletions
|
@ -58,7 +58,8 @@ public abstract class AbstractStatefulTraceRegion extends AbstractTraceRegion {
|
|||
return myRegion.getLineNumber();
|
||||
}
|
||||
|
||||
protected ITextRegionWithLineInformation getMyRegion() {
|
||||
@Override
|
||||
public ITextRegionWithLineInformation getMyRegion() {
|
||||
return myRegion;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ public abstract class AbstractTraceRegion {
|
|||
List<AbstractTraceRegion> result = Lists.newArrayListWithCapacity(2);
|
||||
TraceRegion current = null;
|
||||
int currentEndOffset = 0;
|
||||
for(int i = 0; i < locations.size(); i++) { // avoid concurrent modification exceptions
|
||||
outer: for(int i = 0; i < locations.size(); i++) { // avoid concurrent modification exceptions
|
||||
Pair<ILocationData, AbstractTraceRegion> nextPair = locations.get(i);
|
||||
ILocationData nextLocation = nextPair.getFirst();
|
||||
AbstractTraceRegion nextRegion = nextPair.getSecond();
|
||||
|
@ -217,6 +217,7 @@ public abstract class AbstractTraceRegion {
|
|||
ILocationData newData = createLocationData(nextRegion, myPath, myProjectName);
|
||||
if (!writableLocations.contains(newData))
|
||||
writableLocations.add(newData);
|
||||
continue outer;
|
||||
} else {
|
||||
// walk upwards if necessary
|
||||
while(current != null && currentEndOffset <= nextLocation.getOffset()) {
|
||||
|
@ -269,8 +270,8 @@ public abstract class AbstractTraceRegion {
|
|||
return result;
|
||||
}
|
||||
|
||||
public LocationData createLocationData(AbstractTraceRegion nextRegion, URI myPath, String myProjectName) {
|
||||
return new LocationData(nextRegion.getMyOffset(), nextRegion.getMyLength(), nextRegion.getMyLineNumber(), nextRegion.getMyEndLineNumber(), myPath, myProjectName);
|
||||
public LocationData createLocationData(AbstractTraceRegion region, URI myPath, String myProjectName) {
|
||||
return new LocationData(region.getMyOffset(), region.getMyLength(), region.getMyLineNumber(), region.getMyEndLineNumber(), myPath, myProjectName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,6 +294,10 @@ public abstract class AbstractTraceRegion {
|
|||
|
||||
public abstract int getMyEndLineNumber();
|
||||
|
||||
public ITextRegionWithLineInformation getMyRegion() {
|
||||
return new TextRegionWithLineInformation(getMyOffset(), getMyLength(), getMyLineNumber(), getMyEndLineNumber());
|
||||
}
|
||||
|
||||
public abstract List<ILocationData> getAssociatedLocations();
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
package org.eclipse.xtext.generator.trace;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.xtext.util.TextRegionWithLineInformation;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -24,21 +22,6 @@ import com.google.common.collect.Lists;
|
|||
@NonNullByDefault
|
||||
public class LeafIterator extends AbstractIterator<AbstractTraceRegion> {
|
||||
|
||||
/**
|
||||
* A trace region that will not be added to the child list of the given parent.
|
||||
*/
|
||||
protected static class TemporaryTraceRegion extends AbstractStatefulTraceRegion {
|
||||
protected TemporaryTraceRegion(int myOffset, int myLength, int myLineNumber, int myEndLineNumber, List<ILocationData> locations,
|
||||
AbstractTraceRegion parent) {
|
||||
super(new TextRegionWithLineInformation(myOffset, myLength, myLineNumber, myEndLineNumber), locations, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAsChildIn(AbstractTraceRegion parent) {
|
||||
// we don't want to add temporary regions to the parent's child list
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractTraceRegion current;
|
||||
private int expectedOffset;
|
||||
private int expectedLine;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 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.generator.trace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.xtext.util.TextRegionWithLineInformation;
|
||||
|
||||
/**
|
||||
* A trace region that will not be added to the child list of the given parent.
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TemporaryTraceRegion extends AbstractStatefulTraceRegion {
|
||||
public TemporaryTraceRegion(int myOffset, int myLength, int myLineNumber, int myEndLineNumber, List<ILocationData> locations,
|
||||
AbstractTraceRegion parent) {
|
||||
super(new TextRegionWithLineInformation(myOffset, myLength, myLineNumber, myEndLineNumber), locations, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAsChildIn(AbstractTraceRegion parent) {
|
||||
// we don't want to add temporary regions to the parent's child list
|
||||
}
|
||||
}
|
|
@ -389,4 +389,45 @@ public class TraceRegionTest extends Assert {
|
|||
assertEquals(1, associatedLocation.getLineNumber());
|
||||
assertEquals(2, associatedLocation.getEndLineNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertFor_05() {
|
||||
URI path = URI.createURI("a");
|
||||
TraceRegion parent = new TraceRegion(0, 3, 0, 3, 4, 3, 4, 6, null, path, "projectA");
|
||||
TraceRegion first = new TraceRegion(0, 1, 0, 1, 4, 2, 4, 5, parent, null, null);
|
||||
TraceRegion second = new TraceRegion(2, 1, 2, 3, 4, 2, 4, 5, parent, null, null);
|
||||
List<AbstractTraceRegion> invertedList = parent.invertFor(path, URI.createURI("b"), "projectB");
|
||||
assertEquals(1, invertedList.size());
|
||||
AbstractTraceRegion inverted = invertedList.get(0);
|
||||
assertEquals(1, inverted.getNestedRegions().size());
|
||||
assertEquals(4, inverted.getMyOffset());
|
||||
assertEquals(3, inverted.getMyLength());
|
||||
assertEquals(4, inverted.getMyLineNumber());
|
||||
assertEquals(6, inverted.getMyEndLineNumber());
|
||||
ILocationData associatedLocation = inverted.getMergedAssociatedLocation();
|
||||
assertEquals(0, associatedLocation.getOffset());
|
||||
assertEquals(3, associatedLocation.getLength());
|
||||
assertEquals(0, associatedLocation.getLineNumber());
|
||||
assertEquals(3, associatedLocation.getEndLineNumber());
|
||||
|
||||
AbstractTraceRegion invertedChild = inverted.getNestedRegions().get(0);
|
||||
assertEquals(0, invertedChild.getNestedRegions().size());
|
||||
assertEquals(4, invertedChild.getMyOffset());
|
||||
assertEquals(2, invertedChild.getMyLength());
|
||||
assertEquals(4, invertedChild.getMyLineNumber());
|
||||
assertEquals(5, invertedChild.getMyEndLineNumber());
|
||||
List<ILocationData> associatedLocations = invertedChild.getAssociatedLocations();
|
||||
assertEquals(2, associatedLocations.size());
|
||||
associatedLocation = associatedLocations.get(0);
|
||||
assertEquals(0, associatedLocation.getOffset());
|
||||
assertEquals(1, associatedLocation.getLength());
|
||||
assertEquals(0, associatedLocation.getLineNumber());
|
||||
assertEquals(1, associatedLocation.getEndLineNumber());
|
||||
|
||||
associatedLocation = associatedLocations.get(1);
|
||||
assertEquals(2, associatedLocation.getOffset());
|
||||
assertEquals(1, associatedLocation.getLength());
|
||||
assertEquals(2, associatedLocation.getLineNumber());
|
||||
assertEquals(3, associatedLocation.getEndLineNumber());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue