use of org.eclipse.xtext.util.ReplaceRegion in project xtext-core by eclipse.
the class TokenRegionProvider method getTokenReplaceRegion.
public ReplaceRegion getTokenReplaceRegion(String changedText, ReplaceRegion replaceRegion) {
int lengthDelta = replaceRegion.getText().length() - replaceRegion.getLength();
ITextRegion tokenRegion = getTokenRegion(changedText, new TextRegion(replaceRegion.getOffset(), replaceRegion.getText().length()));
if (tokenRegion.getOffset() == replaceRegion.getOffset() && tokenRegion.getLength() == replaceRegion.getText().length())
return replaceRegion;
else
return new ReplaceRegion(tokenRegion.getOffset(), tokenRegion.getLength() - lengthDelta, changedText.substring(tokenRegion.getOffset(), tokenRegion.getOffset() + tokenRegion.getLength()));
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-core by eclipse.
the class DeltaScenarioProcessor method applyDelta.
protected String applyDelta(String data, int offset, int len, String change) {
StringBuilder builder = new StringBuilder(data);
new ReplaceRegion(offset, len, change).applyTo(builder);
String result = builder.toString();
return result;
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-core by eclipse.
the class ContentAssistService method toCompletionItem.
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) {
CompletionItem completionItem = new CompletionItem();
String label = entry.getLabel();
if (label == null) {
label = entry.getProposal();
}
completionItem.setLabel(label);
completionItem.setDetail(entry.getDescription());
completionItem.setDocumentation(entry.getDocumentation());
String prefix = entry.getPrefix();
if (prefix == null) {
prefix = "";
}
int prefixOffset = caretOffset - prefix.length();
Position prefixPosition = document.getPosition(prefixOffset);
completionItem.setTextEdit(Either.forLeft(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())));
completionItem.setKind(translateKind(entry));
if (!entry.getTextReplacements().isEmpty()) {
if (completionItem.getAdditionalTextEdits() == null) {
completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size()));
}
entry.getTextReplacements().forEach((ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document)));
}
if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) {
completionItem.setInsertTextFormat(InsertTextFormat.Snippet);
}
return completionItem;
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class PartialParserBenchmark method doTime.
public int doTime(IParser parser, int windowSize) {
int result = 0;
for (int j = 0; j < contentToParse.length() - windowSize; j++) {
ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(j, windowSize), contentToParse.substring(j, j + windowSize));
IParseResult newParseResult = parser.reparse(parseResult, replaceRegion);
if (newParseResult.getRootASTElement() != null) {
result++;
}
}
return result;
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class PartialParsingProcessor method processFile.
@Override
public String processFile(String completeData, String data, int offset, int len, String change) throws Exception {
IParseResult initialParseResult = parser.parse(new StringReader(data));
String newData = applyDelta(data, offset, len, change);
ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change);
try {
IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion);
IParseResult parsedFromScratch = parser.parse(new StringReader(newData));
assertEqual(data, newData, parsedFromScratch, reparsed);
return newData;
} catch (Throwable e) {
ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data);
throwMe.initCause(e);
throw throwMe;
}
}
Aggregations