Java Code Examples for org.eclipse.xtext.nodemodel.INode#getTextRegionWithLineInformation()

The following examples show how to use org.eclipse.xtext.nodemodel.INode#getTextRegionWithLineInformation() . 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: N4JSDiagnosticConverter.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IssueLocation getLocationForNode(INode node) {
	ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation();
	N4JSIssueLocation result = new N4JSIssueLocation();
	result.offset = nodeRegion.getOffset();
	result.length = nodeRegion.getLength();

	LineAndColumn lineAndColumnStart = NodeModelUtils.getLineAndColumn(node, result.offset);
	result.lineNumber = lineAndColumnStart.getLine();
	result.column = lineAndColumnStart.getColumn();

	LineAndColumn lineAndColumnEnd = NodeModelUtils.getLineAndColumn(node, result.offset + result.length);
	result.lineNumberEnd = lineAndColumnEnd.getLine();
	result.columnEnd = lineAndColumnEnd.getColumn();
	return result;
}
 
Example 2
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 3
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 4
Source File: DefaultLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.3
 */
protected ITextRegion createRegion(List<INode> nodes, RegionDescription query) {
	if (query == RegionDescription.FULL || query == RegionDescription.SIGNIFICANT)
		return createRegion(nodes);
	ITextRegion result = ITextRegion.EMPTY_REGION;
	for (INode node : nodes) {
		for(INode leafNode: node.getLeafNodes()) {
			if (!isHidden(leafNode, query)) {
				ITextRegionWithLineInformation region = leafNode.getTextRegionWithLineInformation();
				if (region.getLength() != 0) {
					result = result.merge(toZeroBasedRegion(region));
				}
			}
		}
	}
	return result;
}
 
Example 5
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 6
Source File: DiagnosticConverterImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Computes {@link IssueLocation} for the given node.
 */
protected IssueLocation getLocationForNode(INode node) {
	ITextRegionWithLineInformation nodeRegion = node.getTextRegionWithLineInformation();
	int offset = nodeRegion.getOffset();
	int length = nodeRegion.getLength();
	return getLocationForNode(node, offset, length);
}
 
Example 7
Source File: DefaultLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ITextRegion createRegion(final List<INode> nodes) {
	ITextRegion result = ITextRegion.EMPTY_REGION;
	for (INode node : nodes) {
		if (!isHidden(node)) {
			ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
			if (region.getLength() != 0) {
				result = result.merge(toZeroBasedRegion(region));
			}
		}
	}
	return result;
}
 
Example 8
Source File: XtendLocationInFileProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
	if (element instanceof RichStringLiteral) {
		ICompositeNode elementNode = findNodeFor(element);
		if (elementNode == null) {
			return ITextRegion.EMPTY_REGION;
		}
		ITextRegion result = ITextRegion.EMPTY_REGION;
		for (INode node : elementNode.getLeafNodes()) {
			if (isHidden(node)) {
				continue;
			}
			EObject grammarElement = node.getGrammarElement();
			if (!(grammarElement instanceof RuleCall)) {
				continue;
			}
			RuleCall ruleCall = (RuleCall) grammarElement;
			
			ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation();
			int offset = region.getOffset();
			int length = region.getLength();
			if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) {
				offset += 3;
				length -= 6;
			} else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) {
				offset += 3;
				length -= 4;
			} else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) {
				offset += 1;
				length -= 4;
			} else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
				offset += 1;
				length -= 2;
			} else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) {
				offset += 2;
				length -= 5;
			} else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) {
				offset += 2;
				length -= 3;
			} else {
				continue;
			}
			result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber())));
		}
		return result;
	}
	return super.getSignificantTextRegion(element);
}