Java Code Examples for org.eclipse.xtext.util.ITextRegionWithLineInformation#getLineNumber()

The following examples show how to use org.eclipse.xtext.util.ITextRegionWithLineInformation#getLineNumber() . 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: XbaseStratumBreakpointSupport.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isValidLineForBreakpoint(ICompositeNode node, int line) {
	for (INode n : node.getChildren()) {
		ITextRegionWithLineInformation textRegion = n.getTextRegionWithLineInformation();
		if (textRegion.getLineNumber()<= line && textRegion.getEndLineNumber() >= line) {
			EObject eObject = n.getSemanticElement();
			if (eObject instanceof XExpression && !(eObject.eClass() == XbasePackage.Literals.XBLOCK_EXPRESSION)) {
				return true;
			}
			if (n instanceof ICompositeNode && isValidLineForBreakpoint((ICompositeNode) n, line)) {
				return true;
			}
		}
		if (textRegion.getLineNumber() > line) {
			return false;
		}
	}
	return false;
}
 
Example 2
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isMultiline(final XExpression expression, final FormattableDocument doc) {
  final INode node = this._nodeModelAccess.nodeForEObject(expression);
  boolean _and = false;
  if (!(node != null)) {
    _and = false;
  } else {
    boolean _xblockexpression = false;
    {
      final ITextRegionWithLineInformation textRegion = node.getTextRegionWithLineInformation();
      int _lineNumber = textRegion.getLineNumber();
      int _endLineNumber = textRegion.getEndLineNumber();
      _xblockexpression = (_lineNumber != _endLineNumber);
    }
    _and = _xblockexpression;
  }
  return _and;
}
 
Example 3
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ILocationData toLocationData(List<INode> nodes) {
	ITextRegionWithLineInformation result = ITextRegionWithLineInformation.EMPTY_REGION;
	for (INode node : nodes) {
		if (!isHidden(node)) {
			ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
			if (region.getLength() != 0) {
				result = result.merge(new TextRegionWithLineInformation(region.getOffset(), region.getLength(), region.getLineNumber() - 1, region.getEndLineNumber() - 1));
			}
		}
	}
	if (result.getLength() == 0)
		return null;
	return new LocationData(result.getOffset(), result.getLength(), result.getLineNumber(),
			result.getEndLineNumber(), null);
}
 
Example 4
Source File: StorageBasedTextEditorOpener.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getRegionLabel() {
	if (region instanceof ITextRegionWithLineInformation) {
		ITextRegionWithLineInformation lines = ((ITextRegionWithLineInformation) region);
		if (lines.getLineNumber() == lines.getEndLineNumber())
			return String.format("line %d", lines.getLineNumber());
		return String.format("lines %d-%d", lines.getLineNumber(), lines.getEndLineNumber());
	} else if (region != null) {
		return String.format("offset %d, lenght %d", region.getOffset(), region.getLength());
	}
	return "";
}
 
Example 5
Source File: AbstractTraceRegion.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the merged location of all associated locations if they belong to the same resource. Otherwise
 * <code>null</code> is returned.
 */
public ILocationData getMergedAssociatedLocation() {
	List<ILocationData> allData = getAssociatedLocations();
	if (allData.isEmpty()) {
		return null;
	}
	if (allData.size() == 1) {
		return allData.get(0);
	}
	boolean allNull = true;
	SourceRelativeURI path = null;
	ITextRegionWithLineInformation region = ITextRegionWithLineInformation.EMPTY_REGION;
	for (ILocationData data : allData) {
		if (path != null) {
			if (!path.equals(data.getSrcRelativePath())) {
				return null;
			}
		} else {
			if (data.getSrcRelativePath() == null) {
				if (!allNull)
					throw new IllegalStateException(
							"Iff multiple associated locations are present, the path has to be set");
			} else {
				allNull = false;
				path = data.getSrcRelativePath();
			}
		}
		region = region.merge(new TextRegionWithLineInformation(data.getOffset(), data.getLength(),
				data.getLineNumber(), data.getEndLineNumber()));
	}
	return new LocationData(region.getOffset(), region.getLength(), region.getLineNumber(),
			region.getEndLineNumber(), path);
}
 
Example 6
Source File: AbstractEclipseTrace.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ILocationInEclipseResource createLocationInResource(ITextRegionWithLineInformation region, SourceRelativeURI srcRelativePath) {
	return new LocationInEclipseResource(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), srcRelativePath, this);
}
 
Example 7
Source File: DotFoldingRegionProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private boolean equals(ITextRegionWithLineInformation region1,
		ITextRegionWithLineInformation region2) {
	return region1.getLineNumber() == region2.getLineNumber()
			&& region1.getEndLineNumber() == region2.getEndLineNumber();
}
 
Example 8
Source File: LocationData.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public LocationData(ITextRegionWithLineInformation region, SourceRelativeURI path) {
	this(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), path);
}
 
Example 9
Source File: AbstractTrace.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected ILocationInResource createLocationInResource(ITextRegionWithLineInformation region, SourceRelativeURI srcRelativePath) {
	return new LocationInResource(region.getOffset(), region.getLength(), region.getLineNumber(), region.getEndLineNumber(), srcRelativePath, this);
}
 
Example 10
Source File: DefaultLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.5
 */
protected TextRegionWithLineInformation toZeroBasedRegion(ITextRegionWithLineInformation region) {
	return new TextRegionWithLineInformation(region.getOffset(), region.getLength(), region.getLineNumber() - 1, region.getEndLineNumber() - 1);
}