Java Code Examples for org.eclipse.xtext.util.ITextRegionWithLineInformation#EMPTY_REGION

The following examples show how to use org.eclipse.xtext.util.ITextRegionWithLineInformation#EMPTY_REGION . 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: DefaultHierarchyNodeLocationProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected ITextRegionWithLineInformation toTextRegionWithLineInformation(EObject obj, ITextRegion textRegion) {
	if (textRegion == null) {
		return ITextRegionWithLineInformation.EMPTY_REGION;
	}
	if (textRegion instanceof ITextRegionWithLineInformation) {
		return (ITextRegionWithLineInformation) textRegion;
	}
	ICompositeNode node = NodeModelUtils.getNode(obj);
	if (node == null) {
		return new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), 0, 0);
	}
	int startLine = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine() - 1;
	int endLine = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset() + textRegion.getLength()).getLine()
			- 1;
	return new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), startLine, endLine);
}
 
Example 2
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 3
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable generateDocumentation(final String text, final List<INode> documentationNodes, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    final StringConcatenation doc = ((StringConcatenation) _builder);
    doc.newLine();
    doc.append(" * ");
    doc.append(text, " * ");
    doc.newLine();
    doc.append(" */");
    ITreeAppendable _xifexpression = null;
    boolean _isEmpty = documentationNodes.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      ITreeAppendable _xblockexpression_1 = null;
      {
        ITextRegionWithLineInformation documentationTrace = ITextRegionWithLineInformation.EMPTY_REGION;
        for (final INode node : documentationNodes) {
          documentationTrace = documentationTrace.merge(node.getTextRegionWithLineInformation());
        }
        LocationData _locationData = new LocationData(documentationTrace, null);
        appendable.trace(_locationData).append(doc.toString());
        _xblockexpression_1 = appendable.newLine();
      }
      _xifexpression = _xblockexpression_1;
    } else {
      _xifexpression = appendable.append(doc.toString()).newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 4
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 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: DefaultCallHierarchyBuilder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getText(EObject obj, ITextRegionWithLineInformation textRegion) {
	if (obj == null || textRegion == ITextRegionWithLineInformation.EMPTY_REGION) {
		return "";
	}
	ICompositeNode node = NodeModelUtils.getNode(EcoreUtil.getRootContainer(obj));
	if (node == null) {
		return "";
	}
	int endOffset = textRegion.getOffset() + textRegion.getLength();
	return node.getRootNode().getText().substring(textRegion.getOffset(), endOffset);
}
 
Example 7
Source File: DefaultHierarchyNodeLocationProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITextRegionWithLineInformation getTextRegion(EObject obj) {
	if (obj == null) {
		return ITextRegionWithLineInformation.EMPTY_REGION;
	}
	ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(obj);
	return toTextRegionWithLineInformation(obj, textRegion);
}
 
Example 8
Source File: DefaultHierarchyNodeLocationProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITextRegionWithLineInformation getTextRegion(EObject owner, EStructuralFeature feature, int indexInList) {
	if (owner == null) {
		return ITextRegionWithLineInformation.EMPTY_REGION;
	}
	ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList);
	return toTextRegionWithLineInformation(owner, textRegion);
}