Java Code Examples for org.eclipse.xtext.util.ReplaceRegion#getEndOffset()

The following examples show how to use org.eclipse.xtext.util.ReplaceRegion#getEndOffset() . 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: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private boolean isRangePartOfExceedingLookAhead(CompositeNode node, ReplaceRegion replaceRegion) {
	TreeIterator<AbstractNode> iterator = node.basicIterator();
	int lookAhead = node.getLookAhead();
	if (lookAhead == 0) {
		return false;
	}
	while(iterator.hasNext()) {
		AbstractNode child = iterator.next();
		if (child instanceof CompositeNode) {
			if (child.getTotalOffset() < replaceRegion.getEndOffset())
				lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead);
		} else if (!((ILeafNode) child).isHidden()) {
			lookAhead--;
			if (lookAhead == 0) {
				if (child.getTotalOffset() >= replaceRegion.getEndOffset())
					return false;
			}
		}
	}
	return lookAhead > 0;
}
 
Example 2
Source File: FixedPartialParsingHelper.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isRangePartOfExceedingLookAhead(final CompositeNode node, final ReplaceRegion replaceRegion) {
  TreeIterator<AbstractNode> iterator = node.basicIterator();
  int lookAhead = node.getLookAhead();
  if (lookAhead == 0) {
    return false;
  }
  while (iterator.hasNext()) {
    AbstractNode child = iterator.next();
    if (child instanceof CompositeNode) {
      if (child.getTotalOffset() < replaceRegion.getEndOffset()) {
        lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead);
      }
    } else if (!((ILeafNode) child).isHidden()) {
      lookAhead--;
      if (lookAhead == 0) {
        if (child.getTotalOffset() >= replaceRegion.getEndOffset()) {
          return false;
        }
      }
    }
  }
  return lookAhead > 0;
}
 
Example 3
Source File: ReplaceConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public int getReplaceLengthDelta(List<ReplaceRegion> changes, int caretPosition) {
	int delta = 0;
	if(changes != null && !changes.isEmpty()) {
		for(ReplaceRegion change: changes) {
			if(change.getEndOffset() < caretPosition)
				delta += change.getText().length() - change.getLength();
		}
	}
	return delta;
}
 
Example 4
Source File: MultiLineJavaDocTypeReferenceProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public EObjectInComment computeEObjectReferencedInComment(XtextResource resource, int offset) {
	IParseResult parseResult = resource.getParseResult();
	if(parseResult != null) {
		INode rootNode = parseResult.getRootNode();
		INode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
		EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
		if(semanticObject != null) {
			EReference reference = getEReference(semanticObject, node, offset);
			if(reference != null) {
				IScope scope = getScope(semanticObject, reference, node, offset);
				List<ReplaceRegion> eObjectReferences = computeTypeRefRegions(node);
				for(ReplaceRegion eObjectReference : eObjectReferences) {
					if(eObjectReference.getOffset() <= offset && offset <= eObjectReference.getEndOffset()) {
						String eObjectReferenceText = eObjectReference.getText();
						if(!Strings.isNullOrEmpty(eObjectReferenceText)) {
							ITextRegion region = new TextRegion(eObjectReference.getOffset(), eObjectReference.getLength());
							IEObjectDescription candidate = getElementFromScope(scope, node, region, eObjectReferenceText);
							if(candidate != null) {
								EObject eObject = candidate.getEObjectOrProxy();
								if(eObject != null) {
									return new EObjectInComment(eObject, region);
								}
							}
						}
					}
				}
			}
		}
	}
	return null;
}