org.eclipse.xtext.generator.trace.AbstractTraceRegion Java Examples

The following examples show how to use org.eclipse.xtext.generator.trace.AbstractTraceRegion. 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: GeneratorNodeProcessor.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void _doProcess(TraceNode node, Context ctx) {
	if (_hasContent(node, ctx)) {
		AbstractTraceRegion beforeRegion = ctx.getCurrentRegion();
		CompletableTraceRegion newRegion = new CompletableTraceRegion(node.isUseForDebugging(), node.getSourceLocation(),
				beforeRegion);
		int offset = ctx.contentLength();
		int startLineNumber = ctx.currentLineNumber();
		try {
			ctx.setCurrentRegion(newRegion);
			doProcessChildren(node, ctx);
		} finally {
			if (beforeRegion != null) {
				ctx.setCurrentRegion(beforeRegion);
			}
			newRegion.complete(offset, ctx.contentLength() - offset, startLineNumber, ctx.currentLineNumber());
		}
	}
}
 
Example #2
Source File: AbstractXtendInstallDebugInfoMojo.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void installTrace(File traceFile, Collection<File> classFiles) throws FileNotFoundException, IOException {
	ITraceToBytecodeInstaller traceToBytecodeInstaller = createTraceToBytecodeInstaller();
	InputStream in = new FileInputStream(traceFile);
	try {
		AbstractTraceRegion traceRegion = traceRegionSerializer.readTraceRegionFrom(in);
		traceToBytecodeInstaller.setTrace(traceFileNameProvider.getJavaFromTrace(traceFile.getName()), traceRegion);
		if (getLog().isDebugEnabled())
			getLog().debug("Installing trace " + traceFile + " into:");
		for (File classFile : classFiles) {
			if (getLog().isDebugEnabled())
				getLog().debug("  " + classFile);
			byte[] bytecodeWithTraces = traceToBytecodeInstaller.installTrace(Files.toByteArray(classFile));
			if (bytecodeWithTraces != null)
				Files.write(bytecodeWithTraces, classFile);
		}
	} finally {
		in.close();
	}
}
 
Example #3
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected AbstractTraceRegion findTraceRegionAt(int offset, boolean includeRegionEnd) {
	AbstractTraceRegion candidate = getRootTraceRegion();
	if (candidate == null || !encloses(candidate, offset, includeRegionEnd)) {
		// we have an inconsistent state - no candidate matches
		return null;
	}
	outer: while(candidate != null) {
		// TODO binary search?
		List<? extends AbstractTraceRegion> children = candidate.getNestedRegions();
		if (children.isEmpty()) {
			return candidate;
		}
		for(AbstractTraceRegion child: children) {
			if (encloses(child, offset, includeRegionEnd)) {
				candidate = child;
				continue outer;
			} else {
				if (child.getMyOffset() > offset) {
					return candidate;
				}
			}
		}
		return candidate;
	}
	return null;
}
 
Example #4
Source File: TreeAppendableTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testIntermediatesMayBeEmpty() {
	ITextRegionWithLineInformation root = new TextRegionWithLineInformation(47, 11, 12, 137);
	ITextRegionWithLineInformation emptyChild = new TextRegionWithLineInformation(8, 15, 12, 137);
	ITextRegionWithLineInformation emptyGrandChild = new TextRegionWithLineInformation(123, 321, 12, 137);
	expectedRegions = Arrays.asList(root, emptyChild, emptyGrandChild).iterator();
	TreeAppendable appendable = new TreeAppendable(new ImportManager(false), this, this, this, content, "  ", "\n");
	appendable.trace(content).trace(content).append("text");
	assertEquals("text", appendable.getContent());
	AbstractTraceRegion traceRegion = appendable.getTraceRegion();
	assertEquals(1, traceRegion.getNestedRegions().size());
	AbstractTraceRegion child = traceRegion.getNestedRegions().get(0);
	assertEquals(1, child.getNestedRegions().size());
	AbstractTraceRegion grandChild = child.getNestedRegions().get(0);
	assertTrue(grandChild.getNestedRegions().isEmpty());
	assertEquals(0, grandChild.getMyOffset());
	assertEquals(4, grandChild.getMyLength());
	assertEquals(123, grandChild.getMergedAssociatedLocation().getOffset());
	assertEquals(321, grandChild.getMergedAssociatedLocation().getLength());
}
 
Example #5
Source File: TreeAppendableTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoRedundantRegions() {
	ITextRegionWithLineInformation redundant = new TextRegionWithLineInformation(47, 11, 12, 137);
	ITextRegionWithLineInformation second = new TextRegionWithLineInformation(8, 15, 12, 137);
	expectedRegions = Arrays.asList(redundant, redundant, second).iterator();
	TreeAppendable appendable = new TreeAppendable(new ImportManager(false), this, this, this, content, "  ", "\n");
	appendable.append("initial");
	appendable.trace(content).append("first");
	appendable.trace(content).append("second");
	assertEquals("initialfirstsecond", appendable.getContent());
	AbstractTraceRegion traceRegion = appendable.getTraceRegion();
	assertNotNull(traceRegion);
	assertEquals(47, traceRegion.getMergedAssociatedLocation().getOffset());
	assertEquals(11, traceRegion.getMergedAssociatedLocation().getLength());
	assertEquals(0, traceRegion.getMyOffset());
	assertEquals("initialfirstsecond".length(), traceRegion.getMyLength());
	List<AbstractTraceRegion> nestedRegions = traceRegion.getNestedRegions();
	assertEquals(1, nestedRegions.size());
	AbstractTraceRegion child = nestedRegions.get(0);
	assertEquals(8, child.getMergedAssociatedLocation().getOffset());
	assertEquals(15, child.getMergedAssociatedLocation().getLength());
	assertEquals("initialfirst".length(), child.getMyOffset());
	assertEquals("second".length(), child.getMyLength());
}
 
Example #6
Source File: AbstractTraceForURIProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public Trace getTraceToSource(final SomeFile generatedFile) {
	final PersistedTrace persistedTrace = findPersistedTrace(generatedFile);
	if (persistedTrace == null || !persistedTrace.exists()) {
		return null;
	}
	Trace result = newAbstractTrace(generatedFile);
	result.setTraceToSource(true);
	result.setTraceRegionProvider(new ITraceRegionProvider() {
		
		@Override
		public AbstractTraceRegion getTraceRegion() {
			AbstractTraceRegion traceRegion = cachedTraces.getTraceRegion(persistedTrace);
			if (traceRegion == null) {
				throw new TraceNotFoundException();
			}
			return traceRegion;
		}
	});
	return result;
}
 
Example #7
Source File: AppendableBasedTraceRegion.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String toString() {
	return new AbstractTraceRegionToString() {

		@Override
		protected String getRemoteText(SourceRelativeURI uri) {
			return AppendableBasedTraceRegion.this.getRoot().sourceText;
		}

		@Override
		protected String getLocalText() {
			return AppendableBasedTraceRegion.this.getRoot().generatedText;
		}

		@Override
		protected AbstractTraceRegion getTrace() {
			return AppendableBasedTraceRegion.this;
		}

	}.toString();
}
 
Example #8
Source File: AppendableBasedTraceRegion.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void rightCompressTrace(String completeContent) {
	List<AbstractTraceRegion> allNested = getWritableNestedRegions();
	int i = 0;
	while (i < allNested.size()) {
		AppendableBasedTraceRegion nested = (AppendableBasedTraceRegion) allNested.get(i);
		int endOffset = nested.getMyOffset() + nested.getMyLength() - 1;
		int diff = 0;
		while(completeContent.charAt(endOffset - diff) <= ' ' && diff < nested.length) {
			diff++;
		}
		if (diff != 0) {
			nested.endLineNumber -= Strings.countLineBreaks(completeContent, endOffset - diff + 1, endOffset + 1);
			nested.length -= diff;
			nested.rightCompressTrace(completeContent);
		}
		i++;
	}
}
 
Example #9
Source File: AppendableBasedTraceRegion.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void leftCompressTrace(String completeContent) {
	List<AbstractTraceRegion> allNested = getWritableNestedRegions();
	int i = 0;
	while (i < allNested.size()) {
		AppendableBasedTraceRegion nested = (AppendableBasedTraceRegion) allNested.get(i);
		int offset = nested.getMyOffset();
		int diff = 0;
		while(completeContent.charAt(offset + diff) <= ' ' && diff < nested.length) {
			diff++;
		}
		if (diff == nested.length) {
			allNested.remove(i);
		} else {
			nested.lineNumber += Strings.countLineBreaks(completeContent, offset, offset + diff);
			nested.offset += diff;
			nested.length -= diff;
			nested.leftCompressTrace(completeContent);
			i++;
		}
	}
}
 
Example #10
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public AbstractTraceRegion region(final int offset, final int length, final int startLine, final int endLine, final Procedure1<? super TraceRegionMergerTest.TraceBuilder> init) {
  TraceRegion _xblockexpression = null;
  {
    final TraceRegion root = new TraceRegion(offset, length, startLine, endLine, true, 0, 0, 0, 0, this.root, this.uri);
    if ((init != null)) {
      final TraceRegionMergerTest.TraceBuilder child = new TraceRegionMergerTest.TraceBuilder(this.testBuilder, this.uri, root);
      init.apply(child);
    }
    _xblockexpression = root;
  }
  return _xblockexpression;
}
 
Example #11
Source File: TreeAppendableTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLineNumbers() {
	expectedRegions = new AbstractIterator<ITextRegionWithLineInformation>() {
		int start = 0;
		@Override
		protected ITextRegionWithLineInformation computeNext() {
			return new TextRegionWithLineInformation(start++, 1, 1, 1);
		}
	};
	TreeAppendable appendable = new TreeAppendable(new ImportManager(false), this, this, this, content, "  ", "\n");
	appendable.append("start line").increaseIndentation();
	appendable.newLine().trace(content).append("1");
	appendable.trace(content).newLine().append("2");
	appendable.newLine().trace(content).append("3\n4");
	appendable.decreaseIndentation().newLine().append("last line");
	assertEquals(
			"start line\n" +
			"  1\n" +
			"  2\n" +
			"  3\n" +
			"  4\n" +
			"last line", appendable.getContent());
	AbstractTraceRegion rootTraceRegion = appendable.getTraceRegion();
	assertEquals(0, rootTraceRegion.getMyLineNumber());
	assertEquals(5, rootTraceRegion.getMyEndLineNumber());
	AbstractTraceRegion firstChild = rootTraceRegion.getNestedRegions().get(0);
	assertEquals(1, firstChild.getMyLineNumber());
	assertEquals(1, firstChild.getMyEndLineNumber());
	AbstractTraceRegion secondChild = rootTraceRegion.getNestedRegions().get(1);
	assertEquals(2, secondChild.getMyLineNumber());
	assertEquals(2, secondChild.getMyEndLineNumber());
	AbstractTraceRegion thirdChild = rootTraceRegion.getNestedRegions().get(2);
	assertEquals(3, thirdChild.getMyLineNumber());
	assertEquals(4, thirdChild.getMyEndLineNumber());
	expectedRegions = null;
}
 
Example #12
Source File: LineNumberMappingTests.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AbstractTraceRegion getTraceRegion(final CharSequence xtendCode) {
  try {
    final XtendClass clazz = super.clazz(xtendCode.toString());
    final TraceRegionFSAForTest fsa = new TraceRegionFSAForTest();
    this.generator.doGenerate(clazz.eResource(), fsa);
    final AbstractTraceRegion result = ((ITraceRegionProvider) fsa.charSequence).getTraceRegion();
    this.print(result, fsa.charSequence.toString());
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #13
Source File: TreeAppendableTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNoEmptyLeafs() {
	ITextRegionWithLineInformation root = new TextRegionWithLineInformation(47, 11, 12, 137);
	ITextRegionWithLineInformation emptyChild = new TextRegionWithLineInformation(8, 15, 12, 137);
	ITextRegionWithLineInformation emptyGrandChild = new TextRegionWithLineInformation(123, 321, 12, 137);
	expectedRegions = Arrays.asList(root, emptyChild, emptyGrandChild).iterator();
	TreeAppendable appendable = new TreeAppendable(new ImportManager(false), this, this, this, content, "  ", "\n");
	appendable.append("initial");
	appendable.trace(content).trace(content);
	appendable.append("end");
	assertEquals("initialend", appendable.getContent());
	AbstractTraceRegion traceRegion = appendable.getTraceRegion();
	assertTrue(traceRegion.getNestedRegions().isEmpty());
}
 
Example #14
Source File: TreeAppendableTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEmpty() {
	expectedRegions = Collections.<ITextRegionWithLineInformation>singleton(new TextRegionWithLineInformation(47, 11, 12, 137)).iterator();
	TreeAppendable appendable = new TreeAppendable(new ImportManager(false), this, this, this, content, "  ", "\n");
	assertEquals("", appendable.getContent());
	AbstractTraceRegion traceRegion = appendable.getTraceRegion();
	assertNotNull(traceRegion);
	assertEquals(47, traceRegion.getMergedAssociatedLocation().getOffset());
	assertEquals(11, traceRegion.getMergedAssociatedLocation().getLength());
	assertEquals(getURIForTrace(resource), traceRegion.getAssociatedSrcRelativePath());
	assertTrue(traceRegion.getNestedRegions().isEmpty());
}
 
Example #15
Source File: TreeAppendable.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AbstractTraceRegion getTraceRegion() {
	if (locationData == null) {
		throw new IllegalStateException("tree appendable was used without tracing");
	}
	return new AppendableBasedTraceRegion(null, this, 0, 0);
}
 
Example #16
Source File: TraceableTreeAppendable.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void getTraceRegions(List<AbstractTraceRegion> regions) {
	if (this.location != null) {
		regions.add(getTraceRegion());
	}
	for (final TraceableTreeAppendable child : this.children) {
		child.getTraceRegions(regions);
	}
}
 
Example #17
Source File: JavaBreakPointProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private int getJavaLineNumber(final IJavaStratumLineBreakpoint breakpoint) throws CoreException {
	ILocationInEclipseResource javaLocation = getJavaLocation(breakpoint);
	if (javaLocation == null)
		return -1;
	IStorage storage = javaLocation.getPlatformResource();
	if (storage == null) {
		ITextRegionWithLineInformation textRegion = javaLocation.getTextRegion();
		if (textRegion == null)
			return -1;
		return textRegion.getEndLineNumber();
	} else {
		AbstractEclipseTrace sourceTrace = (AbstractEclipseTrace) traceForStorageProvider.getTraceToSource(storage);
		if (sourceTrace == null)
			return -1;
		AbstractTraceRegion rootTraceRegion = sourceTrace.getRootTraceRegion();
		if (rootTraceRegion == null)
			return -1;
		List<LineMapping> lineMappings = lineMappingProvider.getLineMapping(rootTraceRegion);
		if (lineMappings == null) {
			return -1;
		}
		for (LineMapping lineMapping : lineMappings) {
			if (lineMapping.sourceStartLine == breakpoint.getLineNumber()) {
				return lineMapping.targetEndLine + 1;
			}
		}
		return -1;
	}
}
 
Example #18
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Iterable<? extends ILocationInResource> toLocations(final Iterable<AbstractTraceRegion> allTraceRegions) {
	return new Iterable<ILocationInResource>() {

		@Override
		public Iterator<ILocationInResource> iterator() {
			return new AbstractIterator<ILocationInResource>() {

				private Iterator<AbstractTraceRegion> delegate = allTraceRegions.iterator();
				private AbstractTraceRegion region;
				private Iterator<ILocationData> locationDelegate;
				
				@Override
				protected ILocationInResource computeNext() {
					while(true) {
						if (locationDelegate == null || !locationDelegate.hasNext()) {
							if (delegate.hasNext()) {
								region = delegate.next();
								locationDelegate = region.getAssociatedLocations().iterator();
								if (!locationDelegate.hasNext()) {
									continue;
								}
							}
						}
						if (locationDelegate != null && locationDelegate.hasNext()) {
							ILocationData locationData = locationDelegate.next();
							ILocationInResource result = createLocationInResourceFor(locationData, region);
							if (result != null) {
								return result;
							}
							continue;
						}
						return endOfData();
					}
				}
			};
		}
		
	};
}
 
Example #19
Source File: TraceableTreeAppendable.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public AbstractTraceRegion getTraceRegion() {
	if (this.location == null) {
		throw new IllegalStateException("appendable was used without tracing");
	}
	return new AppendableBasedTraceRegion(this);
}
 
Example #20
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Iterable<AbstractTraceRegion> getAllTraceRegions() {
	return new Iterable<AbstractTraceRegion>() {
		@Override
		public Iterator<AbstractTraceRegion> iterator() {
			AbstractTraceRegion root = getRootTraceRegion();
			if (root == null)
				return ImmutableSet.<AbstractTraceRegion>of().iterator();
			final Iterator<AbstractTraceRegion> result = root.leafIterator();
			return result;
		}
	};
}
 
Example #21
Source File: XtendCompilerMojoTraceIT.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private String loadTraceSourcePath(String file) {
	try {
		FileInputStream in = new FileInputStream(file);
		try {
			AbstractTraceRegion region = new TraceRegionSerializer().readTraceRegionFrom(in);
			return region.getAssociatedSrcRelativePath().toString();
		} finally {
			in.close();
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #22
Source File: GeneratorNodeProcessor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
	if (traceRegion == null) {
		throw new TraceNotFoundException();
	}
	return traceRegion;
}
 
Example #23
Source File: TraceEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateText(EObject obj) {
	DebugTraceRegion region = EcoreUtil2.getContainerOfType(obj, DebugTraceRegion.class);
	if (region == null) {
		text.setText("No " + DebugTraceRegion.class.getSimpleName() + " found for " + obj.eClass().getName());
		return;
	}
	final DebugTraceBasedRegion trace = new DebugTraceBasedRegion(null, region);
	SourceRelativeURI sourceURI = trace.getAssociatedSrcRelativePath();
	if (sourceURI == null) {
		text.setText("Could not find associated URI");
		return;
	}
	Registry registry = IResourceServiceProvider.Registry.INSTANCE;
	IResourceServiceProvider serviceProvider = registry.getResourceServiceProvider(sourceURI.getURI());
	URI traceURI = obj.eResource().getURI();
	IStorage localStorage = getLocalStorage(serviceProvider, traceURI);

	StorageAwareTrace traceProvider = serviceProvider.get(StorageAwareTrace.class);
	traceProvider.setLocalStorage(localStorage);
	traceProvider.setTraceToSource(true);
	traceProvider.setTraceRegionProvider(new ITraceRegionProvider() {
		@Override
		public AbstractTraceRegion getTraceRegion() throws TraceNotFoundException {
			return trace;
		}
	});
	String newText = traceProvider.toString();
	text.setText(newText);
}
 
Example #24
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void assertMerged(final Procedure1<? super TraceRegionMergerTest.AssertBuilder> init) {
  final AbstractTraceRegion mergedRoot = new TraceRegionMerger().mergeTraceRegions(this.roots);
  Assert.assertNotNull(mergedRoot);
  LinkedList<AbstractTraceRegion> _newLinkedList = CollectionLiterals.<AbstractTraceRegion>newLinkedList(mergedRoot);
  final TraceRegionMergerTest.AssertBuilder assertBuilder = new TraceRegionMergerTest.AssertBuilder(this, _newLinkedList);
  init.apply(assertBuilder);
  assertBuilder.thatsIt();
}
 
Example #25
Source File: TraceRegionMergerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public TraceRegionMergerTest.TestBuilder traceTo(final String uri, final Function1<? super TraceRegionMergerTest.TraceBuilder, ? extends AbstractTraceRegion> init) {
  TraceRegionMergerTest.TestBuilder _xblockexpression = null;
  {
    final TraceRegionMergerTest.TraceBuilder traceBuilder = new TraceRegionMergerTest.TraceBuilder(this, uri);
    this.roots.add(init.apply(traceBuilder));
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example #26
Source File: CompilerTraceTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AbstractTraceRegion merge(final List<AbstractTraceRegion> regions) {
  boolean _isEmpty = regions.isEmpty();
  boolean _not = (!_isEmpty);
  Assert.assertTrue(_not);
  int _size = regions.size();
  boolean _greaterThan = (_size > 1);
  if (_greaterThan) {
    ITextRegionWithLineInformation rootLocation = ITextRegionWithLineInformation.EMPTY_REGION;
    ITextRegionWithLineInformation associated = ITextRegionWithLineInformation.EMPTY_REGION;
    for (final AbstractTraceRegion child : regions) {
      {
        int _myOffset = child.getMyOffset();
        int _myLength = child.getMyLength();
        int _myLineNumber = child.getMyLineNumber();
        int _myEndLineNumber = child.getMyEndLineNumber();
        TextRegionWithLineInformation _textRegionWithLineInformation = new TextRegionWithLineInformation(_myOffset, _myLength, _myLineNumber, _myEndLineNumber);
        rootLocation = rootLocation.merge(_textRegionWithLineInformation);
        ILocationData childAssociation = child.getMergedAssociatedLocation();
        if ((childAssociation != null)) {
          associated = associated.merge(childAssociation);
        }
      }
    }
    final RootTraceRegionForTesting root = new RootTraceRegionForTesting(rootLocation, associated);
    for (final AbstractTraceRegion child_1 : regions) {
      child_1.setParent(root);
    }
    return root;
  } else {
    return IterableExtensions.<AbstractTraceRegion>head(regions);
  }
}
 
Example #27
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the root trace region where {@link TraceRegion#getMyOffset()} and
 * {@link TraceRegion#getMyLength()} return the information for the
 * resource that this {@link ITrace} is associated with. 
 * @return the root trace region. May be <code>null</code> if no trace data is available.
 */
public final AbstractTraceRegion getRootTraceRegion() {
	if (rootTraceRegion == null) {
		rootTraceRegion = doGetRootTraceRegion();
	}
	return rootTraceRegion;
}
 
Example #28
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractTraceRegion doGetRootTraceRegion() {
	try {
		return traceRegionProvider.getTraceRegion();
	} catch (TraceNotFoundException noTraceFound) {
		return null;
	}
}
 
Example #29
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ILocationInResource getBestAssociatedLocation(ITextRegion region) {
	AbstractTraceRegion right = findTraceRegionAtRightOffset(region.getOffset() + region.getLength());
	if (right != null && encloses(right, region.getOffset(), true)) {
		if (right.getMyOffset() + right.getMyLength() == region.getOffset() + region.getLength())
			return getMergedLocationInResource(right);
	}
	
	AbstractTraceRegion left = findTraceRegionAtLeftOffset(region.getOffset());
	return mergeRegions(left, right);
}
 
Example #30
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a new location for a target resource that matches the given {@code location}.
 * @param location the location
 * @return the location in resource, <code>null</code> detecting a path fails.
 */
protected ILocationInResource createLocationInResourceFor(ILocationData location, AbstractTraceRegion traceRegion) {
	SourceRelativeURI path = location.getSrcRelativePath();
	if (path == null)
		path = traceRegion.getAssociatedSrcRelativePath();
	if (path == null)
		return null;
	return createLocationInResource(location, path);
}